<div><p> ;(function($, fg) {
window.freegle = fg || {};
fg = window.freegle;
/**
* fg.sprintf("%s foo %s", "hello", "world") == "hello foo world"
*/
fg.sprintf = function(str) {
// this is state used in the replacement closure - starts with the
// first argument after 'str' and advances through all arguments
var argIndex = 1;
var localArgs = arguments;
// this gets called once for each match
function replace() {
return localArgs[argIndex++];
};
var res = str.replace(/%s/g, replace);
return (res);
};
fg.popup = function(url, width, height, windowname) {
width = width || 300;
height = height || 300;
var params = {
width: width,
height: height,
top: (screen.height - height) / 3,
left: (screen.width - width) / 2,
directories: 'no',
location: 'no',
menubar: 'no',
resizable: 'no',
scrollbars: 'yes',
status: 'no',
toolbar: 'no'
};
var params_list = [];
for (var key in params) {
params_list.push(key+"="+params[key]);
}
return window.open(url, windowname || url, params_list.join());
};
fg.oauth_services = {
"freebase": {
"name": "Freebase",
"width": 650,
"height": 550,
"onlogin": function(p) {
if ($.blockUI) {
$.blockUI({"message": "</p><h1>Signing in to Freebase/h1>"});
}
window.location.href = "/login_success";
},
"onlogout": function(p) {
if ($.blockUI) {
$.blockUI({"message": "<h1>Signing out of Freebase</h1>"});
}
window.location.href = "/";
}
}
};
fg.service_login = function(service, width, height, success) {
if (!width && fg.oauth_services[service]) {
width = fg.oauth_services[service].width;
}
if (!height && fg.oauth_services[service]) {
height = fg.oauth_services[service].height;
}
if (!success && fg.oauth_services[service] && fg.oauth_services[service].onlogin) {
success = fg.oauth_services[service].onlogin;
}
if (!success) {
success = function(data) {
if ($.blockUI) {
$.blockUI();
}
window.location.reload();
};
}
var newwin = fg.popup("/authorize/"+service, width, height, service);
if (newwin.opener == null) newwin.opener = self;
window.onauthorization = success;
if (window.focus) {
newwin.focus();
}
return false;
};
fg.service_logout = function(service, success) {
if (!success && fg.oauth_services[service] && fg.oauth_services[service].onlogout) {
success = fg.oauth_services[service].onlogout;
}
if (!success) {
success = function(data) {
if ($.blockUI) {
$.blockUI();
}
window.location.reload();
};
}
$.ajax({
url: "/deauthorize/"+service,
success: success
});
};
}) (jQuery, window.freegle);
</h1></div>