-
Notifications
You must be signed in to change notification settings - Fork 1
/
screenful-user.js
42 lines (42 loc) · 2.46 KB
/
screenful-user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Screenful.User={
start: function(){
if(Screenful.User.loggedin){
$(".ScreenfulUser").html("<div class='clickable'><span class='bigscreen'>"+Screenful.User.username+"</span><span class='smallscreen'>@</span> <span class='arrow'>▼</span></div><div class='menu' style='display: none'></div>");
if(Screenful.User.homeUrl) $(".ScreenfulUser .menu").append("<a href='"+Screenful.User.homeUrl+"'>"+Screenful.Loc.home+"</a>");
if(Screenful.User.logoutUrl) $(".ScreenfulUser .menu").append("<a href='"+Screenful.User.logoutUrl+"'>"+Screenful.Loc.logout+"</a>");
if(Screenful.User.changePwdUrl) $(".ScreenfulUser .menu").append("<a href='"+Screenful.User.changePwdUrl+"'>"+Screenful.Loc.changePwd+"</a>");
} else if(Screenful.User.verifyLoginUrl) {
Screenful.User.verifyLogin();
} else {
$(".ScreenfulUser").html("<div class='clickable'><span class='bigscreen'>"+Screenful.Loc.anonymous+"</span><span class='smallscreen'>@</span> <span class='arrow'>▼</span></div><div class='menu' style='display: none'></div>");
if(Screenful.User.homeUrl) $(".ScreenfulUser .menu").append("<a href='"+Screenful.User.homeUrl+"'>"+Screenful.Loc.home+"</a>");
if(Screenful.User.loginUrl) $(".ScreenfulUser .menu").append("<a href='"+Screenful.User.loginUrl+"'>"+Screenful.Loc.login+"</a>");
if(Screenful.User.signupUrl) $(".ScreenfulUser .menu").append("<a href='"+Screenful.User.signupUrl+"'>"+Screenful.Loc.signup+"</a>");
if(Screenful.User.forgotPwdUrl) $(".ScreenfulUser .menu").append("<a href='"+Screenful.User.forgotPwdUrl+"'>"+Screenful.Loc.forgotPwd+"</a>");
}
$(".ScreenfulUser .clickable").on("click", function(e){
var $mymenu=$(e.delegateTarget).closest(".ScreenfulUser").find(".menu");
$(".menu:visible").not($mymenu).slideUp();
$mymenu.hide().slideDown();
e.stopPropagation();
});
$(document).on("click", function(e){
$(".menu:visible").not("#xonomyBubble .menu").slideUp();
});
},
verifyLogin: function(){
$.ajax({url: Screenful.User.verifyLoginUrl, dataType: "json", method: "POST", data: {}}).done(function(data){
if(data.success){
Screenful.User.loggedin=true;
Screenful.User.username=data.username;
Screenful.User.userData=data;
} else {
Screenful.User.loggedin=false;
window.location=Screenful.User.loginUrl;
}
Screenful.User.verifyLoginUrl="";
Screenful.User.start();
});
}
};
$(window).ready(Screenful.User.start);