Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 43 additions & 21 deletions src/jquery.oauthpopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,47 @@
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($){
// inspired by DISQUS
$.oauthpopup = function(options)
{
if (!options || !options.path) {
throw new Error("options.path must not be empty");
}
options = $.extend({
windowName: 'ConnectWithOAuth' // should not include space for IE
, windowOptions: 'location=0,status=0,width=800,height=400'
, callback: function(){ window.location.reload(); }
}, options);

var oauthWindow = window.open(options.path, options.windowName, options.windowOptions);
var oauthInterval = window.setInterval(function(){
if (oauthWindow.closed) {
window.clearInterval(oauthInterval);
options.callback();
(function(factory) {
// Support three module loading scenarios
if (typeof define === 'function' && define['amd']) {
// AMD anonymous module
define(['jquery'], factory);
} else {
// No module loader (plain <script> tag) - put directly in global namespace
factory(jQuery);
}
})(function($){
(function($,window){
// inspired by DISQUS
$.oauthpopup = function(options)
{
if (!options || !options.path) {
throw new Error("options.path must not be empty");
}
}, 1000);
};
})(jQuery);
options = $.extend({
windowName: 'ConnectWithOAuth' // should not include space for IE
, windowOptions: 'location=0,status=0,width=800,height=400'
, callback: function(){ window.location.reload(); }
}, options);

var oauthWindow = window.open(options.path, options.windowName, options.windowOptions),
oauthInterval = 0;
oauthCallback = function() {
if (oauthInterval > 0) {
window.clearInterval(oauthInterval);
}
if (!oauthWindow.closed) {
oauthWindow.close();
}
//pass all arguments to callback
options.callback.apply(null, arguments);
window.oauthCallback = null;
};
oauthInterval = setInterval(function(){
if (oauthWindow.closed) {
callback();
}
}, 1000);
};
})($,window)
});