Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…stop, exit)
  • Loading branch information...
commit 0be534420a6855a83ff3b0e7559932b25cee33e1 1 parent f29591f
Shazron Abdullah authored November 28, 2012

Showing 1 changed file with 45 additions and 8 deletions. Show diff stats Hide diff stats

  1. 53  lib/common/plugin/InAppBrowser.js
53  lib/common/plugin/InAppBrowser.js
@@ -20,15 +20,52 @@
20 20
 */
21 21
 
22 22
 var exec = require('cordova/exec');
  23
+       
  24
+function InAppBrowser()
  25
+{
  26
+   var _channel = require('cordova/channel');
  27
+   this.channels = {
  28
+        'loadstart': _channel.create('loadstart'),
  29
+        'loadstop' : _channel.create('loadstop'),
  30
+        'exit' : _channel.create('exit')
  31
+   };
  32
+}
23 33
 
24  
-var InAppBrowser = {
25  
-    open : function(strUrl, strWindowName, strWindowFeatures) {
26  
-        exec(null, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
27  
-        return InAppBrowser;
28  
-    },
29  
-    close : function() {
30  
-        exec(null, null, "InAppBrowser", "close", []);
  34
+InAppBrowser.prototype._eventHandler = function(event)
  35
+{
  36
+    if (event.type in this.channels) {
  37
+        this.channels[event.type].fire(event);
31 38
     }
32  
-};
  39
+}
  40
+       
  41
+InAppBrowser.open = function(strUrl, strWindowName, strWindowFeatures)
  42
+{
  43
+    var iab = new InAppBrowser();
  44
+    var cb = function(eventname) {
  45
+       iab._eventHandler(eventname);
  46
+    }
  47
+    exec(cb, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
  48
+    return iab;
  49
+}
  50
+
  51
+InAppBrowser.prototype.close = function(eventname, f)
  52
+{
  53
+    exec(null, null, "InAppBrowser", "close", []);
  54
+}
  55
+
  56
+InAppBrowser.prototype.addEventListener = function(eventname, f)
  57
+{
  58
+	if (eventname in this.channels) {
  59
+	    this.channels[eventname].subscribe(f);
  60
+	}
  61
+}
  62
+
  63
+InAppBrowser.prototype.removeEventListener = function(eventname, f)
  64
+{
  65
+	if (eventname in this.channels) {
  66
+	    this.channels[eventname].unsubscribe(f);
  67
+	}
  68
+}
33 69
 
34 70
 module.exports = InAppBrowser.open;
  71
+

0 notes on commit 0be5344

Please sign in to comment.
Something went wrong with that request. Please try again.