Added definition for Firefox Web API

This commit is contained in:
vvakame
2013-07-19 11:55:45 +09:00
parent e1c6346884
commit d9ebddeae2
3 changed files with 68 additions and 0 deletions

View File

@@ -60,6 +60,7 @@ List of Definitions
* [File API: Writer](http://www.w3.org/TR/file-writer-api/) (by [Kon](http://phyzkit.net/))
* [Finite State Machine](https://github.com/jakesgordon/javascript-state-machine) (by [Boris Yankov](https://github.com/borisyankov))
* [Firebase](https://www.firebase.com/docs/javascript/firebase) (by [Vincent Bortone](https://github.com/vbortone))
* [Firefox](https://developer.mozilla.org/en-US/docs/Web/API) (by [vvakame](https://github.com/vvakame))
* [FlexSlider](http://www.woothemes.com/flexslider/) (by [Diullei Gomes](https://github.com/Diullei))
* [Foundation](http://foundation.zurb.com/) (by [Boris Yankov](https://github.com/borisyankov))
* [FPSMeter](http://darsa.in/fpsmeter/) (by [Aaron Lampros](https://github.com/alampros))

28
firefox/firefox-test.ts Normal file
View File

@@ -0,0 +1,28 @@
/// <reference path="firefox.d.ts" />
var manifestUrl = window.location.protocol + "//" + window.location.host + "/manifest.webapp";
var log = (data:any) => {
alert(data);
};
var setupCallback = (src:string, request:DOMRequest<App>) => {
request.onsuccess = (data)=> {
if (request.result && request.result.manifest) {
log('app is installed ' + request.result.manifest.name + " by " + src);
} else if (request.result) {
// bug 806597. https://bugzilla.mozilla.org/show_bug.cgi?id=806597
log("app is installed by " + src);
} else {
log("app is not installed by " + src);
}
};
request.onerror = ()=> {
log('failed, error: ' + request.error.name + " by " + src);
};
};
var apps = navigator.mozApps;
setupCallback("install", apps.install(manifestUrl));
setupCallback("checkInstalled", apps.checkInstalled(manifestUrl));
setupCallback("getSelf", apps.getSelf());

39
firefox/firefox.d.ts vendored Normal file
View File

@@ -0,0 +1,39 @@
// Type definitions for Mozilla Web API
// Project: https://developer.mozilla.org/en-US/docs/Web/API
// Definitions by: vvakame <https://github.com/vvakame/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// required lib.d.ts
// expand Navigator definietion.
interface Navigator {
mozApps:Apps;
}
interface Apps {
install(url:string, receipts?:any[]):DOMRequest<App>;
getSelf():DOMRequest<App>;
getInstalled():DOMRequest<App[]>;
checkInstalled(url:string): DOMRequest<App>;
}
interface DOMRequest<T> {
onsuccess: Function;
onerror: Function;
readyState:string; // "done" or "pending"
result:T;
error:DOMError;
}
interface App {
manifest:any;
manifestURL:string;
origin:string;
installOrigin:string;
installTime:number;
receipts:any[];
launch();
checkForUpdate():DOMRequest<any>;
}