Skip to content

Commit

Permalink
[CB-1951] [cordova-js] InAppBrowser - support events (loadstart, load…
Browse files Browse the repository at this point in the history
…stop, exit)
  • Loading branch information
shazron committed Nov 29, 2012
1 parent f29591f commit 0be5344
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions lib/common/plugin/InAppBrowser.js
Expand Up @@ -20,15 +20,52 @@
*/

var exec = require('cordova/exec');

function InAppBrowser()
{
var _channel = require('cordova/channel');
this.channels = {
'loadstart': _channel.create('loadstart'),
'loadstop' : _channel.create('loadstop'),
'exit' : _channel.create('exit')
};
}

var InAppBrowser = {
open : function(strUrl, strWindowName, strWindowFeatures) {
exec(null, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
return InAppBrowser;
},
close : function() {
exec(null, null, "InAppBrowser", "close", []);
InAppBrowser.prototype._eventHandler = function(event)
{
if (event.type in this.channels) {
this.channels[event.type].fire(event);
}
};
}

InAppBrowser.open = function(strUrl, strWindowName, strWindowFeatures)
{
var iab = new InAppBrowser();
var cb = function(eventname) {
iab._eventHandler(eventname);
}
exec(cb, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
return iab;
}

InAppBrowser.prototype.close = function(eventname, f)
{
exec(null, null, "InAppBrowser", "close", []);
}

InAppBrowser.prototype.addEventListener = function(eventname, f)
{
if (eventname in this.channels) {
this.channels[eventname].subscribe(f);
}
}

InAppBrowser.prototype.removeEventListener = function(eventname, f)
{
if (eventname in this.channels) {
this.channels[eventname].unsubscribe(f);
}
}

module.exports = InAppBrowser.open;

0 comments on commit 0be5344

Please sign in to comment.