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
102
gaia/tv_apps/tv-epg/js/context_menu.js
Executable file
102
gaia/tv_apps/tv-epg/js/context_menu.js
Executable file
|
|
@ -0,0 +1,102 @@
|
|||
/* global MozActivity, PinCard */
|
||||
|
||||
'use strict';
|
||||
|
||||
(function(exports) {
|
||||
function ContextMenu(buttonConfigs, app) {
|
||||
this.selfApp = app;
|
||||
this.buttonConfigs = buttonConfigs;
|
||||
document.addEventListener('contextmenu', this.updateMenu.bind(this));
|
||||
|
||||
// Get app metadata like origin and manifestURL from TVDeck for pinning
|
||||
// channels to home
|
||||
this.selfApp.connect('tvdeck-getmeta').then(function (ports) {
|
||||
ports.forEach(function(port) {
|
||||
port.postMessage('ping');
|
||||
port.onmessage = function(message) {
|
||||
if (message) {
|
||||
this.tvDeckMeta = message.data;
|
||||
this.pinCard = new PinCard(this.tvDeckMeta);
|
||||
this.pinCard.on('update-pin-button', this.updateMenu.bind(this));
|
||||
port.onmessage = null;
|
||||
}
|
||||
}.bind(this);
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
var proto = {};
|
||||
|
||||
proto.updateMenu = function cm_showMenu() {
|
||||
var currentHash = window.location.hash;
|
||||
if (this.pinCard.pinnedChannels[currentHash]) {
|
||||
// Show unpin button if current channel is pinned.
|
||||
this._updatePinButton('unpin-from-home', this._unpinFromHome.bind(this));
|
||||
} else {
|
||||
// Show pin button if current channel is not pinned yet.
|
||||
this._updatePinButton('pin-to-home', this._pinToHome.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
proto._updatePinButton = function cm_updatePinButton(l10nId, onclick) {
|
||||
this.buttonConfigs.forEach(function(buttonConfig) {
|
||||
if (buttonConfig.element) {
|
||||
buttonConfig.element.onclick = onclick;
|
||||
if (buttonConfig.hasText) {
|
||||
buttonConfig.element.setAttribute('data-l10n-id', l10nId);
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
proto._pinToHome = function cm__pinToHome() {
|
||||
if (!this.tvDeckMeta) {
|
||||
console.error('TVDeck meta not found.');
|
||||
return;
|
||||
}
|
||||
var number = window.location.hash.split(',')[2];
|
||||
|
||||
/* jshint nonew:false */
|
||||
new MozActivity({
|
||||
name: 'pin',
|
||||
data: {
|
||||
type: 'Application',
|
||||
group: 'tv',
|
||||
name: {
|
||||
id: 'channel-name',
|
||||
args: {
|
||||
number: number
|
||||
}
|
||||
},
|
||||
manifestURL: this.tvDeckMeta.manifestURL,
|
||||
launchURL: this.tvDeckMeta.origin + '/index.html' + window.location.hash
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
proto._unpinFromHome = function cm__unpinFromHome() {
|
||||
var message = {
|
||||
type: 'unpin',
|
||||
data: {
|
||||
manifestURL: this.tvDeckMeta.manifestURL,
|
||||
launchURL: this.tvDeckMeta.origin + '/index.html' + window.location.hash
|
||||
}
|
||||
};
|
||||
|
||||
if (!this.unpinPorts) {
|
||||
this.selfApp.connect('appdeck-channel').then(function (ports) {
|
||||
this.unpinPorts = ports;
|
||||
this.unpinPorts.forEach(function(port) {
|
||||
port.postMessage(message);
|
||||
});
|
||||
}.bind(this));
|
||||
} else {
|
||||
this.unpinPorts.forEach(function(port) {
|
||||
port.postMessage(message);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
ContextMenu.prototype = proto;
|
||||
exports.ContextMenu = ContextMenu;
|
||||
})(window);
|
||||
Loading…
Reference in a new issue