Bug 948894 - Move inline scripts for about:apps into AboutApps.js. r=mleibovic

This commit is contained in:
Frederik Braun 2013-12-18 12:59:21 +01:00
parent 4d9d84715b
commit 50df192add
2 changed files with 18 additions and 8 deletions

View File

@ -23,15 +23,17 @@ XPCOMUtils.defineLazyGetter(window, "gChromeWin", function()
.getInterface(Ci.nsIDOMWindow)
.QueryInterface(Ci.nsIDOMChromeWindow));
document.addEventListener("DOMContentLoaded", onLoad, false);
var AppsUI = {
uninstall: null,
shortcut: null
};
function openLink(aElement) {
function openLink(aEvent) {
try {
let formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
let url = formatter.formatURLPref(aElement.getAttribute("pref"));
let url = formatter.formatURLPref(aEvent.target.getAttribute("pref"));
let BrowserApp = gChromeWin.BrowserApp;
BrowserApp.addTab(url, { selected: true, parentId: BrowserApp.selectedTab.id });
} catch (ex) {}
@ -41,7 +43,9 @@ var ContextMenus = {
target: null,
init: function() {
document.addEventListener("contextmenu", ContextMenus, false);
document.addEventListener("contextmenu", this, false);
document.getElementById("addToHomescreenLabel").addEventListener("click", this.addToHomescreen, false);
document.getElementById("uninstallLabel").addEventListener("click", this.uninstall, false);
},
handleEvent: function(event) {
@ -82,6 +86,11 @@ function onLoad(aEvent) {
link.setAttribute("href", url);
} catch (e) {}
let elmts = document.querySelectorAll("[pref]");
for (let i = 0; i < elmts.length; i++) {
elmts[i]..addEventListener("click", openLink, false));
}
navigator.mozApps.mgmt.oninstall = onInstall;
navigator.mozApps.mgmt.onuninstall = onUninstall;
updateList();
@ -155,3 +164,4 @@ function onUninstall(aEvent) {
document.getElementById("main-container").classList.add("hidden");
}
}

View File

@ -27,16 +27,16 @@
<script type="text/javascript;version=1.8" src="chrome://browser/content/aboutApps.js"></script>
</head>
<body dir="&locale.dir;" onload="onLoad(event)">
<body dir="&locale.dir;">
<menu type="context" id="appmenu">
<menuitem label="&aboutApps.addToHomescreen;" onclick="ContextMenus.addToHomescreen();"></menuitem>
<menuitem label="&aboutApps.uninstall;" onclick="ContextMenus.uninstall();"></menuitem>
<menuitem id="addToHomescreenLabel" label="&aboutApps.addToHomescreen;"></menuitem>
<menuitem id="uninstallLabel" label="&aboutApps.uninstall;"></menuitem>
</menu>
<div class="header">
<div>&aboutApps.header;</div>
<div id="header-button" role="button" aria-label="&aboutApps.browseMarketplace;" pref="app.marketplaceURL" onclick="openLink(this);"/>
<div id="header-button" role="button" aria-label="&aboutApps.browseMarketplace;" pref="app.marketplaceURL"/>
</div>
<div id="main-container" class="hidden">
@ -47,7 +47,7 @@
</div>
</div>
<div class="list-item" role="button" pref="app.marketplaceURL" onclick="openLink(this);">
<div class="list-item" role="button" pref="app.marketplaceURL">
<img class="icon" src="chrome://browser/skin/images/marketplace-logo.png" />
<div class="inner">
<div id="browse-title" class="title">&aboutApps.browseMarketplace;</div>