From e0d1414c4a9e20d7676aa3f5bd46bb626652c38f Mon Sep 17 00:00:00 2001 From: Dave Johnson Date: Mon, 26 Jul 2010 12:35:06 -0700 Subject: [PATCH] tweaks to PhoneGap.Channel --- example/phonegap.js | 24 +++---- framework/assets/js/channel.js | 81 ------------------------ framework/assets/js/phonegap.js.base | 95 ++++++++++++++++++---------- 3 files changed, 72 insertions(+), 128 deletions(-) delete mode 100644 framework/assets/js/channel.js diff --git a/example/phonegap.js b/example/phonegap.js index 504eac87..9e8c8e27 100644 --- a/example/phonegap.js +++ b/example/phonegap.js @@ -142,19 +142,9 @@ PhoneGap.Channel.merge(function() { // Listen for DOMContentLoaded document.addEventListener('DOMContentLoaded', function() { PhoneGap.onDOMContentLoaded.fire(); -}); +}, false); -// Intercept calls to document.addEventListener and watch for deviceready -PhoneGap._document_addEventListener = document.addEventListener; - -document.addEventListener = function(evt, handler, capture) { - if (evt.toLowerCase() == 'deviceready') { - PhoneGap.onDeviceReady.sob(handler); - } else { - PhoneGap._document_addEventListener.call(document, evt, handler); - } -}; @@ -638,7 +628,17 @@ Device.prototype.exitApp = function() PhoneGap.addConstructor(function() { navigator.device = window.device = new Device(); -}); +});// Intercept calls to document.addEventListener and watch for deviceready +PhoneGap._document_addEventListener = document.addEventListener; + +document.addEventListener = function(evt, handler, capture) { + if (evt.toLowerCase() == 'deviceready') { + PhoneGap.onDeviceReady.sob(handler); + } else { + PhoneGap._document_addEventListener.call(document, evt, handler); + } +}; + PhoneGap.addConstructor(function() { if (typeof navigator.fileMgr == "undefined") navigator.fileMgr = new FileMgr();}); diff --git a/framework/assets/js/channel.js b/framework/assets/js/channel.js deleted file mode 100644 index 61757d71..00000000 --- a/framework/assets/js/channel.js +++ /dev/null @@ -1,81 +0,0 @@ -PhoneGap.Channel = function(type) -{ - this.type = type; - this.handlers = {}; - this.guid = 0; - this.fired = false; - this.enabled = true; -}; - -PhoneGap.Channel.prototype.sub = function(f, c, g) -{ - // need a function to call - if (f == null) - return; - - var func = f; - if (typeof c == "object" && f instanceof Function) - func = PhoneGap.close(c, f); - - g = g || func.observer_guid || f.observer_guid || this.guid++; - func.observer_guid = g; - f.observer_guid = g; - this.handlers[g] = func; - return g; -}; - -PhoneGap.Channel.prototype.sob = function(f, c) -{ - var g = null; - var _this = this; - var m = function() { - f.apply(c || null, arguments); - _this.dub(g); - } - if (this.fired) { - if (typeof c == "object" && f instanceof Function) - f = PhoneGap.close(c, f); - f.apply(this, this.fireArgs); - } else { - g = this.sub(m); - } - return g; -}; - -PhoneGap.Channel.prototype.dub = function(g) -{ - if (g instanceof Function) - g = g.observer_guid; - this.handlers[g] = null; - delete this.handlers[g]; -}; - -PhoneGap.Channel.prototype.fire = function(e) -{ - if (this.enabled) - { - var fail = false; - for (var item in this.handlers) { - var handler = this.handlers[item]; - if (handler instanceof Function) { - var rv = (handler.apply(this, arguments)==false); - fail = fail || rv; - } - } - this.fired = true; - this.fireArgs = arguments; - return !fail; - } - return true; -}; - -PhoneGap.Channel.merge = function(h, e) { - var i = e.length; - var f = function() { - if (!(--i)) h(); - } - for (var j=0; j