Adding support for legacy plugins

This commit is contained in:
macdonst 2012-03-05 15:11:24 -05:00
parent aa4f2cc4d9
commit 8923e52a5e

View File

@ -604,6 +604,15 @@ var cordova = {
shuttingDown:false, shuttingDown:false,
UsePolling:false, UsePolling:false,
// END TODO // 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. * Plugin callback mechanism.
*/ */
@ -672,9 +681,42 @@ var cordova = {
delete cordova.callbacks[callbackId]; 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; module.exports = cordova;
}); });
@ -835,7 +877,7 @@ module.exports = {
path: 'cordova/plugin/CompassHeading' path: 'cordova/plugin/CompassHeading'
}, },
CompassError:{ CompassError:{
path: 'cordova/plugin/CompassConstants' path: 'cordova/plugin/CompassError'
}, },
ConfigurationData: { ConfigurationData: {
path: 'cordova/plugin/ConfigurationData' path: 'cordova/plugin/ConfigurationData'
@ -1289,7 +1331,7 @@ var accelerometer = {
watchAcceleration: function(successCallback, errorCallback, options) { watchAcceleration: function(successCallback, errorCallback, options) {
// Default interval (10 sec) // Default interval (10 sec)
var frequency = (options !== undefined)? options.frequency : 10000; var frequency = (options !== undefined && options.frequency !== undefined)? options.frequency : 10000;
// successCallback required // successCallback required
if (typeof successCallback !== "function") { if (typeof successCallback !== "function") {
@ -1303,7 +1345,6 @@ var accelerometer = {
return; return;
} }
// TODO: srsly wtf is this
// Make sure accelerometer timeout > frequency + 10 sec // Make sure accelerometer timeout > frequency + 10 sec
exec( exec(
function(timeout) { function(timeout) {
@ -1468,7 +1509,7 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) {
return; return;
} }
var quality = 50;
if (options && typeof options.quality == "number") { if (options && typeof options.quality == "number") {
quality = options.quality; quality = options.quality;
} else if (options && typeof options.quality == "string") { } else if (options && typeof options.quality == "string") {
@ -1512,6 +1553,8 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) {
if (typeof options.encodingType == "number") { if (typeof options.encodingType == "number") {
encodingType = options.encodingType; encodingType = options.encodingType;
} }
// TODO: parse MediaType
// TODO: enable allow edit?
exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType]); exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType]);
} }
@ -1695,6 +1738,8 @@ module.exports = CaptureVideoOptions;
define('cordova/plugin/compass', function(require, exports, module) { define('cordova/plugin/compass', function(require, exports, module) {
var exec = require('cordova/exec'), var exec = require('cordova/exec'),
utils = require('cordova/utils'), utils = require('cordova/utils'),
CompassHeading = require('cordova/plugin/CompassHeading'),
CompassError = require('cordova/plugin/CompassError'),
timers = {}, timers = {},
compass = { compass = {
/** /**
@ -1719,15 +1764,16 @@ var exec = require('cordova/exec'),
} }
var win = function(result) { var win = function(result) {
if (result.timestamp) { var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy, result.timestamp);
var timestamp = new Date(result.timestamp); successCallback(ch);
result.timestamp = timestamp;
}
successCallback(result);
}; };
var fail = function(code) {
var ce = new CompassError(code);
errorCallback(ce);
}
// Get heading // Get heading
exec(win, errorCallback, "Compass", "getHeading", []); exec(win, fail, "Compass", "getHeading", []);
}, },
/** /**
@ -1758,14 +1804,16 @@ var exec = require('cordova/exec'),
// Start watch timer to get headings // Start watch timer to get headings
var id = utils.createUUID(); var id = utils.createUUID();
var win = function(result) { var win = function(result) {
if (result.timestamp) { var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy, result.timestamp);
var timestamp = new Date(result.timestamp); successCallback(ch);
result.timestamp = timestamp;
}
successCallback(result);
}; };
var fail = function(code) {
var ce = new CompassError(code);
errorCallback(ce);
};
timers[id] = window.setInterval(function() { timers[id] = window.setInterval(function() {
exec(win, errorCallback, "Compass", "getHeading", []); exec(win, fail, "Compass", "getHeading", []);
}, frequency); }, frequency);
return id; return id;
@ -1782,26 +1830,40 @@ var exec = require('cordova/exec'),
delete timers[id]; delete timers[id];
} }
} }
// TODO: add the filter-based iOS-only methods
}; };
module.exports = compass; module.exports = compass;
}); });
define('cordova/plugin/CompassConstants', function(require, exports, module) { define('cordova/plugin/CompassError', function(require, exports, module) {
module.exports = { /**
COMPASS_INTERNAL_ERR:0, * CompassError.
COMPASS_NOT_SUPPORTED:20 * An error code assigned by an implementation when an error has occured
* @constructor
*/
var CompassError = function(err) {
this.code = (typeof err != 'undefined' ? err : null);
}; };
/**
* Error codes
*/
CompassError.COMPASS_INTERNAL_ERR = 0;
CompassError.COMPASS_NOT_SUPPORTED = 20;
module.exports = CompassError;
}); });
define('cordova/plugin/CompassHeading', function(require, exports, module) { define('cordova/plugin/CompassHeading', function(require, exports, module) {
var CompassHeading = function() { var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, timestamp) {
this.magneticHeading = null; this.magneticHeading = magneticHeading !== undefined ? magneticHeading : null;
this.trueHeading = null; this.trueHeading = trueHeading !== undefined ? trueHeading : null;
this.headingAccuracy = null; this.headingAccuracy = headingAccuracy !== undefined ? headingAccuracy : null;
this.timestamp = new Date(); this.timestamp = timestamp !== undefined ? new Date(timestamp) : new Date();
}; };
module.exports = CompassHeading; module.exports = CompassHeading;
@ -3743,7 +3805,8 @@ module.exports = Metadata;
define('cordova/plugin/network', function(require, exports, module) { define('cordova/plugin/network', function(require, exports, module) {
var exec = require('cordova/exec'), var exec = require('cordova/exec'),
cordova = require('cordova'); cordova = require('cordova'),
channel = require('cordova/channel');
var NetworkConnection = function () { var NetworkConnection = function () {
this.type = null; this.type = null;
@ -3751,8 +3814,7 @@ var NetworkConnection = function () {
this._timer = null; this._timer = null;
this.timeout = 500; this.timeout = 500;
var me = this, var me = this;
channel = require('cordova/channel');
this.getInfo( this.getInfo(
function (info) { function (info) {