~dpm/help-app/web-layout

« back to all changes in this revision

Viewing changes to edit-here/themes/web/static/js/global.js

  • Committer: Daniel Holbach
  • Date: 2015-02-26 16:40:24 UTC
  • mfrom: (56.2.4 help.1425984)
  • Revision ID: daniel.holbach@canonical.com-20150226164024-q1wuukaazskmmerh
mergedĀ lp:~dholbach/ubuntu-devices-help/1425984

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
var ai = [{ url: "http://www.ubuntu.com", title:"Ubuntu" },
 
3
{ url: "http://community.ubuntu.com/", title:"Community" },
 
4
{ url: "http://askubuntu.com", title:"Ask!" },
 
5
{ url: "http://developer.ubuntu.com", title:"Developer" },
 
6
{ url: "https://design.ubuntu.com", title:"Design" },
 
7
{ url: "http://discourse.ubuntu.com", title:"Discourse" },
 
8
{ url: "http://www.ubuntu.com/certification", title:"Hardware" },
 
9
{ url: "https://insights.ubuntu.com", title:"Insights" },
 
10
{ url: "https://jujucharms.com", title:"Juju" },
 
11
{ url: "http://partners.ubuntu.com", title:"Partners" },
 
12
{ url: "http://shop.ubuntu.com", title:"Shop" }];
 
13
 
 
14
var more = [{ url: "http://apps.ubuntu.com", title:"Apps" },
 
15
{ url: "https://help.ubuntu.com", title:"Help" },
 
16
{ url: "http://ubuntuforums.org", title:"Forum" },
 
17
{ url: "http://www.launchpad.net", title:"Launchpad" },
 
18
{ url: "http://maas.ubuntu.com", title:"MAAS" },
 
19
{ url: "http://www.canonical.com", title:"Canonical" }];
 
20
 
 
21
 
 
22
if(!core){ var core = {}; }
 
23
 
 
24
core.setupGlobalNav = function () {
 
25
        core.deployNav(core.getNav());
 
26
        core.trackClicks();
 
27
};
 
28
 
 
29
core.getNav = function() {
 
30
        var begin = '<nav role="navigation" id="nav-global"><div class="nav-global-wrapper"><ul>';
 
31
        var end = '</ul></div></nav>';
 
32
        var mu = '';
 
33
        var i = 0;
 
34
        while(i < ai.length) {
 
35
                mu += '<li><a href="' + ai[i].url + '" ' + core.getActive(ai[i].url) + '>' + ai[i].title + '</a></li>';
 
36
                i++;
 
37
        }
 
38
        i = 0;
 
39
        if(more.length > 0) {
 
40
                mu += '<li class="more"><a href="#">More <span>&rsaquo;</span></a><ul>';
 
41
                while(i < more.length) { mu += '<li><a href="'+ more[i].url +'">' + more[i].title + '</a></li>'; i++; }
 
42
                mu += '</ul>';
 
43
        }
 
44
        return begin + mu + end;
 
45
};
 
46
core.deployNav = function(mu) {
 
47
        var gI = 'body';
 
48
        if(core.globalPrepend) {
 
49
                gI = core.globalPrepend;
 
50
        }
 
51
        YUI().use('node', function(Y) {
 
52
                Y.one(gI).prepend(mu);
 
53
                var ml = Y.one('#nav-global .more');
 
54
                if(ml){
 
55
                        ml.on('click',function(e){
 
56
                                e.stopPropagation();
 
57
                                e.preventDefault();
 
58
                                this.toggleClass('open');
 
59
                                return false;
 
60
                        });
 
61
                        ml.one('span').on('click',function(e){
 
62
                                e.preventDefault();
 
63
                                e.stopPropagation();
 
64
                        });
 
65
                        ml.one('ul').on('click',function(e){ e.stopPropagation(); });
 
66
                }
 
67
                Y.one('body').on('click', function(e){
 
68
                        var ml = Y.one('#nav-global .more');
 
69
                        if(ml.hasClass('open')){
 
70
                                ml.removeClass('open');
 
71
                        }
 
72
                });
 
73
        });
 
74
};
 
75
 
 
76
core.getActive = function(link) {
 
77
        var fullurl = core.getURL();
 
78
        var url = fullurl.substr(0,link.length);
 
79
 
 
80
        if(link == 'http://www.ubuntu.com') {
 
81
                if(fullurl.substr(0,35) == 'http://www.ubuntu.com/certification' ){
 
82
                        return '';
 
83
                }
 
84
        }
 
85
        return (url == link)?'class="active"':'';
 
86
};
 
87
 
 
88
 
 
89
core.getURL = function(){
 
90
        var url = document.URL;
 
91
        url = url.replace('https://developer.ubuntu.com','http://developer.ubuntu.com');
 
92
        return url;
 
93
};
 
94
 
 
95
core.trackClicks = function() {
 
96
        YUI().use('node', function(Y) {
 
97
                Y.all('#nav-global a').on('click',function(e) {
 
98
                        e.preventDefault();
 
99
                        try {
 
100
                                _gaq.push(['_trackEvent', 'Global bar click', e.target.get('text'), core.getURL()]);
 
101
                        } catch(err){}
 
102
                        setTimeout(function() {
 
103
                                document.location.href = e.target.get('href');
 
104
                        }, 100);
 
105
                });
 
106
        });
 
107
};
 
108
 
 
109
if(!core.globalPrepend) {
 
110
        core.setupGlobalNav();
 
111
}
 
 
b'\\ No newline at end of file'