Updates definitions and tests according to 3.6.0 changes.

This commit is contained in:
Vladimir Kotikov
2014-09-01 18:20:06 +04:00
parent 44a5ac12c6
commit 6a002cfbb3
9 changed files with 245 additions and 38 deletions

1
cordova/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
cordova-tests.js

View File

@@ -10,19 +10,33 @@ console.log('cordova.version: ' + cordova.version + ', cordova.platformId: ' + c
cordova.exec(null, null, "NativeClassName", "MethodName");
cordova.define('mymodule', (require, exports, module) => { });
cordova.define('mymodule', (req, exp, mod)=> {
mod.exports = { dummy: () => { console.log("i'm a dummy"); }};
});
var myModule = cordova.require('mymodule');
myModule.dummy();
var argsCheck: ArgsCheck = <ArgsCheck>cordova.require('cordova/argcheck');
argsCheck.checkArgs('ssA', 'cordova.exec', [() => { }, () => { }, 'window', 'openDatabase']);
class Application {
start() { console.log("Starting app"); }
pause() { console.log('app paused'); }
}
declare var app: Application;
document.addEventListener('deviceready', () => { app.start(); });
document.addEventListener('pause', ()=> { app.pause(); });
// Battery status plugin
//----------------------------------------------------------------------
window.addEventListener('batterystatus',
(ev: BatteryStatusEvent) => { console.log('Battery level is ' + ev.level); });
window.addEventListener('batterycritical',
()=> { alert('Battery is critical low!'); });
() => { alert('Battery is critical low!'); });
// Camera plugin
//----------------------------------------------------------------------
@@ -51,10 +65,12 @@ var contact: Contact = navigator.contacts.create({
navigator.contacts.find(["phoneNumbers"],
(contacts: Contact[])=> { alert('Find ' + contacts.length + ' contacts'); },
(error: ContactError) => { alert('Error: ' + error.message); },
{
filter: "+1",
multiple: true
}
new ContactFindOptions("+1", true)
);
navigator.contacts.pickContact(
(contact: Contact)=> { console.log(contact); },
(err: ContactError)=> { console.log(err.message); }
);
// Device API
@@ -105,26 +121,64 @@ function fsaccessor(fs: FileSystem) {
var fsreader: DirectoryReader = fs.root.createReader();
fsreader.readEntries(
(entries: Entry[]) => { console.log(fs.root.name + ' has ' + entries.length + ' child elements'); },
(err: Error)=> { alert('Error: ' + err.message); });
(err: FileError)=> { alert('Error: ' + err.code); });
}
window.requestFileSystem(
window.TEMPORARY,
1024 * 1024 * 5,
fsaccessor,
(err: Error) => { alert('Error: ' + err.message); });
(err: FileError) => { alert('Error: ' + err.code); }
);
window.resolveLocalFileSystemURI(cordova.file.applicationDirectory,
(entry: Entry)=> {
if (entry.isDirectory) {
console.log('successfully resolved ' + entry.fullPath + 'directory');
console.log(entry.toURL());
console.log(entry.toInternalURL());
} else {
var fentry = <FileEntry>entry;
fentry.file((f: File) => { console.log(f.slice(f.size - 10, f.size)); });
fentry.createWriter((writer: FileWriter)=> {
if (writer.readyState == FileWriter.INIT) {
console.log('Init FileWriter');
writer.write(new Blob(['sdfdsfsdf']));
writer.onprogress = function(ev: ProgressEvent) {
console.log('Writing ' + ev.target);
};
}
});
}
},
(error: FileError) => { console.log(error.code); }
);
// FileTransfer plugin
//----------------------------------------------------------------------
var file = new FileTransfer();
file.onprogress = (ev: ProgressEvent) => {
if (ev.lengthComputable) {
console.log(ev.loaded + '/' + ev.total);
}
};
file.download('http://some.server.com/download.php',
'cdvfile://localhost/persistent/path/to/downloads/',
(file: FileEntry)=> { console.log('File Downloaded to ' + file.fullPath); },
(err: FileTransferError)=> { alert('Error ' + err.code); },
(err: FileTransferError) => {
console.error('Error ' + err.code);
if (err.exception) {
console.error('Failed with exception ' + err.exception);
}
},
{ headers: null },
true);
file.abort();
// InAppBrowser plugin
//----------------------------------------------------------------------
@@ -135,6 +189,10 @@ file.download('http://some.server.com/download.php',
var iab = <InAppBrowser>window.open('google.com', '_self');
iab.addEventListener('loadstart', (ev: InAppBrowserEvent) => { console.log('Start opening ' + ev.url); });
iab.show();
iab.executeScript(
{ code: "console.log('Injected script in action')" },
()=> { console.log('Script is executed'); }
);
// Globalization plugin
//----------------------------------------------------------------------
@@ -226,4 +284,6 @@ db.transaction(
// Vibration plugin
//----------------------------------------------------------------------
navigator.notification.vibrate(100);
navigator.notification.vibrate(100);
navigator.notification.vibrateWithPattern([100, 200, 200, 150, 50], 3);
setTimeout(navigator.notification.cancelVibration, 1000);

27
cordova/cordova.d.ts vendored
View File

@@ -44,6 +44,33 @@ interface Cordova {
require(moduleName: string): any;
}
interface Document {
addEventListener(type: "deviceready", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "pause", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "resume", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "backbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "menubutton", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "searchbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "startcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "endcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "volumedownbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "volumeupbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
removeEventListener(type: "deviceready", listener: (ev: Event) => any, useCapture?: boolean): void;
removeEventListener(type: "pause", listener: (ev: Event) => any, useCapture?: boolean): void;
removeEventListener(type: "resume", listener: (ev: Event) => any, useCapture?: boolean): void;
removeEventListener(type: "backbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
removeEventListener(type: "menubutton", listener: (ev: Event) => any, useCapture?: boolean): void;
removeEventListener(type: "searchbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
removeEventListener(type: "startcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
removeEventListener(type: "endcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
removeEventListener(type: "volumedownbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
removeEventListener(type: "volumeupbutton", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: string, listener: (ev: Event) => any, useCapture?: boolean): void;
removeEventListener(type: string, listener: (ev: Event) => any, useCapture?: boolean): void;
}
// cordova/argscheck module
interface ArgsCheck {
checkArgs(argsSpec: string, functionName: string, args: any[], callee?: any): void;

View File

@@ -44,11 +44,11 @@ interface Camera {
}
interface CameraOptions {
/** Picture quality in range o-100 */
/** Picture quality in range 0-100. Default is 50 */
quality?: number;
/**
* Choose the format of the return value.
* Defined in navigator.camera.DestinationType
* Defined in navigator.camera.DestinationType. Default is FILE_URI.
* DATA_URL : 0, Return image as base64-encoded string
* FILE_URI : 1, Return image file URI
* NATIVE_URI : 2 Return image native URI
@@ -56,7 +56,8 @@ interface CameraOptions {
*/
destinationType?: number;
/**
* Set the source of the picture. Defined in navigator.camera.PictureSourceType
* Set the source of the picture.
* Defined in navigator.camera.PictureSourceType. Default is CAMERA.
* PHOTOLIBRARY : 0,
* CAMERA : 1,
* SAVEDPHOTOALBUM : 2
@@ -65,7 +66,8 @@ interface CameraOptions {
/** Allow simple editing of image before selection. */
allowEdit?: boolean;
/**
* Choose the returned image file's encoding. Defined in navigator.camera.EncodingType
* Choose the returned image file's encoding.
* Defined in navigator.camera.EncodingType. Default is JPEG
* JPEG : 0 Return JPEG encoded image
* PNG : 1 Return PNG encoded image
*/
@@ -93,7 +95,12 @@ interface CameraOptions {
correctOrientation?: boolean;
/** Save the image to the photo album on the device after capture. */
saveToPhotoAlbum?: boolean;
/** Choose the camera to use (front- or back-facing). Defined in navigator.camera.Direction */
/**
* Choose the camera to use (front- or back-facing).
* Defined in navigator.camera.Direction. Default is BACK.
* FRONT: 0
* BACK: 1
*/
cameraDirection?: number;
/** iOS-only options that specify popover location in iPad. Defined in CameraPopoverOptions. */
popoverOptions?: CameraPopoverOptions;

View File

@@ -34,6 +34,14 @@ interface Contacts {
onSuccess: (contacts: Contact[]) => void,
onError: (error: ContactError) => void,
options?: ContactFindOptions): void;
/**
* The navigator.contacts.pickContact method launches the Contact Picker to select a single contact.
* The resulting object is passed to the contactSuccess callback function specified by the contactSuccess parameter.
* @param onSuccess Success callback function invoked with the array of Contact objects returned from the database
* @param onError Error callback function, invoked when an error occurs.
*/
pickContact(onSuccess: (contact: Contact) => void,
onError: (error: ContactError) => void): void
}
interface ContactProperties {
@@ -253,10 +261,13 @@ interface ContactFindOptions {
filter?: string;
/** Determines if the find operation returns multiple navigator.contacts. */
multiple?: boolean;
/* Contact fields to be returned back. If specified, the resulting Contact object only features values for these fields. */
desiredFields?: string[];
}
declare var ContactFindOptions: {
/** Constructor for ContactFindOptions object */
new(filter?: string,
multiple?: boolean): ContactFindOptions
multiple?: boolean,
desiredFields?: string[]): ContactFindOptions
};

View File

@@ -59,7 +59,10 @@ interface Notification {
/** Object, passed to promptCallback */
interface NotificationPromptResult {
/** The index of the pressed button. Note that the index uses one-based indexing, so the value is 1, 2, 3, etc. */
/**
* The index of the pressed button. Note that the index uses one-based indexing, so the value is 1, 2, 3, etc.
* 0 is the result when the dialog is dismissed without a button press.
*/
buttonIndex: number;
/** The text entered in the prompt dialog box. */
input1: string;

View File

@@ -18,7 +18,16 @@ interface Window {
type: number,
size: number,
successCallback: (fileSystem: FileSystem) => void,
errorCallback?: (fileError: Error) => void): void;
errorCallback?: (fileError: FileError) => void): void;
/**
* Look up file system Entry referred to by local URI.
* @param string 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
*/
resolveLocalFileSystemURI(uri: string,
successCallback: (entry: Entry) => void,
errorCallback?: (error: FileError) => void): void;
TEMPORARY: number;
PERSISTENT: number;
}
@@ -54,7 +63,7 @@ interface Entry {
*/
getMetadata(
successCallback: (metadata: Metadata) => void,
errorCallback?: (error: Error) => void): void;
errorCallback?: (error: FileError) => void): void;
/**
* Move an entry to a different location on the file system. It is an error to try to:
* move a directory inside itself or to any child at any depth;move an entry into its parent if a name different from its current one isn't provided;
@@ -69,9 +78,9 @@ interface Entry {
* @param errorCallback A callback that is called when errors happen.
*/
moveTo(parent: DirectoryEntry,
newName?: string,
successCallback?: (entry: Entry) => void ,
errorCallback?: (error: Error) => void ): void;
newName?: string,
successCallback?: (entry: Entry) => void,
errorCallback?: (error: FileError) => void): void;
/**
* Copy an entry to a different location on the file system. It is an error to try to:
* copy a directory inside itself or to any child at any depth;
@@ -88,24 +97,34 @@ interface Entry {
* @param errorCallback A callback that is called when errors happen.
*/
copyTo(parent: DirectoryEntry,
newName?: string,
successCallback?: (entry: Entry) => void ,
errorCallback?: (error: Error) => void ): void;
newName?: string,
successCallback?: (entry: Entry) => void,
errorCallback?: (error: FileError) => void): void;
/**
* Returns a URL that can be used as the src attribute of a <video> or <audio> tag.
* If that is not possible, construct a cdvfile:// URL.
* @return string URL
*/
toURL(): string;
/**
* Return a URL that can be passed across the bridge to identify this entry.
* @return string URL that can be passed across the bridge to identify this entry
*/
toInternalURL(): string;
/**
* Deletes 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 the root directory of a filesystem.
* @param successCallback A callback that is called on success.
* @param errorCallback A callback that is called when errors happen.
*/
remove(successCallback: () => void ,
errorCallback?: (error: Error) => void ): void;
remove(successCallback: () => void,
errorCallback?: (error: FileError) => void): void;
/**
* Look up the parent DirectoryEntry containing this Entry. If this Entry is the root of its filesystem, its parent is itself.
* @param successCallback A callback that is called with the time of the last modification.
* @param errorCallback A callback that is called when errors happen.
*/
getParent(successCallback: (entry: Entry) => void ,
errorCallback?: (error: Error) => void ): void;
getParent(successCallback: (entry: Entry) => void,
errorCallback?: (error: FileError) => void): void;
}
/** This interface supplies information about the state of a file or directory. */
@@ -137,7 +156,7 @@ interface DirectoryEntry extends Entry {
*/
getFile(path: string, options?: Flags,
successCallback?: (entry: FileEntry) => void,
errorCallback?: (error: Error) => void): void;
errorCallback?: (error: FileError) => void): void;
/**
* Creates or looks up a directory.
* @param path Either an absolute path or a relative path from this DirectoryEntry
@@ -153,7 +172,7 @@ interface DirectoryEntry extends Entry {
*/
getDirectory(path: string, options?: Flags,
successCallback?: (entry: DirectoryEntry) => void,
errorCallback?: (error: Error) => void): void;
errorCallback?: (error: FileError) => void): void;
/**
* Deletes a directory and all of its contents, if any. In the event of an error (e.g. trying
* to delete a directory that contains a file that cannot be removed), some of the contents
@@ -162,7 +181,7 @@ interface DirectoryEntry extends Entry {
* @param errorCallback A callback that is called when errors happen.
*/
removeRecursively(successCallback: () => void,
errorCallback?: (error: Error) => void): void;
errorCallback?: (error: FileError) => void): void;
}
/**
@@ -194,7 +213,9 @@ interface DirectoryReader {
* of readEntries, successCallback must be called with a zero-length array as an argument.
* @param errorCallback A callback indicating that there was an error reading from the Directory.
*/
readEntries(successCallback: (entries: Entry[]) => void, errorCallback?: (error: Error) => void): void;
readEntries(
successCallback: (entries: Entry[]) => void,
errorCallback?: (error: FileError) => void): void;
}
/** This interface represents a file on a file system. */
@@ -206,14 +227,14 @@ interface FileEntry extends Entry {
*/
createWriter(successCallback: (
writer: FileWriter) => void,
errorCallback?: (error: Error) => void): void;
errorCallback?: (error: FileError) => void): void;
/**
* Returns a File that represents the current state of the file that this FileEntry represents.
* @param successCallback A callback that is called with the File.
* @param errorCallback A callback that is called when errors happen.
*/
file(successCallback: (file: File) => void,
errorCallback?: (error: Error) => void): void;
errorCallback?: (error: FileError) => void): void;
}
/**
@@ -279,4 +300,65 @@ interface FileWriter extends FileSaver {
* @param size The size to which the length of the file is to be adjusted, measured in bytes.
*/
truncate(size: number): void;
}
}
/* FileWriter states */
declare var FileWriter: {
INIT: number;
WRITING: number;
DONE: number
};
interface FileError {
/** Error code */
code: number;
}
declare var FileError: {
new (code: number): FileError;
NOT_FOUND_ERR: number;
SECURITY_ERR: number;
ABORT_ERR: number;
NOT_READABLE_ERR: number;
ENCODING_ERR: number;
NO_MODIFICATION_ALLOWED_ERR: number;
INVALID_STATE_ERR: number;
SYNTAX_ERR: number;
INVALID_MODIFICATION_ERR: number;
QUOTA_EXCEEDED_ERR: number;
TYPE_MISMATCH_ERR: number;
PATH_EXISTS_ERR: number;
};
/*
* Constants defined in fileSystemPaths
*/
interface Cordova {
file: {
/* Read-only directory where the application is installed. */
applicationDirectory: string;
/* Root of app's private writable storage */
applicationStorageDirectory: string;
/* Where to put app-specific data files. */
dataDirectory: string;
/* Cached files that should survive app restarts. Apps should not rely on the OS to delete files in here. */
cacheDirectory: string;
/* Android: the application space on external storage. */
externalApplicationStorageDirectory: string;
/* Android: Where to put app-specific data files on external storage. */
externalDataDirectory: string;
/* Android: the application cache on external storage. */
externalCacheDirectory: string;
/* Android: the external storage (SD card) root. */
externalRootDirectory: string;
/* iOS: Temp directory that the OS can clear at will. */
tempDirectory: string;
/* iOS: Holds app-specific files that should be synced (e.g. to iCloud). */
syncedDataDirectory: string;
/* iOS: Files private to the app, but that are meaningful to other applciations (e.g. Office files) */
documentsDirectory: string;
/* BlackBerry10: Files globally available to all apps */
sharedDirectory: string
}
}

