Bug 322077: clean up toggleSidebar code, patch by Nickolay Ponomarev <asqueella@gmail.com>, r=me

This commit is contained in:
gavin%gavinsharp.com 2006-10-31 14:56:00 +00:00
Родитель 1e5d2dd876
Коммит 05119483fc
5 изменённых файлов: 69 добавлений и 51 удалений

Просмотреть файл

@ -4131,67 +4131,80 @@ function displaySecurityInfo()
BrowserPageInfo(null, "securityTab");
}
// |forceOpen| is a bool that indicates that the sidebar should be forced open. In other words
// the toggle won't be allowed to close the sidebar.
function toggleSidebar(aCommandID, forceOpen) {
/**
* Opens or closes the sidebar identified by commandID.
*
* @param commandID a string identifying the sidebar to toggle; see the
* note below. (Optional if a sidebar is already open.)
* @param forceOpen boolean indicating whether the sidebar should be
* opened regardless of it's current state (optional).
* @note
* We expect to find a xul:broadcaster element with the specified ID.
* The following attributes on that element may be used and/or modified:
* - id (required) the string to match commandID. The convention
* is to use this naming scheme: 'view<sidebar-name>Sidebar'.
* - sidebarurl (required) specifies the URL to load in this sidebar.
* - sidebartitle or label (in that order) specify the title to
* display on the sidebar.
* - checked indicates whether the sidebar is currently displayed.
* Note that toggleSidebar updates this attribute when
* it changes the sidebar's visibility.
* - group this attribute must be set to "sidebar".
*/
function toggleSidebar(commandID, forceOpen) {
var sidebarBox = document.getElementById("sidebar-box");
if (!aCommandID)
aCommandID = sidebarBox.getAttribute("sidebarcommand");
if (!commandID)
commandID = sidebarBox.getAttribute("sidebarcommand");
var elt = document.getElementById(aCommandID);
var sidebar = document.getElementById("sidebar");
var sidebarBroadcaster = document.getElementById(commandID);
var sidebar = document.getElementById("sidebar"); // xul:browser
var sidebarTitle = document.getElementById("sidebar-title");
var sidebarSplitter = document.getElementById("sidebar-splitter");
if (!forceOpen && elt.getAttribute("checked") == "true") {
elt.removeAttribute("checked");
sidebarBox.setAttribute("sidebarcommand", "");
sidebarTitle.setAttribute("value", "");
sidebarBox.hidden = true;
sidebarSplitter.hidden = true;
content.focus();
if (sidebarBroadcaster.getAttribute("checked") == "true") {
if (!forceOpen) {
sidebarBroadcaster.removeAttribute("checked");
sidebarBox.setAttribute("sidebarcommand", "");
sidebarTitle.value = "";
sidebarBox.hidden = true;
sidebarSplitter.hidden = true;
content.focus();
}
return;
}
var elts = document.getElementsByAttribute("group", "sidebar");
for (var i = 0; i < elts.length; ++i)
elts[i].removeAttribute("checked");
// now we need to show the specified sidebar
elt.setAttribute("checked", "true");;
// ..but first update the 'checked' state of all sidebar broadcasters
var broadcasters = document.getElementsByAttribute("group", "sidebar");
for (var i = 0; i < broadcasters.length; ++i) {
// skip elements that observe sidebar broadcasters and random
// other elements
if (broadcasters[i].localName != "broadcaster")
continue;
if (sidebarBox.hidden) {
sidebarBox.hidden = false;
sidebarSplitter.hidden = false;
}
var url = elt.getAttribute("sidebarurl");
var title = elt.getAttribute("sidebartitle");
if (!title)
title = elt.getAttribute("label");
sidebar.setAttribute("src", url);
sidebarBox.setAttribute("src", url);
sidebarBox.setAttribute("sidebarcommand", elt.id);
sidebarTitle.setAttribute("value", title);
if (aCommandID != "viewWebPanelsSidebar") { // no searchbox there
// if the sidebar we want is already constructed, focus the searchbox
if ((aCommandID == "viewBookmarksSidebar" && sidebar.contentDocument.getElementById("bookmarksPanel"))
|| (aCommandID == "viewHistorySidebar" && sidebar.contentDocument.getElementById("history-panel")))
sidebar.contentDocument.getElementById("search-box").focus();
// otherwiese, attach an onload handler
if (broadcasters[i] != sidebarBroadcaster)
broadcasters[i].removeAttribute("checked");
else
sidebar.addEventListener("load", asyncFocusSearchBox, true);
sidebarBroadcaster.setAttribute("checked", "true");
}
}
function asyncFocusSearchBox(event)
{
var sidebar = document.getElementById("sidebar");
var searchBox = sidebar.contentDocument.getElementById("search-box");
if (searchBox)
searchBox.focus();
sidebar.removeEventListener("load", asyncFocusSearchBox, true);
}
sidebarBox.hidden = false;
sidebarSplitter.hidden = false;
var url = sidebarBroadcaster.getAttribute("sidebarurl");
var title = sidebarBroadcaster.getAttribute("sidebartitle");
if (!title)
title = sidebarBroadcaster.getAttribute("label");
sidebar.setAttribute("src", url);
sidebarBox.setAttribute("sidebarcommand", sidebarBroadcaster.id);
sidebarTitle.value = title;
// This is used because we want to delay sidebar load a bit
// when a browser window opens. See delayedStartup()
sidebarBox.setAttribute("src", url);
}
var gHomeButton = {
prefDomain: "browser.startup.homepage",

Просмотреть файл

@ -36,6 +36,10 @@
#
# ***** END LICENSE BLOCK *****
function init() {
document.getElementById("search-box").focus();
}
function manageBookmarks() {
openDialog("chrome://browser/content/bookmarks/bookmarksManager.xul", "", "chrome,dialog=no,resizable=yes");
}

Просмотреть файл

@ -44,8 +44,9 @@
<!DOCTYPE page SYSTEM "chrome://browser/locale/bookmarks/bookmarks.dtd">
<page id="bookmarksPanel"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="init();">
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>

Просмотреть файл

@ -43,8 +43,7 @@
<page id="history-panel" orient="vertical"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
onload="HistoryCommonInit();"
elementtofocus="historyTree">
onload="HistoryCommonInit();">
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsTreeController.js"/>

Просмотреть файл

@ -63,6 +63,7 @@ function HistoryCommonInit()
// XXXBlake we should persist the last search value
// If it's empty, this will do the right thing and just group by the old grouping.
searchHistory(gSearchBox.value);
gSearchBox.focus();
}
function historyOnSelect()