Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
48
assets/webapps/system.gaiamobile.org/js/nfc_handler.js
Normal file
48
assets/webapps/system.gaiamobile.org/js/nfc_handler.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* globals NfcUtils, BaseModule, Service */
|
||||
'use strict';
|
||||
(function() {
|
||||
var NfcHandler = function (core) {
|
||||
this.nfc = core.nfc;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class NfcCore
|
||||
*/
|
||||
BaseModule.create(NfcHandler, {
|
||||
name: 'NfcHandler',
|
||||
|
||||
_start: function nh_start() {
|
||||
this.nfc.addEventListener('peerready', this);
|
||||
},
|
||||
|
||||
handleEvent: function nh_handleEvent(evt) {
|
||||
var nfcUtils = new NfcUtils();
|
||||
if (evt.type !== 'peerready') {
|
||||
return;
|
||||
}
|
||||
var currentApp = Service.query('getTopMostWindow');
|
||||
if (currentApp && currentApp.isBrowser() && currentApp.config.url) {
|
||||
var ndefUri = nfcUtils.parseURIString(currentApp.config.url);
|
||||
this.sendNDEFMessageToNFCPeer(ndefUri, evt);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Send NDEF message to NFC peer.
|
||||
* @param {MozNDEFRecord} message non-null Array of NDEF records.
|
||||
* @param {Events} nfcEvent an event from mozNfc.onpeerready.
|
||||
*/
|
||||
sendNDEFMessageToNFCPeer:
|
||||
function nh_sendNDEFMessageToNFCPeer(message, nfcEvent) {
|
||||
if (!message) {
|
||||
return;
|
||||
}
|
||||
var nfcPeer = nfcEvent.peer;
|
||||
if (!nfcPeer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
nfcPeer.sendNDEF(message);
|
||||
}
|
||||
});
|
||||
}());
|
||||
Loading…
Reference in a new issue