Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[CB-1951] [cordova-js] InAppBrowser - support events (loadstart, load…

…stop, exit)
  • Loading branch information...
commit 0be534420a6855a83ff3b0e7559932b25cee33e1 1 parent f29591f
@shazron shazron authored
Showing with 45 additions and 8 deletions.
  1. +45 −8 lib/common/plugin/InAppBrowser.js
View
53 lib/common/plugin/InAppBrowser.js
@@ -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;
+
Please sign in to comment.
Something went wrong with that request. Please try again.