You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/09/18 19:52:50 UTC
[2/14] android commit: Updated JS snapshot.
Updated JS snapshot.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/302d51cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/302d51cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/302d51cd
Branch: refs/heads/master
Commit: 302d51cdfd950ba4b67f6b545393d0ee745eb754
Parents: d3cbfd5
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Sep 18 13:15:24 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Sep 18 13:25:18 2012 -0400
----------------------------------------------------------------------
framework/assets/js/cordova.android.js | 782 ++++++++++++++++-----------
1 files changed, 465 insertions(+), 317 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/302d51cd/framework/assets/js/cordova.android.js
----------------------------------------------------------------------
diff --git a/framework/assets/js/cordova.android.js b/framework/assets/js/cordova.android.js
index 5baba2b..7a7806e 100644
--- a/framework/assets/js/cordova.android.js
+++ b/framework/assets/js/cordova.android.js
@@ -1,6 +1,6 @@
-// commit 143f5221a6251c9cbccdedc57005c61551b97f12
+// commit d30179b30152b9383a80637e609cf2d785e1aa3e
-// File generated at :: Wed Sep 12 2012 12:51:58 GMT-0700 (PDT)
+// File generated at :: Tue Sep 18 2012 11:34:26 GMT-0400 (EDT)
/*
Licensed to the Apache Software Foundation (ASF) under one
@@ -24,11 +24,16 @@
;(function() {
// file: lib/scripts/require.js
+
var require,
define;
(function () {
var modules = {};
+ // Stack of moduleIds currently being built.
+ var requireStack = [];
+ // Map of module ID -> index into requireStack of modules currently being built.
+ var inProgressModules = {};
function build(module) {
var factory = module.factory;
@@ -41,8 +46,21 @@ var require,
require = function (id) {
if (!modules[id]) {
throw "module " + id + " not found";
+ } else if (id in inProgressModules) {
+ var cycle = requireStack.slice(inProgressModules[id]).join('->') + '->' + id;
+ throw "Cycle in require graph: " + cycle;
}
- return modules[id].factory ? build(modules[id]) : modules[id].exports;
+ if (modules[id].factory) {
+ try {
+ inProgressModules[id] = requireStack.length;
+ requireStack.push(id);
+ return build(modules[id]);
+ } finally {
+ delete inProgressModules[id];
+ requireStack.pop();
+ }
+ }
+ return modules[id].exports;
};
define = function (id, factory) {
@@ -67,8 +85,11 @@ if (typeof module === "object" && typeof require === "function") {
module.exports.require = require;
module.exports.define = define;
}
+
// file: lib/cordova.js
define("cordova", function(require, exports, module) {
+
+
var channel = require('cordova/channel');
/**
@@ -99,11 +120,7 @@ var documentEventHandlers = {},
document.addEventListener = function(evt, handler, capture) {
var e = evt.toLowerCase();
if (typeof documentEventHandlers[e] != 'undefined') {
- if (evt === 'deviceready') {
- documentEventHandlers[e].subscribeOnce(handler);
- } else {
- documentEventHandlers[e].subscribe(handler);
- }
+ documentEventHandlers[e].subscribe(handler);
} else {
m_document_addEventListener.call(document, evt, handler, capture);
}
@@ -163,11 +180,14 @@ var cordova = {
/**
* Methods to add/remove your own addEventListener hijacking on document + window.
*/
- addWindowEventHandler:function(event, opts) {
- return (windowEventHandlers[event] = channel.create(event, opts));
+ addWindowEventHandler:function(event) {
+ return (windowEventHandlers[event] = channel.create(event));
},
- addDocumentEventHandler:function(event, opts) {
- return (documentEventHandlers[event] = channel.create(event, opts));
+ addStickyDocumentEventHandler:function(event) {
+ return (documentEventHandlers[event] = channel.createSticky(event));
+ },
+ addDocumentEventHandler:function(event) {
+ return (documentEventHandlers[event] = channel.create(event));
},
removeWindowEventHandler:function(event) {
delete windowEventHandlers[event];
@@ -242,57 +262,48 @@ var cordova = {
/**
* Called by native code when returning successful result from an action.
- *
- * @param callbackId
- * @param args
*/
callbackSuccess: function(callbackId, args) {
- if (cordova.callbacks[callbackId]) {
-
- // If result is to be sent to callback
- if (args.status == cordova.callbackStatus.OK) {
- try {
- if (cordova.callbacks[callbackId].success) {
- cordova.callbacks[callbackId].success(args.message);
- }
- }
- catch (e) {
- console.log("Error in success callback: "+callbackId+" = "+e);
- }
- }
-
- // Clear callback if not expecting any more results
- if (!args.keepCallback) {
- delete cordova.callbacks[callbackId];
- }
+ try {
+ cordova.callbackFromNative(callbackId, true, args.status, args.message, args.keepCallback);
+ } catch (e) {
+ console.log("Error in error callback: " + callbackId + " = "+e);
}
},
/**
* Called by native code when returning error result from an action.
- *
- * @param callbackId
- * @param args
*/
callbackError: function(callbackId, args) {
- if (cordova.callbacks[callbackId]) {
- try {
- if (cordova.callbacks[callbackId].fail) {
- cordova.callbacks[callbackId].fail(args.message);
- }
- }
- catch (e) {
- console.log("Error in error callback: "+callbackId+" = "+e);
+ // TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
+ // Derive success from status.
+ try {
+ cordova.callbackFromNative(callbackId, false, args.status, args.message, args.keepCallback);
+ } catch (e) {
+ console.log("Error in error callback: " + callbackId + " = "+e);
+ }
+ },
+
+ /**
+ * Called by native code when returning the result from an action.
+ */
+ callbackFromNative: function(callbackId, success, status, message, keepCallback) {
+ var callback = cordova.callbacks[callbackId];
+ if (callback) {
+ if (success && status == cordova.callbackStatus.OK) {
+ callback.success && callback.success(message);
+ } else if (!success) {
+ callback.fail && callback.fail(message);
}
// Clear callback if not expecting any more results
- if (!args.keepCallback) {
+ if (!keepCallback) {
delete cordova.callbacks[callbackId];
}
}
},
addConstructor: function(func) {
- channel.onCordovaReady.subscribeOnce(function() {
+ channel.onCordovaReady.subscribe(function() {
try {
func();
} catch(e) {
@@ -305,7 +316,7 @@ 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');
+channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
module.exports = cordova;
@@ -313,6 +324,7 @@ module.exports = cordova;
// file: lib/common/builder.js
define("cordova/builder", function(require, exports, module) {
+
var utils = require('cordova/utils');
function each(objects, func, context) {
@@ -323,6 +335,17 @@ function each(objects, func, context) {
}
}
+function assignOrWrapInDeprecateGetter(obj, key, value, message) {
+ if (message) {
+ utils.defineGetter(obj, key, function() {
+ window.console && console.log(message);
+ return value;
+ });
+ } else {
+ obj[key] = value;
+ }
+}
+
function include(parent, objects, clobber, merge) {
each(objects, function (obj, key) {
try {
@@ -331,20 +354,20 @@ function include(parent, objects, clobber, merge) {
if (clobber) {
// Clobber if it doesn't exist.
if (typeof parent[key] === 'undefined') {
- parent[key] = result;
+ assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
} else if (typeof obj.path !== 'undefined') {
// If merging, merge properties onto parent, otherwise, clobber.
if (merge) {
recursiveMerge(parent[key], result);
} else {
- parent[key] = result;
+ assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
}
}
result = parent[key];
} else {
// Overwrite if not currently defined.
if (typeof parent[key] == 'undefined') {
- parent[key] = result;
+ assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
} else if (merge && typeof obj.path !== 'undefined') {
// If merging, merge parent onto result
recursiveMerge(result, parent[key]);
@@ -406,25 +429,29 @@ module.exports = {
// file: lib/common/channel.js
define("cordova/channel", function(require, exports, module) {
+
var utils = require('cordova/utils'),
nextGuid = 1;
/**
* Custom pub-sub "channel" that can have functions subscribed to it
* This object is used to define and control firing of events for
- * cordova initialization.
+ * cordova initialization, as well as for custom events thereafter.
*
* The order of events during page load and Cordova startup is as follows:
*
- * onDOMContentLoaded Internal event that is received when the web page is loaded and parsed.
- * onNativeReady Internal event that indicates the Cordova native side is ready.
- * onCordovaReady Internal event fired when all Cordova JavaScript objects have been created.
- * onCordovaInfoReady Internal event fired when device properties are available.
- * onCordovaConnectionReady Internal event fired when the connection property has been set.
- * onDeviceReady User event fired to indicate that Cordova is ready
- * onResume User event fired to indicate a start/resume lifecycle event
- * onPause User event fired to indicate a pause lifecycle event
- * onDestroy Internal event fired when app is being destroyed (User should use window.onunload event, not this one).
+ * onDOMContentLoaded* Internal event that is received when the web page is loaded and parsed.
+ * onNativeReady* Internal event that indicates the Cordova native side is ready.
+ * onCordovaReady* Internal event fired when all Cordova JavaScript objects have been created.
+ * onCordovaInfoReady* Internal event fired when device properties are available.
+ * onCordovaConnectionReady* Internal event fired when the connection property has been set.
+ * onDeviceReady* User event fired to indicate that Cordova is ready
+ * onResume User event fired to indicate a start/resume lifecycle event
+ * onPause User event fired to indicate a pause lifecycle event
+ * onDestroy* Internal event fired when app is being destroyed (User should use window.onunload event, not this one).
+ *
+ * The events marked with an * are sticky. Once they have fired, they will stay in the fired state.
+ * All listeners that subscribe after the event is fired will be executed right away.
*
* The only Cordova events that user code should register for are:
* deviceready Cordova native code is initialized and Cordova APIs can be called from JavaScript
@@ -446,49 +473,45 @@ var utils = require('cordova/utils'),
* Channel
* @constructor
* @param type String the channel name
- * @param opts Object options to pass into the channel, currently
- * supports:
- * onSubscribe: callback that fires when
- * something subscribes to the Channel. Sets
- * context to the Channel.
- * onUnsubscribe: callback that fires when
- * something unsubscribes to the Channel. Sets
- * context to the Channel.
- */
-var Channel = function(type, opts) {
+ */
+var Channel = function(type, sticky) {
this.type = type;
+ // Map of guid -> function.
this.handlers = {};
+ // 0 = Non-sticky, 1 = Sticky non-fired, 2 = Sticky fired.
+ this.state = sticky ? 1 : 0;
+ // Used in sticky mode to remember args passed to fire().
+ this.fireArgs = null;
+ // Used by onHasSubscribersChange to know if there are any listeners.
this.numHandlers = 0;
- this.fired = false;
- this.enabled = true;
- this.events = {
- onSubscribe:null,
- onUnsubscribe:null
- };
- if (opts) {
- if (opts.onSubscribe) this.events.onSubscribe = opts.onSubscribe;
- if (opts.onUnsubscribe) this.events.onUnsubscribe = opts.onUnsubscribe;
- }
+ // Function that is called when the first listener is subscribed, or when
+ // the last listener is unsubscribed.
+ this.onHasSubscribersChange = null;
},
channel = {
/**
* Calls the provided function only after all of the channels specified
- * have been fired.
+ * have been fired. All channels must be sticky channels.
*/
- join: function (h, c) {
- var i = c.length;
- var len = i;
- var f = function() {
- if (!(--i)) h();
- };
+ join: function(h, c) {
+ var len = c.length,
+ i = len,
+ f = function() {
+ if (!(--i)) h();
+ };
for (var j=0; j<len; j++) {
- !c[j].fired?c[j].subscribeOnce(f):i--;
+ if (c[j].state == 0) {
+ throw Error('Can only use join with sticky channels.')
+ }
+ c[j].subscribe(f);
}
- if (!i) h();
+ if (!len) h();
},
- create: function (type, opts) {
- channel[type] = new Channel(type, opts);
- return channel[type];
+ create: function(type) {
+ return channel[type] = new Channel(type, false);
+ },
+ createSticky: function(type) {
+ return channel[type] = new Channel(type, true);
},
/**
@@ -506,13 +529,7 @@ var Channel = function(type, opts) {
*/
waitForInitialization: function(feature) {
if (feature) {
- var c = null;
- if (this[feature]) {
- c = this[feature];
- }
- else {
- c = this.create(feature);
- }
+ var c = channel[feature] || this.createSticky(feature);
this.deviceReadyChannelsMap[feature] = c;
this.deviceReadyChannelsArray.push(c);
}
@@ -532,7 +549,7 @@ var Channel = function(type, opts) {
};
function forceFunction(f) {
- if (f === null || f === undefined || typeof f != 'function') throw "Function required as first argument!";
+ if (typeof f != 'function') throw "Function required as first argument!";
}
/**
@@ -542,67 +559,50 @@ function forceFunction(f) {
* and a guid that can be used to stop subscribing to the channel.
* Returns the guid.
*/
-Channel.prototype.subscribe = function(f, c, g) {
+Channel.prototype.subscribe = function(f, c) {
// need a function to call
forceFunction(f);
+ if (this.state == 2) {
+ f.apply(c || this, this.fireArgs);
+ return;
+ }
- var func = f;
+ var func = f,
+ guid = f.observer_guid;
if (typeof c == "object") { func = utils.close(c, f); }
- g = g || func.observer_guid || f.observer_guid;
- if (!g) {
+ if (!guid) {
// first time any channel has seen this subscriber
- g = nextGuid++;
+ guid = '' + nextGuid++;
}
- func.observer_guid = g;
- f.observer_guid = g;
+ func.observer_guid = guid;
+ f.observer_guid = guid;
// Don't add the same handler more than once.
- if (!this.handlers[g]) {
- this.handlers[g] = func;
+ if (!this.handlers[guid]) {
+ this.handlers[guid] = func;
this.numHandlers++;
- if (this.events.onSubscribe) this.events.onSubscribe.call(this);
- if (this.fired) func.apply(this, this.fireArgs);
- }
- return g;
-};
-
-/**
- * Like subscribe but the function is only called once and then it
- * auto-unsubscribes itself.
- */
-Channel.prototype.subscribeOnce = function(f, c) {
- // need a function to call
- forceFunction(f);
-
- var g = null;
- var _this = this;
- if (this.fired) {
- f.apply(c || null, this.fireArgs);
- } else {
- g = this.subscribe(function() {
- _this.unsubscribe(g);
- f.apply(c || null, arguments);
- });
- f.observer_guid = g;
+ if (this.numHandlers == 1) {
+ this.onHasSubscribersChange && this.onHasSubscribersChange();
+ }
}
- return g;
};
/**
* Unsubscribes the function with the given guid from the channel.
*/
-Channel.prototype.unsubscribe = function(g) {
+Channel.prototype.unsubscribe = function(f) {
// need a function to unsubscribe
- if (g === null || g === undefined) { throw "You must pass _something_ into Channel.unsubscribe"; }
+ forceFunction(f);
- if (typeof g == 'function') { g = g.observer_guid; }
- var handler = this.handlers[g];
+ var guid = f.observer_guid,
+ handler = this.handlers[guid];
if (handler) {
- if (handler.observer_guid) handler.observer_guid=null;
- delete this.handlers[g];
+ delete this.handlers[guid];
this.numHandlers--;
- if (this.events.onUnsubscribe) this.events.onUnsubscribe.call(this);
+ if (this.numHandlers == 0) {
+ this.onHasSubscribersChange && this.onHasSubscribersChange();
+ }
}
};
@@ -610,10 +610,14 @@ Channel.prototype.unsubscribe = function(g) {
* Calls all functions subscribed to this channel.
*/
Channel.prototype.fire = function(e) {
- if (this.enabled) {
- var fail = false;
- this.fired = true;
- this.fireArgs = arguments;
+ var fail = false,
+ fireArgs = Array.prototype.slice.call(arguments);
+ // Apply stickiness.
+ if (this.state == 1) {
+ this.state = 2;
+ this.fireArgs = fireArgs;
+ }
+ if (this.numHandlers) {
// Copy the values first so that it is safe to modify it from within
// callbacks.
var toCall = [];
@@ -621,33 +625,36 @@ Channel.prototype.fire = function(e) {
toCall.push(this.handlers[item]);
}
for (var i = 0; i < toCall.length; ++i) {
- var rv = (toCall[i].apply(this, arguments)===false);
- fail = fail || rv;
+ toCall[i].apply(this, fireArgs);
+ }
+ if (this.state == 2 && this.numHandlers) {
+ this.numHandlers = 0;
+ this.handlers = {};
+ this.onHasSubscribersChange && this.onHasSubscribersChange();
}
- return !fail;
}
- return true;
};
+
// defining them here so they are ready super fast!
// DOM event that is received when the web page is loaded and parsed.
-channel.create('onDOMContentLoaded');
+channel.createSticky('onDOMContentLoaded');
// Event to indicate the Cordova native side is ready.
-channel.create('onNativeReady');
+channel.createSticky('onNativeReady');
// Event to indicate that all Cordova JavaScript objects have been created
// and it's time to run plugin constructors.
-channel.create('onCordovaReady');
+channel.createSticky('onCordovaReady');
// Event to indicate that device properties are available
-channel.create('onCordovaInfoReady');
+channel.createSticky('onCordovaInfoReady');
// Event to indicate that the connection property has been set.
-channel.create('onCordovaConnectionReady');
+channel.createSticky('onCordovaConnectionReady');
// Event to indicate that Cordova is ready
-channel.create('onDeviceReady');
+channel.createSticky('onDeviceReady');
// Event to indicate a resume lifecycle event
channel.create('onResume');
@@ -656,7 +663,7 @@ channel.create('onResume');
channel.create('onPause');
// Event to indicate a destroy lifecycle event
-channel.create('onDestroy');
+channel.createSticky('onDestroy');
// Channels that must fire before "deviceready" is fired.
channel.waitForInitialization('onCordovaReady');
@@ -668,6 +675,7 @@ module.exports = channel;
// file: lib/common/common.js
define("cordova/common", function(require, exports, module) {
+
module.exports = {
objects: {
cordova: {
@@ -705,6 +713,9 @@ module.exports = {
compass:{
path: 'cordova/plugin/compass'
},
+ connection: {
+ path: 'cordova/plugin/network'
+ },
contacts: {
path: 'cordova/plugin/contacts'
},
@@ -721,7 +732,8 @@ module.exports = {
network: {
children: {
connection: {
- path: 'cordova/plugin/network'
+ path: 'cordova/plugin/network',
+ deprecated: 'navigator.network.connection is deprecated. Use navigator.connection instead.'
}
}
},
@@ -872,6 +884,7 @@ module.exports = {
// file: lib/android/exec.js
define("cordova/exec", function(require, exports, module) {
+
/**
* Execute a cordova command. It is up to the native side whether this action
* is synchronous or asynchronous. The native side can return:
@@ -889,6 +902,7 @@ define("cordova/exec", function(require, exports, module) {
var cordova = require('cordova'),
callback = require('cordova/plugin/android/callback'),
polling = require('cordova/plugin/android/polling'),
+ nativeApiProvider = require('cordova/plugin/android/nativeapiprovider'),
jsToNativeBridgeMode,
nativeToJsBridgeMode,
jsToNativeModes = {
@@ -900,7 +914,7 @@ var cordova = require('cordova'),
LOCATION_CHANGE: 2
},
nativeToJsModes = {
- // Polls for messages using the prompt() bridge.
+ // Polls for messages using the JS->Native bridge.
POLLING: 0,
// Does an XHR to a local server, which will send back messages. This is
// broken on ICS when a proxy server is configured.
@@ -930,94 +944,52 @@ function androidExec(success, fail, service, action, args) {
androidExec.setNativeToJsBridgeMode(nativeToJsModes.POLLING);
}
}
- try {
- var callbackId = service + cordova.callbackId++,
- argsJson = JSON.stringify(args),
- result;
- if (success || fail) {
- cordova.callbacks[callbackId] = {success:success, fail:fail};
- }
-
- if (jsToNativeBridgeMode == jsToNativeModes.LOCATION_CHANGE) {
- window.location = 'http://cdv_exec/' + service + '#' + action + '#' + callbackId + '#' + argsJson;
- } else if (jsToNativeBridgeMode == jsToNativeModes.JS_OBJECT) {
- // Explicit cast to string is required on Android 2.1 to convert from
- // a Java string to a JS string.
- result = '' + _cordovaExec.exec(service, action, callbackId, argsJson);
- } else {
- result = prompt(argsJson, "gap:"+JSON.stringify([service, action, callbackId, true]));
- }
-
- // If a result was returned
- if (result) {
- var v = JSON.parse(result);
-
- // If status is OK, then return value back to caller
- if (v.status === cordova.callbackStatus.OK) {
-
- // If there is a success callback, then call it now with
- // returned value
- if (success) {
- try {
- success(v.message);
- } catch (e) {
- console.log("Error in success callback: " + callbackId + " = " + e);
- }
-
- // Clear callback if not expecting any more results
- if (!v.keepCallback) {
- delete cordova.callbacks[callbackId];
- }
- }
- return v.message;
- }
-
- // If no result
- else if (v.status === cordova.callbackStatus.NO_RESULT) {
- // Clear callback if not expecting any more results
- if (!v.keepCallback) {
- delete cordova.callbacks[callbackId];
- }
- }
-
- // If error, then display error
- else {
- console.log("Error: Status="+v.status+" Message="+v.message);
-
- // If there is a fail callback, then call it now with returned value
- if (fail) {
- try {
- fail(v.message);
- }
- catch (e1) {
- console.log("Error in error callback: "+callbackId+" = "+e1);
- }
+ var callbackId = service + cordova.callbackId++,
+ argsJson = JSON.stringify(args);
+ if (success || fail) {
+ cordova.callbacks[callbackId] = {success:success, fail:fail};
+ }
- // Clear callback if not expecting any more results
- if (!v.keepCallback) {
- delete cordova.callbacks[callbackId];
- }
- }
- return null;
- }
- }
- } catch (e2) {
- console.log("Error: "+e2);
+ if (jsToNativeBridgeMode == jsToNativeModes.LOCATION_CHANGE) {
+ window.location = 'http://cdv_exec/' + service + '#' + action + '#' + callbackId + '#' + argsJson;
+ } else {
+ var messages = nativeApiProvider.get().exec(service, action, callbackId, argsJson);
+ // Explicit cast to string is required on Android 2.1 to convert from
+ // a Java string to a JS string.
+ if (messages) {
+ messages = String(messages);
+ }
+ androidExec.processMessages(messages);
}
}
-function onOnLineEvent(e) {
- while (polling.pollOnce());
+function hookOnlineApis() {
+ function proxyEvent(e) {
+ cordova.fireWindowEvent(e.type);
+ }
+ // The network module takes care of firing online and offline events.
+ // It currently fires them only on document though, so we bridge them
+ // to window here (while first listening for exec()-releated online/offline
+ // events).
+ window.addEventListener('online', polling.pollOnce, false);
+ window.addEventListener('offline', polling.pollOnce, false);
+ cordova.addWindowEventHandler('online');
+ cordova.addWindowEventHandler('offline');
+ document.addEventListener('online', proxyEvent, false);
+ document.addEventListener('offline', proxyEvent, false);
}
+hookOnlineApis();
+
androidExec.jsToNativeModes = jsToNativeModes;
androidExec.nativeToJsModes = nativeToJsModes;
androidExec.setJsToNativeBridgeMode = function(mode) {
- if (mode == jsToNativeModes.JS_OBJECT && !window._cordovaExec) {
- console.log('Falling back on PROMPT mode since _cordovaExec is missing.');
+ if (mode == jsToNativeModes.JS_OBJECT && !window._cordovaNative) {
+ console.log('Falling back on PROMPT mode since _cordovaNative is missing.');
mode = jsToNativeModes.PROMPT;
}
+ nativeApiProvider.setPreferPrompt(mode == jsToNativeModes.PROMPT);
jsToNativeBridgeMode = mode;
};
@@ -1029,22 +1001,68 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
polling.stop();
} else if (nativeToJsBridgeMode == nativeToJsModes.HANGING_GET) {
callback.stop();
- } else if (nativeToJsBridgeMode == nativeToJsModes.ONLINE_EVENT) {
- window.removeEventListener('online', onOnLineEvent, false);
- window.removeEventListener('offline', onOnLineEvent, false);
}
nativeToJsBridgeMode = mode;
// Tell the native side to switch modes.
- prompt(mode, "gap_bridge_mode:");
+ nativeApiProvider.get().setNativeToJsBridgeMode(mode);
if (mode == nativeToJsModes.POLLING) {
polling.start();
} else if (mode == nativeToJsModes.HANGING_GET) {
callback.start();
- } else if (mode == nativeToJsModes.ONLINE_EVENT) {
- window.addEventListener('online', onOnLineEvent, false);
- window.addEventListener('offline', onOnLineEvent, false);
+ }
+};
+
+// Processes a single message, as encoded by NativeToJsMessageQueue.java.
+function processMessage(message) {
+ try {
+ var firstChar = message.charAt(0);
+ if (firstChar == 'J') {
+ eval(message.slice(1));
+ } else if (firstChar == 'S' || firstChar == 'F') {
+ var success = firstChar == 'S';
+ var keepCallback = message.charAt(1) == '1';
+ var spaceIdx = message.indexOf(' ', 2);
+ var status = +message.slice(2, spaceIdx);
+ var nextSpaceIdx = message.indexOf(' ', spaceIdx + 1);
+ var callbackId = message.slice(spaceIdx + 1, nextSpaceIdx);
+ var payloadKind = message.charAt(nextSpaceIdx + 1);
+ var payload;
+ if (payloadKind == 's') {
+ payload = message.slice(nextSpaceIdx + 2);
+ } else if (payloadKind == 't') {
+ payload = true;
+ } else if (payloadKind == 'f') {
+ payload = false;
+ } else if (payloadKind == 'n') {
+ payload = +message.slice(nextSpaceIdx + 2);
+ } else {
+ payload = JSON.parse(message.slice(nextSpaceIdx + 1));
+ }
+ cordova.callbackFromNative(callbackId, success, status, payload, keepCallback);
+ } else {
+ console.log("processMessage failed: invalid message:" + message);
+ }
+ } catch (e) {
+ console.log("processMessage failed: Message: " + message);
+ console.log("processMessage failed: Error: " + e);
+ console.log("processMessage failed: Stack: " + e.stack);
+ }
+}
+
+// This is called from the NativeToJsMessageQueue.java.
+androidExec.processMessages = function(messages) {
+ while (messages) {
+ if (messages == '*') {
+ window.setTimeout(polling.pollOnce, 0);
+ break;
+ }
+ var spaceIdx = messages.indexOf(' ');
+ var msgLen = +messages.slice(0, spaceIdx);
+ var message = messages.substr(spaceIdx + 1, msgLen);
+ messages = messages.slice(spaceIdx + msgLen + 1);
+ processMessage(message);
}
};
@@ -1054,6 +1072,7 @@ module.exports = androidExec;
// file: lib/android/platform.js
define("cordova/platform", function(require, exports, module) {
+
module.exports = {
id: "android",
initialize:function() {
@@ -1062,20 +1081,12 @@ module.exports = {
exec = require('cordova/exec');
// Inject a listener for the backbutton on the document.
- var backButtonChannel = cordova.addDocumentEventHandler('backbutton', {
- onSubscribe:function() {
- // If we just attached the first handler, let native know we need to override the back button.
- if (this.numHandlers === 1) {
- exec(null, null, "App", "overrideBackbutton", [true]);
- }
- },
- onUnsubscribe:function() {
- // If we just detached the last handler, let native know we no longer override the back button.
- if (this.numHandlers === 0) {
- exec(null, null, "App", "overrideBackbutton", [false]);
- }
- }
- });
+ var backButtonChannel = cordova.addDocumentEventHandler('backbutton');
+ backButtonChannel.onHasSubscribersChange = function() {
+ // If we just attached the first handler or detached the last handler,
+ // let native know we need to override the back button.
+ exec(null, null, "App", "overrideBackbutton", [this.numHandlers == 1]);
+ };
// Add hardware MENU and SEARCH button handlers
cordova.addDocumentEventHandler('menubutton');
@@ -1177,6 +1188,7 @@ module.exports = {
// file: lib/common/plugin/Acceleration.js
define("cordova/plugin/Acceleration", function(require, exports, module) {
+
var Acceleration = function(x, y, z, timestamp) {
this.x = x;
this.y = y;
@@ -1190,6 +1202,7 @@ module.exports = Acceleration;
// file: lib/common/plugin/Camera.js
define("cordova/plugin/Camera", function(require, exports, module) {
+
var exec = require('cordova/exec'),
Camera = require('cordova/plugin/CameraConstants');
@@ -1306,10 +1319,12 @@ cameraExport.cleanup = function(successCallback, errorCallback) {
};
module.exports = cameraExport;
+
});
// file: lib/common/plugin/CameraConstants.js
define("cordova/plugin/CameraConstants", function(require, exports, module) {
+
module.exports = {
DestinationType:{
DATA_URL: 0, // Return base64 encoded string
@@ -1337,10 +1352,12 @@ module.exports = {
ARROW_ANY : 15
}
};
+
});
// file: lib/common/plugin/CameraPopoverOptions.js
define("cordova/plugin/CameraPopoverOptions", function(require, exports, module) {
+
var Camera = require('cordova/plugin/CameraConstants');
/**
@@ -1357,10 +1374,12 @@ var CameraPopoverOptions = function(x,y,width,height,arrowDir){
};
module.exports = CameraPopoverOptions;
+
});
// file: lib/common/plugin/CaptureAudioOptions.js
define("cordova/plugin/CaptureAudioOptions", function(require, exports, module) {
+
/**
* Encapsulates all audio capture operation configuration options.
*/
@@ -1374,10 +1393,12 @@ var CaptureAudioOptions = function(){
};
module.exports = CaptureAudioOptions;
+
});
// file: lib/common/plugin/CaptureError.js
define("cordova/plugin/CaptureError", function(require, exports, module) {
+
/**
* The CaptureError interface encapsulates all errors in the Capture API.
*/
@@ -1397,10 +1418,12 @@ CaptureError.CAPTURE_NO_MEDIA_FILES = 3;
CaptureError.CAPTURE_NOT_SUPPORTED = 20;
module.exports = CaptureError;
+
});
// file: lib/common/plugin/CaptureImageOptions.js
define("cordova/plugin/CaptureImageOptions", function(require, exports, module) {
+
/**
* Encapsulates all image capture operation configuration options.
*/
@@ -1412,10 +1435,12 @@ var CaptureImageOptions = function(){
};
module.exports = CaptureImageOptions;
+
});
// file: lib/common/plugin/CaptureVideoOptions.js
define("cordova/plugin/CaptureVideoOptions", function(require, exports, module) {
+
/**
* Encapsulates all video capture operation configuration options.
*/
@@ -1429,10 +1454,12 @@ var CaptureVideoOptions = function(){
};
module.exports = CaptureVideoOptions;
+
});
// file: lib/common/plugin/CompassError.js
define("cordova/plugin/CompassError", function(require, exports, module) {
+
/**
* CompassError.
* An error code assigned by an implementation when an error has occured
@@ -1446,10 +1473,12 @@ CompassError.COMPASS_INTERNAL_ERR = 0;
CompassError.COMPASS_NOT_SUPPORTED = 20;
module.exports = CompassError;
+
});
// file: lib/common/plugin/CompassHeading.js
define("cordova/plugin/CompassHeading", function(require, exports, module) {
+
var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, timestamp) {
this.magneticHeading = (magneticHeading !== undefined ? magneticHeading : null);
this.trueHeading = (trueHeading !== undefined ? trueHeading : null);
@@ -1458,10 +1487,12 @@ var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, tim
};
module.exports = CompassHeading;
+
});
// file: lib/common/plugin/ConfigurationData.js
define("cordova/plugin/ConfigurationData", function(require, exports, module) {
+
/**
* Encapsulates a set of parameters that the capture device supports.
*/
@@ -1477,10 +1508,12 @@ function ConfigurationData() {
}
module.exports = ConfigurationData;
+
});
// file: lib/common/plugin/Connection.js
define("cordova/plugin/Connection", function(require, exports, module) {
+
/**
* Network status
*/
@@ -1493,10 +1526,12 @@ module.exports = {
CELL_4G: "4g",
NONE: "none"
};
+
});
// file: lib/common/plugin/Contact.js
define("cordova/plugin/Contact", function(require, exports, module) {
+
var exec = require('cordova/exec'),
ContactError = require('cordova/plugin/ContactError'),
utils = require('cordova/utils');
@@ -1679,6 +1714,7 @@ module.exports = Contact;
// file: lib/common/plugin/ContactAddress.js
define("cordova/plugin/ContactAddress", function(require, exports, module) {
+
/**
* Contact address.
* @constructor
@@ -1704,10 +1740,12 @@ var ContactAddress = function(pref, type, formatted, streetAddress, locality, re
};
module.exports = ContactAddress;
+
});
// file: lib/common/plugin/ContactError.js
define("cordova/plugin/ContactError", function(require, exports, module) {
+
/**
* ContactError.
* An error code assigned by an implementation when an error has occured
@@ -1729,10 +1767,12 @@ ContactError.NOT_SUPPORTED_ERROR = 5;
ContactError.PERMISSION_DENIED_ERROR = 20;
module.exports = ContactError;
+
});
// file: lib/common/plugin/ContactField.js
define("cordova/plugin/ContactField", function(require, exports, module) {
+
/**
* Generic contact field.
* @constructor
@@ -1749,10 +1789,12 @@ var ContactField = function(type, value, pref) {
};
module.exports = ContactField;
+
});
// file: lib/common/plugin/ContactFindOptions.js
define("cordova/plugin/ContactFindOptions", function(require, exports, module) {
+
/**
* ContactFindOptions.
* @constructor
@@ -1766,10 +1808,12 @@ var ContactFindOptions = function(filter, multiple) {
};
module.exports = ContactFindOptions;
+
});
// file: lib/common/plugin/ContactName.js
define("cordova/plugin/ContactName", function(require, exports, module) {
+
/**
* Contact name.
* @constructor
@@ -1790,10 +1834,12 @@ var ContactName = function(formatted, familyName, givenName, middle, prefix, suf
};
module.exports = ContactName;
+
});
// file: lib/common/plugin/ContactOrganization.js
define("cordova/plugin/ContactOrganization", function(require, exports, module) {
+
/**
* Contact organization.
* @constructor
@@ -1817,10 +1863,12 @@ var ContactOrganization = function(pref, type, name, dept, title) {
};
module.exports = ContactOrganization;
+
});
// file: lib/common/plugin/Coordinates.js
define("cordova/plugin/Coordinates", function(require, exports, module) {
+
/**
* This class contains position information.
* @param {Object} lat
@@ -1874,6 +1922,7 @@ module.exports = Coordinates;
// file: lib/common/plugin/DirectoryEntry.js
define("cordova/plugin/DirectoryEntry", function(require, exports, module) {
+
var utils = require('cordova/utils'),
exec = require('cordova/exec'),
Entry = require('cordova/plugin/Entry'),
@@ -1960,6 +2009,7 @@ module.exports = DirectoryEntry;
// file: lib/common/plugin/DirectoryReader.js
define("cordova/plugin/DirectoryReader", function(require, exports, module) {
+
var exec = require('cordova/exec'),
FileError = require('cordova/plugin/FileError') ;
@@ -2007,6 +2057,7 @@ module.exports = DirectoryReader;
// file: lib/common/plugin/Entry.js
define("cordova/plugin/Entry", function(require, exports, module) {
+
var exec = require('cordova/exec'),
FileError = require('cordova/plugin/FileError'),
Metadata = require('cordova/plugin/Metadata');
@@ -2225,10 +2276,12 @@ Entry.prototype.getParent = function(successCallback, errorCallback) {
};
module.exports = Entry;
+
});
// file: lib/common/plugin/File.js
define("cordova/plugin/File", function(require, exports, module) {
+
/**
* Constructor.
* name {DOMString} name of the file, without path information
@@ -2247,10 +2300,12 @@ var File = function(name, fullPath, type, lastModifiedDate, size){
};
module.exports = File;
+
});
// file: lib/common/plugin/FileEntry.js
define("cordova/plugin/FileEntry", function(require, exports, module) {
+
var utils = require('cordova/utils'),
exec = require('cordova/exec'),
Entry = require('cordova/plugin/Entry'),
@@ -2314,10 +2369,12 @@ FileEntry.prototype.file = function(successCallback, errorCallback) {
module.exports = FileEntry;
+
});
// file: lib/common/plugin/FileError.js
define("cordova/plugin/FileError", function(require, exports, module) {
+
/**
* FileError
*/
@@ -2343,10 +2400,12 @@ FileError.TYPE_MISMATCH_ERR = 11;
FileError.PATH_EXISTS_ERR = 12;
module.exports = FileError;
+
});
// file: lib/common/plugin/FileReader.js
define("cordova/plugin/FileReader", function(require, exports, module) {
+
var exec = require('cordova/exec'),
FileError = require('cordova/plugin/FileError'),
ProgressEvent = require('cordova/plugin/ProgressEvent');
@@ -2596,10 +2655,12 @@ FileReader.prototype.readAsArrayBuffer = function(file) {
};
module.exports = FileReader;
+
});
// file: lib/common/plugin/FileSystem.js
define("cordova/plugin/FileSystem", function(require, exports, module) {
+
var DirectoryEntry = require('cordova/plugin/DirectoryEntry');
/**
@@ -2622,6 +2683,7 @@ module.exports = FileSystem;
// file: lib/common/plugin/FileTransfer.js
define("cordova/plugin/FileTransfer", function(require, exports, module) {
+
var exec = require('cordova/exec'),
FileTransferError = require('cordova/plugin/FileTransferError');
@@ -2714,6 +2776,7 @@ module.exports = FileTransfer;
// file: lib/common/plugin/FileTransferError.js
define("cordova/plugin/FileTransferError", function(require, exports, module) {
+
/**
* FileTransferError
* @constructor
@@ -2735,6 +2798,7 @@ module.exports = FileTransferError;
// file: lib/common/plugin/FileUploadOptions.js
define("cordova/plugin/FileUploadOptions", function(require, exports, module) {
+
/**
* Options to customize the HTTP request used to upload files.
* @constructor
@@ -2759,6 +2823,7 @@ module.exports = FileUploadOptions;
// file: lib/common/plugin/FileUploadResult.js
define("cordova/plugin/FileUploadResult", function(require, exports, module) {
+
/**
* FileUploadResult
* @constructor
@@ -2770,10 +2835,12 @@ var FileUploadResult = function() {
};
module.exports = FileUploadResult;
+
});
// file: lib/common/plugin/FileWriter.js
define("cordova/plugin/FileWriter", function(require, exports, module) {
+
var exec = require('cordova/exec'),
FileError = require('cordova/plugin/FileError'),
ProgressEvent = require('cordova/plugin/ProgressEvent');
@@ -3032,6 +3099,7 @@ module.exports = FileWriter;
// file: lib/common/plugin/Flags.js
define("cordova/plugin/Flags", function(require, exports, module) {
+
/**
* Supplies arguments to methods that lookup or create files and directories.
*
@@ -3047,10 +3115,12 @@ function Flags(create, exclusive) {
}
module.exports = Flags;
+
});
// file: lib/common/plugin/LocalFileSystem.js
define("cordova/plugin/LocalFileSystem", function(require, exports, module) {
+
var exec = require('cordova/exec');
/**
@@ -3064,10 +3134,12 @@ LocalFileSystem.TEMPORARY = 0; //temporary, with no guarantee of persistence
LocalFileSystem.PERSISTENT = 1; //persistent
module.exports = LocalFileSystem;
+
});
// file: lib/common/plugin/Media.js
define("cordova/plugin/Media", function(require, exports, module) {
+
var utils = require('cordova/utils'),
exec = require('cordova/exec');
@@ -3259,10 +3331,12 @@ Media.onStatus = function(id, msgType, value) {
};
module.exports = Media;
+
});
// file: lib/common/plugin/MediaError.js
define("cordova/plugin/MediaError", function(require, exports, module) {
+
/**
* This class contains information about any Media errors.
*/
@@ -3299,6 +3373,7 @@ module.exports = MediaError;
// file: lib/common/plugin/MediaFile.js
define("cordova/plugin/MediaFile", function(require, exports, module) {
+
var utils = require('cordova/utils'),
exec = require('cordova/exec'),
File = require('cordova/plugin/File'),
@@ -3338,6 +3413,7 @@ module.exports = MediaFile;
// file: lib/common/plugin/MediaFileData.js
define("cordova/plugin/MediaFileData", function(require, exports, module) {
+
/**
* MediaFileData encapsulates format information of a media file.
*
@@ -3356,10 +3432,12 @@ var MediaFileData = function(codecs, bitrate, height, width, duration){
};
module.exports = MediaFileData;
+
});
// file: lib/common/plugin/Metadata.js
define("cordova/plugin/Metadata", function(require, exports, module) {
+
/**
* Information about the state of the file or directory
*
@@ -3370,10 +3448,12 @@ var Metadata = function(time) {
};
module.exports = Metadata;
+
});
// file: lib/common/plugin/Position.js
define("cordova/plugin/Position", function(require, exports, module) {
+
var Coordinates = require('cordova/plugin/Coordinates');
var Position = function(coords, timestamp) {
@@ -3391,6 +3471,7 @@ module.exports = Position;
// file: lib/common/plugin/PositionError.js
define("cordova/plugin/PositionError", function(require, exports, module) {
+
/**
* Position error object
*
@@ -3408,10 +3489,12 @@ PositionError.POSITION_UNAVAILABLE = 2;
PositionError.TIMEOUT = 3;
module.exports = PositionError;
+
});
// file: lib/common/plugin/ProgressEvent.js
define("cordova/plugin/ProgressEvent", function(require, exports, module) {
+
// If ProgressEvent exists in global context, use it already, otherwise use our own polyfill
// Feature test: See if we can instantiate a native ProgressEvent;
// if so, use that approach,
@@ -3458,10 +3541,12 @@ var ProgressEvent = (function() {
})();
module.exports = ProgressEvent;
+
});
// file: lib/common/plugin/accelerometer.js
define("cordova/plugin/accelerometer", function(require, exports, module) {
+
/**
* This class provides access to device accelerometer data.
* @constructor
@@ -3622,6 +3707,7 @@ module.exports = accelerometer;
// file: lib/android/plugin/android/app.js
define("cordova/plugin/android/app", function(require, exports, module) {
+
var exec = require('cordova/exec');
module.exports = {
@@ -3693,10 +3779,12 @@ module.exports = {
return exec(null, null, "App", "exitApp", []);
}
};
+
});
// file: lib/android/plugin/android/callback.js
define("cordova/plugin/android/callback", function(require, exports, module) {
+
var port = null,
token = null,
xmlhttp;
@@ -3717,17 +3805,8 @@ function startXhr() {
// Need to url decode the response
var msg = decodeURIComponent(xmlhttp.responseText);
- setTimeout(function() {
- try {
- var t = eval(msg);
- }
- catch (e) {
- // If we're getting an error here, seeing the message will help in debugging
- console.log("JSCallback: Message from Server: " + msg);
- console.log("JSCallback Error: "+e);
- }
- }, 1);
setTimeout(startXhr, 1);
+ exec.processMessages(msg);
}
// If callback ping (used to keep XHR request from timing out)
@@ -3779,6 +3858,7 @@ module.exports = {
// file: lib/android/plugin/android/device.js
define("cordova/plugin/android/device", function(require, exports, module) {
+
var channel = require('cordova/channel'),
utils = require('cordova/utils'),
exec = require('cordova/exec'),
@@ -3821,8 +3901,24 @@ module.exports = {
});
+// file: lib/android/plugin/android/nativeapiprovider.js
+define("cordova/plugin/android/nativeapiprovider", function(require, exports, module) {
+
+var nativeApi = this._cordovaNative || require('cordova/plugin/android/promptbasednativeapi');
+var currentApi = nativeApi;
+
+module.exports = {
+ get: function() { return currentApi },
+ setPreferPrompt: function(value) {
+ currentApi = value ? require('cordova/plugin/android/promptbasednativeapi') : nativeApi;
+ }
+};
+
+});
+
// file: lib/android/plugin/android/notification.js
define("cordova/plugin/android/notification", function(require, exports, module) {
+
var exec = require('cordova/exec');
/**
@@ -3876,38 +3972,29 @@ module.exports = {
exec(null, null, 'Notification', 'progressValue', [ value ]);
}
};
+
});
// file: lib/android/plugin/android/polling.js
define("cordova/plugin/android/polling", function(require, exports, module) {
+
var cordova = require('cordova'),
+ nativeApiProvider = require('cordova/plugin/android/nativeapiprovider'),
POLL_INTERVAL = 50,
enabled = false;
function pollOnce() {
- var msg = prompt("", "gap_poll:");
- if (msg) {
- try {
- eval(""+msg);
- }
- catch (e) {
- console.log("JSCallbackPolling: Message from Server: " + msg);
- console.log("JSCallbackPolling Error: "+e);
- }
- return true;
- }
- return false;
+ var exec = require('cordova/exec'),
+ msg = nativeApiProvider.get().retrieveJsMessages();
+ exec.processMessages(msg);
}
function doPoll() {
if (!enabled) {
return;
}
- var nextDelay = POLL_INTERVAL;
- if (pollOnce()) {
- nextDelay = 0;
- }
- setTimeout(doPoll, nextDelay);
+ pollOnce();
+ setTimeout(doPoll, POLL_INTERVAL);
}
module.exports = {
@@ -3924,8 +4011,26 @@ module.exports = {
});
+// file: lib/android/plugin/android/promptbasednativeapi.js
+define("cordova/plugin/android/promptbasednativeapi", function(require, exports, module) {
+
+module.exports = {
+ exec: function(service, action, callbackId, argsJson) {
+ return prompt(argsJson, 'gap:'+JSON.stringify([service, action, callbackId]));
+ },
+ setNativeToJsBridgeMode: function(value) {
+ prompt(value, 'gap_bridge_mode:');
+ },
+ retrieveJsMessages: function() {
+ return prompt('', 'gap_poll:');
+ }
+};
+
+});
+
// file: lib/android/plugin/android/storage.js
define("cordova/plugin/android/storage", function(require, exports, module) {
+
var utils = require('cordova/utils'),
exec = require('cordova/exec'),
channel = require('cordova/channel');
@@ -4308,6 +4413,7 @@ module.exports = {
// file: lib/common/plugin/battery.js
define("cordova/plugin/battery", function(require, exports, module) {
+
/**
* This class contains information about the current battery status.
* @constructor
@@ -4325,34 +4431,26 @@ var Battery = function() {
this._level = null;
this._isPlugged = null;
// Create new event handlers on the window (returns a channel instance)
- var subscriptionEvents = {
- onSubscribe:this.onSubscribe,
- onUnsubscribe:this.onUnsubscribe
- };
this.channels = {
- batterystatus:cordova.addWindowEventHandler("batterystatus", subscriptionEvents),
- batterylow:cordova.addWindowEventHandler("batterylow", subscriptionEvents),
- batterycritical:cordova.addWindowEventHandler("batterycritical", subscriptionEvents)
+ batterystatus:cordova.addWindowEventHandler("batterystatus"),
+ batterylow:cordova.addWindowEventHandler("batterylow"),
+ batterycritical:cordova.addWindowEventHandler("batterycritical")
};
+ for (var key in this.channels) {
+ this.channels[key].onHasSubscribersChange = Battery.onHasSubscribersChange;
+ }
+
};
/**
* Event handlers for when callbacks get registered for the battery.
* Keep track of how many handlers we have so we can start and stop the native battery listener
* appropriately (and hopefully save on battery life!).
*/
-Battery.prototype.onSubscribe = function() {
- var me = battery;
+Battery.onHasSubscribersChange = function() {
// If we just registered the first handler, make sure native listener is started.
- if (handlers() === 1) {
- exec(me._status, me._error, "Battery", "start", []);
- }
-};
-
-Battery.prototype.onUnsubscribe = function() {
- var me = battery;
-
- // If we just unregistered the last handler, make sure native listener is stopped.
- if (handlers() === 0) {
+ if (this.numHandlers === 1 && handlers() === 1) {
+ exec(battery._status, battery._error, "Battery", "start", []);
+ } else if (handlers() === 0) {
exec(null, null, "Battery", "stop", []);
}
};
@@ -4395,10 +4493,12 @@ Battery.prototype._error = function(e) {
var battery = new Battery();
module.exports = battery;
+
});
// file: lib/common/plugin/capture.js
define("cordova/plugin/capture", function(require, exports, module) {
+
var exec = require('cordova/exec'),
MediaFile = require('cordova/plugin/MediaFile');
@@ -4476,6 +4576,7 @@ module.exports = new Capture();
// file: lib/common/plugin/compass.js
define("cordova/plugin/compass", function(require, exports, module) {
+
var exec = require('cordova/exec'),
utils = require('cordova/utils'),
CompassHeading = require('cordova/plugin/CompassHeading'),
@@ -4577,10 +4678,12 @@ var exec = require('cordova/exec'),
};
module.exports = compass;
+
});
// file: lib/common/plugin/console-via-logger.js
define("cordova/plugin/console-via-logger", function(require, exports, module) {
+
//------------------------------------------------------------------------------
var logger = require("cordova/plugin/logger");
@@ -4752,6 +4855,7 @@ for (var key in console) {
// file: lib/common/plugin/contacts.js
define("cordova/plugin/contacts", function(require, exports, module) {
+
var exec = require('cordova/exec'),
ContactError = require('cordova/plugin/ContactError'),
utils = require('cordova/utils'),
@@ -4815,6 +4919,7 @@ module.exports = contacts;
// file: lib/common/plugin/device.js
define("cordova/plugin/device", function(require, exports, module) {
+
var channel = require('cordova/channel'),
utils = require('cordova/utils'),
exec = require('cordova/exec');
@@ -4837,7 +4942,7 @@ function Device() {
var me = this;
- channel.onCordovaReady.subscribeOnce(function() {
+ channel.onCordovaReady.subscribe(function() {
me.getInfo(function(info) {
me.available = true;
me.platform = info.platform;
@@ -4883,6 +4988,7 @@ module.exports = new Device();
// file: lib/common/plugin/echo.js
define("cordova/plugin/echo", function(require, exports, module) {
+
var exec = require('cordova/exec');
/**
@@ -4902,6 +5008,7 @@ module.exports = function(successCallback, errorCallback, message, forceAsync) {
// file: lib/common/plugin/geolocation.js
define("cordova/plugin/geolocation", function(require, exports, module) {
+
var utils = require('cordova/utils'),
exec = require('cordova/exec'),
PositionError = require('cordova/plugin/PositionError'),
@@ -4966,11 +5073,11 @@ var geolocation = {
// Timer var that will fire an error callback if no position is retrieved from native
// before the "timeout" param provided expires
- var timeoutTimer = null;
+ var timeoutTimer = {timer:null};
var win = function(p) {
- clearTimeout(timeoutTimer);
- if (!timeoutTimer) {
+ clearTimeout(timeoutTimer.timer);
+ if (!(timeoutTimer.timer)) {
// Timeout already happened, or native fired error callback for
// this geo request.
// Don't continue with success callback.
@@ -4992,8 +5099,8 @@ var geolocation = {
successCallback(pos);
};
var fail = function(e) {
- clearTimeout(timeoutTimer);
- timeoutTimer = null;
+ clearTimeout(timeoutTimer.timer);
+ timeoutTimer.timer = null;
var err = new PositionError(e.code, e.message);
if (errorCallback) {
errorCallback(err);
@@ -5016,12 +5123,12 @@ var geolocation = {
// If the timeout value was not set to Infinity (default), then
// set up a timeout function that will fire the error callback
// if no successful position was retrieved before timeout expired.
- timeoutTimer = createTimeout(fail, options.timeout);
+ timeoutTimer.timer = createTimeout(fail, options.timeout);
} else {
// This is here so the check in the win function doesn't mess stuff up
// may seem weird but this guarantees timeoutTimer is
// always truthy before we call into native
- timeoutTimer = true;
+ timeoutTimer.timer = true;
}
exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.maximumAge]);
}
@@ -5048,7 +5155,7 @@ var geolocation = {
timers[id] = geolocation.getCurrentPosition(successCallback, errorCallback, options);
var fail = function(e) {
- clearTimeout(timers[id]);
+ clearTimeout(timers[id].timer);
var err = new PositionError(e.code, e.message);
if (errorCallback) {
errorCallback(err);
@@ -5056,9 +5163,9 @@ var geolocation = {
};
var win = function(p) {
- clearTimeout(timers[id]);
+ clearTimeout(timers[id].timer);
if (options.timeout !== Infinity) {
- timers[id] = createTimeout(fail, options.timeout);
+ timers[id].timer = createTimeout(fail, options.timeout);
}
var pos = new Position(
{
@@ -5087,8 +5194,8 @@ var geolocation = {
*/
clearWatch:function(id) {
if (id && timers[id] !== undefined) {
- clearTimeout(timers[id]);
- delete timers[id];
+ clearTimeout(timers[id].timer);
+ timers[id].timer = false;
exec(null, null, "Geolocation", "clearWatch", [id]);
}
}
@@ -5100,6 +5207,7 @@ module.exports = geolocation;
// file: lib/common/plugin/logger.js
define("cordova/plugin/logger", function(require, exports, module) {
+
//------------------------------------------------------------------------------
// The logger module exports the following properties/functions:
//
@@ -5327,9 +5435,20 @@ document.addEventListener("deviceready", logger.__onDeviceReady, false);
// file: lib/common/plugin/network.js
define("cordova/plugin/network", function(require, exports, module) {
+
var exec = require('cordova/exec'),
cordova = require('cordova'),
- channel = require('cordova/channel');
+ channel = require('cordova/channel'),
+ utils = require('cordova/utils');
+
+// Link the onLine property with the Cordova-supplied network info.
+// This works because we clobber the naviagtor object with our own
+// object in bootstrap.js.
+if (typeof navigator != 'undefined') {
+ utils.defineGetter(navigator, 'onLine', function() {
+ return this.connection.type != 'none';
+ });
+}
var NetworkConnection = function () {
this.type = null;
@@ -5339,7 +5458,7 @@ var NetworkConnection = function () {
var me = this;
- channel.onCordovaReady.subscribeOnce(function() {
+ channel.onCordovaReady.subscribe(function() {
me.getInfo(function (info) {
me.type = info;
if (info === "none") {
@@ -5387,10 +5506,12 @@ NetworkConnection.prototype.getInfo = function (successCallback, errorCallback)
};
module.exports = new NetworkConnection();
+
});
// file: lib/common/plugin/notification.js
define("cordova/plugin/notification", function(require, exports, module) {
+
var exec = require('cordova/exec');
/**
@@ -5447,10 +5568,12 @@ module.exports = {
exec(null, null, "Notification", "beep", [count]);
}
};
+
});
// file: lib/common/plugin/requestFileSystem.js
define("cordova/plugin/requestFileSystem", function(require, exports, module) {
+
var FileError = require('cordova/plugin/FileError'),
FileSystem = require('cordova/plugin/FileSystem'),
exec = require('cordova/exec');
@@ -5491,10 +5614,12 @@ var requestFileSystem = function(type, size, successCallback, errorCallback) {
};
module.exports = requestFileSystem;
+
});
// file: lib/common/plugin/resolveLocalFileSystemURI.js
define("cordova/plugin/resolveLocalFileSystemURI", function(require, exports, module) {
+
var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
FileEntry = require('cordova/plugin/FileEntry'),
FileError = require('cordova/plugin/FileError'),
@@ -5548,6 +5673,7 @@ module.exports = function(uri, successCallback, errorCallback) {
// file: lib/common/plugin/splashscreen.js
define("cordova/plugin/splashscreen", function(require, exports, module) {
+
var exec = require('cordova/exec');
var splashscreen = {
@@ -5560,13 +5686,26 @@ var splashscreen = {
};
module.exports = splashscreen;
+
});
// file: lib/common/utils.js
define("cordova/utils", function(require, exports, module) {
+
var utils = exports;
/**
+ * Defines a property getter for obj[key].
+ */
+utils.defineGetter = function(obj, key, func) {
+ if (Object.defineProperty) {
+ Object.defineProperty(obj, key, { get: func });
+ } else {
+ obj.__defineGetter__(key, func);
+ }
+};
+
+/**
* Returns an indication of whether the argument is an array or not
*/
utils.isArray = function(a) {
@@ -5757,7 +5896,16 @@ function formatted(object, formatChar) {
window.cordova = require('cordova');
// file: lib/scripts/bootstrap.js
+
(function (context) {
+ // Replace navigator before any modules are required(), to ensure it happens as soon as possible.
+ // We replace it so that properties that can't be clobbered can instead be overridden.
+ if (typeof navigator != 'undefined') {
+ function CordovaNavigator() {}
+ CordovaNavigator.prototype = navigator;
+ navigator = new CordovaNavigator();
+ }
+
var channel = require("cordova/channel"),
_self = {
boot: function () {
@@ -5799,7 +5947,7 @@ window.cordova = require('cordova');
};
// boot up once native side is ready
- channel.onNativeReady.subscribeOnce(_self.boot);
+ channel.onNativeReady.subscribe(_self.boot);
// _nativeReady is global variable that the native side can set
// to signify that the native code is ready. It is a global since