You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/11/29 02:35:30 UTC
js commit: [CB-1951] [cordova-js] InAppBrowser - support events
(loadstart, loadstop, exit)
Updated Branches:
refs/heads/master f29591f86 -> 0be534420
[CB-1951] [cordova-js] InAppBrowser - support events (loadstart, loadstop, exit)
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/0be53442
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/0be53442
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/0be53442
Branch: refs/heads/master
Commit: 0be534420a6855a83ff3b0e7559932b25cee33e1
Parents: f29591f
Author: Shazron Abdullah <sh...@apache.org>
Authored: Wed Nov 28 17:35:24 2012 -0800
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Wed Nov 28 17:35:24 2012 -0800
----------------------------------------------------------------------
lib/common/plugin/InAppBrowser.js | 53 +++++++++++++++++++++++++++-----
1 files changed, 45 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/0be53442/lib/common/plugin/InAppBrowser.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/InAppBrowser.js b/lib/common/plugin/InAppBrowser.js
index 3967f95..970409f 100644
--- a/lib/common/plugin/InAppBrowser.js
+++ b/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;
+