Skip to content

Instantly share code, notes, and snippets.

@zol
Created April 26, 2013 18:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zol/5469228 to your computer and use it in GitHub Desktop.
Save zol/5469228 to your computer and use it in GitHub Desktop.
WIP cordova In App Browser wrapper.
IAB = {
closed: true, //for meteor to detect closed state
open: function(url, cb, goalURL) {
var that = this;
cordova.exec(function(params) {
switch (params.type) {
case 'loadstart':
console.log('IAB: loadstart url, ' + params.url);
break;
case 'loadstop':
//check goal url agains params.url without anything after the path
console.log('IAB: loadstop url, ' + params.url);
console.log('IAB: Checking goal, ' + params.url + ' == ' + goalURL);
var current = document.createElement('a');
current.href = params.url;
var goal = document.createElement('a');
goal.href = goalURL;
if (current.protocol == goal.protocol &&
current.hostname == goal.hostname &&
current.port == goal.port &&
current.pathname == goal.pathname) {
that.close();
cb('goal', params.url);
}
break;
case 'loaderror':
var msg = 'IAB: loaderror, url:' + params.url;
console.log(msg);
cb('error', msg);
break;
case 'exit':
// TODO: don't fire this if we reached the goal
cb('cancelled');
this.closed = true;
break;
};
}, function(error) {
var msg = 'IAB: load FAILURE, error:' + error;
console.log(msg);
cb('error', msg);
}, "InAppBrowser", "open", [url, '_blank', 'location=yes']);
this.closed = false;
},
// close the currently open IAB
close: function() {
cordova.exec(function(p) {
}, function(error) {
}, "InAppBrowser", "close", []);
this.closed = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment