You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by de...@apache.org on 2012/04/03 14:59:30 UTC
[9/15] Update build to use unified js.
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/46d60472/javascript/device.js
----------------------------------------------------------------------
diff --git a/javascript/device.js b/javascript/device.js
deleted file mode 100644
index 1f2afad..0000000
--- a/javascript/device.js
+++ /dev/null
@@ -1,76 +0,0 @@
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- * Copyright (c) 2011, Research In Motion Limited.
- */
-
-/**
- * navigator.device
- *
- * Represents the mobile device, and provides properties for inspecting the
- * model, version, UUID of the phone, etc.
- */
-(function () {
- "use strict";
-
- /**
- * @constructor
- */
- function Device() {
- var me = this;
-
- Cordova.exec(
- function (device) {
- me.platform = device.platform;
- me.version = device.version;
- me.name = device.name;
- me.uuid = device.uuid;
- me.cordova = device.cordova;
- },
- function (e) {
- console.log("Error initializing Cordova: " + e);
- },
- "Device",
- "getDeviceInfo",
- []
- );
-
- }
-
- /**
- * Define navigator.device.
- */
- Cordova.addConstructor(function () {
- var key;
-
- window.device = new Device();
-
- /* Newer BlackBerry 6 devices now define `navigator.device` */
- if (typeof navigator.device === 'undefined') {
- navigator.device = {};
- }
-
- /* Add Cordova device properties */
- for (key in window.device) {
- navigator.device[key] = window.device[key];
- }
-
- Cordova.onCordovaInfoReady.fire();
- });
-}());
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/46d60472/javascript/file.js
----------------------------------------------------------------------
diff --git a/javascript/file.js b/javascript/file.js
deleted file mode 100644
index be1d2de..0000000
--- a/javascript/file.js
+++ /dev/null
@@ -1,1515 +0,0 @@
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * FileError
- */
-function FileError() {
- this.code = null;
-};
-
-// File error codes
-// Found in DOMException
-FileError.NOT_FOUND_ERR = 1;
-FileError.SECURITY_ERR = 2;
-FileError.ABORT_ERR = 3;
-
-// Added by File API specification
-FileError.NOT_READABLE_ERR = 4;
-FileError.ENCODING_ERR = 5;
-FileError.NO_MODIFICATION_ALLOWED_ERR = 6;
-FileError.INVALID_STATE_ERR = 7;
-FileError.SYNTAX_ERR = 8;
-FileError.INVALID_MODIFICATION_ERR = 9;
-FileError.QUOTA_EXCEEDED_ERR = 10;
-FileError.TYPE_MISMATCH_ERR = 11;
-FileError.PATH_EXISTS_ERR = 12;
-
-/**
- * navigator.fileMgr
- *
- * Provides file utility methods.
- */
-(function() {
- /**
- * Check that navigator.fileMgr has not been initialized.
- */
- if (typeof navigator.fileMgr !== "undefined") {
- return;
- }
-
- /**
- * @constructor
- */
- function FileMgr() {
- };
-
- /**
- * Returns the available memory in bytes for the root file system of the
- * specified file path.
- *
- * @param filePath A file system path
- */
- FileMgr.prototype.getFreeDiskSpace = function(filePath) {
- return blackberry.io.dir.getFreeSpaceForRoot(filePath);
- };
-
- /**
- * Tests whether file exists. Will return false if the path specifies a directory.
- *
- * @param fullPath The full path of the file
- */
- FileMgr.prototype.testFileExists = function(fullPath) {
- return blackberry.io.file.exists(fullPath);
- };
-
- /**
- * Tests whether directory exists. Will return false if the path specifies a file.
- *
- * @param fullPath The full path of the directory
- */
- FileMgr.prototype.testDirectoryExists = function(fullPath) {
- return blackberry.io.dir.exists(fullPath);
- };
-
- /**
- * Reads a file from the device and encodes the contents using the specified
- * encoding.
- *
- * @param fileName The full path of the file to read
- * @param encoding The encoding to use to encode the file's content
- * @param successCallback Callback invoked with file contents
- * @param errorCallback Callback invoked on error
- */
- FileMgr.prototype.readAsText = function(fileName, encoding, successCallback, errorCallback) {
- Cordova.exec(successCallback, errorCallback, "File", "readAsText", [fileName, encoding]);
- };
-
- /**
- * Reads a file from the device and encodes the contents using BASE64 encoding.
- *
- * @param fileName The full path of the file to read.
- * @param successCallback Callback invoked with file contents
- * @param errorCallback Callback invoked on error
- */
- FileMgr.prototype.readAsDataURL = function(fileName, successCallback, errorCallback) {
- Cordova.exec(successCallback, errorCallback, "File", "readAsDataURL", [fileName]);
- };
-
- /**
- * Writes data to the specified file.
- *
- * @param fileName The full path of the file to write
- * @param data The data to be written
- * @param position The position in the file to begin writing
- * @param successCallback Callback invoked after successful write operation
- * @param errorCallback Callback invoked on error
- */
- FileMgr.prototype.write = function(fileName, data, position, successCallback, errorCallback) {
- Cordova.exec(successCallback, errorCallback, "File", "write", [fileName, data, position]);
- };
-
- /**
- * Changes the length of the specified file. Data beyond new length is discarded.
- *
- * @param fileName The full path of the file to truncate
- * @param size The size to which the length of the file is to be adjusted
- * @param successCallback Callback invoked after successful write operation
- * @param errorCallback Callback invoked on error
- */
- FileMgr.prototype.truncate = function(fileName, size, successCallback, errorCallback) {
- Cordova.exec(successCallback, errorCallback, "File", "truncate", [fileName, size]);
- };
-
- /**
- * Define navigator.fileMgr object.
- */
- Cordova.addConstructor(function() {
- navigator.fileMgr = new FileMgr();
- });
-}());
-
-/**
- * FileReader
- *
- * Reads files from the device file system.
- */
-var FileReader = FileReader || (function() {
- /**
- * @constructor
- */
- function FileReader() {
- this.fileName = "";
-
- this.readyState = 0;
-
- // File data
- this.result = null;
-
- // Error
- this.error = null;
-
- // Event handlers
- this.onloadstart = null; // When the read starts.
- this.onprogress = null; // While reading (and decoding) file or fileBlob data, and reporting partial file data (progess.loaded/progress.total)
- this.onload = null; // When the read has successfully completed.
- this.onerror = null; // When the read has failed (see errors).
- this.onloadend = null; // When the request has completed (either in success or failure).
- this.onabort = null; // When the read has been aborted. For instance, by invoking the abort() method.
- };
-
- /**
- * States
- */
- FileReader.EMPTY = 0;
- FileReader.LOADING = 1;
- FileReader.DONE = 2;
-
- /**
- * Abort read file operation.
- */
- FileReader.prototype.abort = function() {
- var event;
-
- // reset everything
- this.readyState = FileReader.DONE;
- this.result = null;
-
- // set error
- var error = new FileError();
- error.code = error.ABORT_ERR;
- this.error = error;
-
- // abort procedure
- if (typeof this.onerror == "function") {
- event = {"type":"error", "target":this};
- this.onerror(event);
- }
- if (typeof this.onabort == "function") {
- event = {"type":"abort", "target":this};
- this.onabort(event);
- }
- if (typeof this.onloadend == "function") {
- event = {"type":"loadend", "target":this};
- this.onloadend(event);
- }
- };
-
- /**
- * Reads and encodes a text file.
- *
- * @param file {File} File object containing file properties
- * @param encoding [Optional] (see http://www.iana.org/assignments/character-sets)
- */
- FileReader.prototype.readAsText = function(file, encoding) {
- var event;
-
- // Use UTF-8 as default encoding
- var enc = encoding ? encoding : "UTF-8";
-
- // start
- this.readyState = FileReader.LOADING;
- if (typeof this.onloadstart == "function") {
- event = {"type":"loadstart", "target":this};
- this.onloadstart(event);
- }
-
- // read and encode file
- this.fileName = file.fullPath;
- var me = this;
- navigator.fileMgr.readAsText(file.fullPath, enc,
-
- // success callback
- function(result) {
- // If DONE (canceled), then don't do anything
- if (me.readyState === FileReader.DONE) {
- return;
- }
-
- // success procedure
- me.result = result;
- if (typeof me.onload == "function") {
- event = {"type":"load", "target":me};
- me.onload(event);
- }
- me.readyState = FileReader.DONE;
- if (typeof me.onloadend == "function") {
- event = {"type":"loadend", "target":me};
- me.onloadend(event);
- }
- },
-
- // error callback
- function(error) {
- // If DONE (canceled), then don't do anything
- if (me.readyState === FileReader.DONE) {
- return;
- }
-
- // capture error
- var err = new FileError();
- err.code = error;
- me.error = err;
-
- // error procedure
- me.result = null;
- if (typeof me.onerror == "function") {
- event = {"type":"error", "target":me};
- me.onerror(event);
- }
- me.readyState = FileReader.DONE;
- if (typeof me.onloadend == "function") {
- event = {"type":"loadend", "target":me};
- me.onloadend(event);
- }
- }
- );
- };
-
- /**
- * Read file and return data as a base64 encoded data url.
- * A data url is of the form:
- * data:[<mediatype>][;base64],<data>
- *
- * @param file {File} File object containing file properties
- */
- FileReader.prototype.readAsDataURL = function(file) {
- var event;
-
- // start
- this.readyState = FileReader.LOADING;
- if (typeof this.onloadstart == "function") {
- event = {"type":"loadstart", "target":this};
- this.onloadstart(event);
- }
-
- // read and encode file
- this.fileName = file.fullPath;
- var me = this;
- navigator.fileMgr.readAsDataURL(file.fullPath,
-
- // success callback
- function(result) {
- // If DONE (canceled), then don't do anything
- if (me.readyState === FileReader.DONE) {
- return;
- }
-
- // success procedure
- me.result = result;
- if (typeof me.onload == "function") {
- event = {"type":"load", "target":me};
- me.onload(event);
- }
- me.readyState = FileReader.DONE;
- if (typeof me.onloadend == "function") {
- event = {"type":"loadend", "target":me};
- me.onloadend(event);
- }
- },
-
- // error callback
- function(error) {
- // If DONE (canceled), then don't do anything
- if (me.readyState === FileReader.DONE) {
- return;
- }
-
- // capture error
- var err = new FileError();
- err.code = error;
- me.error = err;
-
- // error procedure
- me.result = null;
- if (typeof me.onerror == "function") {
- event = {"type":"error", "target":me};
- me.onerror(event);
- }
- me.readyState = FileReader.DONE;
- if (typeof me.onloadend == "function") {
- event = {"type":"loadend", "target":me};
- me.onloadend(event);
- }
- }
- );
- };
-
- /**
- * Read file and return data as a binary data.
- *
- * @param file {File} File object containing file properties
- */
- FileReader.prototype.readAsBinaryString = function(file) {
- // TODO - Can't return binary data to browser.
- if (typeof file.fullPath === "undefined") {
- this.fileName = file;
- } else {
- this.fileName = file.fullPath;
- }
- };
-
- /**
- * Read file and return data as a binary data.
- *
- * @param file {File} File object containing file properties
- */
- FileReader.prototype.readAsArrayBuffer = function(file) {
- // TODO - Can't return binary data to browser.
- if (typeof file.fullPath === "undefined") {
- this.fileName = file;
- } else {
- this.fileName = file.fullPath;
- }
- };
-
- return FileReader;
-}());
-
-/**
- * FileWriter
- *
- * Writes files to the device file system.
- */
-var FileWriter = FileWriter || (function() {
- /**
- * @constructor
- * @param file {File} a File object representing a file on the file system
- */
- function FileWriter(file) {
- this.fileName = file.fullPath || null;
- this.length = file.size || 0;
-
- // default is to write at the beginning of the file
- this.position = 0;
-
- this.readyState = 0; // EMPTY
-
- // Error
- this.error = null;
-
- // Event handlers
- this.onwritestart = null; // When writing starts
- this.onprogress = null; // While writing the file, and reporting partial file data
- this.onwrite = null; // When the write has successfully completed.
- this.onwriteend = null; // When the request has completed (either in success or failure).
- this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method.
- this.onerror = null; // When the write has failed (see errors).
- };
-
- /**
- * States
- */
- FileWriter.INIT = 0;
- FileWriter.WRITING = 1;
- FileWriter.DONE = 2;
-
- /**
- * Abort writing file.
- */
- FileWriter.prototype.abort = function() {
- var event;
-
- // check for invalid state
- if (this.readyState === FileWriter.DONE || this.readyState === FileWriter.INIT) {
- throw FileError.INVALID_STATE_ERR;
- }
-
- // set error
- var error = new FileError();
- error.code = error.ABORT_ERR;
- this.error = error;
-
- // dispatch progress events
- if (typeof this.onerror == "function") {
- event = {"type":"error", "target":this};
- this.onerror(event);
- }
- if (typeof this.onabort == "function") {
- event = {"type":"abort", "target":this};
- this.onabort(event);
- }
-
- // set state
- this.readyState = FileWriter.DONE;
-
- // done
- if (typeof this.writeend == "function") {
- event = {"type":"writeend", "target":this};
- this.writeend(event);
- }
- };
-
- /**
- * Sets the file position at which the next write will occur.
- *
- * @param offset Absolute byte offset into the file
- */
- FileWriter.prototype.seek = function(offset) {
- // Throw an exception if we are already writing a file
- if (this.readyState === FileWriter.WRITING) {
- throw FileError.INVALID_STATE_ERR;
- }
-
- if (!offset) {
- return;
- }
-
- // offset is bigger than file size, set to length of file
- if (offset > this.length) {
- this.position = this.length;
- }
- // seek back from end of file
- else if (offset < 0) {
- this.position = Math.max(offset + this.length, 0);
- }
- // offset in the middle of file
- else {
- this.position = offset;
- }
- };
-
- /**
- * Truncates the file to the specified size.
- *
- * @param size The size to which the file length is to be adjusted
- */
- FileWriter.prototype.truncate = function(size) {
- var event;
-
- // Throw an exception if we are already writing a file
- if (this.readyState === FileWriter.WRITING) {
- throw FileError.INVALID_STATE_ERR;
- }
-
- // start
- this.readyState = FileWriter.WRITING;
- if (typeof this.onwritestart == "function") {
- event = {"type":"writestart", "target":this};
- this.onwritestart(event);
- }
-
- // truncate file
- var me = this;
- navigator.fileMgr.truncate(this.fileName, size,
- // Success callback receives the new file size
- function(result) {
- // If DONE (canceled), then don't do anything
- if (me.readyState === FileWriter.DONE) {
- return;
- }
-
- // new file size is returned
- me.length = result;
- // position is lesser of old position or new file size
- me.position = Math.min(me.position, result);
-
- // success procedure
- if (typeof me.onwrite == "function") {
- event = {"type":"write", "target":me};
- me.onwrite(event);
- }
- me.readyState = FileWriter.DONE;
- if (typeof me.onwriteend == "function") {
- event = {"type":"writeend", "target":me};
- me.onwriteend(event);
- }
- },
-
- // Error callback
- function(error) {
- // If DONE (canceled), then don't do anything
- if (me.readyState === FileWriter.DONE) {
- return;
- }
-
- // Save error
- var err = new FileError();
- err.code = error;
- me.error = err;
-
- // error procedure
- if (typeof me.onerror == "function") {
- event = {"type":"error", "target":me};
- me.onerror(event);
- }
- me.readyState = FileWriter.DONE;
- if (typeof me.onwriteend == "function") {
- event = {"type":"writeend", "target":me};
- me.onwriteend(event);
- }
- }
- );
- };
-
- /**
- * Writes the contents of a file to the device.
- *
- * @param data contents to be written
- */
- FileWriter.prototype.write = function(data) {
- var event;
-
- // Throw an exception if we are already writing a file
- if (this.readyState === FileWriter.WRITING) {
- throw FileError.INVALID_STATE_ERR;
- }
-
- // WRITING state
- this.readyState = FileWriter.WRITING;
- if (typeof this.onwritestart == "function") {
- event = {"type":"writestart", "target":this};
- this.onwritestart(event);
- }
-
- // Write file
- var me = this;
- navigator.fileMgr.write(this.fileName, data, this.position,
-
- // Success callback receives bytes written
- function(result) {
- // If DONE (canceled), then don't do anything
- if (me.readyState === FileWriter.DONE) {
- return;
- }
-
- // position always increases by bytes written because file would be extended
- me.position += result;
-
- // new length is now where writing finished
- me.length = me.position;
-
- // success procedure
- if (typeof me.onwrite == "function") {
- event = {"type":"write", "target":me};
- me.onwrite(event);
- }
- me.readyState = FileWriter.DONE;
- if (typeof me.onwriteend == "function") {
- event = {"type":"writeend", "target":me};
- me.onwriteend(event);
- }
- },
-
- // Error callback
- function(error) {
- // If DONE (canceled), then don't do anything
- if (me.readyState === FileWriter.DONE) {
- return;
- }
-
- // Save error
- var err = new FileError();
- err.code = error;
- me.error = err;
-
- // error procedure
- if (typeof me.onerror == "function") {
- event = {"type":"error", "target":me};
- me.onerror(event);
- }
- me.readyState = FileWriter.DONE;
- if (typeof me.onwriteend == "function") {
- event = {"type":"writeend", "target":me};
- me.onwriteend(event);
- }
- }
- );
- };
-
- return FileWriter;
-}());
-
-/**
- * Represents a file or directory on the local file system.
- */
-var Entry = Entry || (function() {
- /**
- * Represents a file or directory on the local file system.
- *
- * @param isFile
- * {boolean} true if Entry is a file (readonly)
- * @param isDirectory
- * {boolean} true if Entry is a directory (readonly)
- * @param name
- * {DOMString} name of the file or directory, excluding the path
- * leading to it (readonly)
- * @param fullPath
- * {DOMString} the absolute full path to the file or directory
- * (readonly)
- */
- function Entry(entry) {
- // protect against not using 'new'
- if (!(this instanceof Entry)) {
- return new Entry(entry);
- }
- this.isFile = (entry && entry.isFile === true) ? true : false;
- this.isDirectory = (entry && entry.isDirectory === true) ? true : false;
- this.name = (entry && entry.name) || "";
- this.fullPath = (entry && entry.fullPath) || "";
- };
-
- /**
- * Look up the metadata of the entry.
- *
- * @param successCallback
- * {Function} is called with a Metadata object
- * @param errorCallback
- * {Function} is called with a FileError
- */
- Entry.prototype.getMetadata = function(successCallback, errorCallback) {
- var success = function(lastModified) {
- var metadata = new Metadata();
- metadata.modificationTime = new Date(lastModified);
- if (typeof successCallback === "function") {
- successCallback(metadata);
- }
- },
- fail = function(error) {
- LocalFileSystem.onError(error, errorCallback);
- };
-
- Cordova.exec(success, fail, "File", "getMetadata", [this.fullPath]);
- };
-
- /**
- * Move a file or directory to a new location.
- *
- * @param parent
- * {DirectoryEntry} the directory to which to move this entry
- * @param newName
- * {DOMString} new name of the entry, defaults to the current name
- * @param successCallback
- * {Function} called with the new DirectoryEntry object
- * @param errorCallback
- * {Function} called with a FileError
- */
- Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
- // source path
- var srcPath = this.fullPath,
- // entry name
- name = newName || this.name,
- // destination path
- dstPath,
- success = function(entry) {
- var result;
-
- if (entry) {
- // create appropriate Entry object
- result = (entry.isDirectory) ? new DirectoryEntry(entry) : new FileEntry(entry);
- try {
- successCallback(result);
- }
- catch (e) {
- console.log('Error invoking callback: ' + e);
- }
- }
- else {
- // no Entry object returned
- fail(FileError.NOT_FOUND_ERR);
- }
- },
- fail = function(error) {
- LocalFileSystem.onError(error, errorCallback);
- };
-
- // user must specify parent Entry
- if (!parent) {
- fail(FileError.NOT_FOUND_ERR);
- return;
- }
-
- // copy
- Cordova.exec(success, fail, "File", "moveTo", [srcPath, parent.fullPath, name]);
- };
-
- /**
- * Copy a directory to a different location.
- *
- * @param parent
- * {DirectoryEntry} the directory to which to copy the entry
- * @param newName
- * {DOMString} new name of the entry, defaults to the current name
- * @param successCallback
- * {Function} called with the new Entry object
- * @param errorCallback
- * {Function} called with a FileError
- */
- Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
- // source path
- var srcPath = this.fullPath,
- // entry name
- name = newName || this.name,
- // success callback
- success = function(entry) {
- var result;
-
- if (entry) {
- // create appropriate Entry object
- result = (entry.isDirectory) ? new DirectoryEntry(entry) : new FileEntry(entry);
- try {
- successCallback(result);
- }
- catch (e) {
- console.log('Error invoking callback: ' + e);
- }
- }
- else {
- // no Entry object returned
- fail(FileError.NOT_FOUND_ERR);
- }
- },
- fail = function(error) {
- LocalFileSystem.onError(error, errorCallback);
- };
-
- // user must specify parent Entry
- if (!parent) {
- fail(FileError.NOT_FOUND_ERR);
- return;
- }
-
- // copy
- Cordova.exec(success, fail, "File", "copyTo", [srcPath, parent.fullPath, name]);
- };
-
- /**
- * Return a URI that can be used to identify this entry.
- *
- * @param mimeType
- * {DOMString} for a FileEntry, the mime type to be used to
- * interpret the file, when loaded through this URI.
- * @param successCallback
- * {Function} called with the new Entry object
- * @param errorCallback
- * {Function} called with a FileError
- */
- Entry.prototype.toURL = function() {
- // fullPath attribute contains the full URI on BlackBerry
- return this.fullPath;
- };
-
- /**
- * Return a URI that can be used to identify this entry.
- *
- * @param mimeType
- * {DOMString} for a FileEntry, the mime type to be used to
- * interpret the file, when loaded through this URI.
- * @param successCallback
- * {Function} called with the new Entry object
- * @param errorCallback
- * {Function} called with a FileError
- */
- Entry.prototype.toURI = function(mimeType, successCallback, errorCallback) {
- // fullPath attribute contains the full URI on BlackBerry
- console.log("DEPRECATED: Update your code to use 'toURL'");
- return this.fullPath;
- };
-
- /**
- * Remove a file or directory. It is an error to attempt to delete a
- * directory that is not empty. It is an error to attempt to delete a
- * root directory of a file system.
- *
- * @param successCallback {Function} called with no parameters
- * @param errorCallback {Function} called with a FileError
- */
- Entry.prototype.remove = function(successCallback, errorCallback) {
- var path = this.fullPath,
- // directory contents
- contents = [];
-
- // file
- if (blackberry.io.file.exists(path)) {
- try {
- blackberry.io.file.deleteFile(path);
- if (typeof successCallback === "function") {
- successCallback();
- }
- }
- catch (e) {
- // permissions don't allow
- LocalFileSystem.onError(FileError.INVALID_MODIFICATION_ERR, errorCallback);
- }
- }
- // directory
- else if (blackberry.io.dir.exists(path)) {
- // it is an error to attempt to remove the file system root
- if (LocalFileSystem.isFileSystemRoot(path)) {
- LocalFileSystem.onError(FileError.NO_MODIFICATION_ALLOWED_ERR, errorCallback);
- }
- else {
- // check to see if directory is empty
- contents = blackberry.io.dir.listFiles(path);
- if (contents.length !== 0) {
- LocalFileSystem.onError(FileError.INVALID_MODIFICATION_ERR, errorCallback);
- }
- else {
- try {
- // delete
- blackberry.io.dir.deleteDirectory(path, false);
- if (typeof successCallback === "function") {
- successCallback();
- }
- }
- catch (e) {
- // permissions don't allow
- LocalFileSystem.onError(FileError.NO_MODIFICATION_ALLOWED_ERR, errorCallback);
- }
- }
- }
- }
- // not found
- else {
- LocalFileSystem.onError(FileError.NOT_FOUND_ERR, errorCallback);
- }
- };
-
- /**
- * Look up the parent DirectoryEntry of this entry.
- *
- * @param successCallback {Function} called with the parent DirectoryEntry object
- * @param errorCallback {Function} called with a FileError
- */
- Entry.prototype.getParent = function(successCallback, errorCallback) {
- var that = this;
-
- try {
- // On BlackBerry, the TEMPORARY file system is actually a temporary
- // directory that is created on a per-application basis. This is
- // to help ensure that applications do not share the same temporary
- // space. So we check to see if this is the TEMPORARY file system
- // (directory). If it is, we must return this Entry, rather than
- // the Entry for its parent.
- window.requestFileSystem(LocalFileSystem.TEMPORARY, 0,
- function(fileSystem) {
- if (fileSystem.root.fullPath === that.fullPath) {
- successCallback(fileSystem.root);
- }
- else {
- window.resolveLocalFileSystemURI(
- blackberry.io.dir.getParentDirectory(that.fullPath),
- successCallback,
- errorCallback);
- }
- },
- function (error) {
- LocalFileSystem.onError(error, errorCallback);
- });
- }
- catch (e) {
- // FIXME: need a generic error code
- LocalFileSystem.onError(FileError.NOT_FOUND_ERR, errorCallback);
- }
- };
-
- return Entry;
-}());
-
-/**
- * Represents a directory on the local file system.
- */
-var DirectoryEntry = DirectoryEntry || (function() {
- /**
- * Represents a directory on the local file system.
- */
- function DirectoryEntry(entry) {
- DirectoryEntry.__super__.constructor.apply(this, arguments);
- };
-
- // extend Entry
- Cordova.extend(DirectoryEntry, Entry);
-
- /**
- * Create or look up a file.
- *
- * @param path {DOMString}
- * either a relative or absolute path from this directory in
- * which to look up or create a file
- * @param options {Flags}
- * options to create or exclusively create the file
- * @param successCallback {Function}
- * called with the new FileEntry object
- * @param errorCallback {Function}
- * called with a FileError object if error occurs
- */
- DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) {
- // create file if it doesn't exist
- var create = (options && options.create === true) ? true : false,
- // if true, causes failure if create is true and path already exists
- exclusive = (options && options.exclusive === true) ? true : false,
- // file exists
- exists,
- // create a new FileEntry object and invoke success callback
- createEntry = function() {
- var path_parts = path.split('/'),
- name = path_parts[path_parts.length - 1],
- fileEntry = new FileEntry({name: name,
- isDirectory: false, isFile: true, fullPath: path});
-
- // invoke success callback
- if (typeof successCallback === 'function') {
- successCallback(fileEntry);
- }
- };
-
- // determine if path is relative or absolute
- if (!path) {
- LocalFileSystem.onError(FileError.ENCODING_ERR, errorCallback);
- return;
- }
- else if (path.indexOf(this.fullPath) !== 0) {
- // path does not begin with the fullPath of this directory
- // therefore, it is relative
- path = this.fullPath + '/' + path;
- }
-
- // determine if file exists
- try {
- // will return true if path exists AND is a file
- exists = blackberry.io.file.exists(path);
- }
- catch (e) {
- // invalid path
- LocalFileSystem.onError(FileError.ENCODING_ERR, errorCallback);
- return;
- }
-
- // path is a file
- if (exists) {
- if (create && exclusive) {
- // can't guarantee exclusivity
- LocalFileSystem.onError(FileError.PATH_EXISTS_ERR, errorCallback);
- }
- else {
- // create entry for existing file
- createEntry();
- }
- }
- // will return true if path exists AND is a directory
- else if (blackberry.io.dir.exists(path)) {
- // the path is a directory
- LocalFileSystem.onError(FileError.TYPE_MISMATCH_ERR, errorCallback);
- }
- // path does not exist, create it
- else if (create) {
- // create empty file
- navigator.fileMgr.write(path, "", 0,
- function(result) {
- // file created
- createEntry();
- },
- function(error) {
- // unable to create file
- LocalFileSystem.onError(error, errorCallback);
- });
- }
- // path does not exist, don't create
- else {
- // file doesn't exist
- LocalFileSystem.onError(FileError.NOT_FOUND_ERR, errorCallback);
- }
- };
-
- /**
- * Creates or looks up a directory.
- *
- * @param path
- * {DOMString} either a relative or absolute path from this
- * directory in which to look up or create a directory
- * @param options
- * {Flags} options to create or exclusively create the
- * directory
- * @param successCallback
- * {Function} called with the new DirectoryEntry
- * @param errorCallback
- * {Function} called with a FileError
- */
- DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) {
- // create directory if it doesn't exist
- var create = (options && options.create === true) ? true : false,
- // if true, causes failure if create is true and path already exists
- exclusive = (options && options.exclusive === true) ? true : false,
- // directory exists
- exists,
- // create a new DirectoryEntry object and invoke success callback
- createEntry = function() {
- var path_parts = path.split('/'),
- name = path_parts[path_parts.length - 1],
- dirEntry = new DirectoryEntry({name: name,
- isDirectory: true, isFile: false, fullPath: path});
-
- // invoke success callback
- if (typeof successCallback === 'function') {
- successCallback(dirEntry);
- }
- };
-
- // determine if path is relative or absolute
- if (!path) {
- LocalFileSystem.onError(FileError.ENCODING_ERR, errorCallback);
- return;
- }
- else if (path.indexOf(this.fullPath) !== 0) {
- // path does not begin with the fullPath of this directory
- // therefore, it is relative
- path = this.fullPath + '/' + path;
- }
-
- // determine if directory exists
- try {
- // will return true if path exists AND is a directory
- exists = blackberry.io.dir.exists(path);
- }
- catch (e) {
- // invalid path
- LocalFileSystem.onError(FileError.ENCODING_ERR, errorCallback);
- return;
- }
-
- // path is a directory
- if (exists) {
- if (create && exclusive) {
- // can't guarantee exclusivity
- LocalFileSystem.onError(FileError.PATH_EXISTS_ERR, errorCallback);
- }
- else {
- // create entry for existing directory
- createEntry();
- }
- }
- // will return true if path exists AND is a file
- else if (blackberry.io.file.exists(path)) {
- // the path is a file
- LocalFileSystem.onError(FileError.TYPE_MISMATCH_ERR, errorCallback);
- }
- // path does not exist, create it
- else if (create) {
- try {
- // directory path must have trailing slash
- var dirPath = path;
- if (dirPath.substr(-1) !== '/') {
- dirPath += '/';
- }
- blackberry.io.dir.createNewDir(dirPath);
- createEntry();
- }
- catch (e) {
- // unable to create directory
- LocalFileSystem.onError(FileError.NOT_FOUND_ERR, errorCallback);
- }
- }
- // path does not exist, don't create
- else {
- // directory doesn't exist
- LocalFileSystem.onError(FileError.NOT_FOUND_ERR, errorCallback);
- }
- };
-
- /**
- * Delete a directory and all of it's contents.
- *
- * @param successCallback {Function} called with no parameters
- * @param errorCallback {Function} called with a FileError
- */
- DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) {
- // we're removing THIS directory
- var path = this.fullPath;
-
- // attempt to delete directory
- if (blackberry.io.dir.exists(path)) {
- // it is an error to attempt to remove the file system root
- if (LocalFileSystem.isFileSystemRoot(path)) {
- LocalFileSystem.onError(FileError.NO_MODIFICATION_ALLOWED_ERR, errorCallback);
- }
- else {
- try {
- // delete the directory, setting recursive flag to true
- blackberry.io.dir.deleteDirectory(path, true);
- if (typeof successCallback === "function") {
- successCallback();
- }
- } catch (e) {
- // permissions don't allow deletion
- console.log(e);
- LocalFileSystem.onError(FileError.NO_MODIFICATION_ALLOWED_ERR, errorCallback);
- }
- }
- }
- // it's a file, not a directory
- else if (blackberry.io.file.exists(path)) {
- LocalFileSystem.onError(FileError.TYPE_MISMATCH_ERR, errorCallback);
- }
- // not found
- else {
- LocalFileSystem.onError(FileError.NOT_FOUND_ERR, errorCallback);
- }
- };
-
- /**
- * An interface that lists the files and directories in a directory.
- */
- function DirectoryReader(path) {
- this.path = path || null;
- };
-
- /**
- * Creates a new DirectoryReader to read entries from this directory
- */
- DirectoryEntry.prototype.createReader = function() {
- return new DirectoryReader(this.fullPath);
- };
-
- /**
- * Reads the contents of the directory.
- * @param successCallback {Function} called with a list of entries
- * @param errorCallback {Function} called with a FileError
- */
- DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
- var path = this.path,
- // process directory contents
- createEntries = function(array) {
- var entries, entry, num_entries, i, name, result = [];
-
- // get objects from JSONArray
- try {
- entries = JSON.parse(array);
- }
- catch (e) {
- console.log('unable to parse JSON: ' + e);
- LocalFileSystem.onError(FileError.SYNTAX_ERR, errorCallback);
- return;
- }
-
- // append file separator to path
- if (/\/$/.test(path) === false) {
- path += '/';
- }
-
- // create FileEntry or DirectoryEntry object for each listing
- for (i = 0, num_entries = entries.length; i < num_entries; i += 1) {
- name = entries[i];
-
- // if name ends with '/', it's a directory
- if (/\/$/.test(name) === true) {
- // trim file separator
- name = name.substring(0, name.length - 1);
- entry = new DirectoryEntry({
- name: name,
- fullPath: path + name,
- isFile: false,
- isDirectory: true
- });
- }
- else {
- entry = new FileEntry({
- name: name,
- fullPath: path + name,
- isFile: true,
- isDirectory: false
- });
- }
- result.push(entry);
- }
- try {
- successCallback(result);
- }
- catch (e) {
- console.log("Error invoking callback: " + e);
- }
- };
-
- // sanity check
- if (!blackberry.io.dir.exists(path)) {
- LocalFileSystem.onError(FileError.NOT_FOUND_ERR, errorCallback);
- return;
- }
-
- // list directory contents
- Cordova.exec(createEntries, errorCallback, "File", "readEntries", [path]);
- };
-
- return DirectoryEntry;
-}());
-
-/**
- * Represents a file on the local file system.
- */
-var FileEntry = FileEntry || (function() {
- /**
- * Represents a file on the local file system.
- */
- function FileEntry(entry) {
- FileEntry.__super__.constructor.apply(this, arguments);
- };
-
- // extend Entry
- Cordova.extend(FileEntry, Entry);
-
- /**
- * Creates a new FileWriter associated with the file that this FileEntry
- * represents.
- *
- * @param successCallback
- * {Function} called with the new FileWriter
- * @param errorCallback
- * {Function} called with a FileError
- */
- FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
- var writer;
-
- // create a FileWriter using a File object for this entry
- this.file(function(file) {
- try {
- writer = new FileWriter(file);
- successCallback(writer);
- }
- catch (e) {
- console.log("Error invoking callback: " + e);
- }
- }, errorCallback);
- };
-
- /**
- * Returns a File that represents the current state of the file that this
- * FileEntry represents.
- *
- * @param successCallback
- * {Function} called with the new File object
- * @param errorCallback
- * {Function} called with a FileError
- */
- FileEntry.prototype.file = function(successCallback, errorCallback) {
- var properties, file;
-
- // check that file still exists
- if (blackberry.io.file.exists(this.fullPath)) {
- // get file properties
- properties = blackberry.io.file.getFileProperties(this.fullPath);
- file = new File();
- file.name = this.name;
- file.fullPath = this.fullPath;
- file.type = properties.mimeType;
- file.lastModifiedDate = properties.dateModified;
- file.size = properties.size;
-
- try {
- successCallback(file);
- }
- catch (e) {
- console.log("Error invoking callback: " + e);
- }
- }
- // entry is a directory
- else if (blackberry.io.dir.exists(this.fullPath)) {
- LocalFileSystem.onError(FileError.TYPE_MISMATCH_ERR, errorCallback);
- }
- // entry has been deleted
- else {
- LocalFileSystem.onError(FileError.NOT_FOUND_ERR, errorCallback);
- }
- };
-
- return FileEntry;
-}());
-
-/**
- * An interface representing a file system
- *
- * name {DOMString} unique name of the file system (readonly)
- * root {DirectoryEntry} directory of the file system (readonly)
- */
-function FileSystem() {
- this.name = null;
- this.root = null;
-};
-
-/**
- * Information about the state of the file or directory.
- *
- * modificationTime {Date} (readonly)
- */
-function Metadata() {
- this.modificationTime = null;
-};
-
-/**
- * Supplies arguments to methods that lookup or create files and directories.
- *
- * @param create
- * {boolean} file or directory if it doesn't exist
- * @param exclusive
- * {boolean} used with create; if true the command will fail if
- * target path exists
- */
-function Flags(create, exclusive) {
- this.create = create || false;
- this.exclusive = exclusive || false;
-};
-
-/**
- * Contains properties of a file on the file system.
- */
-var File = (function() {
- /**
- * Constructor.
- * 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
- */
- function File() {
- this.name = null;
- this.fullPath = null;
- this.type = null;
- this.lastModifiedDate = null;
- this.size = 0;
- };
-
- return File;
-}());
-
-/**
- * Represents a local file system.
- */
-var LocalFileSystem = LocalFileSystem || (function() {
-
- /**
- * Define file system types.
- */
- var LocalFileSystem = {
- TEMPORARY: 0, // temporary, with no guarantee of persistence
- PERSISTENT: 1 // persistent
- };
-
- /**
- * Static method for invoking error callbacks.
- * @param error FileError code
- * @param errorCallback error callback to invoke
- */
- LocalFileSystem.onError = function(error, errorCallback) {
- var err = new FileError();
- err.code = error;
- try {
- errorCallback(err);
- }
- catch (e) {
- console.log('Error invoking callback: ' + e);
- }
- };
-
- /**
- * Utility method to determine if the specified path is the root file
- * system path.
- * @param path fully qualified path
- */
- LocalFileSystem.isFileSystemRoot = function(path) {
- return Cordova.exec(null, null, "File", "isFileSystemRoot", [path]);
- };
-
- /**
- * Request a file system in which to store application data.
- * @param type local file system type
- * @param size indicates how much storage space, in bytes, the application expects to need
- * @param successCallback invoked with a FileSystem object
- * @param errorCallback invoked if error occurs retrieving file system
- */
- var _requestFileSystem = function(type, size, successCallback, errorCallback) {
- // if successful, return a FileSystem object
- var success = function(file_system) {
- var result;
-
- if (file_system) {
- // grab the name from the file system object
- result = {
- name: file_system.name || null
- };
-
- // create Entry object from file system root
- result.root = new DirectoryEntry(file_system.root);
- try {
- successCallback(result);
- }
- catch (e) {
- console.log('Error invoking callback: ' + e);
- }
- }
- else {
- // no FileSystem object returned
- fail(FileError.NOT_FOUND_ERR);
- }
- },
- // error callback
- fail = function(error) {
- LocalFileSystem.onError(error, errorCallback);
- };
-
- Cordova.exec(success, fail, "File", "requestFileSystem", [type, size]);
- };
-
- /**
- * Look up file system Entry referred to by local URI.
- * @param {DOMString} uri URI referring to a local file or directory
- * @param successCallback invoked with Entry object corresponding to URI
- * @param errorCallback invoked if error occurs retrieving file system entry
- */
- var _resolveLocalFileSystemURI = function(uri, successCallback, errorCallback) {
- // if successful, return either a file or directory entry
- var success = function(entry) {
- var result;
-
- if (entry) {
- // create appropriate Entry object
- result = (entry.isDirectory) ? new DirectoryEntry(entry) : new FileEntry(entry);
- try {
- successCallback(result);
- }
- catch (e) {
- console.log('Error invoking callback: ' + e);
- }
- }
- else {
- // no Entry object returned
- fail(FileError.NOT_FOUND_ERR);
- }
- };
-
- // error callback
- var fail = function(error) {
- LocalFileSystem.onError(error, errorCallback);
- };
- Cordova.exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]);
- };
-
- /**
- * Add the FileSystem interface into the browser.
- */
- Cordova.addConstructor(function() {
- if(typeof window.requestFileSystem === "undefined") {
- window.requestFileSystem = _requestFileSystem;
- }
- if(typeof window.resolveLocalFileSystemURI === "undefined") {
- window.resolveLocalFileSystemURI = _resolveLocalFileSystemURI;
- }
- });
-
- return LocalFileSystem;
-}());
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/46d60472/javascript/filetransfer.js
----------------------------------------------------------------------
diff --git a/javascript/filetransfer.js b/javascript/filetransfer.js
deleted file mode 100644
index ee3cc42..0000000
--- a/javascript/filetransfer.js
+++ /dev/null
@@ -1,144 +0,0 @@
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * Options to customize the HTTP request used to upload files.
- *
- * @constructor
- * @param fileKey
- * {String} Name of file request parameter.
- * @param fileName
- * {String} Filename to be used by the server. Defaults to image.jpg.
- * @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.
- */
-var FileUploadOptions = function(fileKey, fileName, mimeType, params) {
- this.fileKey = fileKey || null;
- this.fileName = fileName || null;
- this.mimeType = mimeType || null;
- this.params = params || null;
-};
-
-/**
- * FileUploadResult
- * @constructor
- */
-var FileUploadResult = function() {
- this.bytesSent = 0;
- this.responseCode = null;
- this.response = null;
-};
-
-/**
- * FileTransferError
- * @constructor
- */
-var FileTransferError = function() {
- this.code = null;
-};
-
-FileTransferError.FILE_NOT_FOUND_ERR = 1;
-FileTransferError.INVALID_URL_ERR = 2;
-FileTransferError.CONNECTION_ERR = 3;
-
-/**
- * FileTransfer transfers files to a remote server.
- */
-var FileTransfer = FileTransfer || (function() {
- /**
- * @constructor
- */
- function FileTransfer() {
- };
-
- /**
- * Given an absolute file path, uploads a file on the device to a remote
- * server using a multipart HTTP request.
- *
- * @param filePath
- * {String} Full path of the file on the device
- * @param server
- * {String} URL of the server to receive the file
- * @param successCallback
- * (Function} Callback to be invoked when upload has completed
- * @param errorCallback
- * {Function} Callback to be invoked upon error
- * @param options
- * {FileUploadOptions} Optional parameters such as file name and
- * mimetype
- */
- FileTransfer.prototype.upload = function(filePath, server, successCallback,
- errorCallback, options, debug) {
-
- // check for options
- var fileKey = null;
- var fileName = null;
- var mimeType = null;
- var params = null;
- var chunkedMode = true;
- if (options) {
- fileKey = options.fileKey;
- fileName = options.fileName;
- mimeType = options.mimeType;
- if (options.chunkedMode !== null
- || typeof options.chunkedMode !== "undefined") {
- chunkedMode = options.chunkedMode;
- }
- if (options.params) {
- params = options.params;
- } else {
- params = {};
- }
- }
-
- Cordova.exec(successCallback, errorCallback, 'FileTransfer', 'upload',
- [ filePath, server, fileKey, fileName, mimeType, params, debug,
- chunkedMode ]);
- };
-
- /**
- * Downloads a file form a given URL and saves it to the specified
- * directory.
- *
- * @param source
- * {String} URL of the server to receive the file
- * @param target
- * {String} Full path of the file on the device
- * @param successCallback
- * (Function} Callback to be invoked when upload has completed
- * @param errorCallback
- * {Function} Callback to be invoked upon error
- */
- FileTransfer.prototype.download = function(source, target, successCallback,
- errorCallback) {
- var castSuccess = function(entry) {
- if (typeof successCallback === "function") {
- var fileEntry = new FileEntry(entry);
- successCallback(entry);
- }
- };
- Cordova.exec(castSuccess, errorCallback, 'FileTransfer',
- 'download', [ source, target ]);
- };
-
- return FileTransfer;
-}());
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/46d60472/javascript/geolocation.js
----------------------------------------------------------------------
diff --git a/javascript/geolocation.js b/javascript/geolocation.js
deleted file mode 100644
index c8d7bc1..0000000
--- a/javascript/geolocation.js
+++ /dev/null
@@ -1,230 +0,0 @@
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * Position error object
- *
- * @param code
- * @param message
- */
-function PositionError(code, message) {
- this.code = code;
- this.message = message;
-};
-
-PositionError.PERMISSION_DENIED = 1;
-PositionError.POSITION_UNAVAILABLE = 2;
-PositionError.TIMEOUT = 3;
-
-/**
- * navigator._geo
- *
- * Provides access to device GPS.
- */
-var Geolocation = Geolocation || (function() {
- /**
- * @constructor
- */
- function Geolocation() {
-
- // The last known GPS position.
- this.lastPosition = null;
-
- // Geolocation listeners
- this.listeners = {};
- };
-
- /**
- * Acquires the current geo position.
- *
- * @param {Function} successCallback The function to call when the position data is available
- * @param {Function} errorCallback The function to call when there is an error getting the heading position. (OPTIONAL)
- * @param {PositionOptions} options The options for getting the position data. (OPTIONAL)
- */
- Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
-
- var id = "global";
- if (navigator._geo.listeners[id]) {
- console.log("Geolocation Error: Still waiting for previous getCurrentPosition() request.");
- try {
- errorCallback(new PositionError(PositionError.TIMEOUT,
- "Geolocation Error: Still waiting for previous getCurrentPosition() request."));
- } catch (e) {
- }
- return;
- }
-
- // default maximumAge value should be 0, and set if positive
- var maximumAge = 0;
-
- // default timeout value should be infinity, but that's a really long time
- var timeout = 3600000;
-
- var enableHighAccuracy = false;
- if (options) {
- if (options.maximumAge && (options.maximumAge > 0)) {
- maximumAge = options.maximumAge;
- }
- if (options.enableHighAccuracy) {
- enableHighAccuracy = options.enableHighAccuracy;
- }
- if (options.timeout) {
- timeout = (options.timeout < 0) ? 0 : options.timeout;
- }
- }
- navigator._geo.listeners[id] = {"success" : successCallback, "fail" : errorCallback };
- Cordova.exec(null, errorCallback, "Geolocation", "getCurrentPosition",
- [id, maximumAge, timeout, enableHighAccuracy]);
- };
-
- /**
- * Monitors changes to geo position. When a change occurs, the successCallback
- * is invoked with the new location.
- *
- * @param {Function} successCallback The function to call each time the location data is available
- * @param {Function} errorCallback The function to call when there is an error getting the location data. (OPTIONAL)
- * @param {PositionOptions} options The options for getting the location data such as frequency. (OPTIONAL)
- * @return String The watch id that must be passed to #clearWatch to stop watching.
- */
- Geolocation.prototype.watchPosition = function(successCallback, errorCallback, options) {
-
- // default maximumAge value should be 0, and set if positive
- var maximumAge = 0;
-
- // DO NOT set timeout to a large value for watchPosition in BlackBerry.
- // The interval used for updates is half the timeout value, so a large
- // timeout value will mean a long wait for the first location.
- var timeout = 10000;
-
- var enableHighAccuracy = false;
- if (options) {
- if (options.maximumAge && (options.maximumAge > 0)) {
- maximumAge = options.maximumAge;
- }
- if (options.enableHighAccuracy) {
- enableHighAccuracy = options.enableHighAccuracy;
- }
- if (options.timeout) {
- timeout = (options.timeout < 0) ? 0 : options.timeout;
- }
- }
- var id = Cordova.createUUID();
- navigator._geo.listeners[id] = {"success" : successCallback, "fail" : errorCallback };
- Cordova.exec(null, errorCallback, "Geolocation", "watchPosition",
- [id, maximumAge, timeout, enableHighAccuracy]);
- return id;
- };
-
- /*
- * Native callback when watch position has a new position.
- */
- Geolocation.prototype.success = function(id, result) {
-
- var p = result.message;
- var coords = new Coordinates(p.latitude, p.longitude, p.altitude,
- p.accuracy, p.heading, p.speed, p.alt_accuracy);
- var loc = new Position(coords, p.timestamp);
- try {
- navigator._geo.lastPosition = loc;
- navigator._geo.listeners[id].success(loc);
- }
- catch (e) {
- console.log("Geolocation Error: Error calling success callback function.");
- }
-
- if (id == "global") {
- delete navigator._geo.listeners["global"];
- }
- };
-
- /**
- * Native callback when watch position has an error.
- *
- * @param {String} id The ID of the watch
- * @param {Object} result The result containing status and message
- */
- Geolocation.prototype.fail = function(id, result) {
- var code = result.status;
- var msg = result.message;
- try {
- navigator._geo.listeners[id].fail(new PositionError(code, msg));
- }
- catch (e) {
- console.log("Geolocation Error: Error calling error callback function.");
- }
-
- if (id == "global") {
- delete navigator._geo.listeners["global"];
- }
- };
-
- /**
- * Clears the specified position watch.
- *
- * @param {String} id The ID of the watch returned from #watchPosition
- */
- Geolocation.prototype.clearWatch = function(id) {
- Cordova.exec(null, null, "Geolocation", "stop", [id]);
- delete navigator._geo.listeners[id];
- };
-
- /**
- * Is Cordova implementation being used.
- */
- var usingCordova = false;
-
- /**
- * Force Cordova implementation to override navigator.geolocation.
- */
- var useCordova = function() {
- if (usingCordova) {
- return;
- }
- usingCordova = true;
-
- // Set built-in geolocation methods to our own implementations
- // (Cannot replace entire geolocation, but can replace individual methods)
- navigator.geolocation.getCurrentPosition = navigator._geo.getCurrentPosition;
- navigator.geolocation.watchPosition = navigator._geo.watchPosition;
- navigator.geolocation.clearWatch = navigator._geo.clearWatch;
- navigator.geolocation.success = navigator._geo.success;
- navigator.geolocation.fail = navigator._geo.fail;
- };
-
- /**
- * Define navigator.geolocation object.
- */
- Cordova.addConstructor(function() {
- navigator._geo = new Geolocation();
-
- // if no native geolocation object, use Cordova geolocation
- if (typeof navigator.geolocation === 'undefined') {
- navigator.geolocation = navigator._geo;
- usingCordova = true;
- }
- });
-
- /**
- * Enable developers to override browser implementation.
- */
- return {
- useCordova: useCordova
- };
-}());
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/46d60472/javascript/network.js
----------------------------------------------------------------------
diff --git a/javascript/network.js b/javascript/network.js
deleted file mode 100644
index b25562f..0000000
--- a/javascript/network.js
+++ /dev/null
@@ -1,97 +0,0 @@
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * Network status
- */
-Connection = {
- UNKNOWN: "unknown",
- ETHERNET: "ethernet",
- WIFI: "wifi",
- CELL_2G: "2g",
- CELL_3G: "3g",
- CELL_4G: "4g",
- NONE: "none"
-};
-
-/**
- * navigator.network
- */
-(function() {
- /**
- * Check to see that navigator.network has not been initialized.
- */
- if (typeof navigator.network !== "undefined") {
- return;
- }
-
- /**
- * This class contains information about the current network Connection.
- * @constructor
- */
- var NetworkConnection = function() {
- this.type = null;
- this._firstRun = true;
-
- var me = this;
- this.getInfo(
- function(info) {
- me.type = info.type;
- if (typeof info.event !== "undefined") {
- Cordova.fireDocumentEvent(info.event);
- }
-
- // should only fire this once
- if (me._firstRun) {
- me._firstRun = false;
- Cordova.onCordovaConnectionReady.fire();
- }
- },
- function(e) {
- // If we can't get the network info we should still tell Cordova
- // to fire the deviceready event.
- if (me._firstRun) {
- me._firstRun = false;
- Cordova.onCordovaConnectionReady.fire();
- }
- console.log("Error initializing Network Connection: " + e);
- });
- };
-
- /**
- * Get connection info
- *
- * @param {Function} successCallback The function to call when the Connection data is available
- * @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL)
- */
- NetworkConnection.prototype.getInfo = function(successCallback, errorCallback) {
- // Get info
- Cordova.exec(successCallback, errorCallback, "Network Status", "getConnectionInfo", []);
- };
-
- /**
- * Define navigator.network and navigator.network.connection objects
- */
- Cordova.addConstructor(function() {
- navigator.network = new Object();
-
- navigator.network.connection = new NetworkConnection();
- });
-}());
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/46d60472/javascript/notification.js
----------------------------------------------------------------------
diff --git a/javascript/notification.js b/javascript/notification.js
deleted file mode 100644
index bb53046..0000000
--- a/javascript/notification.js
+++ /dev/null
@@ -1,145 +0,0 @@
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * navigator.notification
- *
- * Provides access to notifications on the device.
- */
-(function() {
- /**
- * Check that navigator.notification has not been initialized.
- */
- if (typeof navigator.notification !== "undefined") {
- return;
- }
-
- /**
- * @constructor
- */
- function Notification() {
- };
-
- /**
- * Display an activity dialog
- */
- Notification.prototype.activityStart = function(title, message) {
- // If title and message not specified then mimic Android behavior of
- // using default strings.
- if (typeof title === "undefined" && typeof message == "undefined") {
- title = "Busy";
- message = 'Please wait...';
- }
-
- Cordova.exec(null, null, 'Notification', 'activityStart', [title, message]);
- };
-
- /**
- * Close an activity dialog
- */
- Notification.prototype.activityStop = function() {
- Cordova.exec(null, null, 'Notification', 'activityStop', []);
- };
-
- /**
- * Open a native alert dialog, with a customizable title and button text.
- * @param {String} message Message to print in the body of the alert
- * @param {Function} completeCallback The callback that is invoked when user clicks a button.
- * @param {String} title Title of the alert dialog (default: 'Alert')
- * @param {String} buttonLabel Label of the close button (default: 'OK')
- */
- Notification.prototype.alert = function(message, completeCallback, title, buttonLabel) {
- var _title = (title || "Alert");
- var _buttonLabel = (buttonLabel || "OK");
- Cordova.exec(completeCallback, null, 'Notification', 'alert', [message, _title, _buttonLabel]);
- };
-
- /**
- * Causes the device to blink a status LED.
- *
- * @param {Integer} count The number of blinks.
- * @param {String} color The color of the light.
- */
- Notification.prototype.blink = function(count, color) {
- // NOT IMPLEMENTED
- };
-
- /**
- * Open a custom confirmation dialog, with a customizable title and button text.
- * @param {String} message Message to print in the body of the dialog
- * @param {Function}resultCallback The callback that is invoked when a user clicks a button.
- * @param {String} title Title of the alert dialog (default: 'Confirm')
- * @param {String} buttonLabels Comma separated list of the button labels (default: 'OK,Cancel')
- */
- Notification.prototype.confirm = function(message, resultCallback, title, buttonLabels) {
- var _title = (title || "Confirm");
- var _buttonLabels = (buttonLabels || "OK,Cancel");
- return Cordova.exec(resultCallback, null, 'Notification', 'confirm', [message, _title, _buttonLabels]);
- };
-
- /**
- * Display a progress dialog with progress bar that goes from 0 to 100.
- *
- * @param {String} title Title of the progress dialog.
- * @param {String} message Message to display in the dialog.
- */
- Notification.prototype.progressStart = function(title, message) {
- Cordova.exec(null, null, 'Notification', 'progressStart', [title, message]);
- };
-
- /**
- * Close the progress dialog.
- */
- Notification.prototype.progressStop = function() {
- Cordova.exec(null, null, 'Notification', 'progressStop', []);
- };
-
- /**
- * Set the progress dialog value.
- *
- * @param {Number} value 0-100
- */
- Notification.prototype.progressValue = function(value) {
- Cordova.exec(null, null, 'Notification', 'progressValue', [value]);
- };
-
- /**
- * Causes the device to vibrate.
- * @param {Integer} mills The number of milliseconds to vibrate for.
- */
- Notification.prototype.vibrate = function(mills) {
- Cordova.exec(null, null, 'Notification', 'vibrate', [mills]);
- };
-
- /**
- * Causes the device to beep.
- * @param {Integer} count The number of beeps.
- */
- Notification.prototype.beep = function(count) {
- Cordova.exec(null, null, 'Notification', 'beep', [count]);
- };
-
- /**
- * Define navigator.notification object.
- */
- Cordova.addConstructor(function() {
- navigator.notification = new Notification();
- });
-}());
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/46d60472/javascript/playbook/battery.js
----------------------------------------------------------------------
diff --git a/javascript/playbook/battery.js b/javascript/playbook/battery.js
deleted file mode 100644
index 2192a94..0000000
--- a/javascript/playbook/battery.js
+++ /dev/null
@@ -1,176 +0,0 @@
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * navigator.battery
- */
-(function() {
- /**
- * Check to see that navigator.battery has not been initialized.
- */
- if (typeof navigator.battery !== "undefined") {
- return;
- }
- /**
- * This class contains information about the current battery status.
- * @constructor
- */
- var Battery = function() {
- this._level = null;
- this._isPlugged = null;
- this._batteryListener = [];
- this._lowListener = [];
- this._criticalListener = [];
- // Register one listener to each of level and state change events using WebWorks API.
- blackberry.system.event.deviceBatteryStateChange(this._stateChange);
- blackberry.system.event.deviceBatteryLevelChange(this._levelChange);
- };
-
- /**
- * Registers as an event producer for battery events.
- *
- * @param {Object} eventType
- * @param {Object} handler
- * @param {Object} add
- */
- Battery.prototype.eventHandler = function(eventType, handler, add) {
- var me = navigator.battery;
- if (add) {
- // Register the event listener in the proper array
- if (eventType === "batterystatus") {
- var pos = me._batteryListener.indexOf(handler);
- if (pos === -1) {
- me._batteryListener.push(handler);
- }
- } else if (eventType === "batterylow") {
- var pos = me._lowListener.indexOf(handler);
- if (pos === -1) {
- me._lowListener.push(handler);
- }
- } else if (eventType === "batterycritical") {
- var pos = me._criticalListener.indexOf(handler);
- if (pos === -1) {
- me._criticalListener.push(handler);
- }
- }
- } else {
- // Remove the event listener from the proper array
- if (eventType === "batterystatus") {
- var pos = me._batteryListener.indexOf(handler);
- if (pos > -1) {
- me._batteryListener.splice(pos, 1);
- }
- } else if (eventType === "batterylow") {
- var pos = me._lowListener.indexOf(handler);
- if (pos > -1) {
- me._lowListener.splice(pos, 1);
- }
- } else if (eventType === "batterycritical") {
- var pos = me._criticalListener.indexOf(handler);
- if (pos > -1) {
- me._criticalListener.splice(pos, 1);
- }
- }
- }
- };
-
- /**
- * Callback for battery state change using WebWorks API
- *
- * @param {Object} state
- */
- Battery.prototype._stateChange = function(state) {
- var me = navigator.battery;
- if (state === 2 || state === 3) { // state is either CHARGING or UNPLUGGED
- var info = {
- "level":me._level,
- "isPlugged":me._isPlugged
- };
-
- if (state === 2 && (me._isPlugged === false || me._isPlugged === null)) {
- me._isPlugged = info.isPlugged = true;
- me._fire('status', info);
- } else if (state === 3 && (me._isPlugged === true || me._isPlugged === null)) {
- me._isPlugged = info.isPlugged = false;
-
- me._fire('status', info);
- }
- }
- };
-
- /**
- * Callback for battery level change using WebWorks API
- *
- * @param {Object} level
- */
- Battery.prototype._levelChange = function(level) {
- var me = navigator.battery;
-
- if (level != me._level) {
- me._level = level;
- var info = {
- "level":me._level,
- "isPlugged":me._isPlugged
- };
-
- // Fire off the basic battery status change event listeners.
- me._fire('status', info);
-
- // Fire low battery events if applicable
- if (level == 20 || level == 5) {
- if (level == 20) {
- me._fire('low', info);
- } else {
- me._fire('critical', info);
- }
- }
- }
- };
-
- /**
- * Helper function to fire all listeners of a type.
- *
- * @param {Object} type
- * @param {Object} data
- */
- Battery.prototype._fire = function(type, data) {
- var targetAr = '_batteryListener';
-
- if (type == 'critical') {
- targetAr = '_criticalListener';
- } else if (type == 'low') {
- targetAr = '_lowListener';
- }
- for (var i = 0, l = this[targetAr].length; i < l; i++) {
- this[targetAr][i](data);
- }
- };
-
- Cordova.addConstructor(function() {
-
- if (typeof navigator.battery === "undefined") {
- navigator.battery = new Battery();
- Cordova.addWindowEventHandler("batterystatus", navigator.battery.eventHandler);
- Cordova.addWindowEventHandler("batterylow", navigator.battery.eventHandler);
- Cordova.addWindowEventHandler("batterycritical", navigator.battery.eventHandler);
- }
- });
-
-}());