2010-04-21 23:08:34 +02:00
|
|
|
if (typeof window.Sign == 'undefined') {
|
|
|
|
window.Sign = {
|
|
|
|
window_position: function() {
|
|
|
|
var position = {};
|
|
|
|
|
|
|
|
if (typeof(window.innerWidth) == 'number') {
|
|
|
|
// Non-IE
|
2010-05-05 02:26:26 +02:00
|
|
|
position.width = window.outerWidth;
|
|
|
|
position.height = window.outerHeight;
|
|
|
|
position.top = window.screenY;
|
|
|
|
position.left = window.screenX;
|
2010-04-21 23:08:34 +02:00
|
|
|
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
|
|
|
|
// IE 6+ in 'standards compliant mode'
|
2010-05-05 02:26:26 +02:00
|
|
|
position.width = document.body.clientWidth;
|
|
|
|
position.height = document.body.clientHeight;
|
|
|
|
position.top = window.screenTop;
|
|
|
|
position.left = window.screenLeft;
|
2010-04-21 23:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return position;
|
|
|
|
},
|
|
|
|
|
|
|
|
popup : function(url, width, height, windowname) {
|
|
|
|
width = width || 700;
|
|
|
|
height = height || 500;
|
|
|
|
|
|
|
|
var pos = window.Sign.window_position();
|
2010-05-05 02:26:26 +02:00
|
|
|
var left = Math.floor((pos.width - width) / 2) + pos.left;
|
|
|
|
var top = Math.floor((pos.height - height) / 2) + pos.top;
|
2010-04-21 23:08:34 +02:00
|
|
|
|
|
|
|
// Chrome might fix this bug, but until then add some padding
|
|
|
|
// to the height of the popup for the urlbar
|
|
|
|
var is_chrome = /chrome/.test(navigator.userAgent.toLowerCase());
|
|
|
|
if (is_chrome) {
|
|
|
|
height += 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
top: top,
|
|
|
|
left: left,
|
|
|
|
directories: 'no',
|
|
|
|
location: 'no',
|
|
|
|
menubar: 'no',
|
|
|
|
resizable: 'no',
|
|
|
|
scrollbars: 'yes',
|
|
|
|
status: 'no',
|
|
|
|
toolbar: 'no'
|
|
|
|
};
|
|
|
|
|
|
|
|
var params_list = [];
|
|
|
|
for (var key in params) {
|
2010-05-05 02:26:26 +02:00
|
|
|
if (params.hasOwnProperty(key)) {
|
|
|
|
params_list.push(key + "=" + params[key]);
|
|
|
|
}
|
2010-04-21 23:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return window.open(url, windowname || "", params_list.join(","));
|
|
|
|
},
|
2010-04-23 10:25:52 +02:00
|
|
|
|
2010-04-21 23:08:34 +02:00
|
|
|
signintize : function(cont) {
|
|
|
|
$('.signedin').show();
|
|
|
|
$('.signedout').hide();
|
|
|
|
if (window.user) {
|
|
|
|
$('.user').html('<a href="http://freebase.com/view' + window.user.id + '">' + window.user.username + '</a>');
|
|
|
|
}
|
|
|
|
if (typeof cont == 'function') cont();
|
|
|
|
},
|
|
|
|
|
|
|
|
signin : function(success, provider, width, height) {
|
2010-04-23 10:25:52 +02:00
|
|
|
var newwin = window.Sign.popup("/command/authorize/" + provider, width, height);
|
2010-04-21 23:08:34 +02:00
|
|
|
|
2010-04-23 10:25:52 +02:00
|
|
|
if (newwin !== null) {
|
|
|
|
newwin.opener = window;
|
|
|
|
}
|
2010-04-21 23:08:34 +02:00
|
|
|
|
|
|
|
window.onauthorization = function() {
|
|
|
|
if (typeof success == 'undefined') {
|
|
|
|
window.location.reload();
|
|
|
|
} else {
|
|
|
|
$.ajax({
|
2010-04-23 10:25:52 +02:00
|
|
|
url: "/command/check-authorization/" + provider,
|
2010-04-21 23:08:34 +02:00
|
|
|
dataType: "json",
|
|
|
|
success: function(data) {
|
|
|
|
window.user = data;
|
|
|
|
window.Sign.signintize(success);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-04-23 10:25:52 +02:00
|
|
|
if (window.focus && newwin !== null) {
|
2010-04-21 23:08:34 +02:00
|
|
|
newwin.focus();
|
|
|
|
}
|
2010-04-23 10:25:52 +02:00
|
|
|
|
2010-04-21 23:08:34 +02:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
signoutize : function(cont) {
|
|
|
|
$('.signedin').hide();
|
|
|
|
$('.signedout').show();
|
|
|
|
if (typeof cont == 'function') cont();
|
|
|
|
},
|
|
|
|
|
|
|
|
signout : function(success,provider) {
|
|
|
|
$.ajax({
|
2010-04-23 10:25:52 +02:00
|
|
|
url: "/command/deauthorize/" + provider,
|
2010-04-21 23:08:34 +02:00
|
|
|
success: function() {
|
|
|
|
if (typeof success == 'undefined') {
|
|
|
|
window.location.reload();
|
|
|
|
} else {
|
|
|
|
window.Sign.signoutize(success);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|