Updated Branches: refs/heads/master fe04a3617 -> c5b7427a6
Update cordova.ios.js. Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/c5b7427a Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/c5b7427a Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/c5b7427a Branch: refs/heads/master Commit: c5b7427a6226f7b418dcc88785b56fb961e2047d Parents: fe04a36 Author: Andrew Grieve <agri...@chromium.org> Authored: Tue Sep 18 11:53:10 2012 -0400 Committer: Andrew Grieve <agri...@chromium.org> Committed: Tue Sep 18 11:53:10 2012 -0400 ---------------------------------------------------------------------- CordovaLib/javascript/cordova.ios.js | 528 ++++++++++++++++++----------- 1 files changed, 336 insertions(+), 192 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/c5b7427a/CordovaLib/javascript/cordova.ios.js ---------------------------------------------------------------------- diff --git a/CordovaLib/javascript/cordova.ios.js b/CordovaLib/javascript/cordova.ios.js index e96ef50..cce90a9 100644 --- a/CordovaLib/javascript/cordova.ios.js +++ b/CordovaLib/javascript/cordova.ios.js @@ -1,6 +1,6 @@ -// commit 143f5221a6251c9cbccdedc57005c61551b97f12 +// commit d30179b30152b9383a80637e609cf2d785e1aa3e -// File generated at :: Wed Sep 12 2012 15:26: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; + } + 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].factory ? build(modules[id]) : modules[id].exports; + 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)); + }, + addStickyDocumentEventHandler:function(event) { + return (documentEventHandlers[event] = channel.createSticky(event)); }, - addDocumentEventHandler:function(event, opts) { - return (documentEventHandlers[event] = channel.create(event, opts)); + 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) { + return channel[type] = new Channel(type, false); }, - create: function (type, opts) { - channel[type] = new Channel(type, opts); - return channel[type]; + 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/ios/exec.js define("cordova/exec", function(require, exports, module) { + /** * Creates a gap bridge iframe used to notify the native code about queued * commands. @@ -918,7 +931,7 @@ function shouldBundleCommandJson() { } function iOSExec() { - if (!channel.onCordovaReady.fired) { + if (channel.onCordovaReady.state != 2) { utils.alert("ERROR: Attempting to call cordova.exec()" + " before 'deviceready'. Ignoring."); return; @@ -1003,6 +1016,7 @@ module.exports = iOSExec; // file: lib/ios/platform.js define("cordova/platform", function(require, exports, module) { + module.exports = { id: "ios", initialize:function() { @@ -1059,6 +1073,7 @@ logger.useConsole(false); // 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; @@ -1072,6 +1087,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'); @@ -1188,10 +1204,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 @@ -1219,10 +1237,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'); /** @@ -1239,10 +1259,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. */ @@ -1256,10 +1278,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. */ @@ -1279,10 +1303,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. */ @@ -1294,10 +1320,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. */ @@ -1311,10 +1339,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 @@ -1328,10 +1358,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); @@ -1340,10 +1372,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. */ @@ -1359,10 +1393,12 @@ function ConfigurationData() { } module.exports = ConfigurationData; + }); // file: lib/common/plugin/Connection.js define("cordova/plugin/Connection", function(require, exports, module) { + /** * Network status */ @@ -1375,10 +1411,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'); @@ -1561,6 +1599,7 @@ module.exports = Contact; // file: lib/common/plugin/ContactAddress.js define("cordova/plugin/ContactAddress", function(require, exports, module) { + /** * Contact address. * @constructor @@ -1586,10 +1625,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 @@ -1611,10 +1652,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 @@ -1631,10 +1674,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 @@ -1648,10 +1693,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 @@ -1672,10 +1719,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 @@ -1699,10 +1748,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 @@ -1756,6 +1807,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'), @@ -1842,6 +1894,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') ; @@ -1889,6 +1942,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'); @@ -2107,10 +2161,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 @@ -2129,10 +2185,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'), @@ -2196,10 +2254,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 */ @@ -2225,10 +2285,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'); @@ -2478,10 +2540,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'); /** @@ -2504,6 +2568,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'); @@ -2596,6 +2661,7 @@ module.exports = FileTransfer; // file: lib/common/plugin/FileTransferError.js define("cordova/plugin/FileTransferError", function(require, exports, module) { + /** * FileTransferError * @constructor @@ -2617,6 +2683,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 @@ -2641,6 +2708,7 @@ module.exports = FileUploadOptions; // file: lib/common/plugin/FileUploadResult.js define("cordova/plugin/FileUploadResult", function(require, exports, module) { + /** * FileUploadResult * @constructor @@ -2652,10 +2720,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'); @@ -2914,6 +2984,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. * @@ -2929,10 +3000,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'); /** @@ -2946,10 +3019,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'); @@ -3141,10 +3216,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. */ @@ -3181,6 +3258,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'), @@ -3220,6 +3298,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. * @@ -3238,10 +3317,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 * @@ -3252,10 +3333,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) { @@ -3273,6 +3356,7 @@ module.exports = Position; // file: lib/common/plugin/PositionError.js define("cordova/plugin/PositionError", function(require, exports, module) { + /** * Position error object * @@ -3290,10 +3374,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, @@ -3340,10 +3426,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 @@ -3504,6 +3592,7 @@ module.exports = accelerometer; // file: lib/common/plugin/battery.js define("cordova/plugin/battery", function(require, exports, module) { + /** * This class contains information about the current battery status. * @constructor @@ -3521,34 +3610,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", []); } }; @@ -3591,10 +3672,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'); @@ -3672,6 +3755,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'), @@ -3773,10 +3857,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"); @@ -3948,6 +4034,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'), @@ -4011,6 +4098,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'); @@ -4033,7 +4121,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; @@ -4079,6 +4167,7 @@ module.exports = new Device(); // file: lib/common/plugin/echo.js define("cordova/plugin/echo", function(require, exports, module) { + var exec = require('cordova/exec'); /** @@ -4098,6 +4187,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'), @@ -4162,11 +4252,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. @@ -4188,8 +4278,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); @@ -4212,12 +4302,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]); } @@ -4244,7 +4334,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); @@ -4252,9 +4342,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( { @@ -4283,8 +4373,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]); } } @@ -4296,6 +4386,7 @@ module.exports = geolocation; // file: lib/ios/plugin/ios/Contact.js define("cordova/plugin/ios/Contact", function(require, exports, module) { + var exec = require('cordova/exec'), ContactError = require('cordova/plugin/ContactError'); @@ -4326,10 +4417,12 @@ module.exports = { } } }; + }); // file: lib/ios/plugin/ios/Entry.js define("cordova/plugin/ios/Entry", function(require, exports, module) { + module.exports = { toURL:function() { // TODO: refactor path in a cross-platform way so we can eliminate @@ -4341,10 +4434,12 @@ module.exports = { return "file://localhost" + this.fullPath; } }; + }); // file: lib/ios/plugin/ios/FileReader.js define("cordova/plugin/ios/FileReader", function(require, exports, module) { + var exec = require('cordova/exec'), FileError = require('cordova/plugin/FileError'), FileReader = require('cordova/plugin/FileReader'), @@ -4432,10 +4527,12 @@ module.exports = { "File", "readAsText", [this.fileName, enc]); } }; + }); // file: lib/ios/plugin/ios/console.js define("cordova/plugin/ios/console", function(require, exports, module) { + var exec = require('cordova/exec'); /** @@ -4515,10 +4612,12 @@ DebugConsole.prototype.error = function(message) { }; module.exports = new DebugConsole(); + }); // file: lib/ios/plugin/ios/contacts.js define("cordova/plugin/ios/contacts", function(require, exports, module) { + var exec = require('cordova/exec'); /** @@ -4560,10 +4659,12 @@ module.exports = { exec(win, null, "Contacts","chooseContact", [options]); } }; + }); // file: lib/ios/plugin/ios/nativecomm.js define("cordova/plugin/ios/nativecomm", function(require, exports, module) { + var cordova = require('cordova'); /** @@ -4580,6 +4681,7 @@ module.exports = function() { // file: lib/ios/plugin/ios/notification.js define("cordova/plugin/ios/notification", function(require, exports, module) { + var Media = require('cordova/plugin/Media'); module.exports = { @@ -4587,10 +4689,12 @@ module.exports = { (new Media('beep.wav')).play(); } }; + }); // file: lib/common/plugin/logger.js define("cordova/plugin/logger", function(require, exports, module) { + //------------------------------------------------------------------------------ // The logger module exports the following properties/functions: // @@ -4818,9 +4922,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; @@ -4830,7 +4945,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") { @@ -4878,10 +4993,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'); /** @@ -4938,10 +5055,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'); @@ -4982,10 +5101,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'), @@ -5039,6 +5160,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 = { @@ -5051,13 +5173,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) { @@ -5248,7 +5383,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 () { @@ -5290,7 +5434,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