View File

@@ -14,7 +14,7 @@
*/
interface FileTransfer {
/** Called with a ProgressEvent whenever a new chunk of data is transferred. */
onprogress: Function;
onprogress: (event: ProgressEvent) => void;
/**
* Sends a file to a server.
* @param fileURL Filesystem URL representing the file on the device. For backwards compatibility,
@@ -116,12 +116,15 @@ interface FileTransferError {
target: string;
/** HTTP status code. This attribute is only available when a response code is received from the HTTP connection. */
http_status: number;
/* Request body */
body: any;
/* Exception that is thrown by native code */
exception: any;
}
declare var FileTransferError: {
/** Constructor for FileTransferError object */
new (code?: number, source?: string, target?: string, status?: number, body?: any): FileTransferError;
new (code?: number, source?: string, target?: string, status?: number, body?: any, exception?: any): FileTransferError;
FILE_NOT_FOUND_ERR: number;
INVALID_URL_ERR: number;
CONNECTION_ERR: number;

View File

@@ -12,4 +12,17 @@ interface Notification {
* @param time Milliseconds to vibrate the device. Ignored on iOS.
*/
vibrate(time: number): void
/**
* Vibrates the device with a given pattern.
* @param number[] pattern Pattern with which to vibrate the device.
* The first value - number of milliseconds to wait before turning the vibrator on.
* The next value - the number of milliseconds for which to keep the vibrator on before turning it off.
* @param number repeat Optional index into the pattern array at which to start repeating (will repeat until canceled),
* or -1 for no repetition (default).
*/
vibrateWithPattern(pattern: number[], repeat: number): void;
/**
* Immediately cancels any currently running vibration.
*/
cancelVibration(): void;
}