Updated Branches: refs/heads/master b24c29003 -> facaa38a0
[CB-683] handle pause and resume events like any other event Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/facaa38a Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/facaa38a Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/facaa38a Branch: refs/heads/master Commit: facaa38a0bd924aa15c14c372537c00382f1e593 Parents: b24c290 Author: Fil Maj <maj....@gmail.com> Authored: Thu May 10 16:30:43 2012 -0700 Committer: Fil Maj <maj....@gmail.com> Committed: Thu May 10 16:34:57 2012 -0700 ---------------------------------------------------------------------- lib/cordova.js | 24 +++++++----------------- 1 files changed, 7 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/facaa38a/lib/cordova.js ---------------------------------------------------------------------- diff --git a/lib/cordova.js b/lib/cordova.js index d3da481..852951a 100644 --- a/lib/cordova.js +++ b/lib/cordova.js @@ -27,17 +27,7 @@ var documentEventHandlers = {}, document.addEventListener = function(evt, handler, capture) { var e = evt.toLowerCase(); - if (e == 'deviceready') { - channel.onDeviceReady.subscribeOnce(handler); - } else if (e == 'resume') { - channel.onResume.subscribe(handler); - // if subscribing listener after event has already fired, invoke the handler - if (channel.onResume.fired && typeof handler == 'function') { - handler(); - } - } else if (e == 'pause') { - channel.onPause.subscribe(handler); - } else if (typeof documentEventHandlers[e] != 'undefined') { + if (typeof documentEventHandlers[e] != 'undefined') { documentEventHandlers[e].subscribe(handler); } else { m_document_addEventListener.call(document, evt, handler, capture); @@ -55,13 +45,8 @@ window.addEventListener = function(evt, handler, capture) { document.removeEventListener = function(evt, handler, capture) { var e = evt.toLowerCase(); - // Check for pause/resume events first. - if (e == 'resume') { - channel.onResume.unsubscribe(handler); - } else if (e == 'pause') { - channel.onPause.unsubscribe(handler); // If unsubcribing from an event that is handled by a plugin - } else if (typeof documentEventHandlers[e] != "undefined") { + if (typeof documentEventHandlers[e] != "undefined") { documentEventHandlers[e].unsubscribe(handler); } else { m_document_removeEventListener.call(document, evt, handler, capture); @@ -247,6 +232,11 @@ var cordova = { } }; +// Register pause, resume and deviceready channels as events on document. +channel.onPause = cordova.addDocumentEventHandler('pause'); +channel.onResume = cordova.addDocumentEventHandler('resume'); +channel.onDeviceReady = cordova.addDocumentEventHandler('deviceready'); + // Adds deprecation warnings to functions of an object (but only logs a message once) function deprecateFunctions(obj, objLabel) { var newObj = {};