http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/76f64673/lib0/plugin/ios/FileReader.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/ios/FileReader.js b/lib0/plugin/ios/FileReader.js new file mode 100644 index 0000000..5711393 --- /dev/null +++ b/lib0/plugin/ios/FileReader.js @@ -0,0 +1,87 @@ +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/lib0/plugin/ios/console.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/ios/console.js b/lib0/plugin/ios/console.js new file mode 100644 index 0000000..8651591 --- /dev/null +++ b/lib0/plugin/ios/console.js @@ -0,0 +1,102 @@ +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/lib0/plugin/ios/device.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/ios/device.js b/lib0/plugin/ios/device.js new file mode 100644 index 0000000..c6d117b --- /dev/null +++ b/lib0/plugin/ios/device.js @@ -0,0 +1,30 @@ +/** + * 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/lib0/plugin/ios/nativecomm.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/ios/nativecomm.js b/lib0/plugin/ios/nativecomm.js new file mode 100644 index 0000000..938a68c --- /dev/null +++ b/lib0/plugin/ios/nativecomm.js @@ -0,0 +1,10 @@ +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/lib0/plugin/ios/notification.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/ios/notification.js b/lib0/plugin/ios/notification.js new file mode 100644 index 0000000..a49567d --- /dev/null +++ b/lib0/plugin/ios/notification.js @@ -0,0 +1,7 @@ +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/lib0/plugin/network.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/network.js b/lib0/plugin/network.js new file mode 100644 index 0000000..29e1aee --- /dev/null +++ b/lib0/plugin/network.js @@ -0,0 +1,59 @@ +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/lib0/plugin/notification.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/notification.js b/lib0/plugin/notification.js new file mode 100644 index 0000000..305ee3d --- /dev/null +++ b/lib0/plugin/notification.js @@ -0,0 +1,56 @@ +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/lib0/plugin/playbook/device.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/playbook/device.js b/lib0/plugin/playbook/device.js new file mode 100644 index 0000000..90ec376 --- /dev/null +++ b/lib0/plugin/playbook/device.js @@ -0,0 +1,23 @@ +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/lib0/plugin/playbook/manager.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/playbook/manager.js b/lib0/plugin/playbook/manager.js new file mode 100644 index 0000000..312a1d2 --- /dev/null +++ b/lib0/plugin/playbook/manager.js @@ -0,0 +1,285 @@ +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/lib0/plugin/requestFileSystem.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/requestFileSystem.js b/lib0/plugin/requestFileSystem.js new file mode 100644 index 0000000..afee5d7 --- /dev/null +++ b/lib0/plugin/requestFileSystem.js @@ -0,0 +1,40 @@ +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/lib0/plugin/resolveLocalFileSystemURI.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/resolveLocalFileSystemURI.js b/lib0/plugin/resolveLocalFileSystemURI.js new file mode 100644 index 0000000..fbf849b --- /dev/null +++ b/lib0/plugin/resolveLocalFileSystemURI.js @@ -0,0 +1,41 @@ +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/lib0/plugin/webworks/manager.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/webworks/manager.js b/lib0/plugin/webworks/manager.js new file mode 100644 index 0000000..7ea6592 --- /dev/null +++ b/lib0/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/lib0/plugin/wp7/device.js ---------------------------------------------------------------------- diff --git a/lib0/plugin/wp7/device.js b/lib0/plugin/wp7/device.js new file mode 100644 index 0000000..b51fe93 --- /dev/null +++ b/lib0/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/require.js ---------------------------------------------------------------------- diff --git a/lib0/require.js b/lib0/require.js new file mode 100644 index 0000000..a92249d --- /dev/null +++ b/lib0/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/lib0/utils.js ---------------------------------------------------------------------- diff --git a/lib0/utils.js b/lib0/utils.js new file mode 100644 index 0000000..49f6093 --- /dev/null +++ b/lib0/utils.js @@ -0,0 +1,94 @@ +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/test/runner.js ---------------------------------------------------------------------- diff --git a/test/runner.js b/test/runner.js index 91f6ab8..6a7ebcc 100644 --- a/test/runner.js +++ b/test/runner.js @@ -21,6 +21,7 @@ function collect(path, files, matches) { module.exports = { node: function () { + console.log('starting node-based tests') var jas = require("../thirdparty/jasmine/jasmine"), TerminalReporter = require('./reporter').TerminalReporter, jsdom, document, window; @@ -43,7 +44,14 @@ module.exports = { //load in our modules var testLibName = _path.join(__dirname, '..', 'pkg', 'cordova.test-debug.js') var testLib = fs.readFileSync(testLibName, 'utf8') - eval(testLib); + try { + eval(testLib); + } + catch (e) { + console.log("error eval()ing " + testLibName + ": " + e) + console.log(e.stack) + throw e + } //hijack require require = window.cordova.require; @@ -67,6 +75,7 @@ module.exports = { env.execute(); }, browser: function () { + console.log('starting browser-based tests') var connect = require('connect'), html = fs.readFileSync(__dirname + "/suite.html", "utf-8"), doc,