2011-01-08 07:03:27 -08:00
|
|
|
var AppMenu = {
|
2011-09-01 10:04:31 -07:00
|
|
|
offset: 10,
|
2011-01-08 07:03:27 -08:00
|
|
|
get panel() {
|
|
|
|
delete this.panel;
|
|
|
|
return this.panel = document.getElementById("appmenu");
|
|
|
|
},
|
|
|
|
|
2011-08-24 16:20:56 -07:00
|
|
|
get popup() {
|
|
|
|
delete this.popup;
|
|
|
|
return this.popup = document.getElementById("appmenu-popup");
|
|
|
|
},
|
|
|
|
|
2011-04-08 10:52:07 -07:00
|
|
|
shouldShow: function appmenu_shouldShow(aElement) {
|
|
|
|
return !aElement.hidden;
|
|
|
|
},
|
|
|
|
|
|
|
|
overflowMenu : [],
|
|
|
|
|
2011-01-08 07:03:27 -08:00
|
|
|
show: function show() {
|
2011-06-23 12:14:43 -07:00
|
|
|
let modals = document.getElementsByClassName("modal-block").length;
|
2011-09-01 10:04:29 -07:00
|
|
|
if (AwesomeScreen.activePanel || BrowserUI.isPanelVisible() || modals > 0 || BrowserUI.activeDialog)
|
2011-01-08 07:03:27 -08:00
|
|
|
return;
|
2011-04-08 10:52:07 -07:00
|
|
|
|
2011-08-24 16:20:56 -07:00
|
|
|
// Figure if we should show a menu-list or a pop-up menu
|
|
|
|
let menuButton = document.getElementById("tool-menu");
|
|
|
|
let listFormat = (getComputedStyle(menuButton).visibility == "visible");
|
|
|
|
|
|
|
|
addEventListener("keypress", this, true);
|
|
|
|
|
|
|
|
if (listFormat) {
|
2011-09-01 10:04:31 -07:00
|
|
|
let listbox = document.getElementById("appmenu-popup-appcommands");
|
2011-08-24 16:20:56 -07:00
|
|
|
while (listbox.firstChild)
|
|
|
|
listbox.removeChild(listbox.firstChild);
|
|
|
|
|
2011-09-01 10:04:31 -07:00
|
|
|
let siteCommandsBox = document.getElementById("appmenu-popup-sitecommands");
|
|
|
|
while (siteCommandsBox.firstChild)
|
|
|
|
siteCommandsBox.removeChild(siteCommandsBox.firstChild);
|
|
|
|
|
2011-08-24 16:20:56 -07:00
|
|
|
let childrenCount = this.panel.childElementCount;
|
|
|
|
for (let i = 0; i < childrenCount; i++) {
|
|
|
|
let child = this.panel.children[i];
|
|
|
|
|
|
|
|
if (!this.shouldShow(child))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
child.setAttribute("show", true);
|
|
|
|
|
|
|
|
let item = document.createElement("richlistitem");
|
2011-09-01 10:04:31 -07:00
|
|
|
item.setAttribute("class", child.className);
|
2011-08-24 16:20:56 -07:00
|
|
|
item.onclick = function() { child.click(); }
|
|
|
|
|
|
|
|
let label = document.createElement("label");
|
2011-09-02 12:35:38 -07:00
|
|
|
label.textContent = child.label;
|
2011-08-24 16:20:56 -07:00
|
|
|
item.appendChild(label);
|
|
|
|
|
2011-09-01 10:04:31 -07:00
|
|
|
if (item.classList.contains("appmenu-pageaction"))
|
|
|
|
siteCommandsBox.appendChild(item);
|
|
|
|
else
|
|
|
|
listbox.appendChild(item);
|
2011-04-08 10:52:07 -07:00
|
|
|
}
|
2011-08-24 16:20:56 -07:00
|
|
|
this.popup.hidden = false;
|
2011-09-02 10:16:48 -07:00
|
|
|
this.popup.anchorTo(menuButton, "after_end");
|
2011-08-24 16:20:56 -07:00
|
|
|
|
|
|
|
BrowserUI.lockToolbar();
|
|
|
|
BrowserUI.pushPopup(this, [this.popup, menuButton]);
|
|
|
|
} else {
|
|
|
|
let shown = 0;
|
|
|
|
let lastShown = null;
|
|
|
|
this.overflowMenu = [];
|
|
|
|
let childrenCount = this.panel.childElementCount;
|
|
|
|
for (let i = 0; i < childrenCount; i++) {
|
|
|
|
if (this.shouldShow(this.panel.children[i])) {
|
|
|
|
if (shown == 6 && this.overflowMenu.length == 0) {
|
|
|
|
// if we are trying to show more than 6 elements fall back to showing a more button
|
|
|
|
lastShown.removeAttribute("show");
|
|
|
|
this.overflowMenu.push(lastShown);
|
|
|
|
this.panel.appendChild(this.createMoreButton());
|
|
|
|
}
|
|
|
|
if (this.overflowMenu.length > 0) {
|
|
|
|
this.overflowMenu.push(this.panel.children[i]);
|
|
|
|
} else {
|
|
|
|
lastShown = this.panel.children[i];
|
|
|
|
lastShown.setAttribute("show", shown);
|
|
|
|
shown++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-08 07:03:27 -08:00
|
|
|
|
2011-08-24 16:20:56 -07:00
|
|
|
this.panel.setAttribute("count", shown);
|
|
|
|
this.panel.hidden = false;
|
2011-01-08 07:03:27 -08:00
|
|
|
|
2011-08-24 16:20:56 -07:00
|
|
|
BrowserUI.lockToolbar();
|
|
|
|
BrowserUI.pushPopup(this, [this.panel, Elements.toolbarContainer]);
|
|
|
|
}
|
2011-01-08 07:03:27 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function hide() {
|
2011-02-15 10:26:51 -08:00
|
|
|
this.panel.hidden = true;
|
2011-08-24 16:20:56 -07:00
|
|
|
this.popup.hidden = true;
|
2011-04-08 10:52:07 -07:00
|
|
|
let moreButton = document.getElementById("appmenu-more-button");
|
|
|
|
if (moreButton)
|
|
|
|
moreButton.parentNode.removeChild(moreButton);
|
|
|
|
|
|
|
|
for (let i = 0; i < this.panel.childElementCount; i++) {
|
|
|
|
if (this.panel.children[i].hasAttribute("show"))
|
|
|
|
this.panel.children[i].removeAttribute("show");
|
|
|
|
}
|
2011-01-08 07:03:27 -08:00
|
|
|
|
|
|
|
removeEventListener("keypress", this, true);
|
|
|
|
|
|
|
|
BrowserUI.unlockToolbar();
|
|
|
|
BrowserUI.popPopup(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle: function toggle() {
|
2011-08-24 16:20:56 -07:00
|
|
|
(this.panel.hidden && this.popup.hidden) ? this.show() : this.hide();
|
2011-01-08 07:03:27 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function handleEvent(aEvent) {
|
|
|
|
this.hide();
|
2011-04-08 10:52:07 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
showAsList: function showAsList() {
|
|
|
|
// allow menu to hide to remove the more button before we show the menulist
|
|
|
|
setTimeout((function() {
|
2011-05-28 10:02:50 -07:00
|
|
|
AppMenuOverflow.show(this.overflowMenu);
|
2011-04-08 10:52:07 -07:00
|
|
|
}).bind(this), 0)
|
|
|
|
},
|
|
|
|
|
|
|
|
createMoreButton: function() {
|
|
|
|
let button = document.createElement("toolbarbutton");
|
|
|
|
button.setAttribute("id", "appmenu-more-button");
|
|
|
|
button.setAttribute("class", "appmenu-button");
|
|
|
|
button.setAttribute("label", Strings.browser.GetStringFromName("appMenu.more"));
|
|
|
|
button.setAttribute("show", 6);
|
|
|
|
button.setAttribute("oncommand", "AppMenu.showAsList();");
|
|
|
|
return button;
|
2011-01-08 07:03:27 -08:00
|
|
|
}
|
|
|
|
};
|
2011-05-28 10:02:50 -07:00
|
|
|
|
|
|
|
|
|
|
|
var AppMenuOverflow = {
|
|
|
|
get container() {
|
|
|
|
delete this.container;
|
|
|
|
return this.container = document.getElementById("appmenu-overflow");
|
|
|
|
},
|
|
|
|
|
|
|
|
get list() {
|
|
|
|
delete this.list;
|
|
|
|
return this.list = document.getElementById("appmenu-overflow-commands");
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function show(aList) {
|
|
|
|
let container = this.container;
|
|
|
|
let listbox = this.list;
|
|
|
|
while (listbox.firstChild)
|
|
|
|
listbox.removeChild(listbox.firstChild);
|
|
|
|
|
|
|
|
let children = aList;
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let child = children[i];
|
|
|
|
let item = document.createElement("richlistitem");
|
|
|
|
item.setAttribute("class", "appmenu-button");
|
|
|
|
item.onclick = function() { child.click(); }
|
|
|
|
|
|
|
|
let label = document.createElement("label");
|
|
|
|
label.setAttribute("value", child.label);
|
|
|
|
item.appendChild(label);
|
|
|
|
|
|
|
|
listbox.appendChild(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
container.hidden = false;
|
|
|
|
BrowserUI.pushPopup(this, [this.container]);
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function hide() {
|
|
|
|
this.container.hidden = true;
|
|
|
|
BrowserUI.popPopup(this);
|
|
|
|
}
|
|
|
|
};
|