Skip to content
Prev Previous commit
Next Next commit
Prevent window from being patched twice
  • Loading branch information
jperl committed Jun 11, 2014
commit d930983a8fc8b8829a5a12461ef655259f17bac7
9 changes: 4 additions & 5 deletions patch_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// https://github.com/zeroasterisk/MeteorRider
window.patchWindow = function () {

// Prevent the window from being patched twice.
if (window.IAB) return;

// Make sure the InAppBrowser is loaded before patching the window.
var inAppBrowserLoaded = !!(window.cordova && window.cordova.require('org.apache.cordova.inappbrowser.inappbrowser'));
if (!inAppBrowserLoaded) return false;
Expand Down Expand Up @@ -76,13 +79,9 @@ window.patchWindow = function () {
};
}

// Clear patchWindow to prevent it from being called multiple times.
window.patchWindow = function () {
};

return true;
};

// Patch the window after cordova is finished loading
// if the InAppBrowser is not available yet.
if (!window.patchWindow()) document.addEventListener('deviceready', window.patchWindow, false);
if (!window.patchWindow()) document.addEventListener('deviceready', window.patchWindow, false);