root / snf-astakos-app / astakos / im / static / im / cloudbar / cloudbar.js @ 0f4a8a68
History | View | Annotate | Download (4.3 kB)
1 |
$(document).ready(function(){ |
---|---|
2 |
|
3 |
/*
|
4 |
* LINKS CONFIGURATION
|
5 |
*/
|
6 |
|
7 |
var PROFILE_URL = "https://accounts.cloud.grnet.gr"; |
8 |
|
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}; |
13 |
|
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'; |
17 |
|
18 |
var cssloc = window.CLOUDBAR_LOCATION || "http://127.0.0.1:8989/"; |
19 |
|
20 |
// load css
|
21 |
var css = $("<link />"); |
22 |
css.attr({rel:'stylesheet', type:'text/css', href:cssloc + 'cloudbar.css'}); |
23 |
$("head").append(css); |
24 |
|
25 |
// load service specific css
|
26 |
var SKIP_ADDITIONAL_CSS = window.SKIP_ADDITIONAL_CSS == undefined ? false : window.SKIP_ADDITIONAL_CSS; |
27 |
|
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); |
32 |
} |
33 |
|
34 |
var root = $('body'); |
35 |
var bar = $('<div class="header"></div>'); |
36 |
var services = $('<ul class="services"></ul>'); |
37 |
var profile = $('<div class="profile"></div>'); |
38 |
|
39 |
var get_services_url = window.GET_SERVICES_URL || window.CLOUDBAR_SERVICES;
|
40 |
|
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){ |
44 |
var sli = $("<li>"); |
45 |
var slink = $("<a>"); |
46 |
if (el.icon) {
|
47 |
slink.append($('<img src="'+cssloc+el.icon+'"/>')); |
48 |
slink.addClass("with-icon");
|
49 |
} else {
|
50 |
slink.text(el.name); |
51 |
} |
52 |
slink.attr('href', el.url);
|
53 |
slink.attr('title', el.name);
|
54 |
sli.append(slink); |
55 |
services.append(sli); |
56 |
if (el.id == ACTIVE_MENU) {
|
57 |
sli.addClass("active");
|
58 |
} |
59 |
}); |
60 |
}); |
61 |
|
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(); |
68 |
|
69 |
$.getJSON(get_menu_url, function(data) { |
70 |
$.each(data, function(i,el) { |
71 |
if (i == 0){ |
72 |
username.text(el.name); |
73 |
username.attr('href', el.url);
|
74 |
}else{
|
75 |
var link = $("<a />"); |
76 |
link.text(el.name); |
77 |
link.attr({href:el.url});
|
78 |
var li = $("<li />"); |
79 |
li.append(link); |
80 |
usermenu.append(li); |
81 |
} |
82 |
}); |
83 |
}); |
84 |
|
85 |
//profile.filter(".user a").attr("href",
|
86 |
//profile.find("li a").get(0).attr("href"))
|
87 |
|
88 |
user.append(username); |
89 |
user.append(usermenu); |
90 |
profile.append(user); |
91 |
bar.append(profile).append(services); |
92 |
|
93 |
|
94 |
root.prepend(bar); |
95 |
var firstlink = profile.find("ul li:first-child a").attr("href"); |
96 |
profile.find(".user > a").attr("href", firstlink); |
97 |
|
98 |
// ie fix
|
99 |
user.hover(function(){$(this).addClass("hover")}, function(){$(this).removeClass("hover")}); |
100 |
}); |