mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 03:53:09 +08:00
JavaScript cleanup to pass jsHint
I did my best to clean up the JavaScript so it would pass through jsHint more cleanly. There still are issues but there are a lot fewer now. This helped to make the JS code more consistent.
This commit is contained in:
parent
6c3eefe6f9
commit
1d79b6617b
@ -3,25 +3,25 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!PhoneGap.hasResource("accelerometer")) {
|
if (!PhoneGap.hasResource("accelerometer")) {
|
||||||
PhoneGap.addResource("accelerometer");
|
PhoneGap.addResource("accelerometer");
|
||||||
|
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
function Acceleration(x, y, z) {
|
var Acceleration = function(x, y, z) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.timestamp = new Date().getTime();
|
this.timestamp = new Date().getTime();
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides access to device accelerometer data.
|
* This class provides access to device accelerometer data.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
Accelerometer = function() {
|
var Accelerometer = function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The last known acceleration. type=Acceleration()
|
* The last known acceleration. type=Acceleration()
|
||||||
@ -32,7 +32,7 @@ Accelerometer = function() {
|
|||||||
* List of accelerometer watch timers
|
* List of accelerometer watch timers
|
||||||
*/
|
*/
|
||||||
this.timers = {};
|
this.timers = {};
|
||||||
}
|
};
|
||||||
|
|
||||||
Accelerometer.ERROR_MSG = ["Not running", "Starting", "", "Failed to start"];
|
Accelerometer.ERROR_MSG = ["Not running", "Starting", "", "Failed to start"];
|
||||||
|
|
||||||
@ -123,4 +123,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.accelerometer = new Accelerometer();
|
navigator.accelerometer = new Accelerometer();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -13,7 +13,7 @@ PhoneGap.addResource("app");
|
|||||||
* Constructor
|
* Constructor
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
App = function() {};
|
var App = function() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the resource cache.
|
* Clear the resource cache.
|
||||||
@ -91,4 +91,4 @@ App.prototype.exitApp = function() {
|
|||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
navigator.app = window.app = new App();
|
navigator.app = window.app = new App();
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!PhoneGap.hasResource("camera")) {
|
if (!PhoneGap.hasResource("camera")) {
|
||||||
@ -14,7 +14,7 @@ PhoneGap.addResource("camera");
|
|||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
Camera = function() {
|
var Camera = function() {
|
||||||
this.successCallback = null;
|
this.successCallback = null;
|
||||||
this.errorCallback = null;
|
this.errorCallback = null;
|
||||||
this.options = null;
|
this.options = null;
|
||||||
@ -94,4 +94,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.camera = new Camera();
|
navigator.camera = new Camera();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -6,11 +6,58 @@
|
|||||||
* Copyright (c) 2010-2011, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("capture")) {
|
||||||
|
PhoneGap.addResource("capture");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a single file.
|
||||||
|
*
|
||||||
|
* name {DOMString} name of the file, without path information
|
||||||
|
* fullPath {DOMString} the full path of the file, including the name
|
||||||
|
* type {DOMString} mime type
|
||||||
|
* lastModifiedDate {Date} last modified date
|
||||||
|
* size {Number} size of the file in bytes
|
||||||
|
*/
|
||||||
|
var MediaFile = function(name, fullPath, type, lastModifiedDate, size){
|
||||||
|
this.name = name || null;
|
||||||
|
this.fullPath = fullPath || null;
|
||||||
|
this.type = type || null;
|
||||||
|
this.lastModifiedDate = lastModifiedDate || null;
|
||||||
|
this.size = size || 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch device camera application for recording video(s).
|
||||||
|
*
|
||||||
|
* @param {Function} successCB
|
||||||
|
* @param {Function} errorCB
|
||||||
|
*/
|
||||||
|
MediaFile.prototype.getFormatData = function(successCallback, errorCallback){
|
||||||
|
PhoneGap.exec(successCallback, errorCallback, "Capture", "getFormatData", [this.fullPath, this.type]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MediaFileData encapsulates format information of a media file.
|
||||||
|
*
|
||||||
|
* @param {DOMString} codecs
|
||||||
|
* @param {long} bitrate
|
||||||
|
* @param {long} height
|
||||||
|
* @param {long} width
|
||||||
|
* @param {float} duration
|
||||||
|
*/
|
||||||
|
var MediaFileData = function(codecs, bitrate, height, width, duration){
|
||||||
|
this.codecs = codecs || null;
|
||||||
|
this.bitrate = bitrate || 0;
|
||||||
|
this.height = height || 0;
|
||||||
|
this.width = width || 0;
|
||||||
|
this.duration = duration || 0;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The CaptureError interface encapsulates all errors in the Capture API.
|
* The CaptureError interface encapsulates all errors in the Capture API.
|
||||||
*/
|
*/
|
||||||
function CaptureError() {
|
var CaptureError = function(){
|
||||||
this.code = null;
|
this.code = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Capture error codes
|
// Capture error codes
|
||||||
@ -23,7 +70,7 @@ CaptureError.CAPTURE_NOT_SUPPORTED = 20;
|
|||||||
/**
|
/**
|
||||||
* The Capture interface exposes an interface to the camera and microphone of the hosting device.
|
* The Capture interface exposes an interface to the camera and microphone of the hosting device.
|
||||||
*/
|
*/
|
||||||
function Capture() {
|
var Capture = function(){
|
||||||
this.supportedAudioModes = [];
|
this.supportedAudioModes = [];
|
||||||
this.supportedImageModes = [];
|
this.supportedImageModes = [];
|
||||||
this.supportedVideoModes = [];
|
this.supportedVideoModes = [];
|
||||||
@ -31,157 +78,114 @@ function Capture() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch audio recorder application for recording audio clip(s).
|
* Launch audio recorder application for recording audio clip(s).
|
||||||
*
|
*
|
||||||
* @param {Function} successCB
|
* @param {Function} successCB
|
||||||
* @param {Function} errorCB
|
* @param {Function} errorCB
|
||||||
* @param {CaptureAudioOptions} options
|
* @param {CaptureAudioOptions} options
|
||||||
*/
|
*/
|
||||||
Capture.prototype.captureAudio = function(successCallback, errorCallback, options) {
|
Capture.prototype.captureAudio = function(successCallback, errorCallback, options){
|
||||||
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureAudio", [options]);
|
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureAudio", [options]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch camera application for taking image(s).
|
* Launch camera application for taking image(s).
|
||||||
*
|
*
|
||||||
* @param {Function} successCB
|
* @param {Function} successCB
|
||||||
* @param {Function} errorCB
|
* @param {Function} errorCB
|
||||||
* @param {CaptureImageOptions} options
|
* @param {CaptureImageOptions} options
|
||||||
*/
|
*/
|
||||||
Capture.prototype.captureImage = function(successCallback, errorCallback, options) {
|
Capture.prototype.captureImage = function(successCallback, errorCallback, options){
|
||||||
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureImage", [options]);
|
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureImage", [options]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch camera application for taking image(s).
|
* Launch camera application for taking image(s).
|
||||||
*
|
*
|
||||||
* @param {Function} successCB
|
* @param {Function} successCB
|
||||||
* @param {Function} errorCB
|
* @param {Function} errorCB
|
||||||
* @param {CaptureImageOptions} options
|
* @param {CaptureImageOptions} options
|
||||||
*/
|
*/
|
||||||
Capture.prototype._castMediaFile = function(pluginResult) {
|
Capture.prototype._castMediaFile = function(pluginResult){
|
||||||
var mediaFiles = [];
|
var mediaFiles = [];
|
||||||
var i;
|
var i;
|
||||||
for (i=0; i<pluginResult.message.length; i++) {
|
for (i = 0; i < pluginResult.message.length; i++) {
|
||||||
var mediaFile = new MediaFile();
|
var mediaFile = new MediaFile();
|
||||||
mediaFile.name = pluginResult.message[i].name;
|
mediaFile.name = pluginResult.message[i].name;
|
||||||
mediaFile.fullPath = pluginResult.message[i].fullPath;
|
mediaFile.fullPath = pluginResult.message[i].fullPath;
|
||||||
mediaFile.type = pluginResult.message[i].type;
|
mediaFile.type = pluginResult.message[i].type;
|
||||||
mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate;
|
mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate;
|
||||||
mediaFile.size = pluginResult.message[i].size;
|
mediaFile.size = pluginResult.message[i].size;
|
||||||
mediaFiles.push(mediaFile);
|
mediaFiles.push(mediaFile);
|
||||||
}
|
}
|
||||||
pluginResult.message = mediaFiles;
|
pluginResult.message = mediaFiles;
|
||||||
return pluginResult;
|
return pluginResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch device camera application for recording video(s).
|
* Launch device camera application for recording video(s).
|
||||||
*
|
*
|
||||||
* @param {Function} successCB
|
* @param {Function} successCB
|
||||||
* @param {Function} errorCB
|
* @param {Function} errorCB
|
||||||
* @param {CaptureVideoOptions} options
|
* @param {CaptureVideoOptions} options
|
||||||
*/
|
*/
|
||||||
Capture.prototype.captureVideo = function(successCallback, errorCallback, options) {
|
Capture.prototype.captureVideo = function(successCallback, errorCallback, options){
|
||||||
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureVideo", [options]);
|
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureVideo", [options]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates a set of parameters that the capture device supports.
|
* Encapsulates a set of parameters that the capture device supports.
|
||||||
*/
|
*/
|
||||||
function ConfigurationData() {
|
var ConfigurationData = function(){
|
||||||
// The ASCII-encoded string in lower case representing the media type.
|
// The ASCII-encoded string in lower case representing the media type.
|
||||||
this.type = null;
|
this.type = null;
|
||||||
// The height attribute represents height of the image or video in pixels.
|
// The height attribute represents height of the image or video in pixels.
|
||||||
// In the case of a sound clip this attribute has value 0.
|
// In the case of a sound clip this attribute has value 0.
|
||||||
this.height = 0;
|
this.height = 0;
|
||||||
// The width attribute represents width of the image or video in pixels.
|
// The width attribute represents width of the image or video in pixels.
|
||||||
// In the case of a sound clip this attribute has value 0
|
// In the case of a sound clip this attribute has value 0
|
||||||
this.width = 0;
|
this.width = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates all image capture operation configuration options.
|
* Encapsulates all image capture operation configuration options.
|
||||||
*/
|
*/
|
||||||
function CaptureImageOptions() {
|
var CaptureImageOptions = function(){
|
||||||
// Upper limit of images user can take. Value must be equal or greater than 1.
|
// Upper limit of images user can take. Value must be equal or greater than 1.
|
||||||
this.limit = 1;
|
this.limit = 1;
|
||||||
// The selected image mode. Must match with one of the elements in supportedImageModes array.
|
// The selected image mode. Must match with one of the elements in supportedImageModes array.
|
||||||
this.mode = null;
|
this.mode = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates all video capture operation configuration options.
|
* Encapsulates all video capture operation configuration options.
|
||||||
*/
|
*/
|
||||||
function CaptureVideoOptions() {
|
var CaptureVideoOptions = function(){
|
||||||
// Upper limit of videos user can record. Value must be equal or greater than 1.
|
// Upper limit of videos user can record. Value must be equal or greater than 1.
|
||||||
this.limit = 1;
|
this.limit = 1;
|
||||||
// Maximum duration of a single video clip in seconds.
|
// Maximum duration of a single video clip in seconds.
|
||||||
this.duration = 0;
|
this.duration = 0;
|
||||||
// The selected video mode. Must match with one of the elements in supportedVideoModes array.
|
// The selected video mode. Must match with one of the elements in supportedVideoModes array.
|
||||||
this.mode = null;
|
this.mode = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates all audio capture operation configuration options.
|
* Encapsulates all audio capture operation configuration options.
|
||||||
*/
|
*/
|
||||||
function CaptureAudioOptions() {
|
var CaptureAudioOptions = function(){
|
||||||
// Upper limit of sound clips user can record. Value must be equal or greater than 1.
|
// Upper limit of sound clips user can record. Value must be equal or greater than 1.
|
||||||
this.limit = 1;
|
this.limit = 1;
|
||||||
// Maximum duration of a single sound clip in seconds.
|
// Maximum duration of a single sound clip in seconds.
|
||||||
this.duration = 0;
|
this.duration = 0;
|
||||||
// The selected audio mode. Must match with one of the elements in supportedAudioModes array.
|
// The selected audio mode. Must match with one of the elements in supportedAudioModes array.
|
||||||
this.mode = null;
|
this.mode = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
PhoneGap.addConstructor(function(){
|
||||||
* Represents a single file.
|
if (typeof navigator.device === "undefined") {
|
||||||
*
|
navigator.device = window.device = new Device();
|
||||||
* name {DOMString} name of the file, without path information
|
}
|
||||||
* fullPath {DOMString} the full path of the file, including the name
|
if (typeof navigator.device.capture === "undefined") {
|
||||||
* type {DOMString} mime type
|
navigator.device.capture = window.device.capture = new Capture();
|
||||||
* lastModifiedDate {Date} last modified date
|
}
|
||||||
* size {Number} size of the file in bytes
|
|
||||||
*/
|
|
||||||
function MediaFile(name, fullPath, type, lastModifiedDate, size) {
|
|
||||||
this.name = name || null;
|
|
||||||
this.fullPath = fullPath || null;
|
|
||||||
this.type = type || null;
|
|
||||||
this.lastModifiedDate = lastModifiedDate || null;
|
|
||||||
this.size = size || 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Launch device camera application for recording video(s).
|
|
||||||
*
|
|
||||||
* @param {Function} successCB
|
|
||||||
* @param {Function} errorCB
|
|
||||||
*/
|
|
||||||
MediaFile.prototype.getFormatData = function(successCallback, errorCallback) {
|
|
||||||
PhoneGap.exec(successCallback, errorCallback, "Capture", "getFormatData", [this.fullPath, this.type]);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MediaFileData encapsulates format information of a media file.
|
|
||||||
*
|
|
||||||
* @param {DOMString} codecs
|
|
||||||
* @param {long} bitrate
|
|
||||||
* @param {long} height
|
|
||||||
* @param {long} width
|
|
||||||
* @param {float} duration
|
|
||||||
*/
|
|
||||||
function MediaFileData(codecs, bitrate, height, width, duration) {
|
|
||||||
this.codecs = codecs || null;
|
|
||||||
this.bitrate = bitrate || 0;
|
|
||||||
this.height = height || 0;
|
|
||||||
this.width = width || 0;
|
|
||||||
this.duration = duration || 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
|
||||||
if (typeof navigator.device === "undefined") {
|
|
||||||
navigator.device = window.device = new Device();
|
|
||||||
}
|
|
||||||
if (typeof navigator.device.capture === "undefined") {
|
|
||||||
navigator.device.capture = window.device.capture = new Capture();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!PhoneGap.hasResource("compass")) {
|
if (!PhoneGap.hasResource("compass")) {
|
||||||
@ -13,7 +13,7 @@ PhoneGap.addResource("compass");
|
|||||||
* This class provides access to device Compass data.
|
* This class provides access to device Compass data.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
Compass = function() {
|
var Compass = function() {
|
||||||
/**
|
/**
|
||||||
* The last known Compass position.
|
* The last known Compass position.
|
||||||
*/
|
*/
|
||||||
@ -116,4 +116,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.compass = new Compass();
|
navigator.compass = new Compass();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!PhoneGap.hasResource("contact")) {
|
if (!PhoneGap.hasResource("contact")) {
|
||||||
@ -306,4 +306,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.service.contacts = new Contacts();
|
navigator.service.contacts = new Contacts();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO: Needs to be commented
|
// TODO: Needs to be commented
|
||||||
@ -40,4 +40,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.Crypto = new Crypto();
|
navigator.Crypto = new Crypto();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -14,7 +14,7 @@ PhoneGap.addResource("device");
|
|||||||
* phone, etc.
|
* phone, etc.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
Device = function() {
|
var Device = function() {
|
||||||
this.available = PhoneGap.available;
|
this.available = PhoneGap.available;
|
||||||
this.platform = null;
|
this.platform = null;
|
||||||
this.version = null;
|
this.version = null;
|
||||||
@ -72,7 +72,7 @@ Device.prototype.getInfo = function(successCallback, errorCallback) {
|
|||||||
*/
|
*/
|
||||||
Device.prototype.overrideBackButton = function() {
|
Device.prototype.overrideBackButton = function() {
|
||||||
console.log("Device.overrideBackButton() is deprecated. Use App.overrideBackbutton(true).");
|
console.log("Device.overrideBackButton() is deprecated. Use App.overrideBackbutton(true).");
|
||||||
app.overrideBackbutton(true);
|
navigator.app.overrideBackbutton(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -83,7 +83,7 @@ Device.prototype.overrideBackButton = function() {
|
|||||||
*/
|
*/
|
||||||
Device.prototype.resetBackButton = function() {
|
Device.prototype.resetBackButton = function() {
|
||||||
console.log("Device.resetBackButton() is deprecated. Use App.overrideBackbutton(false).");
|
console.log("Device.resetBackButton() is deprecated. Use App.overrideBackbutton(false).");
|
||||||
app.overrideBackbutton(false);
|
navigator.app.overrideBackbutton(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -94,7 +94,7 @@ Device.prototype.resetBackButton = function() {
|
|||||||
*/
|
*/
|
||||||
Device.prototype.exitApp = function() {
|
Device.prototype.exitApp = function() {
|
||||||
console.log("Device.exitApp() is deprecated. Use App.exitApp().");
|
console.log("Device.exitApp() is deprecated. Use App.exitApp().");
|
||||||
app.exitApp();
|
navigator.app.exitApp();
|
||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
@ -102,4 +102,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.device = window.device = new Device();
|
navigator.device = window.device = new Device();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!PhoneGap.hasResource("file")) {
|
if (!PhoneGap.hasResource("file")) {
|
||||||
@ -15,7 +15,7 @@ PhoneGap.addResource("file");
|
|||||||
* is called.
|
* is called.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
FileProperties = function(filePath) {
|
var FileProperties = function(filePath) {
|
||||||
this.filePath = filePath;
|
this.filePath = filePath;
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
this.lastModifiedDate = null;
|
this.lastModifiedDate = null;
|
||||||
@ -31,7 +31,7 @@ FileProperties = function(filePath) {
|
|||||||
* @param lastModifiedDate {Date} last modified date
|
* @param lastModifiedDate {Date} last modified date
|
||||||
* @param size {Number} size of the file in bytes
|
* @param size {Number} size of the file in bytes
|
||||||
*/
|
*/
|
||||||
File = function(name, fullPath, type, lastModifiedDate, size) {
|
var File = function(name, fullPath, type, lastModifiedDate, size) {
|
||||||
this.name = name || null;
|
this.name = name || null;
|
||||||
this.fullPath = fullPath || null;
|
this.fullPath = fullPath || null;
|
||||||
this.type = type || null;
|
this.type = type || null;
|
||||||
@ -40,7 +40,7 @@ File = function(name, fullPath, type, lastModifiedDate, size) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
function FileError() {
|
var FileError = function() {
|
||||||
this.code = null;
|
this.code = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -66,8 +66,8 @@ FileError.PATH_EXISTS_ERR = 12;
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
function FileMgr() {
|
var FileMgr = function() {
|
||||||
}
|
};
|
||||||
|
|
||||||
FileMgr.prototype.getFileProperties = function(filePath) {
|
FileMgr.prototype.getFileProperties = function(filePath) {
|
||||||
return PhoneGap.exec(null, null, "File", "getFileProperties", [filePath]);
|
return PhoneGap.exec(null, null, "File", "getFileProperties", [filePath]);
|
||||||
@ -132,7 +132,7 @@ PhoneGap.addConstructor(function() {
|
|||||||
* To read from the SD card, the file name is "sdcard/my_file.txt"
|
* To read from the SD card, the file name is "sdcard/my_file.txt"
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
FileReader = function() {
|
var FileReader = function() {
|
||||||
this.fileName = "";
|
this.fileName = "";
|
||||||
|
|
||||||
this.readyState = 0;
|
this.readyState = 0;
|
||||||
@ -384,7 +384,7 @@ FileReader.prototype.readAsArrayBuffer = function(file) {
|
|||||||
* @param file {File} File object containing file properties
|
* @param file {File} File object containing file properties
|
||||||
* @param append if true write to the end of the file, otherwise overwrite the file
|
* @param append if true write to the end of the file, otherwise overwrite the file
|
||||||
*/
|
*/
|
||||||
FileWriter = function(file) {
|
var FileWriter = function(file) {
|
||||||
this.fileName = "";
|
this.fileName = "";
|
||||||
this.length = 0;
|
this.length = 0;
|
||||||
if (file) {
|
if (file) {
|
||||||
@ -638,136 +638,13 @@ FileWriter.prototype.truncate = function(size) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @constructor */
|
|
||||||
function LocalFileSystem() {
|
|
||||||
};
|
|
||||||
|
|
||||||
// File error codes
|
|
||||||
LocalFileSystem.TEMPORARY = 0;
|
|
||||||
LocalFileSystem.PERSISTENT = 1;
|
|
||||||
LocalFileSystem.RESOURCE = 2;
|
|
||||||
LocalFileSystem.APPLICATION = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Requests a filesystem in which to store application data.
|
|
||||||
*
|
|
||||||
* @param {int} type of file system being requested
|
|
||||||
* @param {Function} successCallback is called with the new FileSystem
|
|
||||||
* @param {Function} errorCallback is called with a FileError
|
|
||||||
*/
|
|
||||||
LocalFileSystem.prototype.requestFileSystem = function(type, size, successCallback, errorCallback) {
|
|
||||||
if (type < 0 || type > 3) {
|
|
||||||
if (typeof errorCallback == "function") {
|
|
||||||
errorCallback({
|
|
||||||
"code": FileError.SYNTAX_ERR
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
PhoneGap.exec(successCallback, errorCallback, "File", "requestFileSystem", [type, size]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {DOMString} uri referring to a local file in a filesystem
|
|
||||||
* @param {Function} successCallback is called with the new entry
|
|
||||||
* @param {Function} errorCallback is called with a FileError
|
|
||||||
*/
|
|
||||||
LocalFileSystem.prototype.resolveLocalFileSystemURI = function(uri, successCallback, errorCallback) {
|
|
||||||
PhoneGap.exec(successCallback, errorCallback, "File", "resolveLocalFileSystemURI", [uri]);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function returns and array of contacts. It is required as we need to convert raw
|
|
||||||
* JSON objects into concrete Contact objects. Currently this method is called after
|
|
||||||
* navigator.service.contacts.find but before the find methods success call back.
|
|
||||||
*
|
|
||||||
* @param a JSON Objects that need to be converted to DirectoryEntry or FileEntry objects.
|
|
||||||
* @returns an entry
|
|
||||||
*/
|
|
||||||
LocalFileSystem.prototype._castFS = function(pluginResult) {
|
|
||||||
var entry = null;
|
|
||||||
entry = new DirectoryEntry();
|
|
||||||
entry.isDirectory = pluginResult.message.root.isDirectory;
|
|
||||||
entry.isFile = pluginResult.message.root.isFile;
|
|
||||||
entry.name = pluginResult.message.root.name;
|
|
||||||
entry.fullPath = pluginResult.message.root.fullPath;
|
|
||||||
pluginResult.message.root = entry;
|
|
||||||
return pluginResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalFileSystem.prototype._castEntry = function(pluginResult) {
|
|
||||||
var entry = null;
|
|
||||||
if (pluginResult.message.isDirectory) {
|
|
||||||
console.log("This is a dir");
|
|
||||||
entry = new DirectoryEntry();
|
|
||||||
}
|
|
||||||
else if (pluginResult.message.isFile) {
|
|
||||||
console.log("This is a file");
|
|
||||||
entry = new FileEntry();
|
|
||||||
}
|
|
||||||
entry.isDirectory = pluginResult.message.isDirectory;
|
|
||||||
entry.isFile = pluginResult.message.isFile;
|
|
||||||
entry.name = pluginResult.message.name;
|
|
||||||
entry.fullPath = pluginResult.message.fullPath;
|
|
||||||
pluginResult.message = entry;
|
|
||||||
return pluginResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalFileSystem.prototype._castEntries = function(pluginResult) {
|
|
||||||
var entries = pluginResult.message;
|
|
||||||
var retVal = [];
|
|
||||||
for (i=0; i<entries.length; i++) {
|
|
||||||
retVal.push(window.localFileSystem._createEntry(entries[i]));
|
|
||||||
}
|
|
||||||
pluginResult.message = retVal;
|
|
||||||
return pluginResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalFileSystem.prototype._createEntry = function(castMe) {
|
|
||||||
var entry = null;
|
|
||||||
if (castMe.isDirectory) {
|
|
||||||
console.log("This is a dir");
|
|
||||||
entry = new DirectoryEntry();
|
|
||||||
}
|
|
||||||
else if (castMe.isFile) {
|
|
||||||
console.log("This is a file");
|
|
||||||
entry = new FileEntry();
|
|
||||||
}
|
|
||||||
entry.isDirectory = castMe.isDirectory;
|
|
||||||
entry.isFile = castMe.isFile;
|
|
||||||
entry.name = castMe.name;
|
|
||||||
entry.fullPath = castMe.fullPath;
|
|
||||||
return entry;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalFileSystem.prototype._castDate = function(pluginResult) {
|
|
||||||
if (pluginResult.message.modificationTime) {
|
|
||||||
var modTime = new Date(pluginResult.message.modificationTime);
|
|
||||||
pluginResult.message.modificationTime = modTime;
|
|
||||||
}
|
|
||||||
else if (pluginResult.message.lastModifiedDate) {
|
|
||||||
var file = new File();
|
|
||||||
file.size = pluginResult.message.size;
|
|
||||||
file.type = pluginResult.message.type;
|
|
||||||
file.name = pluginResult.message.name;
|
|
||||||
file.fullPath = pluginResult.message.fullPath;
|
|
||||||
file.lastModifedDate = new Date(pluginResult.message.lastModifiedDate);
|
|
||||||
pluginResult.message = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pluginResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about the state of the file or directory
|
* Information about the state of the file or directory
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* {Date} modificationTime (readonly)
|
* {Date} modificationTime (readonly)
|
||||||
*/
|
*/
|
||||||
Metadata = function() {
|
var Metadata = function() {
|
||||||
this.modificationTime=null;
|
this.modificationTime=null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -778,7 +655,7 @@ Metadata = function() {
|
|||||||
* @param {boolean} create file or directory if it doesn't exist
|
* @param {boolean} create file or directory if it doesn't exist
|
||||||
* @param {boolean} exclusive if true the command will fail if the file or directory exists
|
* @param {boolean} exclusive if true the command will fail if the file or directory exists
|
||||||
*/
|
*/
|
||||||
Flags = function(create, exclusive) {
|
var Flags = function(create, exclusive) {
|
||||||
this.create = create || false;
|
this.create = create || false;
|
||||||
this.exclusive = exclusive || false;
|
this.exclusive = exclusive || false;
|
||||||
};
|
};
|
||||||
@ -790,11 +667,29 @@ Flags = function(create, exclusive) {
|
|||||||
* {DOMString} name the unique name of the file system (readonly)
|
* {DOMString} name the unique name of the file system (readonly)
|
||||||
* {DirectoryEntry} root directory of the file system (readonly)
|
* {DirectoryEntry} root directory of the file system (readonly)
|
||||||
*/
|
*/
|
||||||
FileSystem = function() {
|
var FileSystem = function() {
|
||||||
this.name = null;
|
this.name = null;
|
||||||
this.root = null;
|
this.root = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface that lists the files and directories in a directory.
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
var DirectoryReader = function(fullPath){
|
||||||
|
this.fullPath = fullPath || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of entries from a directory.
|
||||||
|
*
|
||||||
|
* @param {Function} successCallback is called with a list of entries
|
||||||
|
* @param {Function} errorCallback is called with a FileError
|
||||||
|
*/
|
||||||
|
DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
|
||||||
|
PhoneGap.exec(successCallback, errorCallback, "File", "readEntries", [this.fullPath]);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface representing a directory on the file system.
|
* An interface representing a directory on the file system.
|
||||||
*
|
*
|
||||||
@ -805,7 +700,7 @@ FileSystem = function() {
|
|||||||
* {DOMString} fullPath the absolute full path to the directory (readonly)
|
* {DOMString} fullPath the absolute full path to the directory (readonly)
|
||||||
* {FileSystem} filesystem on which the directory resides (readonly)
|
* {FileSystem} filesystem on which the directory resides (readonly)
|
||||||
*/
|
*/
|
||||||
DirectoryEntry = function() {
|
var DirectoryEntry = function() {
|
||||||
this.isFile = false;
|
this.isFile = false;
|
||||||
this.isDirectory = true;
|
this.isDirectory = true;
|
||||||
this.name = null;
|
this.name = null;
|
||||||
@ -918,24 +813,6 @@ DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCall
|
|||||||
PhoneGap.exec(successCallback, errorCallback, "File", "removeRecursively", [this.fullPath]);
|
PhoneGap.exec(successCallback, errorCallback, "File", "removeRecursively", [this.fullPath]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* An interface that lists the files and directories in a directory.
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
function DirectoryReader(fullPath){
|
|
||||||
this.fullPath = fullPath || null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of entries from a directory.
|
|
||||||
*
|
|
||||||
* @param {Function} successCallback is called with a list of entries
|
|
||||||
* @param {Function} errorCallback is called with a FileError
|
|
||||||
*/
|
|
||||||
DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
|
|
||||||
PhoneGap.exec(successCallback, errorCallback, "File", "readEntries", [this.fullPath]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface representing a directory on the file system.
|
* An interface representing a directory on the file system.
|
||||||
*
|
*
|
||||||
@ -946,7 +823,7 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback)
|
|||||||
* {DOMString} fullPath the absolute full path to the file (readonly)
|
* {DOMString} fullPath the absolute full path to the file (readonly)
|
||||||
* {FileSystem} filesystem on which the directory resides (readonly)
|
* {FileSystem} filesystem on which the directory resides (readonly)
|
||||||
*/
|
*/
|
||||||
FileEntry = function() {
|
var FileEntry = function() {
|
||||||
this.isFile = true;
|
this.isFile = true;
|
||||||
this.isDirectory = false;
|
this.isDirectory = false;
|
||||||
this.name = null;
|
this.name = null;
|
||||||
@ -1028,7 +905,7 @@ FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
|
|||||||
this.file(function(filePointer) {
|
this.file(function(filePointer) {
|
||||||
var writer = new FileWriter(filePointer);
|
var writer = new FileWriter(filePointer);
|
||||||
|
|
||||||
if (writer.fileName == null || writer.fileName == "") {
|
if (writer.fileName === null || writer.fileName === "") {
|
||||||
if (typeof errorCallback == "function") {
|
if (typeof errorCallback == "function") {
|
||||||
errorCallback({
|
errorCallback({
|
||||||
"code": FileError.INVALID_STATE_ERR
|
"code": FileError.INVALID_STATE_ERR
|
||||||
@ -1052,6 +929,127 @@ FileEntry.prototype.file = function(successCallback, errorCallback) {
|
|||||||
PhoneGap.exec(successCallback, errorCallback, "File", "getFileMetadata", [this.fullPath]);
|
PhoneGap.exec(successCallback, errorCallback, "File", "getFileMetadata", [this.fullPath]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @constructor */
|
||||||
|
var LocalFileSystem = function() {
|
||||||
|
};
|
||||||
|
|
||||||
|
// File error codes
|
||||||
|
LocalFileSystem.TEMPORARY = 0;
|
||||||
|
LocalFileSystem.PERSISTENT = 1;
|
||||||
|
LocalFileSystem.RESOURCE = 2;
|
||||||
|
LocalFileSystem.APPLICATION = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requests a filesystem in which to store application data.
|
||||||
|
*
|
||||||
|
* @param {int} type of file system being requested
|
||||||
|
* @param {Function} successCallback is called with the new FileSystem
|
||||||
|
* @param {Function} errorCallback is called with a FileError
|
||||||
|
*/
|
||||||
|
LocalFileSystem.prototype.requestFileSystem = function(type, size, successCallback, errorCallback) {
|
||||||
|
if (type < 0 || type > 3) {
|
||||||
|
if (typeof errorCallback == "function") {
|
||||||
|
errorCallback({
|
||||||
|
"code": FileError.SYNTAX_ERR
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PhoneGap.exec(successCallback, errorCallback, "File", "requestFileSystem", [type, size]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {DOMString} uri referring to a local file in a filesystem
|
||||||
|
* @param {Function} successCallback is called with the new entry
|
||||||
|
* @param {Function} errorCallback is called with a FileError
|
||||||
|
*/
|
||||||
|
LocalFileSystem.prototype.resolveLocalFileSystemURI = function(uri, successCallback, errorCallback) {
|
||||||
|
PhoneGap.exec(successCallback, errorCallback, "File", "resolveLocalFileSystemURI", [uri]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function returns and array of contacts. It is required as we need to convert raw
|
||||||
|
* JSON objects into concrete Contact objects. Currently this method is called after
|
||||||
|
* navigator.service.contacts.find but before the find methods success call back.
|
||||||
|
*
|
||||||
|
* @param a JSON Objects that need to be converted to DirectoryEntry or FileEntry objects.
|
||||||
|
* @returns an entry
|
||||||
|
*/
|
||||||
|
LocalFileSystem.prototype._castFS = function(pluginResult) {
|
||||||
|
var entry = null;
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
entry.isDirectory = pluginResult.message.root.isDirectory;
|
||||||
|
entry.isFile = pluginResult.message.root.isFile;
|
||||||
|
entry.name = pluginResult.message.root.name;
|
||||||
|
entry.fullPath = pluginResult.message.root.fullPath;
|
||||||
|
pluginResult.message.root = entry;
|
||||||
|
return pluginResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalFileSystem.prototype._castEntry = function(pluginResult) {
|
||||||
|
var entry = null;
|
||||||
|
if (pluginResult.message.isDirectory) {
|
||||||
|
console.log("This is a dir");
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
}
|
||||||
|
else if (pluginResult.message.isFile) {
|
||||||
|
console.log("This is a file");
|
||||||
|
entry = new FileEntry();
|
||||||
|
}
|
||||||
|
entry.isDirectory = pluginResult.message.isDirectory;
|
||||||
|
entry.isFile = pluginResult.message.isFile;
|
||||||
|
entry.name = pluginResult.message.name;
|
||||||
|
entry.fullPath = pluginResult.message.fullPath;
|
||||||
|
pluginResult.message = entry;
|
||||||
|
return pluginResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalFileSystem.prototype._castEntries = function(pluginResult) {
|
||||||
|
var entries = pluginResult.message;
|
||||||
|
var retVal = [];
|
||||||
|
for (var i=0; i<entries.length; i++) {
|
||||||
|
retVal.push(window.localFileSystem._createEntry(entries[i]));
|
||||||
|
}
|
||||||
|
pluginResult.message = retVal;
|
||||||
|
return pluginResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalFileSystem.prototype._createEntry = function(castMe) {
|
||||||
|
var entry = null;
|
||||||
|
if (castMe.isDirectory) {
|
||||||
|
console.log("This is a dir");
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
}
|
||||||
|
else if (castMe.isFile) {
|
||||||
|
console.log("This is a file");
|
||||||
|
entry = new FileEntry();
|
||||||
|
}
|
||||||
|
entry.isDirectory = castMe.isDirectory;
|
||||||
|
entry.isFile = castMe.isFile;
|
||||||
|
entry.name = castMe.name;
|
||||||
|
entry.fullPath = castMe.fullPath;
|
||||||
|
return entry;
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalFileSystem.prototype._castDate = function(pluginResult) {
|
||||||
|
if (pluginResult.message.modificationTime) {
|
||||||
|
var modTime = new Date(pluginResult.message.modificationTime);
|
||||||
|
pluginResult.message.modificationTime = modTime;
|
||||||
|
}
|
||||||
|
else if (pluginResult.message.lastModifiedDate) {
|
||||||
|
var file = new File();
|
||||||
|
file.size = pluginResult.message.size;
|
||||||
|
file.type = pluginResult.message.type;
|
||||||
|
file.name = pluginResult.message.name;
|
||||||
|
file.fullPath = pluginResult.message.fullPath;
|
||||||
|
file.lastModifedDate = new Date(pluginResult.message.lastModifiedDate);
|
||||||
|
pluginResult.message = file;
|
||||||
|
}
|
||||||
|
return pluginResult;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the FileSystem interface into the browser.
|
* Add the FileSystem interface into the browser.
|
||||||
*/
|
*/
|
||||||
@ -1062,4 +1060,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
if(typeof window.requestFileSystem == "undefined") window.requestFileSystem = pgLocalFileSystem.requestFileSystem;
|
if(typeof window.requestFileSystem == "undefined") window.requestFileSystem = pgLocalFileSystem.requestFileSystem;
|
||||||
if(typeof window.resolveLocalFileSystemURI == "undefined") window.resolveLocalFileSystemURI = pgLocalFileSystem.resolveLocalFileSystemURI;
|
if(typeof window.resolveLocalFileSystemURI == "undefined") window.resolveLocalFileSystemURI = pgLocalFileSystem.resolveLocalFileSystemURI;
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!PhoneGap.hasResource("filetransfer")) {
|
if (!PhoneGap.hasResource("filetransfer")) {
|
||||||
@ -13,13 +13,13 @@ PhoneGap.addResource("filetransfer");
|
|||||||
* FileTransfer uploads a file to a remote server.
|
* FileTransfer uploads a file to a remote server.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
FileTransfer = function() {};
|
var FileTransfer = function() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FileUploadResult
|
* FileUploadResult
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
FileUploadResult = function() {
|
var FileUploadResult = function() {
|
||||||
this.bytesSent = 0;
|
this.bytesSent = 0;
|
||||||
this.responseCode = null;
|
this.responseCode = null;
|
||||||
this.response = null;
|
this.response = null;
|
||||||
@ -29,7 +29,7 @@ FileUploadResult = function() {
|
|||||||
* FileTransferError
|
* FileTransferError
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
FileTransferError = function() {
|
var FileTransferError = function() {
|
||||||
this.code = null;
|
this.code = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -76,10 +76,10 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
|
|||||||
* @param mimeType {String} Mimetype of the uploaded file. Defaults to image/jpeg.
|
* @param mimeType {String} Mimetype of the uploaded file. Defaults to image/jpeg.
|
||||||
* @param params {Object} Object with key: value params to send to the server.
|
* @param params {Object} Object with key: value params to send to the server.
|
||||||
*/
|
*/
|
||||||
FileUploadOptions = function(fileKey, fileName, mimeType, params) {
|
var FileUploadOptions = function(fileKey, fileName, mimeType, params) {
|
||||||
this.fileKey = fileKey || null;
|
this.fileKey = fileKey || null;
|
||||||
this.fileName = fileName || null;
|
this.fileName = fileName || null;
|
||||||
this.mimeType = mimeType || null;
|
this.mimeType = mimeType || null;
|
||||||
this.params = params || null;
|
this.params = params || null;
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!PhoneGap.hasResource("geolocation")) {
|
if (!PhoneGap.hasResource("geolocation")) {
|
||||||
@ -13,7 +13,7 @@ PhoneGap.addResource("geolocation");
|
|||||||
* This class provides access to device GPS data.
|
* This class provides access to device GPS data.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
Geolocation = function() {
|
var Geolocation = function() {
|
||||||
|
|
||||||
// The last known GPS position.
|
// The last known GPS position.
|
||||||
this.lastPosition = null;
|
this.lastPosition = null;
|
||||||
@ -29,7 +29,7 @@ Geolocation = function() {
|
|||||||
* @param code
|
* @param code
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
PositionError = function(code, message) {
|
var PositionError = function(code, message) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
};
|
};
|
||||||
@ -195,4 +195,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
Geolocation.usingPhoneGap = true;
|
Geolocation.usingPhoneGap = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -3,67 +3,12 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!PhoneGap.hasResource("media")) {
|
if (!PhoneGap.hasResource("media")) {
|
||||||
PhoneGap.addResource("media");
|
PhoneGap.addResource("media");
|
||||||
|
|
||||||
/**
|
|
||||||
* List of media objects.
|
|
||||||
* PRIVATE
|
|
||||||
*/
|
|
||||||
PhoneGap.mediaObjects = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Object that receives native callbacks.
|
|
||||||
* PRIVATE
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
PhoneGap.Media = function() {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the media object.
|
|
||||||
* PRIVATE
|
|
||||||
*
|
|
||||||
* @param id The media object id (string)
|
|
||||||
*/
|
|
||||||
PhoneGap.Media.getMediaObject = function(id) {
|
|
||||||
return PhoneGap.mediaObjects[id];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Audio has status update.
|
|
||||||
* PRIVATE
|
|
||||||
*
|
|
||||||
* @param id The media object id (string)
|
|
||||||
* @param status The status code (int)
|
|
||||||
* @param msg The status message (string)
|
|
||||||
*/
|
|
||||||
PhoneGap.Media.onStatus = function(id, msg, value) {
|
|
||||||
var media = PhoneGap.mediaObjects[id];
|
|
||||||
|
|
||||||
// If state update
|
|
||||||
if (msg === Media.MEDIA_STATE) {
|
|
||||||
if (value === Media.MEDIA_STOPPED) {
|
|
||||||
if (media.successCallback) {
|
|
||||||
media.successCallback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (media.statusCallback) {
|
|
||||||
media.statusCallback(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (msg === Media.MEDIA_DURATION) {
|
|
||||||
media._duration = value;
|
|
||||||
}
|
|
||||||
else if (msg === Media.MEDIA_ERROR) {
|
|
||||||
if (media.errorCallback) {
|
|
||||||
media.errorCallback(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides access to the device media, interfaces to both sound and video
|
* This class provides access to the device media, interfaces to both sound and video
|
||||||
*
|
*
|
||||||
@ -78,7 +23,7 @@ PhoneGap.Media.onStatus = function(id, msg, value) {
|
|||||||
* @param positionCallback The callback to be called when media position has changed.
|
* @param positionCallback The callback to be called when media position has changed.
|
||||||
* positionCallback(long position) - OPTIONAL
|
* positionCallback(long position) - OPTIONAL
|
||||||
*/
|
*/
|
||||||
Media = function(src, successCallback, errorCallback, statusCallback, positionCallback) {
|
var Media = function(src, successCallback, errorCallback, statusCallback, positionCallback) {
|
||||||
|
|
||||||
// successCallback optional
|
// successCallback optional
|
||||||
if (successCallback && (typeof successCallback !== "function")) {
|
if (successCallback && (typeof successCallback !== "function")) {
|
||||||
@ -133,7 +78,7 @@ Media.MEDIA_MSG = ["None", "Starting", "Running", "Paused", "Stopped"];
|
|||||||
* This class contains information about any Media errors.
|
* This class contains information about any Media errors.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
MediaError = function() {
|
var MediaError = function() {
|
||||||
this.code = null;
|
this.code = null;
|
||||||
this.message = "";
|
this.message = "";
|
||||||
};
|
};
|
||||||
@ -208,4 +153,59 @@ Media.prototype.stopRecord = function() {
|
|||||||
Media.prototype.release = function() {
|
Media.prototype.release = function() {
|
||||||
PhoneGap.exec(null, null, "Media", "release", [this.id]);
|
PhoneGap.exec(null, null, "Media", "release", [this.id]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of media objects.
|
||||||
|
* PRIVATE
|
||||||
|
*/
|
||||||
|
PhoneGap.mediaObjects = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object that receives native callbacks.
|
||||||
|
* PRIVATE
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
PhoneGap.Media = function() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the media object.
|
||||||
|
* PRIVATE
|
||||||
|
*
|
||||||
|
* @param id The media object id (string)
|
||||||
|
*/
|
||||||
|
PhoneGap.Media.getMediaObject = function(id) {
|
||||||
|
return PhoneGap.mediaObjects[id];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Audio has status update.
|
||||||
|
* PRIVATE
|
||||||
|
*
|
||||||
|
* @param id The media object id (string)
|
||||||
|
* @param status The status code (int)
|
||||||
|
* @param msg The status message (string)
|
||||||
|
*/
|
||||||
|
PhoneGap.Media.onStatus = function(id, msg, value) {
|
||||||
|
var media = PhoneGap.mediaObjects[id];
|
||||||
|
|
||||||
|
// If state update
|
||||||
|
if (msg === Media.MEDIA_STATE) {
|
||||||
|
if (value === Media.MEDIA_STOPPED) {
|
||||||
|
if (media.successCallback) {
|
||||||
|
media.successCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (media.statusCallback) {
|
||||||
|
media.statusCallback(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (msg === Media.MEDIA_DURATION) {
|
||||||
|
media._duration = value;
|
||||||
|
}
|
||||||
|
else if (msg === Media.MEDIA_ERROR) {
|
||||||
|
if (media.errorCallback) {
|
||||||
|
media.errorCallback(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!PhoneGap.hasResource("network")) {
|
if (!PhoneGap.hasResource("network")) {
|
||||||
@ -13,7 +13,7 @@ PhoneGap.addResource("network");
|
|||||||
* This class contains information about any NetworkStatus.
|
* This class contains information about any NetworkStatus.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
NetworkStatus = function() {
|
var NetworkStatus = function() {
|
||||||
//this.code = null;
|
//this.code = null;
|
||||||
//this.message = "";
|
//this.message = "";
|
||||||
};
|
};
|
||||||
@ -26,7 +26,7 @@ NetworkStatus.REACHABLE_VIA_WIFI_NETWORK = 2;
|
|||||||
* This class provides access to device Network data (reachability).
|
* This class provides access to device Network data (reachability).
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
Network = function() {
|
var Network = function() {
|
||||||
/**
|
/**
|
||||||
* The last known Network status.
|
* The last known Network status.
|
||||||
* { hostName: string, ipAddress: string,
|
* { hostName: string, ipAddress: string,
|
||||||
@ -63,7 +63,7 @@ Network.prototype.isReachable = function(uri, callback, options) {
|
|||||||
* This class contains information about the current network Connection.
|
* This class contains information about the current network Connection.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
Connection = function() {
|
var Connection = function() {
|
||||||
this.type = null;
|
this.type = null;
|
||||||
this.homeNW = null;
|
this.homeNW = null;
|
||||||
this.currentNW = null;
|
this.currentNW = null;
|
||||||
@ -109,4 +109,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.network.connection = new Connection();
|
navigator.network.connection = new Connection();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!PhoneGap.hasResource("notification")) {
|
if (!PhoneGap.hasResource("notification")) {
|
||||||
@ -13,7 +13,7 @@ PhoneGap.addResource("notification");
|
|||||||
* This class provides access to notifications on the device.
|
* This class provides access to notifications on the device.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
Notification = function() {
|
var Notification = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,4 +119,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.notification = new Notification();
|
navigator.notification = new Notification();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
@ -33,7 +33,7 @@ if (typeof PhoneGap === "undefined") {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (typeof(DeviceInfo) !== 'object') {
|
if (typeof(DeviceInfo) !== 'object') {
|
||||||
DeviceInfo = {};
|
var DeviceInfo = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -440,7 +440,7 @@ PhoneGap.stringify = function(args) {
|
|||||||
var s = "[";
|
var s = "[";
|
||||||
var i, type, start, name, nameType, a;
|
var i, type, start, name, nameType, a;
|
||||||
for (i = 0; i < args.length; i++) {
|
for (i = 0; i < args.length; i++) {
|
||||||
if (args[i] != null) {
|
if (args[i] !== null) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
s = s + ",";
|
s = s + ",";
|
||||||
}
|
}
|
||||||
@ -939,4 +939,4 @@ var PluginManager = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!PhoneGap.hasResource("position")) {
|
if (!PhoneGap.hasResource("position")) {
|
||||||
@ -20,13 +20,13 @@ PhoneGap.addResource("position");
|
|||||||
* @param {Object} vel
|
* @param {Object} vel
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
Position = function(coords, timestamp) {
|
var Position = function(coords, timestamp) {
|
||||||
this.coords = coords;
|
this.coords = coords;
|
||||||
this.timestamp = (timestamp !== 'undefined') ? timestamp : new Date().getTime();
|
this.timestamp = (timestamp !== 'undefined') ? timestamp : new Date().getTime();
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
function Coordinates(lat, lng, alt, acc, head, vel, altacc) {
|
var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) {
|
||||||
/**
|
/**
|
||||||
* The latitude of the position.
|
* The latitude of the position.
|
||||||
*/
|
*/
|
||||||
@ -55,13 +55,13 @@ function Coordinates(lat, lng, alt, acc, head, vel, altacc) {
|
|||||||
* The altitude accuracy of the position.
|
* The altitude accuracy of the position.
|
||||||
*/
|
*/
|
||||||
this.altitudeAccuracy = (altacc !== 'undefined') ? altacc : null;
|
this.altitudeAccuracy = (altacc !== 'undefined') ? altacc : null;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class specifies the options for requesting position data.
|
* This class specifies the options for requesting position data.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
PositionOptions = function() {
|
var PositionOptions = function() {
|
||||||
/**
|
/**
|
||||||
* Specifies the desired position accuracy.
|
* Specifies the desired position accuracy.
|
||||||
*/
|
*/
|
||||||
@ -77,7 +77,7 @@ PositionOptions = function() {
|
|||||||
* This class contains information about any GSP errors.
|
* This class contains information about any GSP errors.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
PositionError = function() {
|
var PositionError = function() {
|
||||||
this.code = null;
|
this.code = null;
|
||||||
this.message = "";
|
this.message = "";
|
||||||
};
|
};
|
||||||
@ -86,4 +86,4 @@ PositionError.UNKNOWN_ERROR = 0;
|
|||||||
PositionError.PERMISSION_DENIED = 1;
|
PositionError.PERMISSION_DENIED = 1;
|
||||||
PositionError.POSITION_UNAVAILABLE = 2;
|
PositionError.POSITION_UNAVAILABLE = 2;
|
||||||
PositionError.TIMEOUT = 3;
|
PositionError.TIMEOUT = 3;
|
||||||
};
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -15,6 +15,35 @@
|
|||||||
if (!PhoneGap.hasResource("storage")) {
|
if (!PhoneGap.hasResource("storage")) {
|
||||||
PhoneGap.addResource("storage");
|
PhoneGap.addResource("storage");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL result set object
|
||||||
|
* PRIVATE METHOD
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
var DroidDB_Rows = function() {
|
||||||
|
this.resultSet = []; // results array
|
||||||
|
this.length = 0; // number of rows
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get item from SQL result set
|
||||||
|
*
|
||||||
|
* @param row The row number to return
|
||||||
|
* @return The row object
|
||||||
|
*/
|
||||||
|
DroidDB_Rows.prototype.item = function(row) {
|
||||||
|
return this.resultSet[row];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL result set that is returned to user.
|
||||||
|
* PRIVATE METHOD
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
var DroidDB_Result = function() {
|
||||||
|
this.rows = new DroidDB_Rows();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Storage object that is called by native code when performing queries.
|
* Storage object that is called by native code when performing queries.
|
||||||
* PRIVATE METHOD
|
* PRIVATE METHOD
|
||||||
@ -103,6 +132,36 @@ DroidDB.prototype.fail = function(reason, id) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL query object
|
||||||
|
* PRIVATE METHOD
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @param tx The transaction object that this query belongs to
|
||||||
|
*/
|
||||||
|
var DroidDB_Query = function(tx) {
|
||||||
|
|
||||||
|
// Set the id of the query
|
||||||
|
this.id = PhoneGap.createUUID();
|
||||||
|
|
||||||
|
// Add this query to the queue
|
||||||
|
droiddb.queryQueue[this.id] = this;
|
||||||
|
|
||||||
|
// Init result
|
||||||
|
this.resultSet = [];
|
||||||
|
|
||||||
|
// Set transaction that this query belongs to
|
||||||
|
this.tx = tx;
|
||||||
|
|
||||||
|
// Add this query to transaction list
|
||||||
|
this.tx.queryList[this.id] = this;
|
||||||
|
|
||||||
|
// Callbacks
|
||||||
|
this.successCallback = null;
|
||||||
|
this.errorCallback = null;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transaction object
|
* Transaction object
|
||||||
* PRIVATE METHOD
|
* PRIVATE METHOD
|
||||||
@ -121,37 +180,6 @@ var DroidDB_Tx = function() {
|
|||||||
this.queryList = {};
|
this.queryList = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var DatabaseShell = function() {
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start a transaction.
|
|
||||||
* Does not support rollback in event of failure.
|
|
||||||
*
|
|
||||||
* @param process {Function} The transaction function
|
|
||||||
* @param successCallback {Function}
|
|
||||||
* @param errorCallback {Function}
|
|
||||||
*/
|
|
||||||
DatabaseShell.prototype.transaction = function(process, errorCallback, successCallback) {
|
|
||||||
var tx = new DroidDB_Tx();
|
|
||||||
tx.successCallback = successCallback;
|
|
||||||
tx.errorCallback = errorCallback;
|
|
||||||
try {
|
|
||||||
process(tx);
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Transaction error: "+e);
|
|
||||||
if (tx.errorCallback) {
|
|
||||||
try {
|
|
||||||
tx.errorCallback(e);
|
|
||||||
} catch (ex) {
|
|
||||||
console.log("Transaction error calling user error callback: "+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark query in transaction as complete.
|
* Mark query in transaction as complete.
|
||||||
* If all queries are complete, call the user's transaction success callback.
|
* If all queries are complete, call the user's transaction success callback.
|
||||||
@ -203,36 +231,6 @@ DroidDB_Tx.prototype.queryFailed = function(id, reason) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* SQL query object
|
|
||||||
* PRIVATE METHOD
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
* @param tx The transaction object that this query belongs to
|
|
||||||
*/
|
|
||||||
var DroidDB_Query = function(tx) {
|
|
||||||
|
|
||||||
// Set the id of the query
|
|
||||||
this.id = PhoneGap.createUUID();
|
|
||||||
|
|
||||||
// Add this query to the queue
|
|
||||||
droiddb.queryQueue[this.id] = this;
|
|
||||||
|
|
||||||
// Init result
|
|
||||||
this.resultSet = [];
|
|
||||||
|
|
||||||
// Set transaction that this query belongs to
|
|
||||||
this.tx = tx;
|
|
||||||
|
|
||||||
// Add this query to transaction list
|
|
||||||
this.tx.queryList[this.id] = this;
|
|
||||||
|
|
||||||
// Callbacks
|
|
||||||
this.successCallback = null;
|
|
||||||
this.errorCallback = null;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute SQL statement
|
* Execute SQL statement
|
||||||
*
|
*
|
||||||
@ -260,33 +258,33 @@ DroidDB_Tx.prototype.executeSql = function(sql, params, successCallback, errorCa
|
|||||||
PhoneGap.exec(null, null, "Storage", "executeSql", [sql, params, query.id]);
|
PhoneGap.exec(null, null, "Storage", "executeSql", [sql, params, query.id]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
var DatabaseShell = function() {
|
||||||
* SQL result set that is returned to user.
|
|
||||||
* PRIVATE METHOD
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
DroidDB_Result = function() {
|
|
||||||
this.rows = new DroidDB_Rows();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL result set object
|
* Start a transaction.
|
||||||
* PRIVATE METHOD
|
* Does not support rollback in event of failure.
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
DroidDB_Rows = function() {
|
|
||||||
this.resultSet = []; // results array
|
|
||||||
this.length = 0; // number of rows
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get item from SQL result set
|
|
||||||
*
|
*
|
||||||
* @param row The row number to return
|
* @param process {Function} The transaction function
|
||||||
* @return The row object
|
* @param successCallback {Function}
|
||||||
|
* @param errorCallback {Function}
|
||||||
*/
|
*/
|
||||||
DroidDB_Rows.prototype.item = function(row) {
|
DatabaseShell.prototype.transaction = function(process, errorCallback, successCallback) {
|
||||||
return this.resultSet[row];
|
var tx = new DroidDB_Tx();
|
||||||
|
tx.successCallback = successCallback;
|
||||||
|
tx.errorCallback = errorCallback;
|
||||||
|
try {
|
||||||
|
process(tx);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Transaction error: "+e);
|
||||||
|
if (tx.errorCallback) {
|
||||||
|
try {
|
||||||
|
tx.errorCallback(e);
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("Transaction error calling user error callback: "+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -298,13 +296,12 @@ DroidDB_Rows.prototype.item = function(row) {
|
|||||||
* @param size Database size in bytes
|
* @param size Database size in bytes
|
||||||
* @return Database object
|
* @return Database object
|
||||||
*/
|
*/
|
||||||
DroidDB_openDatabase = function(name, version, display_name, size) {
|
var DroidDB_openDatabase = function(name, version, display_name, size) {
|
||||||
PhoneGap.exec(null, null, "Storage", "openDatabase", [name, version, display_name, size]);
|
PhoneGap.exec(null, null, "Storage", "openDatabase", [name, version, display_name, size]);
|
||||||
var db = new DatabaseShell();
|
var db = new DatabaseShell();
|
||||||
return db;
|
return db;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For browsers with no localStorage we emulate it with SQLite. Follows the w3c api.
|
* For browsers with no localStorage we emulate it with SQLite. Follows the w3c api.
|
||||||
* TODO: Do similar for sessionStorage.
|
* TODO: Do similar for sessionStorage.
|
||||||
@ -385,13 +382,14 @@ var CupcakeLocalStorage = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
};
|
||||||
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
alert("Database error "+e+".");
|
alert("Database error "+e+".");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
var setupDroidDB = function() {
|
var setupDroidDB = function() {
|
||||||
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
|
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
|
||||||
@ -402,24 +400,24 @@ PhoneGap.addConstructor(function() {
|
|||||||
} else {
|
} else {
|
||||||
window.openDatabase_orig = window.openDatabase;
|
window.openDatabase_orig = window.openDatabase;
|
||||||
window.openDatabase = function(name, version, desc, size){
|
window.openDatabase = function(name, version, desc, size){
|
||||||
// Some versions of Android will throw a SECURITY_ERR so we need
|
// Some versions of Android will throw a SECURITY_ERR so we need
|
||||||
// to catch the exception and seutp our own DB handling.
|
// to catch the exception and seutp our own DB handling.
|
||||||
var db = null;
|
var db = null;
|
||||||
try {
|
try {
|
||||||
db = window.openDatabase_orig(name, version, desc, size);
|
db = window.openDatabase_orig(name, version, desc, size);
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
db = null;
|
db = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (db == null) {
|
if (db == null) {
|
||||||
setupDroidDB();
|
setupDroidDB();
|
||||||
return DroidDB_openDatabase(name, version, desc, size);
|
return DroidDB_openDatabase(name, version, desc, size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof window.localStorage === "undefined") {
|
if (typeof window.localStorage === "undefined") {
|
||||||
@ -427,4 +425,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
PhoneGap.waitForInitialization("cupcakeStorage");
|
PhoneGap.waitForInitialization("cupcakeStorage");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user