mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +08:00
Pre-2.6 prep
This commit is contained in:
parent
b028ad3604
commit
31bc015cdd
@ -33,7 +33,7 @@
|
||||
<p class="event received">Device is Ready</p>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="cordova-2.5.0.js"></script>
|
||||
<script type="text/javascript" src="cordova-2.6.0rc1.js"></script>
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
<script type="text/javascript">
|
||||
app.initialize();
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Platform: android
|
||||
|
||||
// commit f50d20a87431c79a54572263729461883f611a53
|
||||
// commit bbf1562d4934b1331ffb263424b6ae054cedeb71
|
||||
|
||||
// File generated at :: Tue Feb 26 2013 13:37:51 GMT-0800 (PST)
|
||||
// File generated at :: Thu Mar 21 2013 10:34:05 GMT-0700 (PDT)
|
||||
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
@ -262,7 +262,7 @@ var cordova = {
|
||||
*/
|
||||
callbackSuccess: function(callbackId, args) {
|
||||
try {
|
||||
cordova.callbackFromNative(callbackId, true, args.status, args.message, args.keepCallback);
|
||||
cordova.callbackFromNative(callbackId, true, args.status, [args.message], args.keepCallback);
|
||||
} catch (e) {
|
||||
console.log("Error in error callback: " + callbackId + " = "+e);
|
||||
}
|
||||
@ -275,7 +275,7 @@ var cordova = {
|
||||
// TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
|
||||
// Derive success from status.
|
||||
try {
|
||||
cordova.callbackFromNative(callbackId, false, args.status, args.message, args.keepCallback);
|
||||
cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback);
|
||||
} catch (e) {
|
||||
console.log("Error in error callback: " + callbackId + " = "+e);
|
||||
}
|
||||
@ -284,13 +284,13 @@ var cordova = {
|
||||
/**
|
||||
* Called by native code when returning the result from an action.
|
||||
*/
|
||||
callbackFromNative: function(callbackId, success, status, message, keepCallback) {
|
||||
callbackFromNative: function(callbackId, success, status, args, keepCallback) {
|
||||
var callback = cordova.callbacks[callbackId];
|
||||
if (callback) {
|
||||
if (success && status == cordova.callbackStatus.OK) {
|
||||
callback.success && callback.success(message);
|
||||
callback.success && callback.success.apply(null, args);
|
||||
} else if (!success) {
|
||||
callback.fail && callback.fail(message);
|
||||
callback.fail && callback.fail.apply(null, args);
|
||||
}
|
||||
|
||||
// Clear callback if not expecting any more results
|
||||
@ -724,6 +724,9 @@ channel.createSticky('onCordovaInfoReady');
|
||||
// Event to indicate that the connection property has been set.
|
||||
channel.createSticky('onCordovaConnectionReady');
|
||||
|
||||
// Event to indicate that all automatically loaded JS plugins are loaded and ready.
|
||||
channel.createSticky('onPluginsReady');
|
||||
|
||||
// Event to indicate that Cordova is ready
|
||||
channel.createSticky('onDeviceReady');
|
||||
|
||||
@ -900,7 +903,7 @@ androidExec.nativeToJsModes = nativeToJsModes;
|
||||
|
||||
androidExec.setJsToNativeBridgeMode = function(mode) {
|
||||
if (mode == jsToNativeModes.JS_OBJECT && !window._cordovaNative) {
|
||||
console.log('Falling back on PROMPT mode since _cordovaNative is missing.');
|
||||
console.log('Falling back on PROMPT mode since _cordovaNative is missing. Expected for Android 3.2 and lower only.');
|
||||
mode = jsToNativeModes.PROMPT;
|
||||
}
|
||||
nativeApiProvider.setPreferPrompt(mode == jsToNativeModes.PROMPT);
|
||||
@ -958,10 +961,12 @@ function processMessage(message) {
|
||||
arraybuffer[i] = bytes.charCodeAt(i);
|
||||
}
|
||||
payload = arraybuffer.buffer;
|
||||
} else if (payloadKind == 'S') {
|
||||
payload = window.atob(message.slice(nextSpaceIdx + 2));
|
||||
} else {
|
||||
payload = JSON.parse(message.slice(nextSpaceIdx + 1));
|
||||
}
|
||||
cordova.callbackFromNative(callbackId, success, status, payload, keepCallback);
|
||||
cordova.callbackFromNative(callbackId, success, status, [payload], keepCallback);
|
||||
} else {
|
||||
console.log("processMessage failed: invalid message:" + message);
|
||||
}
|
||||
@ -1203,9 +1208,10 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) {
|
||||
var correctOrientation = !!options.correctOrientation;
|
||||
var saveToPhotoAlbum = !!options.saveToPhotoAlbum;
|
||||
var popoverOptions = getValue(options.popoverOptions, null);
|
||||
var cameraDirection = getValue(options.cameraDirection, Camera.Direction.BACK);
|
||||
|
||||
var args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType,
|
||||
mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions];
|
||||
mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions, cameraDirection];
|
||||
|
||||
exec(successCallback, errorCallback, "Camera", "takePicture", args);
|
||||
return new CameraPopoverHandle();
|
||||
@ -1248,6 +1254,10 @@ module.exports = {
|
||||
ARROW_LEFT : 4,
|
||||
ARROW_RIGHT : 8,
|
||||
ARROW_ANY : 15
|
||||
},
|
||||
Direction:{
|
||||
BACK: 0,
|
||||
FRONT: 1
|
||||
}
|
||||
};
|
||||
|
||||
@ -2439,14 +2449,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
||||
// Default encoding is UTF-8
|
||||
var enc = encoding ? encoding : "UTF-8";
|
||||
var me = this;
|
||||
var execArgs = [this._fileName, enc];
|
||||
|
||||
// Maybe add slice parameters.
|
||||
if (file.end < file.size) {
|
||||
execArgs.push(file.start, file.end);
|
||||
} else if (file.start > 0) {
|
||||
execArgs.push(file.start);
|
||||
}
|
||||
var execArgs = [this._fileName, enc, file.start, file.end];
|
||||
|
||||
// Read file
|
||||
exec(
|
||||
@ -2515,14 +2518,7 @@ FileReader.prototype.readAsDataURL = function(file) {
|
||||
}
|
||||
|
||||
var me = this;
|
||||
var execArgs = [this._fileName];
|
||||
|
||||
// Maybe add slice parameters.
|
||||
if (file.end < file.size) {
|
||||
execArgs.push(file.start, file.end);
|
||||
} else if (file.start > 0) {
|
||||
execArgs.push(file.start);
|
||||
}
|
||||
var execArgs = [this._fileName, file.start, file.end];
|
||||
|
||||
// Read file
|
||||
exec(
|
||||
@ -2585,9 +2581,59 @@ FileReader.prototype.readAsBinaryString = function(file) {
|
||||
if (initRead(this, file)) {
|
||||
return this._realReader.readAsBinaryString(file);
|
||||
}
|
||||
// TODO - Can't return binary data to browser.
|
||||
console.log('method "readAsBinaryString" is not supported at this time.');
|
||||
this.abort();
|
||||
|
||||
var me = this;
|
||||
var execArgs = [this._fileName, file.start, file.end];
|
||||
|
||||
// Read file
|
||||
exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me._readyState = FileReader.DONE;
|
||||
|
||||
me._result = r;
|
||||
|
||||
// If onload callback
|
||||
if (typeof me.onload === "function") {
|
||||
me.onload(new ProgressEvent("load", {target:me}));
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
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", "readAsBinaryString", execArgs);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2599,9 +2645,59 @@ FileReader.prototype.readAsArrayBuffer = function(file) {
|
||||
if (initRead(this, file)) {
|
||||
return this._realReader.readAsArrayBuffer(file);
|
||||
}
|
||||
// TODO - Can't return binary data to browser.
|
||||
console.log('This method is not supported at this time.');
|
||||
this.abort();
|
||||
|
||||
var me = this;
|
||||
var execArgs = [this._fileName, file.start, file.end];
|
||||
|
||||
// Read file
|
||||
exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me._readyState === FileReader.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state
|
||||
me._readyState = FileReader.DONE;
|
||||
|
||||
me._result = r;
|
||||
|
||||
// If onload callback
|
||||
if (typeof me.onload === "function") {
|
||||
me.onload(new ProgressEvent("load", {target:me}));
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
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", "readAsArrayBuffer", execArgs);
|
||||
};
|
||||
|
||||
module.exports = FileReader;
|
||||
@ -2647,6 +2743,38 @@ function newProgressEvent(result) {
|
||||
return pe;
|
||||
}
|
||||
|
||||
function getBasicAuthHeader(urlString) {
|
||||
var header = null;
|
||||
|
||||
if (window.btoa) {
|
||||
// parse the url using the Location object
|
||||
var url = document.createElement('a');
|
||||
url.href = urlString;
|
||||
|
||||
var credentials = null;
|
||||
var protocol = url.protocol + "//";
|
||||
var origin = protocol + url.host;
|
||||
|
||||
// check whether there are the username:password credentials in the url
|
||||
if (url.href.indexOf(origin) != 0) { // credentials found
|
||||
var atIndex = url.href.indexOf("@");
|
||||
credentials = url.href.substring(protocol.length, atIndex);
|
||||
}
|
||||
|
||||
if (credentials) {
|
||||
var authHeader = "Authorization";
|
||||
var authHeaderValue = "Basic " + window.btoa(credentials);
|
||||
|
||||
header = {
|
||||
name : authHeader,
|
||||
value : authHeaderValue
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
var idCounter = 0;
|
||||
|
||||
/**
|
||||
@ -2677,6 +2805,18 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
|
||||
var params = null;
|
||||
var chunkedMode = true;
|
||||
var headers = null;
|
||||
|
||||
var basicAuthHeader = getBasicAuthHeader(server);
|
||||
if (basicAuthHeader) {
|
||||
if (!options) {
|
||||
options = new FileUploadOptions();
|
||||
}
|
||||
if (!options.headers) {
|
||||
options.headers = {};
|
||||
}
|
||||
options.headers[basicAuthHeader.name] = basicAuthHeader.value;
|
||||
}
|
||||
|
||||
if (options) {
|
||||
fileKey = options.fileKey;
|
||||
fileName = options.fileName;
|
||||
@ -2694,7 +2834,7 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
|
||||
}
|
||||
|
||||
var fail = errorCallback && function(e) {
|
||||
var error = new FileTransferError(e.code, e.source, e.target, e.http_status);
|
||||
var error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body);
|
||||
errorCallback(error);
|
||||
};
|
||||
|
||||
@ -2718,10 +2858,28 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
|
||||
* @param successCallback (Function} Callback to be invoked when upload has completed
|
||||
* @param errorCallback {Function} Callback to be invoked upon error
|
||||
* @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false
|
||||
* @param options {FileDownloadOptions} Optional parameters such as headers
|
||||
*/
|
||||
FileTransfer.prototype.download = function(source, target, successCallback, errorCallback, trustAllHosts) {
|
||||
FileTransfer.prototype.download = function(source, target, successCallback, errorCallback, trustAllHosts, options) {
|
||||
argscheck.checkArgs('ssFF*', 'FileTransfer.download', arguments);
|
||||
var self = this;
|
||||
|
||||
var basicAuthHeader = getBasicAuthHeader(source);
|
||||
if (basicAuthHeader) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
if (!options.headers) {
|
||||
options.headers = {};
|
||||
}
|
||||
options.headers[basicAuthHeader.name] = basicAuthHeader.value;
|
||||
}
|
||||
|
||||
var headers = null;
|
||||
if (options) {
|
||||
headers = options.headers || null;
|
||||
}
|
||||
|
||||
var win = function(result) {
|
||||
if (typeof result.lengthComputable != "undefined") {
|
||||
if (self.onprogress) {
|
||||
@ -2744,11 +2902,11 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro
|
||||
};
|
||||
|
||||
var fail = errorCallback && function(e) {
|
||||
var error = new FileTransferError(e.code, e.source, e.target, e.http_status);
|
||||
var error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body);
|
||||
errorCallback(error);
|
||||
};
|
||||
|
||||
exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id]);
|
||||
exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id, headers]);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -3146,6 +3304,7 @@ function InAppBrowser() {
|
||||
this.channels = {
|
||||
'loadstart': channel.create('loadstart'),
|
||||
'loadstop' : channel.create('loadstop'),
|
||||
'loaderror' : channel.create('loaderror'),
|
||||
'exit' : channel.create('exit')
|
||||
};
|
||||
}
|
||||
@ -3176,7 +3335,7 @@ module.exports = function(strUrl, strWindowName, strWindowFeatures) {
|
||||
var cb = function(eventname) {
|
||||
iab._eventHandler(eventname);
|
||||
};
|
||||
exec(cb, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
|
||||
exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
|
||||
return iab;
|
||||
};
|
||||
|
||||
@ -4940,7 +5099,8 @@ modulemapper.merges('cordova/plugin/android/device', 'device');
|
||||
// file: lib/common/plugin/echo.js
|
||||
define("cordova/plugin/echo", function(require, exports, module) {
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var exec = require('cordova/exec'),
|
||||
utils = require('cordova/utils');
|
||||
|
||||
/**
|
||||
* Sends the given message through exec() to the Echo plugin, which sends it back to the successCallback.
|
||||
@ -4950,11 +5110,25 @@ var exec = require('cordova/exec');
|
||||
* @param forceAsync Whether to force an async return value (for testing native->js bridge).
|
||||
*/
|
||||
module.exports = function(successCallback, errorCallback, message, forceAsync) {
|
||||
var action = forceAsync ? 'echoAsync' : 'echo';
|
||||
if (!forceAsync && message.constructor == ArrayBuffer) {
|
||||
action = 'echoArrayBuffer';
|
||||
var action = 'echo';
|
||||
var messageIsMultipart = (utils.typeName(message) == "Array");
|
||||
var args = messageIsMultipart ? message : [message];
|
||||
|
||||
if (utils.typeName(message) == 'ArrayBuffer') {
|
||||
if (forceAsync) {
|
||||
console.warn('Cannot echo ArrayBuffer with forced async, falling back to sync.');
|
||||
}
|
||||
action += 'ArrayBuffer';
|
||||
} else if (messageIsMultipart) {
|
||||
if (forceAsync) {
|
||||
console.warn('Cannot echo MultiPart Array with forced async, falling back to sync.');
|
||||
}
|
||||
action += 'MultiPart';
|
||||
} else if (forceAsync) {
|
||||
action += 'Async';
|
||||
}
|
||||
exec(successCallback, errorCallback, "Echo", action, [message]);
|
||||
|
||||
exec(successCallback, errorCallback, "Echo", action, args);
|
||||
};
|
||||
|
||||
|
||||
@ -5950,6 +6124,7 @@ modulemapper.defaults('cordova/plugin/Connection', 'Connection');
|
||||
define("cordova/plugin/notification", function(require, exports, module) {
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var platform = require('cordova/platform');
|
||||
|
||||
/**
|
||||
* Provides access to notifications on the device.
|
||||
@ -5978,14 +6153,52 @@ module.exports = {
|
||||
* @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')
|
||||
* @param {Array} buttonLabels Array of the labels of the buttons (default: ['OK', 'Cancel'])
|
||||
*/
|
||||
confirm: function(message, resultCallback, title, buttonLabels) {
|
||||
var _title = (title || "Confirm");
|
||||
var _buttonLabels = (buttonLabels || "OK,Cancel");
|
||||
var _buttonLabels = (buttonLabels || ["OK", "Cancel"]);
|
||||
|
||||
// Strings are deprecated!
|
||||
if (typeof _buttonLabels === 'string') {
|
||||
console.log("Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array).");
|
||||
}
|
||||
|
||||
// Android and iOS take an array of button label names.
|
||||
// Other platforms take a comma separated list.
|
||||
// For compatibility, we convert to the desired type based on the platform.
|
||||
if (platform.id == "android" || platform.id == "ios") {
|
||||
if (typeof _buttonLabels === 'string') {
|
||||
var buttonLabelString = _buttonLabels;
|
||||
_buttonLabels = buttonLabelString.split(",");
|
||||
}
|
||||
} else {
|
||||
if (Array.isArray(_buttonLabels)) {
|
||||
var buttonLabelArray = _buttonLabels;
|
||||
_buttonLabels = buttonLabelArray.toString();
|
||||
}
|
||||
}
|
||||
exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Open a native prompt dialog, with a customizable title and button text.
|
||||
* The following results are returned to the result callback:
|
||||
* buttonIndex Index number of the button selected.
|
||||
* input1 The text entered in the prompt dialog box.
|
||||
*
|
||||
* @param {String} message Dialog message to display (default: "Prompt message")
|
||||
* @param {Function} resultCallback The callback that is called when user clicks on a button.
|
||||
* @param {String} title Title of the dialog (default: "Prompt")
|
||||
* @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"])
|
||||
*/
|
||||
prompt: function(message, resultCallback, title, buttonLabels) {
|
||||
var _message = (message || "Prompt message");
|
||||
var _title = (title || "Prompt");
|
||||
var _buttonLabels = (buttonLabels || ["OK","Cancel"]);
|
||||
exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Causes the device to vibrate.
|
||||
*
|
||||
@ -6409,44 +6622,26 @@ window.cordova = require('cordova');
|
||||
(function (context) {
|
||||
// Replace navigator before any modules are required(), to ensure it happens as soon as possible.
|
||||
// We replace it so that properties that can't be clobbered can instead be overridden.
|
||||
if (context.navigator) {
|
||||
function replaceNavigator(origNavigator) {
|
||||
var CordovaNavigator = function() {};
|
||||
CordovaNavigator.prototype = context.navigator;
|
||||
context.navigator = new CordovaNavigator();
|
||||
CordovaNavigator.prototype = origNavigator;
|
||||
var newNavigator = new CordovaNavigator();
|
||||
// This work-around really only applies to new APIs that are newer than Function.bind.
|
||||
// Without it, APIs such as getGamepads() break.
|
||||
if (CordovaNavigator.bind) {
|
||||
for (var key in origNavigator) {
|
||||
if (typeof origNavigator[key] == 'function') {
|
||||
newNavigator[key] = origNavigator[key].bind(origNavigator);
|
||||
}
|
||||
}
|
||||
}
|
||||
return newNavigator;
|
||||
}
|
||||
if (context.navigator) {
|
||||
context.navigator = replaceNavigator(context.navigator);
|
||||
}
|
||||
|
||||
var channel = require("cordova/channel"),
|
||||
_self = {
|
||||
boot: function () {
|
||||
/**
|
||||
* Create all cordova objects once page has fully loaded and native side is ready.
|
||||
*/
|
||||
channel.join(function() {
|
||||
var builder = require('cordova/builder'),
|
||||
platform = require('cordova/platform');
|
||||
|
||||
builder.buildIntoButDoNotClobber(platform.defaults, context);
|
||||
builder.buildIntoAndClobber(platform.clobbers, context);
|
||||
builder.buildIntoAndMerge(platform.merges, context);
|
||||
|
||||
// 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() {
|
||||
require('cordova').fireDocumentEvent('deviceready');
|
||||
}, channel.deviceReadyChannelsArray);
|
||||
|
||||
}, [ channel.onDOMContentLoaded, channel.onNativeReady ]);
|
||||
}
|
||||
};
|
||||
|
||||
// boot up once native side is ready
|
||||
channel.onNativeReady.subscribe(_self.boot);
|
||||
var channel = require("cordova/channel");
|
||||
|
||||
// _nativeReady is global variable that the native side can set
|
||||
// to signify that the native code is ready. It is a global since
|
||||
@ -6455,7 +6650,132 @@ window.cordova = require('cordova');
|
||||
channel.onNativeReady.fire();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create all cordova objects once page has fully loaded and native side is ready.
|
||||
*/
|
||||
channel.join(function() {
|
||||
var builder = require('cordova/builder'),
|
||||
platform = require('cordova/platform');
|
||||
|
||||
builder.buildIntoButDoNotClobber(platform.defaults, context);
|
||||
builder.buildIntoAndClobber(platform.clobbers, context);
|
||||
builder.buildIntoAndMerge(platform.merges, context);
|
||||
|
||||
// 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() {
|
||||
require('cordova').fireDocumentEvent('deviceready');
|
||||
}, channel.deviceReadyChannelsArray);
|
||||
|
||||
}, [ channel.onDOMContentLoaded, channel.onNativeReady, channel.onPluginsReady ]);
|
||||
|
||||
}(window));
|
||||
|
||||
// file: lib/scripts/plugin_loader.js
|
||||
|
||||
// Tries to load all plugins' js-modules.
|
||||
// This is an async process, but onDeviceReady is blocked on onPluginsReady.
|
||||
// onPluginsReady is fired when there are no plugins to load, or they are all done.
|
||||
(function (context) {
|
||||
// To be populated with the handler by handlePluginsObject.
|
||||
var onScriptLoadingComplete;
|
||||
|
||||
var scriptCounter = 0;
|
||||
function scriptLoadedCallback() {
|
||||
scriptCounter--;
|
||||
if (scriptCounter === 0) {
|
||||
onScriptLoadingComplete && onScriptLoadingComplete();
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to inject a <script> tag.
|
||||
function injectScript(path) {
|
||||
scriptCounter++;
|
||||
var script = document.createElement("script");
|
||||
script.onload = scriptLoadedCallback;
|
||||
script.src = path;
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
// Called when:
|
||||
// * There are plugins defined and all plugins are finished loading.
|
||||
// * There are no plugins to load.
|
||||
function finishPluginLoading() {
|
||||
context.cordova.require('cordova/channel').onPluginsReady.fire();
|
||||
}
|
||||
|
||||
// Handler for the cordova_plugins.json content.
|
||||
// See plugman's plugin_loader.js for the details of this object.
|
||||
// This function is only called if the really is a plugins array that isn't empty.
|
||||
// Otherwise the XHR response handler will just call finishPluginLoading().
|
||||
function handlePluginsObject(modules) {
|
||||
// First create the callback for when all plugins are loaded.
|
||||
var mapper = context.cordova.require('cordova/modulemapper');
|
||||
onScriptLoadingComplete = function() {
|
||||
// Loop through all the plugins and then through their clobbers and merges.
|
||||
for (var i = 0; i < modules.length; i++) {
|
||||
var module = modules[i];
|
||||
if (!module) continue;
|
||||
|
||||
if (module.clobbers && module.clobbers.length) {
|
||||
for (var j = 0; j < module.clobbers.length; j++) {
|
||||
mapper.clobbers(module.id, module.clobbers[j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (module.merges && module.merges.length) {
|
||||
for (var k = 0; k < module.merges.length; k++) {
|
||||
mapper.merges(module.id, module.merges[k]);
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, if runs is truthy we want to simply require() the module.
|
||||
// This can be skipped if it had any merges or clobbers, though,
|
||||
// since the mapper will already have required the module.
|
||||
if (module.runs && !(module.clobbers && module.clobbers.length) && !(module.merges && module.merges.length)) {
|
||||
context.cordova.require(module.id);
|
||||
}
|
||||
}
|
||||
|
||||
finishPluginLoading();
|
||||
};
|
||||
|
||||
// Now inject the scripts.
|
||||
for (var i = 0; i < modules.length; i++) {
|
||||
injectScript(modules[i].file);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to XHR the cordova_plugins.json file asynchronously.
|
||||
var xhr = new context.XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (this.readyState != 4) { // not DONE
|
||||
return;
|
||||
}
|
||||
|
||||
// If the response is a JSON string which composes an array, call handlePluginsObject.
|
||||
// If the request fails, or the response is not a JSON array, just call finishPluginLoading.
|
||||
if (this.status == 200) {
|
||||
var obj = JSON.parse(this.responseText);
|
||||
if (obj && obj instanceof Array && obj.length > 0) {
|
||||
handlePluginsObject(obj);
|
||||
} else {
|
||||
finishPluginLoading();
|
||||
}
|
||||
} else {
|
||||
finishPluginLoading();
|
||||
}
|
||||
};
|
||||
xhr.open('GET', 'cordova_plugins.json', true); // Async
|
||||
xhr.send();
|
||||
}(window));
|
||||
|
||||
|
||||
|
||||
})();
|
@ -19,7 +19,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<script src="cordova-2.5.0.js"></script>
|
||||
<script src="cordova-2.6.0rc1.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
@ -38,7 +38,7 @@ import android.telephony.TelephonyManager;
|
||||
public class Device extends CordovaPlugin {
|
||||
public static final String TAG = "Device";
|
||||
|
||||
public static String cordovaVersion = "2.5.0"; // Cordova version
|
||||
public static String cordovaVersion = "2.6.0rc1"; // Cordova version
|
||||
public static String platform = "Android"; // Device OS
|
||||
public static String uuid; // Device UUID
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user