Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = function(grunt) {
'src/hello.polyfill.js',
'src/hello.js',
'src/hello.chromeapp.js',
'src/hello.phonegap.js',
'src/modules/dropbox.js',
'src/modules/facebook.js',
'src/modules/flickr.js',
Expand Down
108 changes: 11 additions & 97 deletions src/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -1259,102 +1259,6 @@ hello.utils.extend(hello.utils, {
optionsArray.push(name + (value !== null ? '=' + value : ''));
});

// Create a function for reopening the popup, and assigning events to the new popup object
// This is a fix whereby triggering the
var open = function(url) {

// Trigger callback
var popup = window.open(
url,
'_blank',
optionsArray.join(',')
);

// PhoneGap support
// Add an event listener to listen to the change in the popup windows URL
// This must appear before popup.focus();
try {
if (popup && popup.addEventListener) {

// Get the origin of the redirect URI

var a = hello.utils.url(redirectUri);
var redirectUriOrigin = a.origin || (a.protocol + '//' + a.hostname);

// Listen to changes in the InAppBrowser window

popup.addEventListener('loadstart', function(e) {

var url = e.url;

// Is this the path, as given by the redirectUri?
// Check the new URL agains the redirectUriOrigin.
// According to #63 a user could click 'cancel' in some dialog boxes ....
// The popup redirects to another page with the same origin, yet we still wish it to close.

if (url.indexOf(redirectUriOrigin) !== 0) {
return;
}

// Split appart the URL
var a = hello.utils.url(url);

// We dont have window operations on the popup so lets create some
// The location can be augmented in to a location object like so...

var _popup = {
location: {
// Change the location of the popup
assign: function(location) {

// Unfourtunatly an app is may not change the location of a InAppBrowser window.
// So to shim this, just open a new one.

popup.addEventListener('exit', function() {

// For some reason its failing to close the window if a new window opens too soon.

setTimeout(function() {
open(location);
}, 1000);
});
},

search: a.search,
hash: a.hash,
href: a.href
},
close: function() {
if (popup.close) {
popup.close();
}
}
};

// Then this URL contains information which HelloJS must process
// URL string
// Window - any action such as window relocation goes here
// Opener - the parent window which opened this, aka this script

hello.utils.responseHandler(_popup, window);

// Always close the popup regardless of whether the hello.utils.responseHandler detects a state parameter or not in the querystring.
// Such situations might arise such as those in #63

_popup.close();

});
}
}
catch (e) {}

if (popup && popup.focus) {
popup.focus();
}

return popup;
};

// Call the open() function with the initial path
//
// OAuth redirect, fixes URI fragments from being lost in Safari
Expand All @@ -1368,7 +1272,17 @@ hello.utils.extend(hello.utils, {
url = redirectUri + '#oauth_redirect=' + encodeURIComponent(encodeURIComponent(url));
}

return open(url);
var popup = window.open(
url,
'_blank',
optionsArray.join(',')
);

if (popup && popup.focus) {
popup.focus();
}

return popup;
},

// OAuth and API response handler
Expand Down
83 changes: 83 additions & 0 deletions src/hello.phonegap.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,87 @@
hello.utils.iframe = function(url, redirectUri) {
hello.utils.popup(url, redirectUri, {hidden: 'yes'});
};

// Augment the popup
var utilPopup = hello.utils.popup;

// Replace popup
hello.utils.popup = function(url, redirectUri, options) {

// Run the standard
var popup = utilPopup.call(this, url, redirectUri, options);

// Create a function for reopening the popup, and assigning events to the new popup object
// PhoneGap support
// Add an event listener to listen to the change in the popup windows URL
// This must appear before popup.focus();
try {
if (popup && popup.addEventListener) {

// Get the origin of the redirect URI

var a = hello.utils.url(redirectUri);
var redirectUriOrigin = a.origin || (a.protocol + '//' + a.hostname);

// Listen to changes in the InAppBrowser window

popup.addEventListener('loadstart', function(e) {

var url = e.url;

// Is this the path, as given by the redirectUri?
// Check the new URL agains the redirectUriOrigin.
// According to #63 a user could click 'cancel' in some dialog boxes ....
// The popup redirects to another page with the same origin, yet we still wish it to close.

if (url.indexOf(redirectUriOrigin) !== 0) {
return;
}

// Split appart the URL
var a = hello.utils.url(url);

// We dont have window operations on the popup so lets create some
// The location can be augmented in to a location object like so...

var _popup = {
location: {
// Change the location of the popup
assign: function(location) {

// Unfourtunatly an app is may not change the location of a InAppBrowser window.
// So to shim this, just open a new one.
popup.executeScript({code: 'window.location.href = "' + location + ';"'});
},

search: a.search,
hash: a.hash,
href: a.href
},
close: function() {
if (popup.close) {
popup.close();
try {
popup.closed = true;
}
catch (_e) {}
}
}
};

// Then this URL contains information which HelloJS must process
// URL string
// Window - any action such as window relocation goes here
// Opener - the parent window which opened this, aka this script

hello.utils.responseHandler(_popup, window);

});
}
}
catch (e) {}

return popup;
};

})();