Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / static / im / cloudbar / cloudbar.js @ 904fd3cd

History | View | Annotate | Download (6.2 kB)

1
function equalWidths ( secondEl, firstEl) {
2
        secondEl.css('width',firstEl.outerWidth() );
3
}
4

    
5

    
6

    
7
$(document).ready(function(){
8
    
9
    /*
10
    * LINKS CONFIGURATION
11
    */
12

    
13
    var PROFILE_URL = "https://accounts.cloud.grnet.gr";
14

    
15
    // cookie plugin https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js 
16
    //  * Copyright (c) 2010 Klaus Hartl, @carhartl
17
    //  * Dual licensed under the MIT and GPL licenses
18
    var cookie=function(key,value,options){if(arguments.length>1&&(!/Object/.test(Object.prototype.toString.call(value))||value===null||value===undefined)){options=$.extend({},options);if(value===null||value===undefined){options.expires=-1}if(typeof options.expires==='number'){var days=options.expires,t=options.expires=new Date();t.setDate(t.getDate()+days)}value=String(value);return(document.cookie=[encodeURIComponent(key),'=',options.raw?value:encodeURIComponent(value),options.expires?'; expires='+options.expires.toUTCString():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''))}options=value||{};var decode=options.raw?function(s){return s}:decodeURIComponent;var pairs=document.cookie.split('; ');for(var i=0,pair;pair=pairs[i]&&pairs[i].split('=');i++){if(decode(pair[0])===key)return decode(pair[1]||'')}return null};
19

    
20
    var ACTIVE_MENU = window.CLOUDBAR_ACTIVE_SERVICE || 'cloud';
21
    var USER_DATA = window.CLOUDBAR_USER_DATA || {'user': 'Not logged in', 'logged_in': false};
22
    var COOKIE_NAME = window.CLOUDBAR_COOKIE_NAME || '_pithos2_a';
23

    
24
    var cssloc = window.CLOUDBAR_LOCATION || "http://127.0.0.1:8989/";
25
    
26
    // load css
27
    var css = $("<link />");
28
    css.attr({rel:'stylesheet', type:'text/css', href:cssloc + 'cloudbar.css'});
29
    $("head").append(css);
30
    
31
    // load fonts
32
    var font_url = 'https://fonts.googleapis.com/css?family=Open+Sans:400,600,700&subset=latin,greek-ext,greek';
33
    var css_font = $("<link />");
34
    css_font.attr({rel:'stylesheet', type:'text/css', href:font_url});
35
    $("head").append(css_font);
36

    
37
    // load service specific css
38
    var SKIP_ADDITIONAL_CSS = window.SKIP_ADDITIONAL_CSS == undefined ? false : window.SKIP_ADDITIONAL_CSS;
39

    
40
    if (!SKIP_ADDITIONAL_CSS) {
41
        var css = $("<link />");
42
        css.attr({rel:'stylesheet', type:'text/css', href:cssloc + 'service_' + ACTIVE_MENU + '.css'});
43
        $("head").append(css);
44
    }
45

    
46
    var root = $('body');
47
    var bar = $('<div class="cloudbar servicesbar clearfix"></div>');
48
    var services = $('<ul class="services"></ul>');
49
    var profile = $('<div class="profile"></div>');
50
    
51
    var get_services_url = window.GET_SERVICES_URL || window.CLOUDBAR_SERVICES;
52
    
53
    // create services links and set the active class to the current service
54
    $.getJSON(get_services_url + "?callback=?", function(data) {
55
            $.each(data, function(i, el){
56
            var sli = $("<li class='service-"+el.name+"'>");
57
            var slink = $("<a>");
58
            if (!el.cloudbar) { el.cloudbar = {} }
59
            var title = el.cloudbar.name || el.verbose_name || el.name;
60
            if (!el.cloudbar.show) { return }
61
            if (el.cloudbar.icon) {
62
                var iconloc = el.cloudbar.icon;
63
                if (el.cloudbar.icon.substring(0, 4) != 'http') {
64
                  iconloc = cssloc + el.cloudbar.icon;
65
                }
66
                slink.append($('<img alt="'+title+'" src="'+iconloc+'"/>'));
67
                slink.addClass("with-icon");
68
            } else {
69
                slink.html(title);
70
            }
71
            slink.attr('href', el.url);
72
            slink.attr('title', el.name);
73
            sli.append(slink);
74
            services.append(sli);
75
            if (el.id == ACTIVE_MENU || el.name == ACTIVE_MENU) {
76
                sli.addClass("active");
77
            }
78
        });
79
      });
80
    
81
    // create profile links
82
    var user = $('<div class="user"></div>');    
83
    if (ACTIVE_MENU == "accounts") { user.addClass("hover active")}
84
    var username = $('<a href="#"></a>');
85
    var usermenu = $("<ul>");
86
    var get_menu_url = (window.GET_MENU_URL || window.CLOUDBAR_MENU) + '?callback=?&location=' + window.location.toString().split("?")[0];
87

    
88
    $.getJSON(get_menu_url, function(data) {
89
        $.each(data, function(i,el) {
90
            if (i == 0){
91
                username.html('<span>'+el.name+'</span>');
92
                username.attr('href', el.url);
93
                user.removeClass('full');
94
            }else{
95
                var link = $("<a />");
96
                link.text(el.name);
97
                link.attr({href:el.url});
98
                var li = $("<li />");
99
                li.append(link);
100
                usermenu.append(li);
101
                user.addClass('full');
102
            }
103
        });
104
    
105
    });
106
    
107
    //profile.filter(".user a").attr("href", 
108
                                   //profile.find("li a").get(0).attr("href"))
109
    
110
    user.append(username);
111
    user.append(usermenu);
112
    profile.append(user);
113
    bar.append(profile).append(services);
114
    
115

    
116
    root.css('border-top', 'none');
117
    root.prepend(bar);
118
    var firstlink = profile.find("ul li:first-child a").attr("href");
119
    profile.find(".user > a").attr("href", firstlink);
120

    
121
 
122
    // ie fix
123
    user.hover(
124
            function(){
125
                    equalWidths ( $('.cloudbar .profile ul'), $('.cloudbar .profile'));
126
                    $(this).addClass("hover")}, 
127
            function(){
128
                    $(this).removeClass("hover")
129
                    }
130
            );
131
     
132
    equalWidths ( $('.cloudbar .profile ul'), $('.cloudbar .profile'));
133
     
134
        $('.cloudbar .profile .full>a').live('focus', function(e){
135
                console.info('i just focused');
136
                e.preventDefault();
137
        equalWidths ( $('.cloudbar .profile ul'), $('.cloudbar .profile'));
138
                   $(this).siblings('ul').show();
139
                   $(this).addClass('open');
140
        })        ;
141
         
142
        $('.cloudbar .profile .full>a').live('click', function(e){
143
                e.preventDefault();
144
        }); 
145
 
146
         $('.cloudbar .profile ul li:last a').live('focusout', function(e){        
147
                 console.info('i just focused out in style');
148
                 $(this).parents('ul').attr('style', '');
149
                 $(this).parents('ul').removeAttr('style');
150
                 equalWidths ( $('.cloudbar .profile ul'), $('.cloudbar .profile'));
151
                 $(this).parents('ul').siblings('a').removeClass('open');
152
         });
153
    
154
});
155

    
156
$(window).resize(function() {
157
        equalWidths ( $('.cloudbar .profile ul'), $('.cloudbar .profile'));
158
});