diff --git a/README.md b/README.md index 5176fe729c..64740d3206 100755 --- a/README.md +++ b/README.md @@ -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)) diff --git a/firefox/firefox-test.ts b/firefox/firefox-test.ts new file mode 100644 index 0000000000..30f7d7493c --- /dev/null +++ b/firefox/firefox-test.ts @@ -0,0 +1,28 @@ +/// + +var manifestUrl = window.location.protocol + "//" + window.location.host + "/manifest.webapp"; + +var log = (data:any) => { + alert(data); +}; + +var setupCallback = (src:string, request:DOMRequest) => { + 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()); diff --git a/firefox/firefox.d.ts b/firefox/firefox.d.ts new file mode 100644 index 0000000000..dd052f1a8f --- /dev/null +++ b/firefox/firefox.d.ts @@ -0,0 +1,39 @@ +// Type definitions for Mozilla Web API +// Project: https://developer.mozilla.org/en-US/docs/Web/API +// Definitions by: 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; + getSelf():DOMRequest; + getInstalled():DOMRequest; + checkInstalled(url:string): DOMRequest; +} + +interface DOMRequest { + 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; +} +