You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pm...@apache.org on 2012/03/22 13:50:23 UTC
[9/12] 2nd try at file refactoring
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/compass.js
----------------------------------------------------------------------
diff --git a/lib/plugin/compass.js b/lib/plugin/compass.js
deleted file mode 100644
index 1685f2d..0000000
--- a/lib/plugin/compass.js
+++ /dev/null
@@ -1,90 +0,0 @@
-var exec = require('cordova/exec'),
- utils = require('cordova/utils'),
- CompassHeading = require('cordova/plugin/CompassHeading'),
- CompassError = require('cordova/plugin/CompassError'),
- timers = {},
- compass = {
- /**
- * Asynchronously acquires the current heading.
- * @param {Function} successCallback The function to call when the heading
- * data is available
- * @param {Function} errorCallback The function to call when there is an error
- * getting the heading data.
- * @param {CompassOptions} options The options for getting the heading data (not used).
- */
- getCurrentHeading:function(successCallback, errorCallback) {
- // successCallback required
- if (typeof successCallback !== "function") {
- console.log("Compass Error: successCallback is not a function");
- return;
- }
-
- // errorCallback optional
- if (errorCallback && (typeof errorCallback !== "function")) {
- console.log("Compass Error: errorCallback is not a function");
- return;
- }
-
- var win = function(result) {
- var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy, result.timestamp);
- successCallback(ch);
- };
- var fail = function(code) {
- var ce = new CompassError(code);
- errorCallback(ce);
- }
-
- // Get heading
- exec(win, fail, "Compass", "getHeading", []);
- },
-
- /**
- * Asynchronously acquires the heading repeatedly at a given interval.
- * @param {Function} successCallback The function to call each time the heading
- * data is available
- * @param {Function} errorCallback The function to call when there is an error
- * getting the heading data.
- * @param {HeadingOptions} options The options for getting the heading data
- * such as timeout and the frequency of the watch.
- */
- watchHeading:function(successCallback, errorCallback, options) {
- // Default interval (100 msec)
- var frequency = (options !== undefined && options.frequency !== undefined) ? options.frequency : 100;
-
- // successCallback required
- if (typeof successCallback !== "function") {
- console.log("Compass Error: successCallback is not a function");
- return;
- }
-
- // errorCallback optional
- if (errorCallback && (typeof errorCallback !== "function")) {
- console.log("Compass Error: errorCallback is not a function");
- return;
- }
-
- // Start watch timer to get headings
- var id = utils.createUUID();
-
- timers[id] = window.setInterval(function() {
- compass.getCurrentHeading(successCallback, errorCallback);
- }, frequency);
-
- return id;
- },
-
- /**
- * Clears the specified heading watch.
- * @param {String} watchId The ID of the watch returned from #watchHeading.
- */
- clearWatch:function(id) {
- // Stop javascript timer & remove from timer list
- if (id && timers[id]) {
- clearInterval(timers[id]);
- delete timers[id];
- }
- }
- // TODO: add the filter-based iOS-only methods
- };
-
-module.exports = compass;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/contacts.js
----------------------------------------------------------------------
diff --git a/lib/plugin/contacts.js b/lib/plugin/contacts.js
deleted file mode 100644
index 7212f7b..0000000
--- a/lib/plugin/contacts.js
+++ /dev/null
@@ -1,57 +0,0 @@
-var exec = require('cordova/exec'),
- ContactError = require('cordova/plugin/ContactError'),
- Contact = require('cordova/plugin/Contact');
-
-/**
-* Represents a group of Contacts.
-* @constructor
-*/
-var contacts = {
- /**
- * Returns an array of Contacts matching the search criteria.
- * @param fields that should be searched
- * @param successCB success callback
- * @param errorCB error callback
- * @param {ContactFindOptions} options that can be applied to contact searching
- * @return array of Contacts matching search criteria
- */
- find:function(fields, successCB, errorCB, options) {
- if (!successCB) {
- throw new TypeError("You must specify a success callback for the find command.");
- }
- if (!fields || (fields instanceof Array && fields.length === 0)) {
- if (typeof errorCB === "function") {
- errorCB(new ContactError(ContactError.INVALID_ARGUMENT_ERROR));
- }
- } else {
- var win = function(result) {
- var cs = [];
- for (var i = 0, l = result.length; i < l; i++) {
- cs.push(contacts.create(result[i]));
- }
- successCB(cs);
- };
- exec(win, errorCB, "Contacts", "search", [fields, options]);
- }
- },
-
- /**
- * This function creates a new contact, but it does not persist the contact
- * to device storage. To persist the contact to device storage, invoke
- * contact.save().
- * @param properties an object who's properties will be examined to create a new Contact
- * @returns new Contact object
- */
- create:function(properties) {
- var i;
- var contact = new Contact();
- for (i in properties) {
- if (typeof contact[i] !== 'undefined' && properties.hasOwnProperty(i)) {
- contact[i] = properties[i];
- }
- }
- return contact;
- }
-};
-
-module.exports = contacts;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/errgen/device.js
----------------------------------------------------------------------
diff --git a/lib/plugin/errgen/device.js b/lib/plugin/errgen/device.js
deleted file mode 100644
index 4e05777..0000000
--- a/lib/plugin/errgen/device.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * this represents the mobile device, and provides properties for inspecting the model, version, UUID of the
- * phone, etc.
- * @constructor
- */
-
-//------------------------------------------------------------------------------
-function Device() {
- window.DeviceInfo = {}
-
- this.platform = "errgen"
- this.version = "any"
- this.name = "errgen"
- this.phonegap = {}
- this.gap = this.phonegap
- this.uuid = "1234-5678-9012-3456"
- this.available = true
-
- require('cordova/channel').onCordovaInfoReady.fire()
-}
-
-//------------------------------------------------------------------------------
-module.exports = window.DeviceInfo = new Device()
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/geolocation.js
----------------------------------------------------------------------
diff --git a/lib/plugin/geolocation.js b/lib/plugin/geolocation.js
deleted file mode 100644
index e1169f6..0000000
--- a/lib/plugin/geolocation.js
+++ /dev/null
@@ -1,94 +0,0 @@
-var utils = require('cordova/utils'),
- exec = require('cordova/exec'),
- PositionError = require('cordova/plugin/PositionError'),
- Position = require('cordova/plugin/Position');
-
-var timers = {}; // list of timers in use
-
-// Returns default params, overrides if provided with values
-function parseParameters(options) {
- var opt = {
- maximumAge: 10000,
- enableHighAccuracy: false,
- timeout: 10000
- };
-
- if (options) {
- if (options.maximumAge !== undefined) {
- opt.maximumAge = options.maximumAge;
- }
- if (options.enableHighAccuracy !== undefined) {
- opt.enableHighAccuracy = options.enableHighAccuracy;
- }
- if (options.timeout !== undefined) {
- opt.timeout = options.timeout;
- }
- }
-
- return opt;
-}
-
-var geolocation = {
- /**
- * Asynchronously aquires the current position.
- *
- * @param {Function} successCallback The function to call when the position data is available
- * @param {Function} errorCallback The function to call when there is an error getting the heading position. (OPTIONAL)
- * @param {PositionOptions} options The options for getting the position data. (OPTIONAL)
- */
- getCurrentPosition:function(successCallback, errorCallback, options) {
- options = parseParameters(options);
-
- var win = function(p) {
- successCallback(new Position(
- {
- latitude:p.latitude,
- longitude:p.longitude,
- altitude:p.altitude,
- accuracy:p.accuracy,
- heading:p.heading,
- velocity:p.velocity,
- altitudeAccuracy:p.altitudeAccuracy
- },
- p.timestamp || new Date()
- ));
- };
- var fail = function(e) {
- errorCallback(new PositionError(e.code, e.message));
- };
-
- exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]);
- },
- /**
- * Asynchronously watches the geolocation for changes to geolocation. When a change occurs,
- * the successCallback is called with the new location.
- *
- * @param {Function} successCallback The function to call each time the location data is available
- * @param {Function} errorCallback The function to call when there is an error getting the location data. (OPTIONAL)
- * @param {PositionOptions} options The options for getting the location data such as frequency. (OPTIONAL)
- * @return String The watch id that must be passed to #clearWatch to stop watching.
- */
- watchPosition:function(successCallback, errorCallback, options) {
- options = parseParameters(options);
-
- var id = utils.createUUID();
- timers[id] = window.setInterval(function() {
- geolocation.getCurrentPosition(successCallback, errorCallback, options);
- }, options.timeout);
-
- return id;
- },
- /**
- * Clears the specified heading watch.
- *
- * @param {String} id The ID of the watch returned from #watchPosition
- */
- clearWatch:function(id) {
- if (id && timers[id] !== undefined) {
- window.clearInterval(timers[id]);
- delete timers[id];
- }
- }
-};
-
-module.exports = geolocation;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/ios/Entry.js
----------------------------------------------------------------------
diff --git a/lib/plugin/ios/Entry.js b/lib/plugin/ios/Entry.js
deleted file mode 100644
index 230da8a..0000000
--- a/lib/plugin/ios/Entry.js
+++ /dev/null
@@ -1,7 +0,0 @@
-module.exports = {
- toURL:function() {
- // TODO: refactor path in a cross-platform way so we can eliminate
- // these kinds of platform-specific hacks.
- return "file://localhost" + this.fullPath;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/ios/FileReader.js
----------------------------------------------------------------------
diff --git a/lib/plugin/ios/FileReader.js b/lib/plugin/ios/FileReader.js
deleted file mode 100644
index 5711393..0000000
--- a/lib/plugin/ios/FileReader.js
+++ /dev/null
@@ -1,87 +0,0 @@
-var exec = require('cordova/exec'),
- FileError = require('cordova/plugin/FileError'),
- FileReader = require('cordova/plugin/FileReader'),
- ProgressEvent = require('cordova/plugin/ProgressEvent');
-
-module.exports = {
- readAsText:function(file, encoding) {
- // Figure out pathing
- this.fileName = '';
- if (typeof file.fullPath === 'undefined') {
- this.fileName = file;
- } else {
- this.fileName = file.fullPath;
- }
-
- // Already loading something
- if (this.readyState == FileReader.LOADING) {
- throw new FileError(FileError.INVALID_STATE_ERR);
- }
-
- // LOADING state
- this.readyState = FileReader.LOADING;
-
- // If loadstart callback
- if (typeof this.onloadstart === "function") {
- this.onloadstart(new ProgressEvent("loadstart", {target:this}));
- }
-
- // Default encoding is UTF-8
- var enc = encoding ? encoding : "UTF-8";
-
- var me = this;
-
- // Read file
- exec(
- // Success callback
- function(r) {
- // If DONE (cancelled), then don't do anything
- if (me.readyState === FileReader.DONE) {
- return;
- }
-
- // Save result
- me.result = decodeURIComponent(r);
-
- // If onload callback
- if (typeof me.onload === "function") {
- me.onload(new ProgressEvent("load", {target:me}));
- }
-
- // DONE state
- me.readyState = FileReader.DONE;
-
- // If onloadend callback
- if (typeof me.onloadend === "function") {
- me.onloadend(new ProgressEvent("loadend", {target:me}));
- }
- },
- // Error callback
- function(e) {
- // If DONE (cancelled), then don't do anything
- if (me.readyState === FileReader.DONE) {
- return;
- }
-
- // DONE state
- me.readyState = FileReader.DONE;
-
- // null result
- me.result = null;
-
- // Save error
- me.error = new FileError(e);
-
- // If onerror callback
- if (typeof me.onerror === "function") {
- me.onerror(new ProgressEvent("error", {target:me}));
- }
-
- // If onloadend callback
- if (typeof me.onloadend === "function") {
- me.onloadend(new ProgressEvent("loadend", {target:me}));
- }
- },
- "File", "readAsText", [this.fileName, enc]);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/ios/console.js
----------------------------------------------------------------------
diff --git a/lib/plugin/ios/console.js b/lib/plugin/ios/console.js
deleted file mode 100644
index 8651591..0000000
--- a/lib/plugin/ios/console.js
+++ /dev/null
@@ -1,102 +0,0 @@
-var exec = require('cordova/exec');
-
-/**
- * String indentation/formatting
- */
-function indent(str) {
- return str.replace(/^/mg, " ");
-}
-/**
- * Format a string for pretty logging
- */
-function makeStructured(obj, depth) {
- var str = "";
- for (var i in obj) {
- try {
- if (typeof(obj[i]) == 'object' && depth < maxDepth) {
- str += i + ":\n" + indent(makeStructured(obj[i])) + "\n";
- } else {
- str += i + " = " + indent(String(obj[i])).replace(/^ {4}/, "") + "\n";
- }
- } catch(e) {
- str += i + " = EXCEPTION: " + e.message + "\n";
- }
- }
- return str;
-}
-
-/**
- * This class provides access to the debugging console.
- * @constructor
- */
-var DebugConsole = function() {
- this.winConsole = window.console;
- this.logLevel = DebugConsole.INFO_LEVEL;
-};
-
-// from most verbose, to least verbose
-DebugConsole.ALL_LEVEL = 1; // same as first level
-DebugConsole.INFO_LEVEL = 1;
-DebugConsole.WARN_LEVEL = 2;
-DebugConsole.ERROR_LEVEL = 4;
-DebugConsole.NONE_LEVEL = 8;
-
-DebugConsole.prototype.setLevel = function(level) {
- this.logLevel = level;
-};
-
-/**
- * Utility function for rendering and indenting strings, or serializing
- * objects to a string capable of being printed to the console.
- * @param {Object|String} message The string or object to convert to an indented string
- * @private
- */
-DebugConsole.prototype.processMessage = function(message, maxDepth) {
- if (maxDepth === undefined) maxDepth = 0;
- if (typeof(message) != 'object') {
- return (this.isDeprecated ? "WARNING: debug object is deprecated, please use console object \n" + message : message);
- } else {
- return ("Object:\n" + makeStructured(message, maxDepth));
- }
-};
-
-/**
- * Print a normal log message to the console
- * @param {Object|String} message Message or object to print to the console
- */
-DebugConsole.prototype.log = function(message, maxDepth) {
- if (this.logLevel <= DebugConsole.INFO_LEVEL)
- exec(null, null, 'Debug Console', 'log',
- [ this.processMessage(message, maxDepth), { logLevel: 'INFO' } ]
- );
- else
- this.winConsole.log(message);
-};
-
-/**
- * Print a warning message to the console
- * @param {Object|String} message Message or object to print to the console
- */
-DebugConsole.prototype.warn = function(message, maxDepth) {
- if (this.logLevel <= DebugConsole.WARN_LEVEL)
- exec(null, null, 'Debug Console', 'log',
- [ this.processMessage(message, maxDepth), { logLevel: 'WARN' } ]
- );
- else
- this.winConsole.error(message);
-};
-
-/**
- * Print an error message to the console
- * @param {Object|String} message Message or object to print to the console
- */
-DebugConsole.prototype.error = function(message, maxDepth) {
- if (this.logLevel <= DebugConsole.ERROR_LEVEL)
- exec(null, null, 'Debug Console', 'log',
- [ this.processMessage(message, maxDepth), { logLevel: 'ERROR' } ]
- );
- else
- this.winConsole.error(message);
-};
-
-module.exports = new DebugConsole();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/ios/device.js
----------------------------------------------------------------------
diff --git a/lib/plugin/ios/device.js b/lib/plugin/ios/device.js
deleted file mode 100644
index c6d117b..0000000
--- a/lib/plugin/ios/device.js
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * this represents the mobile device, and provides properties for inspecting the model, version, UUID of the
- * phone, etc.
- * @constructor
- */
-var exec = require('cordova/exec'),
- channel = require('cordova/channel');
-
-var Device = function() {
- this.platform = null;
- this.version = null;
- this.name = null;
- this.cordova = null;
- this.uuid = null;
-};
-
-Device.prototype.setInfo = function(info) {
- try {
- this.platform = info.platform;
- this.version = info.version;
- this.name = info.name;
- this.cordova = info.gap;
- this.uuid = info.uuid;
- channel.onCordovaInfoReady.fire();
- } catch(e) {
- alert('Error during device info setting in cordova/plugin/ios/device!');
- }
-};
-
-module.exports = new Device();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/ios/nativecomm.js
----------------------------------------------------------------------
diff --git a/lib/plugin/ios/nativecomm.js b/lib/plugin/ios/nativecomm.js
deleted file mode 100644
index 938a68c..0000000
--- a/lib/plugin/ios/nativecomm.js
+++ /dev/null
@@ -1,10 +0,0 @@
-var cordova = require('cordova');
-
-/**
- * Called by native code to retrieve all queued commands and clear the queue.
- */
-module.exports = function() {
- var json = JSON.stringify(cordova.commandQueue);
- cordova.commandQueue = [];
- return json;
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/ios/notification.js
----------------------------------------------------------------------
diff --git a/lib/plugin/ios/notification.js b/lib/plugin/ios/notification.js
deleted file mode 100644
index a49567d..0000000
--- a/lib/plugin/ios/notification.js
+++ /dev/null
@@ -1,7 +0,0 @@
-var Media = require('cordova/plugin/Media');
-
-module.exports = {
- beep:function(count) {
- (new Media('beep.wav')).play();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/network.js
----------------------------------------------------------------------
diff --git a/lib/plugin/network.js b/lib/plugin/network.js
deleted file mode 100644
index 29e1aee..0000000
--- a/lib/plugin/network.js
+++ /dev/null
@@ -1,59 +0,0 @@
-var exec = require('cordova/exec'),
- cordova = require('cordova'),
- channel = require('cordova/channel');
-
-var NetworkConnection = function () {
- this.type = null;
- this._firstRun = true;
- this._timer = null;
- this.timeout = 500;
-
- var me = this;
-
- this.getInfo(
- function (info) {
- me.type = info;
- if (info === "none") {
- // set a timer if still offline at the end of timer send the offline event
- me._timer = setTimeout(function(){
- cordova.fireDocumentEvent("offline");
- me._timer = null;
- }, me.timeout);
- } else {
- // If there is a current offline event pending clear it
- if (me._timer !== null) {
- clearTimeout(me._timer);
- me._timer = null;
- }
- cordova.fireDocumentEvent("online");
- }
-
- // should only fire this once
- if (me._firstRun) {
- me._firstRun = false;
- channel.onCordovaConnectionReady.fire();
- }
- },
- function (e) {
- // If we can't get the network info we should still tell Cordova
- // to fire the deviceready event.
- if (me._firstRun) {
- me._firstRun = false;
- channel.onCordovaConnectionReady.fire();
- }
- console.log("Error initializing Network Connection: " + e);
- });
-};
-
-/**
- * Get connection info
- *
- * @param {Function} successCallback The function to call when the Connection data is available
- * @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL)
- */
-NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) {
- // Get info
- exec(successCallback, errorCallback, "Network Status", "getConnectionInfo", []);
-};
-
-module.exports = new NetworkConnection();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/notification.js
----------------------------------------------------------------------
diff --git a/lib/plugin/notification.js b/lib/plugin/notification.js
deleted file mode 100644
index 305ee3d..0000000
--- a/lib/plugin/notification.js
+++ /dev/null
@@ -1,56 +0,0 @@
-var exec = require('cordova/exec');
-
-/**
- * Provides access to notifications on the device.
- */
-
-module.exports = {
-
- /**
- * Open a native alert dialog, with a customizable title and button text.
- *
- * @param {String} message Message to print in the body of the alert
- * @param {Function} completeCallback The callback that is called when user clicks on a button.
- * @param {String} title Title of the alert dialog (default: Alert)
- * @param {String} buttonLabel Label of the close button (default: OK)
- */
- alert: function(message, completeCallback, title, buttonLabel) {
- var _title = (title || "Alert");
- var _buttonLabel = (buttonLabel || "OK");
- exec(completeCallback, null, "Notification", "alert", [message, _title, _buttonLabel]);
- },
-
- /**
- * Open a native confirm dialog, with a customizable title and button text.
- * The result that the user selects is returned to the result callback.
- *
- * @param {String} message Message to print in the body of the alert
- * @param {Function} resultCallback The callback that is called when user clicks on a button.
- * @param {String} title Title of the alert dialog (default: Confirm)
- * @param {String} buttonLabels Comma separated list of the labels of the buttons (default: 'OK,Cancel')
- */
- confirm: function(message, resultCallback, title, buttonLabels) {
- var _title = (title || "Confirm");
- var _buttonLabels = (buttonLabels || "OK,Cancel");
- exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]);
- },
-
- /**
- * Causes the device to vibrate.
- *
- * @param {Integer} mills The number of milliseconds to vibrate for.
- */
- vibrate: function(mills) {
- exec(null, null, "Notification", "vibrate", [mills]);
- },
-
- /**
- * Causes the device to beep.
- * On Android, the default notification ringtone is played "count" times.
- *
- * @param {Integer} count The number of beeps.
- */
- beep: function(count) {
- exec(null, null, "Notification", "beep", [count]);
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/playbook/device.js
----------------------------------------------------------------------
diff --git a/lib/plugin/playbook/device.js b/lib/plugin/playbook/device.js
deleted file mode 100644
index 90ec376..0000000
--- a/lib/plugin/playbook/device.js
+++ /dev/null
@@ -1,23 +0,0 @@
-var me = {},
- exec = require('cordova/exec'),
- channel = require('cordova/channel');
-
-exec(
- function (device) {
- me.platform = device.platform;
- me.version = device.version;
- me.name = device.name;
- me.uuid = device.uuid;
- me.cordova = device.cordova;
-
- channel.onCordovaInfoReady.fire();
- },
- function (e) {
- console.log("error initializing cordova: " + e);
- },
- "Device",
- "getDeviceInfo",
- []
-);
-
-module.exports = me;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/playbook/manager.js
----------------------------------------------------------------------
diff --git a/lib/plugin/playbook/manager.js b/lib/plugin/playbook/manager.js
deleted file mode 100644
index 312a1d2..0000000
--- a/lib/plugin/playbook/manager.js
+++ /dev/null
@@ -1,285 +0,0 @@
-var webworks = require('cordova/plugin/webworks/manager'),
- cordova = require('cordova'),
- /**
- * Private list of HTML 5 audio objects, indexed by the Cordova media object ids
- */
- audioObjects = {},
- retInvalidAction = function () {
- return { "status" : cordova.callbackStatus.INVALID_ACTION, "message" : "Action not found" };
- },
- retAsyncCall = function () {
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- },
- cameraAPI = {
- execute: function (webWorksResult, action, args, win, fail) {
- if (action === 'takePicture') {
- blackberry.media.camera.takePicture(win, fail, fail);
- return retAsyncCall();
- }
- else {
- return retInvalidAction();
- }
- }
- },
- deviceAPI = {
- execute: function (webWorksResult, action, args, win, fail) {
- if (action === 'getDeviceInfo') {
- return {"status" : cordova.callbackStatus.OK,
- "message" : {
- "version" : blackberry.system.softwareVersion,
- "name" : blackberry.system.model,
- "uuid" : blackberry.identity.PIN,
- "platform" : "PlayBook",
- "cordova" : "1.4.1"
- }
- };
- }
- return retInvalidAction();
- }
- },
- loggerAPI = {
- execute: function (webWorksResult, action, args, win, fail) {
- if (action === 'log') {
- console.log(args);
- return {"status" : cordova.callbackStatus.OK,
- "message" : 'Message logged to console: ' + args};
- }
- else {
- return retInvalidAction();
- }
- }
- },
- mediaAPI = {
- execute: function (webWorksResult, action, args, win, fail) {
- if (!args.length) {
- return {"status" : 9, "message" : "Media Object id was not sent in arguments"};
- }
-
- var id = args[0],
- audio = audioObjects[id],
- result;
-
- switch (action) {
- case 'startPlayingAudio':
- if (args.length === 1) {
- result = {"status" : 9, "message" : "Media source argument not found"};
-
- }
-
- if (audio) {
- audio.pause();
- audioObjects[id] = undefined;
- }
-
- audio = audioObjects[id] = new Audio(args[1]);
- audio.play();
-
- result = {"status" : 1, "message" : "Audio play started" };
- break;
- case 'stopPlayingAudio':
- if (!audio) {
- return {"status" : 2, "message" : "Audio Object has not been initialized"};
- }
-
- audio.pause();
- audioObjects[id] = undefined;
-
- result = {"status" : 1, "message" : "Audio play stopped" };
- break;
- case 'seekToAudio':
- if (!audio) {
- result = {"status" : 2, "message" : "Audio Object has not been initialized"};
- } else if (args.length === 1) {
- result = {"status" : 9, "message" : "Media seek time argument not found"};
- } else {
- try {
- audio.currentTime = args[1];
- } catch (e) {
- console.log('Error seeking audio: ' + e);
- return {"status" : 3, "message" : "Error seeking audio: " + e};
- }
-
- result = {"status" : 1, "message" : "Seek to audio succeeded" };
- }
- break;
- case 'pausePlayingAudio':
- if (!audio) {
- return {"status" : 2, "message" : "Audio Object has not been initialized"};
- }
-
- audio.pause();
-
- result = {"status" : 1, "message" : "Audio paused" };
- break;
- case 'getCurrentPositionAudio':
- if (!audio) {
- return {"status" : 2, "message" : "Audio Object has not been initialized"};
- }
-
- result = {"status" : 1, "message" : audio.currentTime };
- break;
- case 'getDuration':
- if (!audio) {
- return {"status" : 2, "message" : "Audio Object has not been initialized"};
- }
-
- result = {"status" : 1, "message" : audio.duration };
- break;
- case 'startRecordingAudio':
- if (args.length <= 1) {
- result = {"status" : 9, "message" : "Media start recording, insufficient arguments"};
- }
-
- blackberry.media.microphone.record(args[1], win, fail);
- result = retAsyncCall();
- break;
- case 'stopRecordingAudio':
- break;
- case 'release':
- if (audio) {
- audioObjects[id] = undefined;
- audio.src = undefined;
- //delete audio;
- }
-
- result = {"status" : 1, "message" : "Media resources released"};
- break;
- default:
- result = retInvalidAction();
- }
-
- return result;
- }
- },
- mediaCaptureAPI = {
- execute: function (webWorksResult, action, args, win, fail) {
- var limit = args[0],
- pictureFiles = [],
- captureMethod;
-
- function captureCB(filePath) {
- var mediaFile;
-
- if (filePath) {
- mediaFile = new MediaFile();
- mediaFile.fullPath = filePath;
- pictureFiles.push(mediaFile);
- }
-
- if (limit > 0) {
- limit--;
- blackberry.media.camera[captureMethod](win, fail, fail);
- return;
- }
-
- win(pictureFiles);
-
- return retAsyncCall();
- }
-
- switch (action) {
- case 'getSupportedAudioModes':
- case 'getSupportedImageModes':
- case 'getSupportedVideoModes':
- return {"status": cordova.callbackStatus.OK, "message": []};
- case 'captureImage':
- captureMethod = "takePicture";
- captureCB();
- break;
- case 'captureVideo':
- captureMethod = "takeVideo";
- captureCB();
- break;
- case 'captureAudio':
- return {"status": cordova.callbackStatus.INVALID_ACTION, "message": "captureAudio is not currently supported"};
- }
-
- return retAsyncCall();
- }
- },
- networkAPI = {
- execute: function (webWorksResult, action, args, win, fail) {
- if (action !== 'getConnectionInfo') {
- return retInvalidAction();
- }
-
- var connectionType = require("cordova/plugin/Connection").NONE,
- eventType = "offline",
- callbackID,
- request;
-
- /**
- * For PlayBooks, we currently only have WiFi connections, so return WiFi if there is
- * any access at all.
- * TODO: update if/when PlayBook gets other connection types...
- */
- if (blackberry.system.hasDataCoverage()) {
- connectionType = require("cordova/plugin/Connection").WIFI;
- eventType = "online";
- }
-
- //Register an event handler for the networkChange event
- callbackID = blackberry.events.registerEventHandler("networkChange", win);
-
- //pass our callback id down to our network extension
- request = new blackberry.transport.RemoteFunctionCall("org/apache/cordova/getConnectionInfo");
- request.addParam("networkStatusChangedID", callbackID);
- request.makeSyncCall();
-
- return { "status": cordova.callbackStatus.OK, "message": {"type": connectionType, "event": eventType } };
- }
- },
- notificationAPI = {
- execute: function (webWorksResult, action, args, win, fail) {
- if (args.length !== 3) {
- return {"status" : 9, "message" : "Notification action - " + action + " arguments not found"};
-
- }
-
- //Unpack and map the args
- var msg = args[0],
- title = args[1],
- btnLabel = args[2],
- btnLabels;
-
- switch (action) {
- case 'alert':
- blackberry.ui.dialog.customAskAsync.apply(this, [ msg, [ btnLabel ], win, { "title" : title } ]);
- return retAsyncCall();
- case 'confirm':
- btnLabels = btnLabel.split(",");
- blackberry.ui.dialog.customAskAsync.apply(this, [msg, btnLabels, win, {"title" : title} ]);
- return retAsyncCall();
- }
- return retInvalidAction();
-
- }
- },
- plugins = {
- 'Camera' : cameraAPI,
- 'Device' : deviceAPI,
- 'Logger' : loggerAPI,
- 'Media' : mediaAPI,
- 'MediaCapture' : mediaCaptureAPI,
- 'Network Status' : networkAPI,
- 'Notification' : notificationAPI
- };
-
-module.exports = {
- exec: function (win, fail, clazz, action, args) {
- var wwResult = webworks.exec(win, fail, clazz, action, args);
-
- //We got a sync result or a not found from WW that we can pass on to get a native mixin
- //For async calls there's nothing to do
- if ((wwResult.status === cordova.callbackStatus.OK ||
- wwResult.status === cordova.callbackStatus.CLASS_NOT_FOUND_EXCEPTION) &&
- plugins[clazz]) {
- return plugins[clazz].execute(wwResult.message, action, args, win, fail);
- }
-
- return wwResult;
- },
- resume: function () {},
- pause: function () {},
- destroy: function () {}
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/requestFileSystem.js
----------------------------------------------------------------------
diff --git a/lib/plugin/requestFileSystem.js b/lib/plugin/requestFileSystem.js
deleted file mode 100644
index afee5d7..0000000
--- a/lib/plugin/requestFileSystem.js
+++ /dev/null
@@ -1,40 +0,0 @@
-var FileError = require('cordova/plugin/FileError'),
- FileSystem = require('cordova/plugin/FileSystem'),
- exec = require('cordova/exec');
-
-/**
- * Request a file system in which to store application data.
- * @param type local file system type
- * @param size indicates how much storage space, in bytes, the application expects to need
- * @param successCallback invoked with a FileSystem object
- * @param errorCallback invoked if error occurs retrieving file system
- */
-var requestFileSystem = function(type, size, successCallback, errorCallback) {
- var fail = function(code) {
- if (typeof errorCallback === 'function') {
- errorCallback(new FileError(code));
- }
- };
-
- if (type < 0 || type > 3) {
- fail(FileError.SYNTAX_ERR);
- } else {
- // if successful, return a FileSystem object
- var success = function(file_system) {
- if (file_system) {
- if (typeof successCallback === 'function') {
- // grab the name and root from the file system object
- var result = new FileSystem(file_system.name, file_system.root);
- successCallback(result);
- }
- }
- else {
- // no FileSystem object returned
- fail(FileError.NOT_FOUND_ERR);
- }
- };
- exec(success, fail, "File", "requestFileSystem", [type, size]);
- }
-};
-
-module.exports = requestFileSystem;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/lib/plugin/resolveLocalFileSystemURI.js b/lib/plugin/resolveLocalFileSystemURI.js
deleted file mode 100644
index fbf849b..0000000
--- a/lib/plugin/resolveLocalFileSystemURI.js
+++ /dev/null
@@ -1,41 +0,0 @@
-var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
- FileEntry = require('cordova/plugin/FileEntry'),
- exec = require('cordova/exec');
-
-/**
- * Look up file system Entry referred to by local URI.
- * @param {DOMString} uri URI referring to a local file or directory
- * @param successCallback invoked with Entry object corresponding to URI
- * @param errorCallback invoked if error occurs retrieving file system entry
- */
-module.exports = function(uri, successCallback, errorCallback) {
- // error callback
- var fail = function(error) {
- if (typeof errorCallback === 'function') {
- errorCallback(new FileError(error));
- }
- };
- // if successful, return either a file or directory entry
- var success = function(entry) {
- var result;
-
- if (entry) {
- if (typeof successCallback === 'function') {
- // create appropriate Entry object
- result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath) : new FileEntry(entry.name, entry.fullPath);
- try {
- successCallback(result);
- }
- catch (e) {
- console.log('Error invoking callback: ' + e);
- }
- }
- }
- else {
- // no Entry object returned
- fail(FileError.NOT_FOUND_ERR);
- }
- };
-
- exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]);
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/webworks/manager.js
----------------------------------------------------------------------
diff --git a/lib/plugin/webworks/manager.js b/lib/plugin/webworks/manager.js
deleted file mode 100644
index 7ea6592..0000000
--- a/lib/plugin/webworks/manager.js
+++ /dev/null
@@ -1,14 +0,0 @@
-// Define JavaScript plugin implementations that are common across
-// WebWorks platforms (phone/tablet).
-var plugins = {},
- cordova = require('cordova');
-
-module.exports = {
- exec: function (win, fail, clazz, action, args) {
- if (plugins[clazz]) {
- return plugins[clazz].execute(action, args, win, fail);
- }
-
- return {"status" : cordova.callbackStatus.CLASS_NOT_FOUND_EXCEPTION, "message" : "Class " + clazz + " cannot be found"};
- }
-};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/plugin/wp7/device.js
----------------------------------------------------------------------
diff --git a/lib/plugin/wp7/device.js b/lib/plugin/wp7/device.js
deleted file mode 100644
index b51fe93..0000000
--- a/lib/plugin/wp7/device.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * this represents the mobile device, and provides properties for inspecting the model, version, UUID of the
- * phone, etc.
- * @constructor
- */
-var Device = function()
-{
- this.platform = null;
- this.version = null;
- this.name = null;
- this.phonegap = null;
- this.uuid = null;
- try {
- this.platform = DeviceInfo.platform;
- this.version = DeviceInfo.version;
- this.name = DeviceInfo.name;
- this.phonegap = DeviceInfo.gap;
- this.uuid = DeviceInfo.uuid;
- }
- catch(e) {
- // TODO:
- }
- this.available = PhoneGap.available = !!this.uuid;
-};
-
-module.exports = new Device();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/require.js
----------------------------------------------------------------------
diff --git a/lib/require.js b/lib/require.js
deleted file mode 100644
index a92249d..0000000
--- a/lib/require.js
+++ /dev/null
@@ -1,43 +0,0 @@
-var require,
- define;
-
-(function () {
- var modules = {};
-
- function build(module) {
- var factory = module.factory;
- module.exports = {};
- delete module.factory;
- factory(require, module.exports, module);
- return module.exports;
- }
-
- require = function (id) {
- if (!modules[id]) {
- throw "module " + id + " not found";
- }
- return modules[id].factory ? build(modules[id]) : modules[id].exports;
- };
-
- define = function (id, factory) {
- if (modules[id]) {
- throw "module " + id + " already defined";
- }
-
- modules[id] = {
- id: id,
- factory: factory
- };
- };
-
- define.remove = function (id) {
- delete modules[id];
- };
-
-})();
-
-//Export for use in node
-if (typeof module === "object" && typeof require === "function") {
- module.exports.require = require;
- module.exports.define = define;
-}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/scripts/bootstrap-errgen.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap-errgen.js b/lib/scripts/bootstrap-errgen.js
new file mode 100644
index 0000000..cc479e8
--- /dev/null
+++ b/lib/scripts/bootstrap-errgen.js
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+require('cordova/channel').onNativeReady.fire()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/scripts/bootstrap-playbook.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap-playbook.js b/lib/scripts/bootstrap-playbook.js
new file mode 100644
index 0000000..19cf867
--- /dev/null
+++ b/lib/scripts/bootstrap-playbook.js
@@ -0,0 +1 @@
+require('cordova/channel').onNativeReady.fire();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/scripts/bootstrap.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap.js b/lib/scripts/bootstrap.js
new file mode 100755
index 0000000..73875ee
--- /dev/null
+++ b/lib/scripts/bootstrap.js
@@ -0,0 +1,69 @@
+(function (context) {
+ var channel = require("cordova/channel"),
+ _self = {
+ boot: function () {
+ //---------------
+ // Event handling
+ //---------------
+
+ /**
+ * Listen for DOMContentLoaded and notify our channel subscribers.
+ */
+ document.addEventListener('DOMContentLoaded', function() {
+ channel.onDOMContentLoaded.fire();
+ }, false);
+ if (document.readyState == 'complete') {
+ channel.onDOMContentLoaded.fire();
+ }
+
+ /**
+ * Create all cordova objects once page has fully loaded and native side is ready.
+ */
+ channel.join(function() {
+ var builder = require('cordova/builder'),
+ base = require('cordova/common'),
+ platform = require('cordova/platform');
+
+ // Drop the common globals into the window object, but be nice and don't overwrite anything.
+ builder.build(base.objects).intoButDontClobber(window);
+
+ // Drop the platform-specific globals into the window object
+ // and clobber any existing object.
+ builder.build(platform.objects).intoAndClobber(window);
+
+ // Merge the platform-specific overrides/enhancements into
+ // the window object.
+ if (typeof platform.merges !== 'undefined') {
+ builder.build(platform.merges).intoAndMerge(window);
+ }
+
+ // Call the platform-specific initialization
+ platform.initialize();
+
+ // Fire event to notify that all objects are created
+ channel.onCordovaReady.fire();
+
+ // Fire onDeviceReady event once all constructors have run and
+ // cordova info has been received from native side.
+ channel.join(function() {
+ channel.onDeviceReady.fire();
+
+ // Fire the onresume event, since first one happens before JavaScript is loaded
+ channel.onResume.fire();
+ }, channel.deviceReadyChannelsArray);
+
+ }, [ channel.onDOMContentLoaded, channel.onNativeReady ]);
+ }
+ };
+
+ // boot up once native side is ready
+ channel.onNativeReady.subscribeOnce(_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
+ // it may be called before any cordova JS is ready.
+ if (window._nativeReady) {
+ channel.onNativeReady.fire();
+ }
+
+}(window));
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/scripts/require.js
----------------------------------------------------------------------
diff --git a/lib/scripts/require.js b/lib/scripts/require.js
new file mode 100644
index 0000000..a92249d
--- /dev/null
+++ b/lib/scripts/require.js
@@ -0,0 +1,43 @@
+var require,
+ define;
+
+(function () {
+ var modules = {};
+
+ function build(module) {
+ var factory = module.factory;
+ module.exports = {};
+ delete module.factory;
+ factory(require, module.exports, module);
+ return module.exports;
+ }
+
+ require = function (id) {
+ if (!modules[id]) {
+ throw "module " + id + " not found";
+ }
+ return modules[id].factory ? build(modules[id]) : modules[id].exports;
+ };
+
+ define = function (id, factory) {
+ if (modules[id]) {
+ throw "module " + id + " already defined";
+ }
+
+ modules[id] = {
+ id: id,
+ factory: factory
+ };
+ };
+
+ define.remove = function (id) {
+ delete modules[id];
+ };
+
+})();
+
+//Export for use in node
+if (typeof module === "object" && typeof require === "function") {
+ module.exports.require = require;
+ module.exports.define = define;
+}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/test/exec.js
----------------------------------------------------------------------
diff --git a/lib/test/exec.js b/lib/test/exec.js
new file mode 100644
index 0000000..a5d1a69
--- /dev/null
+++ b/lib/test/exec.js
@@ -0,0 +1 @@
+module.exports = jasmine.createSpy();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/utils.js
----------------------------------------------------------------------
diff --git a/lib/utils.js b/lib/utils.js
deleted file mode 100644
index 49f6093..0000000
--- a/lib/utils.js
+++ /dev/null
@@ -1,94 +0,0 @@
-function UUIDcreatePart(length) {
- var uuidpart = "";
- for (var i=0; i<length; i++) {
- var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
- if (uuidchar.length == 1) {
- uuidchar = "0" + uuidchar;
- }
- uuidpart += uuidchar;
- }
- return uuidpart;
-}
-
-var _self = {
- /**
- * Does a deep clone of the object.
- */
- clone: function(obj) {
- if(!obj) {
- return obj;
- }
-
- var retVal, i;
-
- if(obj instanceof Array){
- retVal = [];
- for(i = 0; i < obj.length; ++i){
- retVal.push(_self.clone(obj[i]));
- }
- return retVal;
- }
-
- if (obj instanceof Function) {
- return obj;
- }
-
- if(!(obj instanceof Object)){
- return obj;
- }
-
- if(obj instanceof Date){
- return obj;
- }
-
- retVal = {};
- for(i in obj){
- if(!(i in retVal) || retVal[i] != obj[i]) {
- retVal[i] = _self.clone(obj[i]);
- }
- }
- return retVal;
- },
-
- close: function(context, func, params) {
- if (typeof params === 'undefined') {
- return function() {
- return func.apply(context, arguments);
- };
- } else {
- return function() {
- return func.apply(context, params);
- };
- }
- },
-
- /**
- * Create a UUID
- */
- createUUID: function() {
- return UUIDcreatePart(4) + '-' +
- UUIDcreatePart(2) + '-' +
- UUIDcreatePart(2) + '-' +
- UUIDcreatePart(2) + '-' +
- UUIDcreatePart(6);
- },
-
- /**
- * Extends a child object from a parent object using classical inheritance
- * pattern.
- */
- extend: (function() {
- // proxy used to establish prototype chain
- var F = function() {};
- // extend Child from Parent
- return function(Child, Parent) {
- F.prototype = Parent.prototype;
- Child.prototype = new F();
- Child.__super__ = Parent.prototype;
- Child.prototype.constructor = Child;
- };
- }())
-
-};
-
-module.exports = _self;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/webworks/plugin/webworks/manager.js
----------------------------------------------------------------------
diff --git a/lib/webworks/plugin/webworks/manager.js b/lib/webworks/plugin/webworks/manager.js
new file mode 100644
index 0000000..7ea6592
--- /dev/null
+++ b/lib/webworks/plugin/webworks/manager.js
@@ -0,0 +1,14 @@
+// Define JavaScript plugin implementations that are common across
+// WebWorks platforms (phone/tablet).
+var plugins = {},
+ cordova = require('cordova');
+
+module.exports = {
+ exec: function (win, fail, clazz, action, args) {
+ if (plugins[clazz]) {
+ return plugins[clazz].execute(action, args, win, fail);
+ }
+
+ return {"status" : cordova.callbackStatus.CLASS_NOT_FOUND_EXCEPTION, "message" : "Class " + clazz + " cannot be found"};
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/wp7/exec.js
----------------------------------------------------------------------
diff --git a/lib/wp7/exec.js b/lib/wp7/exec.js
new file mode 100644
index 0000000..78eef40
--- /dev/null
+++ b/lib/wp7/exec.js
@@ -0,0 +1,57 @@
+var cordova = require('cordova');
+
+/**
+ * Execute a cordova command. It is up to the native side whether this action
+ * is synchronous or asynchronous. The native side can return:
+ * Synchronous: PluginResult object as a JSON string
+ * Asynchrounous: Empty string ""
+ * If async, the native side will cordova.callbackSuccess or cordova.callbackError,
+ * depending upon the result of the action.
+ *
+ * @param {Function} success The success callback
+ * @param {Function} fail The fail callback
+ * @param {String} service The name of the service to use
+ * @param {String} action Action to be run in cordova
+ * @param {String[]} [args] Zero or more arguments to pass to the method
+ */
+
+module.exports = function(success, fail, service, action, args) {
+ var callbackId = service + cordova.callbackId++;
+ if (typeof success == "function" || typeof fail == "function") {
+ cordova.callbacks[callbackId] = {success:success, fail:fail};
+ }
+ // generate a new command string, ex. DebugConsole/log/DebugConsole23/{"message":"wtf dude?"}
+ var command = service + "/" + action + "/" + callbackId + "/" + JSON.stringify(args);
+ // pass it on to Notify
+ window.external.Notify(command);
+};
+
+// TODO: is this what native side invokes?
+// if so pluginize under plugin/wp7
+cordovaCommandResult = function(status,callbackId,args,cast) {
+ if(status === "backbutton") {
+
+ cordova.fireEvent(document,"backbutton");
+ return "true";
+
+ } else if(status === "resume") {
+
+ cordova.onResume.fire();
+ return "true";
+
+ } else if(status === "pause") {
+
+ cordova.onPause.fire();
+ return "true";
+ }
+
+ var safeStatus = parseInt(status, 10);
+ if(safeStatus === cordova.callbackStatus.NO_RESULT ||
+ safeStatus === cordova.callbackStatus.OK) {
+ cordova.CallbackSuccess(callbackId,args,cast);
+ }
+ else
+ {
+ cordova.CallbackError(callbackId,args,cast);
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/wp7/platform.js
----------------------------------------------------------------------
diff --git a/lib/wp7/platform.js b/lib/wp7/platform.js
new file mode 100644
index 0000000..f2d74b4
--- /dev/null
+++ b/lib/wp7/platform.js
@@ -0,0 +1,16 @@
+module.exports = {
+ id: "wp7",
+ initialize:function() {},
+ objects: {
+ navigator: {
+ children: {
+ device: {
+ path: "cordova/plugin/wp7/device"
+ }
+ }
+ },
+ device: {
+ path: 'cordova/plugin/wp7/device'
+ }
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib/wp7/plugin/wp7/device.js
----------------------------------------------------------------------
diff --git a/lib/wp7/plugin/wp7/device.js b/lib/wp7/plugin/wp7/device.js
new file mode 100644
index 0000000..b51fe93
--- /dev/null
+++ b/lib/wp7/plugin/wp7/device.js
@@ -0,0 +1,26 @@
+/**
+ * this represents the mobile device, and provides properties for inspecting the model, version, UUID of the
+ * phone, etc.
+ * @constructor
+ */
+var Device = function()
+{
+ this.platform = null;
+ this.version = null;
+ this.name = null;
+ this.phonegap = null;
+ this.uuid = null;
+ try {
+ this.platform = DeviceInfo.platform;
+ this.version = DeviceInfo.version;
+ this.name = DeviceInfo.name;
+ this.phonegap = DeviceInfo.gap;
+ this.uuid = DeviceInfo.uuid;
+ }
+ catch(e) {
+ // TODO:
+ }
+ this.available = PhoneGap.available = !!this.uuid;
+};
+
+module.exports = new Device();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib0/bootstrap.js
----------------------------------------------------------------------
diff --git a/lib0/bootstrap.js b/lib0/bootstrap.js
new file mode 100755
index 0000000..73875ee
--- /dev/null
+++ b/lib0/bootstrap.js
@@ -0,0 +1,69 @@
+(function (context) {
+ var channel = require("cordova/channel"),
+ _self = {
+ boot: function () {
+ //---------------
+ // Event handling
+ //---------------
+
+ /**
+ * Listen for DOMContentLoaded and notify our channel subscribers.
+ */
+ document.addEventListener('DOMContentLoaded', function() {
+ channel.onDOMContentLoaded.fire();
+ }, false);
+ if (document.readyState == 'complete') {
+ channel.onDOMContentLoaded.fire();
+ }
+
+ /**
+ * Create all cordova objects once page has fully loaded and native side is ready.
+ */
+ channel.join(function() {
+ var builder = require('cordova/builder'),
+ base = require('cordova/common'),
+ platform = require('cordova/platform');
+
+ // Drop the common globals into the window object, but be nice and don't overwrite anything.
+ builder.build(base.objects).intoButDontClobber(window);
+
+ // Drop the platform-specific globals into the window object
+ // and clobber any existing object.
+ builder.build(platform.objects).intoAndClobber(window);
+
+ // Merge the platform-specific overrides/enhancements into
+ // the window object.
+ if (typeof platform.merges !== 'undefined') {
+ builder.build(platform.merges).intoAndMerge(window);
+ }
+
+ // Call the platform-specific initialization
+ platform.initialize();
+
+ // Fire event to notify that all objects are created
+ channel.onCordovaReady.fire();
+
+ // Fire onDeviceReady event once all constructors have run and
+ // cordova info has been received from native side.
+ channel.join(function() {
+ channel.onDeviceReady.fire();
+
+ // Fire the onresume event, since first one happens before JavaScript is loaded
+ channel.onResume.fire();
+ }, channel.deviceReadyChannelsArray);
+
+ }, [ channel.onDOMContentLoaded, channel.onNativeReady ]);
+ }
+ };
+
+ // boot up once native side is ready
+ channel.onNativeReady.subscribeOnce(_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
+ // it may be called before any cordova JS is ready.
+ if (window._nativeReady) {
+ channel.onNativeReady.fire();
+ }
+
+}(window));
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib0/bootstrap/errgen.js
----------------------------------------------------------------------
diff --git a/lib0/bootstrap/errgen.js b/lib0/bootstrap/errgen.js
new file mode 100644
index 0000000..cc479e8
--- /dev/null
+++ b/lib0/bootstrap/errgen.js
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+require('cordova/channel').onNativeReady.fire()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib0/bootstrap/playbook.js
----------------------------------------------------------------------
diff --git a/lib0/bootstrap/playbook.js b/lib0/bootstrap/playbook.js
new file mode 100644
index 0000000..19cf867
--- /dev/null
+++ b/lib0/bootstrap/playbook.js
@@ -0,0 +1 @@
+require('cordova/channel').onNativeReady.fire();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib0/builder.js
----------------------------------------------------------------------
diff --git a/lib0/builder.js b/lib0/builder.js
new file mode 100644
index 0000000..0ff2f73
--- /dev/null
+++ b/lib0/builder.js
@@ -0,0 +1,86 @@
+function each(objects, func, context) {
+ for (var prop in objects) {
+ if (objects.hasOwnProperty(prop)) {
+ func.apply(context, [objects[prop], prop]);
+ }
+ }
+}
+
+function include(parent, objects, clobber, merge) {
+ each(objects, function (obj, key) {
+ try {
+ var result = obj.path ? require(obj.path) : {};
+
+ if (clobber) {
+ // Clobber if it doesn't exist.
+ if (typeof parent[key] === 'undefined') {
+ parent[key] = result;
+ } else if (typeof obj.path !== 'undefined') {
+ // If merging, merge properties onto parent, otherwise, clobber.
+ if (merge) {
+ recursiveMerge(parent[key], result);
+ } else {
+ parent[key] = result;
+ }
+ }
+ result = parent[key];
+ } else {
+ // Overwrite if not currently defined.
+ if (typeof parent[key] == 'undefined') {
+ parent[key] = result;
+ } else if (merge && typeof obj.path !== 'undefined') {
+ // If merging, merge parent onto result
+ recursiveMerge(result, parent[key]);
+ parent[key] = result;
+ } else {
+ // Set result to what already exists, so we can build children into it if they exist.
+ result = parent[key];
+ }
+ }
+
+ if (obj.children) {
+ include(result, obj.children, clobber, merge);
+ }
+ } catch(e) {
+ alert('Exception building cordova JS globals: ' + e + ' for key "' + key + '"');
+ }
+ });
+}
+
+/**
+ * Merge properties from one object onto another recursively. Properties from
+ * the src object will overwrite existing target property.
+ *
+ * @param target Object to merge properties into.
+ * @param src Object to merge properties from.
+ */
+function recursiveMerge(target, src) {
+ for (var prop in src) {
+ if (src.hasOwnProperty(prop)) {
+ if (typeof target.prototype !== 'undefined' && target.prototype.constructor === target) {
+ // If the target object is a constructor override off prototype.
+ target.prototype[prop] = src[prop];
+ } else {
+ target[prop] = typeof src[prop] === 'object' ? recursiveMerge(
+ target[prop], src[prop]) : src[prop];
+ }
+ }
+ }
+ return target;
+}
+
+module.exports = {
+ build: function (objects) {
+ return {
+ intoButDontClobber: function (target) {
+ include(target, objects, false, false);
+ },
+ intoAndClobber: function(target) {
+ include(target, objects, true, false);
+ },
+ intoAndMerge: function(target) {
+ include(target, objects, true, true);
+ }
+ };
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib0/channel.js
----------------------------------------------------------------------
diff --git a/lib0/channel.js b/lib0/channel.js
new file mode 100755
index 0000000..baf08b6
--- /dev/null
+++ b/lib0/channel.js
@@ -0,0 +1,207 @@
+/**
+ * Custom pub-sub channel that can have functions subscribed to it
+ * @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) {
+ this.type = type;
+ this.handlers = {};
+ this.numHandlers = 0;
+ this.guid = 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;
+ }
+ },
+ channel = {
+ /**
+ * Calls the provided function only after all of the channels specified
+ * have been fired.
+ */
+ join: function (h, c) {
+ var i = c.length;
+ var len = i;
+ var f = function() {
+ if (!(--i)) h();
+ };
+ for (var j=0; j<len; j++) {
+ !c[j].fired?c[j].subscribeOnce(f):i--;
+ }
+ if (!i) h();
+ },
+ create: function (type, opts) {
+ channel[type] = new Channel(type, opts);
+ return channel[type];
+ },
+
+ /**
+ * cordova Channels that must fire before "deviceready" is fired.
+ */
+ deviceReadyChannelsArray: [],
+ deviceReadyChannelsMap: {},
+
+ /**
+ * Indicate that a feature needs to be initialized before it is ready to be used.
+ * This holds up Cordova's "deviceready" event until the feature has been initialized
+ * and Cordova.initComplete(feature) is called.
+ *
+ * @param feature {String} The unique feature name
+ */
+ waitForInitialization: function(feature) {
+ if (feature) {
+ var c = null;
+ if (this[feature]) {
+ c = this[feature];
+ }
+ else {
+ c = this.create(feature);
+ }
+ this.deviceReadyChannelsMap[feature] = c;
+ this.deviceReadyChannelsArray.push(c);
+ }
+ },
+
+ /**
+ * Indicate that initialization code has completed and the feature is ready to be used.
+ *
+ * @param feature {String} The unique feature name
+ */
+ initializationComplete: function(feature) {
+ var c = this.deviceReadyChannelsMap[feature];
+ if (c) {
+ c.fire();
+ }
+ }
+ },
+ utils = require('cordova/utils');
+
+/**
+ * Subscribes the given function to the channel. Any time that
+ * Channel.fire is called so too will the function.
+ * Optionally specify an execution context for the function
+ * and a guid that can be used to stop subscribing to the channel.
+ * Returns the guid.
+ */
+Channel.prototype.subscribe = function(f, c, g) {
+ // need a function to call
+ if (f === null || f === undefined) { return; }
+
+ var func = f;
+ if (typeof c == "object" && f instanceof Function) { func = utils.close(c, f); }
+
+ g = g || func.observer_guid || f.observer_guid || this.guid++;
+ func.observer_guid = g;
+ f.observer_guid = g;
+ this.handlers[g] = func;
+ this.numHandlers++;
+ if (this.events.onSubscribe) this.events.onSubscribe.call(this);
+ 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
+ if (f === null || f === undefined) { return; }
+
+ var g = null;
+ var _this = this;
+ var m = function() {
+ f.apply(c || null, arguments);
+ _this.unsubscribe(g);
+ };
+ if (this.fired) {
+ if (typeof c == "object" && f instanceof Function) { f = utils.close(c, f); }
+ f.apply(this, this.fireArgs);
+ } else {
+ g = this.subscribe(m);
+ }
+ return g;
+};
+
+/**
+ * Unsubscribes the function with the given guid from the channel.
+ */
+Channel.prototype.unsubscribe = function(g) {
+ // need a function to unsubscribe
+ if (g === null || g === undefined) { return; }
+
+ if (g instanceof Function) { g = g.observer_guid; }
+ this.handlers[g] = null;
+ delete this.handlers[g];
+ this.numHandlers--;
+ if (this.events.onUnsubscribe) this.events.onUnsubscribe.call(this);
+};
+
+/**
+ * Calls all functions subscribed to this channel.
+ */
+Channel.prototype.fire = function(e) {
+ if (this.enabled) {
+ var fail = false;
+ this.fired = true;
+ for (var item in this.handlers) {
+ var handler = this.handlers[item];
+ if (handler instanceof Function) {
+ var rv = (handler.apply(this, arguments)===false);
+ fail = fail || rv;
+ }
+ }
+ this.fireArgs = arguments;
+ return !fail;
+ }
+ return true;
+};
+
+//HACK: 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');
+
+// Event to indicate the Cordova native side is ready.
+channel.create('onNativeReady');
+
+// Event to indicate that all Cordova JavaScript objects have been created
+// and it's time to run plugin constructors.
+channel.create('onCordovaReady');
+
+// Event to indicate that device properties are available
+channel.create('onCordovaInfoReady');
+
+// Event to indicate that the connection property has been set.
+channel.create('onCordovaConnectionReady');
+
+// Event to indicate that Cordova is ready
+channel.create('onDeviceReady');
+
+// Event to indicate a resume lifecycle event
+channel.create('onResume');
+
+// Event to indicate a pause lifecycle event
+channel.create('onPause');
+
+// Event to indicate a destroy lifecycle event
+channel.create('onDestroy');
+
+// Channels that must fire before "deviceready" is fired.
+channel.waitForInitialization('onCordovaReady');
+channel.waitForInitialization('onCordovaInfoReady');
+channel.waitForInitialization('onCordovaConnectionReady');
+
+module.exports = channel;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib0/cordova.js
----------------------------------------------------------------------
diff --git a/lib0/cordova.js b/lib0/cordova.js
new file mode 100644
index 0000000..3d5b2a5
--- /dev/null
+++ b/lib0/cordova.js
@@ -0,0 +1,232 @@
+var channel = require('cordova/channel');
+/**
+ * Intercept calls to addEventListener + removeEventListener and handle deviceready,
+ * resume, and pause events.
+ */
+var m_document_addEventListener = document.addEventListener;
+var m_document_removeEventListener = document.removeEventListener;
+var m_window_addEventListener = window.addEventListener;
+var m_window_removeEventListener = window.removeEventListener;
+
+/**
+ * Houses custom event handlers to intercept on document + window event listeners.
+ */
+var documentEventHandlers = {},
+ windowEventHandlers = {};
+
+document.addEventListener = function(evt, handler, capture) {
+ var e = evt.toLowerCase();
+ if (e == 'deviceready') {
+ channel.onDeviceReady.subscribeOnce(handler);
+ } else if (e == 'resume') {
+ channel.onResume.subscribe(handler);
+ // if subscribing listener after event has already fired, invoke the handler
+ if (channel.onResume.fired && handler instanceof Function) {
+ handler();
+ }
+ } else if (e == 'pause') {
+ channel.onPause.subscribe(handler);
+ } else if (typeof documentEventHandlers[e] != 'undefined') {
+ documentEventHandlers[e].subscribe(handler);
+ } else {
+ m_document_addEventListener.call(document, evt, handler, capture);
+ }
+};
+
+window.addEventListener = function(evt, handler, capture) {
+ var e = evt.toLowerCase();
+ if (typeof windowEventHandlers[e] != 'undefined') {
+ windowEventHandlers[e].subscribe(handler);
+ } else {
+ m_window_addEventListener.call(window, evt, handler, capture);
+ }
+};
+
+document.removeEventListener = function(evt, handler, capture) {
+ var e = evt.toLowerCase();
+ // If unsubcribing from an event that is handled by a plugin
+ if (typeof documentEventHandlers[e] != "undefined") {
+ documentEventHandlers[e].unsubscribe(handler);
+ } else {
+ m_document_removeEventListener.call(document, evt, handler, capture);
+ }
+};
+
+window.removeEventListener = function(evt, handler, capture) {
+ var e = evt.toLowerCase();
+ // If unsubcribing from an event that is handled by a plugin
+ if (typeof windowEventHandlers[e] != "undefined") {
+ windowEventHandlers[e].unsubscribe(handler);
+ } else {
+ m_window_removeEventListener.call(window, evt, handler, capture);
+ }
+};
+
+function createEvent(type, data) {
+ var event = document.createEvent('Events');
+ event.initEvent(type, false, false);
+ if (data) {
+ for (var i in data) {
+ if (data.hasOwnProperty(i)) {
+ event[i] = data[i];
+ }
+ }
+ }
+ return event;
+}
+
+var cordova = {
+ define:define,
+ require:require,
+ /**
+ * Methods to add/remove your own addEventListener hijacking on document + window.
+ */
+ addWindowEventHandler:function(event, opts) {
+ return (windowEventHandlers[event] = channel.create(event, opts));
+ },
+ addDocumentEventHandler:function(event, opts) {
+ return (documentEventHandlers[event] = channel.create(event, opts));
+ },
+ removeWindowEventHandler:function(event) {
+ delete windowEventHandlers[event];
+ },
+ removeDocumentEventHandler:function(event) {
+ delete documentEventHandlers[event];
+ },
+ /**
+ * Method to fire event from native code
+ */
+ fireDocumentEvent: function(type, data) {
+ var evt = createEvent(type, data);
+ if (typeof documentEventHandlers[type] != 'undefined') {
+ documentEventHandlers[type].fire(evt);
+ } else {
+ document.dispatchEvent(evt);
+ }
+ },
+ fireWindowEvent: function(type, data) {
+ var evt = createEvent(type,data);
+ if (typeof windowEventHandlers[type] != 'undefined') {
+ windowEventHandlers[type].fire(evt);
+ } else {
+ window.dispatchEvent(evt);
+ }
+ },
+ // TODO: this is Android only; think about how to do this better
+ shuttingDown:false,
+ UsePolling:false,
+ // END TODO
+
+ // TODO: iOS only
+ // This queue holds the currently executing command and all pending
+ // commands executed with cordova.exec().
+ commandQueue:[],
+ // Indicates if we're currently in the middle of flushing the command
+ // queue on the native side.
+ commandQueueFlushing:false,
+ // END TODO
+ /**
+ * Plugin callback mechanism.
+ */
+ callbackId: 0,
+ callbacks: {},
+ callbackStatus: {
+ NO_RESULT: 0,
+ OK: 1,
+ CLASS_NOT_FOUND_EXCEPTION: 2,
+ ILLEGAL_ACCESS_EXCEPTION: 3,
+ INSTANTIATION_EXCEPTION: 4,
+ MALFORMED_URL_EXCEPTION: 5,
+ IO_EXCEPTION: 6,
+ INVALID_ACTION: 7,
+ JSON_EXCEPTION: 8,
+ ERROR: 9
+ },
+
+ /**
+ * 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];
+ }
+ }
+ },
+
+ /**
+ * 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);
+ }
+
+ // Clear callback if not expecting any more results
+ if (!args.keepCallback) {
+ delete cordova.callbacks[callbackId];
+ }
+ }
+ },
+
+ addPlugin: function(name, obj) {
+ if (!window.plugins[name]) {
+ window.plugins[name] = obj;
+ }
+ else {
+ console.log("Error: Plugin "+name+" already exists.");
+ }
+ },
+
+ addConstructor: function(func) {
+ channel.onCordovaReady.subscribeOnce(function() {
+ try {
+ func();
+ } catch(e) {
+ console.log("Failed to run constructor: " + e);
+ }
+ });
+ }
+};
+
+/**
+ * Legacy variable for plugin support
+ */
+if (!window.PhoneGap) {
+ window.PhoneGap = cordova;
+}
+
+/**
+ * Plugins object
+ */
+if (!window.plugins) {
+ window.plugins = {};
+}
+
+module.exports = cordova;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib0/exec/android.js
----------------------------------------------------------------------
diff --git a/lib0/exec/android.js b/lib0/exec/android.js
new file mode 100644
index 0000000..b3410bb
--- /dev/null
+++ b/lib0/exec/android.js
@@ -0,0 +1,82 @@
+/**
+ * Execute a cordova command. It is up to the native side whether this action
+ * is synchronous or asynchronous. The native side can return:
+ * Synchronous: PluginResult object as a JSON string
+ * Asynchrounous: Empty string ""
+ * If async, the native side will cordova.callbackSuccess or cordova.callbackError,
+ * depending upon the result of the action.
+ *
+ * @param {Function} success The success callback
+ * @param {Function} fail The fail callback
+ * @param {String} service The name of the service to use
+ * @param {String} action Action to be run in cordova
+ * @param {String[]} [args] Zero or more arguments to pass to the method
+ */
+var cordova = require('cordova');
+
+module.exports = function(success, fail, service, action, args) {
+ try {
+ var callbackId = service + cordova.callbackId++;
+ if (success || fail) {
+ cordova.callbacks[callbackId] = {success:success, fail:fail};
+ }
+
+ var r = prompt(JSON.stringify(args), "gap:"+JSON.stringify([service, action, callbackId, true]));
+
+ // If a result was returned
+ if (r.length > 0) {
+ eval("var v="+r+";");
+
+ // 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);
+ }
+
+ // Clear callback if not expecting any more results
+ if (!v.keepCallback) {
+ delete cordova.callbacks[callbackId];
+ }
+ }
+ return null;
+ }
+ }
+ } catch (e2) {
+ console.log("Error: "+e2);
+ }
+};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib0/exec/blackberry.js
----------------------------------------------------------------------
diff --git a/lib0/exec/blackberry.js b/lib0/exec/blackberry.js
new file mode 100644
index 0000000..a5fb81f
--- /dev/null
+++ b/lib0/exec/blackberry.js
@@ -0,0 +1,56 @@
+/**
+ * Execute a cordova command. It is up to the native side whether this action
+ * is synchronous or asynchronous. The native side can return:
+ * Synchronous: PluginResult object as a JSON string
+ * Asynchrounous: Empty string ""
+ * If async, the native side will cordova.callbackSuccess or cordova.callbackError,
+ * depending upon the result of the action.
+ *
+ * @param {Function} success The success callback
+ * @param {Function} fail The fail callback
+ * @param {String} service The name of the service to use
+ * @param {String} action Action to be run in cordova
+ * @param {String[]} [args] Zero or more arguments to pass to the method
+ */
+var blackberry = require('cordova/plugin/blackberry/manager'),
+ cordova = require('cordova');
+
+module.exports = function(success, fail, service, action, args) {
+ try {
+ var v = blackberry.exec(success, fail, service, action, args);
+
+ // 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: "+ service + "." + action + " = "+e);
+ }
+
+ }
+ return v.message;
+ } else if (v.status == cordova.callbackStatus.NO_RESULT) {
+
+ } else {
+ // If error, then display error
+ console.log("Error: " + service + "." + action + " 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 (e) {
+ console.log("Error in error callback: " + service + "." + action + " = "+e);
+ }
+ }
+ return null;
+ }
+ } catch (e) {
+ alert("Error: "+e);
+ }
+};