root / snf-astakos-app / astakos / im / static / im / cloudbar / cloudbar.js @ 36dacb92
History | View | Annotate | Download (6.4 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 USER_DATA = window.CLOUDBAR_USER_DATA || {'user': 'Not logged in', 'logged_in': false}; |
21 |
var COOKIE_NAME = window.CLOUDBAR_COOKIE_NAME || '_pithos2_a'; |
22 |
|
23 |
var cssloc = window.CLOUDBAR_LOCATION || "http://127.0.0.1:8989/"; |
24 |
|
25 |
// load css
|
26 |
var css = $("<link />"); |
27 |
css.attr({rel:'stylesheet', type:'text/css', href:cssloc + 'cloudbar.css'}); |
28 |
$("head").append(css); |
29 |
|
30 |
// load fonts
|
31 |
var font_url = 'https://fonts.googleapis.com/css?family=Open+Sans:400,600,700&subset=latin,greek-ext,greek'; |
32 |
var css_font = $("<link />"); |
33 |
css_font.attr({rel:'stylesheet', type:'text/css', href:font_url}); |
34 |
$("head").append(css_font); |
35 |
|
36 |
// load service specific css
|
37 |
var SKIP_ADDITIONAL_CSS = window.SKIP_ADDITIONAL_CSS == undefined ? false : window.SKIP_ADDITIONAL_CSS; |
38 |
|
39 |
if (!SKIP_ADDITIONAL_CSS) {
|
40 |
var css = $("<link />"); |
41 |
$("head").append(css); |
42 |
} |
43 |
|
44 |
var root = $('body'); |
45 |
var bar = $('<div class="cloudbar servicesbar clearfix"></div>'); |
46 |
var services = $('<ul class="services"></ul>'); |
47 |
var profile = $('<div class="profile"></div>'); |
48 |
|
49 |
var get_services_url = window.GET_SERVICES_URL || window.CLOUDBAR_SERVICES;
|
50 |
|
51 |
// create services links and set the active class to the current service
|
52 |
$.getJSON(get_services_url + "?callback=?", function(data) { |
53 |
var active_found = false; |
54 |
$.each(data, function(i, el){ |
55 |
var sli = $("<li class='service-"+el.name+"'>"); |
56 |
var slink = $("<a>"); |
57 |
if (!el.cloudbar) { el.cloudbar = {} }
|
58 |
var title = el.cloudbar.name || el.verbose_name || el.name;
|
59 |
if (!el.cloudbar.show) { return } |
60 |
if (el.cloudbar.icon) {
|
61 |
var iconloc = el.cloudbar.icon;
|
62 |
if (el.cloudbar.icon.substring(0, 4) != 'http') { |
63 |
iconloc = cssloc + el.cloudbar.icon; |
64 |
} |
65 |
slink.append($('<img alt="'+title+'" src="'+iconloc+'"/>')); |
66 |
slink.addClass("with-icon");
|
67 |
} else {
|
68 |
slink.html(title); |
69 |
} |
70 |
slink.attr('href', el.url);
|
71 |
slink.attr('title', el.name);
|
72 |
sli.append(slink); |
73 |
services.append(sli); |
74 |
var urlReg = new RegExp('^'+el.url+'.*'); |
75 |
if (urlReg.test(window.location.toString())) {
|
76 |
active_found = true;
|
77 |
sli.addClass("active");
|
78 |
} |
79 |
}); |
80 |
// no active service found, activate accounts
|
81 |
if (!active_found) {
|
82 |
$('.cloudbar .user').addClass("hover active"); |
83 |
} |
84 |
}); |
85 |
|
86 |
// create profile links
|
87 |
var user = $('<div class="user"></div>'); |
88 |
var username = $('<a href="#"></a>'); |
89 |
var usermenu = $("<ul>"); |
90 |
var get_menu_url = (window.GET_MENU_URL || window.CLOUDBAR_MENU) + '?callback=?&location=' + window.location.toString().split("?")[0]; |
91 |
|
92 |
$.getJSON(get_menu_url, function(data) { |
93 |
$.each(data, function(i,el) { |
94 |
if (i == 0){ |
95 |
username.html('<span>'+el.name+'</span>'); |
96 |
username.attr('href', el.url);
|
97 |
user.removeClass('full');
|
98 |
$('body').addClass('user-not-authenticated'); |
99 |
}else{
|
100 |
var link = $("<a />"); |
101 |
link.text(el.name); |
102 |
link.attr({href:el.url});
|
103 |
var li = $("<li />"); |
104 |
li.append(link); |
105 |
usermenu.append(li); |
106 |
user.addClass('full');
|
107 |
$('body').removeClass('user-not-authenticated'); |
108 |
} |
109 |
}); |
110 |
|
111 |
}); |
112 |
|
113 |
//profile.filter(".user a").attr("href",
|
114 |
//profile.find("li a").get(0).attr("href"))
|
115 |
|
116 |
user.append(username); |
117 |
user.append(usermenu); |
118 |
profile.append(user); |
119 |
bar.append(profile).append(services); |
120 |
|
121 |
|
122 |
root.css('border-top', 'none'); |
123 |
root.prepend(bar); |
124 |
var firstlink = profile.find("ul li:first-child a").attr("href"); |
125 |
profile.find(".user > a").attr("href", firstlink); |
126 |
|
127 |
|
128 |
// ie fix
|
129 |
user.hover( |
130 |
function(){
|
131 |
equalWidths ( $('.cloudbar .profile ul'), $('.cloudbar .profile')); |
132 |
$(this).addClass("hover")}, |
133 |
function(){
|
134 |
$(this).removeClass("hover") |
135 |
} |
136 |
); |
137 |
|
138 |
equalWidths ( $('.cloudbar .profile ul'), $('.cloudbar .profile')); |
139 |
|
140 |
$('.cloudbar .profile .full>a').live('focus', function(e){ |
141 |
console.info('i just focused');
|
142 |
e.preventDefault(); |
143 |
equalWidths ( $('.cloudbar .profile ul'), $('.cloudbar .profile')); |
144 |
$(this).siblings('ul').show(); |
145 |
$(this).addClass('open'); |
146 |
}) ; |
147 |
|
148 |
$('.cloudbar .profile .full>a').live('click', function(e){ |
149 |
e.preventDefault(); |
150 |
}); |
151 |
|
152 |
$('.cloudbar .profile ul li:last a').live('focusout', function(e){ |
153 |
console.info('i just focused out in style');
|
154 |
$(this).parents('ul').attr('style', ''); |
155 |
$(this).parents('ul').removeAttr('style'); |
156 |
equalWidths ( $('.cloudbar .profile ul'), $('.cloudbar .profile')); |
157 |
$(this).parents('ul').siblings('a').removeClass('open'); |
158 |
}); |
159 |
|
160 |
}); |
161 |
|
162 |
$(window).resize(function() { |
163 |
equalWidths ( $('.cloudbar .profile ul'), $('.cloudbar .profile')); |
164 |
}); |