Adding newly-built phonegap.js to repo post-build.

This commit is contained in:
filmaj 2010-03-04 15:14:40 -08:00
parent bdf01735cd
commit 941d6805ec

View File

@ -436,6 +436,39 @@ Contacts.prototype.droidDone = function()
PhoneGap.addConstructor(function() { PhoneGap.addConstructor(function() {
if(typeof navigator.contacts == "undefined") navigator.contacts = new Contacts(); if(typeof navigator.contacts == "undefined") navigator.contacts = new Contacts();
}); });
var Crypto = function()
{
}
Crypto.prototype.encrypt = function(seed, string, callback)
{
GapCrypto.encrypt(seed, string);
this.encryptWin = callback;
}
Crypto.prototype.decrypt = function(seed, string, callback)
{
GapCrypto.decrypt(seed, string);
this.decryptWin = callback;
}
Crypto.prototype.gotCryptedString = function(string)
{
this.encryptWin(string);
}
Crypto.prototype.getPlainString = function(string)
{
this.decryptWin(string);
}
PhoneGap.addConstructor(function() {
if (typeof navigator.Crypto == "undefined")
{
navigator.Crypto = new Crypto();
}
});
/** /**
* this represents the mobile device, and provides properties for inspecting the model, version, UUID of the * this represents the mobile device, and provides properties for inspecting the model, version, UUID of the
* phone, etc. * phone, etc.
@ -465,114 +498,231 @@ function Device() {
PhoneGap.addConstructor(function() { PhoneGap.addConstructor(function() {
navigator.device = window.device = new Device(); navigator.device = window.device = new Device();
}); });
/**
* This class provides generic read and write access to the mobile device file system.
*/
function File() { PhoneGap.addConstructor(function() { if (typeof navigator.fileMgr == "undefined") navigator.fileMgr = new FileMgr();});
/**
* The data of a file.
*/
this.data = "";
/**
* The name of the file.
*/
this.name = "";
}
/** /**
* Reads a file from the mobile device. This function is asyncronous. * This class provides iPhone read and write access to the mobile device file system.
* @param {String} fileName The name (including the path) to the file on the mobile device. * Based loosely on http://www.w3.org/TR/2009/WD-FileAPI-20091117/#dfn-empty
* The file name will likely be device dependent.
* @param {Function} successCallback The function to call when the file is successfully read.
* @param {Function} errorCallback The function to call when there is an error reading the file from the device.
*/ */
File.prototype.read = function(fileName, successCallback, errorCallback) { function FileMgr()
{
this.fileWriters = {}; // empty maps
this.fileReaders = {};
this.docsFolderPath = "../../Documents";
this.tempFolderPath = "../../tmp";
this.freeDiskSpace = -1;
this.getFileBasePaths();
} }
/** // private, called from Native Code
* Writes a file to the mobile device. FileMgr.prototype._setPaths = function(docs,temp)
* @param {File} file The file to write to the device. {
*/ this.docsFolderPath = docs;
File.prototype.write = function(file) { this.tempFolderPath = temp;
} }
PhoneGap.addConstructor(function() { // private, called from Native Code
if (typeof navigator.file == "undefined") navigator.file = new File(); FileMgr.prototype._setFreeDiskSpace = function(val)
}); {
this.freeDiskSpace = val;
}
File.prototype.read = function(fileName, successCallback, errorCallback) {
this.failCallback = errorCallback; // FileWriters add/remove
this.winCallback = successCallback; // called internally by writers
FileMgr.prototype.addFileWriter = function(filePath,fileWriter)
{
this.fileWriters[filePath] = fileWriter;
}
FileMgr.prototype.removeFileWriter = function(filePath)
{
this.fileWriters[filePath] = null;
}
// File readers add/remove
// called internally by readers
FileMgr.prototype.addFileReader = function(filePath,fileReader)
{
this.fileReaders[filePath] = fileReader;
}
FileMgr.prototype.removeFileReader = function(filePath)
{
this.fileReaders[filePath] = null;
}
/*******************************************
*
* private reader callback delegation
* called from native code
*/
FileMgr.prototype.reader_onloadstart = function(filePath,result)
{
this.fileReaders[filePath].onloadstart(result);
}
FileMgr.prototype.reader_onprogress = function(filePath,result)
{
this.fileReaders[filePath].onprogress(result);
}
FileMgr.prototype.reader_onload = function(filePath,result)
{
this.fileReaders[filePath].result = unescape(result);
this.fileReaders[filePath].onload(this.fileReaders[filePath].result);
}
FileMgr.prototype.reader_onerror = function(filePath,err)
{
this.fileReaders[filePath].result = err;
this.fileReaders[filePath].onerror(err);
}
FileMgr.prototype.reader_onloadend = function(filePath,result)
{
this.fileReaders[filePath].onloadend(result);
}
/*******************************************
*
* private writer callback delegation
* called from native code
*/
FileMgr.prototype.writer_onerror = function(filePath,err)
{
this.fileWriters[filePath].onerror(err);
}
FileMgr.prototype.writer_oncomplete = function(filePath,result)
{
this.fileWriters[filePath].oncomplete(result); // result contains bytes written
}
FileMgr.prototype.getFileBasePaths = function()
{
//PhoneGap.exec("File.getFileBasePaths");
}
FileMgr.prototype.testFileExists = function(fileName, successCallback, errorCallback)
{
var test = FileUtil.testFileExists(fileName);
test ? successCallback() : errorCallback();
}
FileMgr.prototype.testDirectoryExists = function(dirName, successCallback, errorCallback)
{
this.successCallback = successCallback;
this.errorCallback = errorCallback;
var test = FileUtil.testDirectoryExists(dirName);
test ? successCallback() : errorCallback();
}
FileMgr.prototype.createDirectory = function(dirName, successCallback, errorCallback)
{
this.successCallback = successCallback;
this.errorCallback = errorCallback;
var test = FileUtils.createDirectory(dirName);
test ? successCallback() : errorCallback();
}
FileMgr.prototype.deleteDirectory = function(dirName, successCallback, errorCallback)
{
this.successCallback = successCallback;
this.errorCallback = errorCallback;
var test = FileUtils.deleteDirectory(dirName);
test ? successCallback() : errorCallback();
}
FileMgr.prototype.deleteFile = function(fileName, successCallback, errorCallback)
{
this.successCallback = successCallback;
this.errorCallback = errorCallback;
FileUtils.deleteFile(fileName);
test ? successCallback() : errorCallback();
}
FileMgr.prototype.getFreeDiskSpace = function(successCallback, errorCallback)
{
if(this.freeDiskSpace > 0)
{
return this.freeDiskSpace;
}
else
{
this.successCallback = successCallback;
this.errorCallback = errorCallback;
this.freeDiskSpace = FileUtils.getFreeDiskSpace();
(this.freeDiskSpace > 0) ? successCallback() : errorCallback();
}
}
// File Reader
function FileReader()
{
this.fileName = "";
this.result = null;
this.onloadstart = null;
this.onprogress = null;
this.onload = null;
this.onerror = null;
this.onloadend = null;
}
FileReader.prototype.abort = function()
{
// Not Implemented
}
FileReader.prototype.readAsText = function(file)
{
if(this.fileName && this.fileName.length > 0)
{
navigator.fileMgr.removeFileReader(this.fileName,this);
}
this.fileName = file;
navigator.fileMgr.addFileReader(this.fileName,this);
return FileUtil.read(fileName); return FileUtil.read(fileName);
} }
File.prototype.hasRead = function(data) // File Writer
function FileWriter()
{ {
if(data.substr("FAIL")) this.fileName = "";
this.failCallback(data); this.result = null;
else this.readyState = 0; // EMPTY
this.winCallback(data); this.result = null;
this.onerror = null;
this.oncomplete = null;
} }
/** FileWriter.prototype.writeAsText = function(file,text,bAppend)
* Writes a file to the mobile device.
* @param {File} file The file to write to the device.
*/
File.prototype.write = function(file, str, mode, successCallback, failCallback) {
this.winCallback = successCallback;
this.failCallback = failCallback;
var call = FileUtil.write(file, str, mode);
}
File.prototype.testFileExists = function(file, successCallback, failCallback)
{ {
var exists = FileUtil.testFileExists(file); if(this.fileName && this.fileName.length > 0)
if(exists) {
successCallback(); navigator.fileMgr.removeFileWriter(this.fileName,this);
else }
failCallback(); this.fileName = file;
return exists; if(bAppend != true)
} {
bAppend = false; // for null values
File.prototype.testDirectoryExists = function(file, successCallback, failCallback) }
{ navigator.fileMgr.addFileWriter(file,this);
var exists = FileUtil.testDirectoryExists(file); this.readyState = 0; // EMPTY
if(exists) var call = FileUtil.write(file, text, bAppend);
successCallback(); this.result = null;
else
failCallback();
return exists;
}
File.prototype.createDirectory = function(dir, successCallback, failCallback)
{
var good = FileUtils.createDirectory(dir);
good ? successCallback() : failCallback();
}
File.prototype.deleteDirectory = function(dir, successCallback, failCallback)
{
var good = FileUtils.deleteDirectory(dir);
good ? successCallback() : failCallback();
}
File.prototype.deleteFile = function(dir, successCallback, failCallback)
{
var good = FileUtils.deleteFile(dir);
good ? successCallback() : failCallback();
}
File.prototype.getFreeDiskSpace = function(successCallback, failCallback)
{
var diskSpace = FileUtils.getFreeDiskSpace();
if(diskSpace > 0)
successCallback();
else
failCallback();
return diskSpace;
} }
/** /**
* This class provides access to device GPS data. * This class provides access to device GPS data.