1 $(document).ready(function(){
7 var PROFILE_URL = "https://accounts.cloud.grnet.gr";
9 // cookie plugin https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js
10 // * Copyright (c) 2010 Klaus Hartl, @carhartl
11 // * Dual licensed under the MIT and GPL licenses
12 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};
14 var ACTIVE_MENU = window.CLOUDBAR_ACTIVE_SERVICE || 'cloud';
15 var USER_DATA = window.CLOUDBAR_USER_DATA || {'user': 'Not logged in', 'logged_in': false};
16 var COOKIE_NAME = window.CLOUDBAR_COOKIE_NAME || '_pithos2_a';
18 var cssloc = window.CLOUDBAR_LOCATION || "http://127.0.0.1:8989/";
21 var css = $("<link />");
22 css.attr({rel:'stylesheet', type:'text/css', href:cssloc + 'cloudbar.css'});
23 $("head").append(css);
25 // load service specific css
26 var SKIP_ADDITIONAL_CSS = window.SKIP_ADDITIONAL_CSS == undefined ? false : window.SKIP_ADDITIONAL_CSS;
28 if (!SKIP_ADDITIONAL_CSS) {
29 var css = $("<link />");
30 css.attr({rel:'stylesheet', type:'text/css', href:cssloc + 'service_' + ACTIVE_MENU + '.css'});
31 $("head").append(css);
35 var bar = $('<div class="cloudbar clearfix"></div>');
36 var services = $('<ul class="services"></ul>');
37 var profile = $('<div class="profile"></div>');
39 var get_services_url = window.GET_SERVICES_URL || window.CLOUDBAR_SERVICES;
41 // create services links and set the active class to the current service
42 $.getJSON(get_services_url + "?callback=?", function(data) {
43 $.each(data, function(i, el){
47 slink.append($('<img src="'+cssloc+el.icon+'"/>'));
48 slink.addClass("with-icon");
52 slink.attr('href', el.url);
53 slink.attr('title', el.name);
56 if (el.id == ACTIVE_MENU || el.name == ACTIVE_MENU) {
57 sli.addClass("active");
62 // create profile links
63 var user = $('<div class="user"></div>');
64 if (ACTIVE_MENU == "accounts") { user.addClass("hover active")}
65 var username = $('<a href="#"></a>');
66 var usermenu = $("<ul>");
67 var get_menu_url = (window.GET_MENU_URL || window.CLOUDBAR_MENU) + '?callback=?&location=' + window.location.toString();
69 $.getJSON(get_menu_url, function(data) {
70 $.each(data, function(i,el) {
72 username.html('<span>'+el.name+'</span>');
73 username.attr('href', el.url);
74 user.removeClass('full');
76 var link = $("<a />");
78 link.attr({href:el.url});
82 user.addClass('full');
87 //profile.filter(".user a").attr("href",
88 //profile.find("li a").get(0).attr("href"))
90 user.append(username);
91 user.append(usermenu);
93 bar.append(profile).append(services);
97 var firstlink = profile.find("ul li:first-child a").attr("href");
98 profile.find(".user > a").attr("href", firstlink);
101 user.hover(function(){$(this).addClass("hover")}, function(){$(this).removeClass("hover")});
103 /*$('.cloudbar .profile ul').mouseover(function(){
104 $(this).parents('.profile').css('backgroundColor','#000');
107 $('.cloudbar .profile ul').mouseout(function(){
108 $(this).parents('.profile').css('backgroundColor','#01A1AE');
111 $('.cloudbar .profile .full>a').live('click', function(e){
113 $(this).siblings('ul').toggle();
114 $(this).toggleClass('open');
117 var profileWidth = profile.outerWidth();
118 $('.header .profile ul').css('width',profileWidth );