Created
April 26, 2013 18:12
-
-
Save zol/5469228 to your computer and use it in GitHub Desktop.
WIP cordova In App Browser wrapper.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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