B2G/gecko/browser/base/content/browser.js
/**
 * 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 its 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".
 */
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 its 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: 'viewSidebar'.
- 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".
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 its 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 : ' viewSidebar ' . - 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 (!commandID)
    commandID = sidebarBox.getAttribute("sidebarcommand");
  var sidebarBroadcaster = document.getElementById(commandID);
  var sidebar = document.getElementById("sidebar"); 
  var sidebarTitle = document.getElementById("sidebar-title");
  var sidebarSplitter = document.getElementById("sidebar-splitter");
  if (sidebarBroadcaster.getAttribute("checked") == "true") {
    if (!forceOpen) {
      sidebar.setAttribute("src", "about:blank");
      sidebar.docShell.createAboutBlankContentViewer(null);
      sidebarBroadcaster.removeAttribute("checked");
      sidebarBox.setAttribute("sidebarcommand", "");
      sidebarTitle.value = "";
      sidebarBox.hidden = true;
      sidebarSplitter.hidden = true;
      gBrowser.selectedBrowser.focus();
    } else {
      fireSidebarFocusedEvent();
    }
    return;
  }
  var broadcasters = document.getElementsByAttribute("group", "sidebar");
  for (let broadcaster of broadcasters) {
    if (broadcaster.localName != "broadcaster")
      continue;
    if (broadcaster != sidebarBroadcaster)
      broadcaster.removeAttribute("checked");
    else
      sidebarBroadcaster.setAttribute("checked", "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;
  sidebarBox.setAttribute("src", url);
  if (sidebar.contentDocument.location.href != url)
    sidebar.addEventListener("load", sidebarOnLoad, true);
  else 
    fireSidebarFocusedEvent();
}
function toggleSidebar ( commandID , forceOpen ) { var sidebarBox = document . getElementById ( "sidebar-box" ) ; if ( ! commandID ) commandID = sidebarBox . getAttribute ( "sidebarcommand" ) ; var sidebarBroadcaster = document . getElementById ( commandID ) ; var sidebar = document . getElementById ( "sidebar" ) ; var sidebarTitle = document . getElementById ( "sidebar-title" ) ; var sidebarSplitter = document . getElementById ( "sidebar-splitter" ) ; if ( sidebarBroadcaster . getAttribute ( "checked" ) == "true" ) { if ( ! forceOpen ) { sidebar . setAttribute ( "src" , "about:blank" ) ; sidebar . docShell . createAboutBlankContentViewer ( null ) ; sidebarBroadcaster . removeAttribute ( "checked" ) ; sidebarBox . setAttribute ( "sidebarcommand" , "" ) ; sidebarTitle . value = "" ; sidebarBox . hidden = true ; sidebarSplitter . hidden = true ; gBrowser . selectedBrowser . focus ( ) ; } else { fireSidebarFocusedEvent ( ) ; } return ; } var broadcasters = document . getElementsByAttribute ( "group" , "sidebar" ) ; for ( let broadcaster of broadcasters ) { if ( broadcaster . localName != "broadcaster" ) continue ; if ( broadcaster != sidebarBroadcaster ) broadcaster . removeAttribute ( "checked" ) ; else sidebarBroadcaster . setAttribute ( "checked" , "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 ; sidebarBox . setAttribute ( "src" , url ) ; if ( sidebar . contentDocument . location . href != url ) sidebar . addEventListener ( "load" , sidebarOnLoad , true ) ; else fireSidebarFocusedEvent ( ) ; }
Opens or closes the sidebar identified by commandID.
Opens or closes the sidebar identified by commandID .
// xul:browser // Replace the document currently displayed in the sidebar with about:blank // so that we can free memory by unloading the page. We need to explicitly // create a new content viewer because the old one doesn't get destroyed // until about:blank has loaded (which does not happen as long as the // element is hidden). // now we need to show the specified sidebar // ..but first update the 'checked' state of all sidebar broadcasters // skip elements that observe sidebar broadcasters and random // other elements // kick off async load // We set this attribute here in addition to setting it on the <browser> // element itself, because the code in gBrowserInit.onUnload persists this // attribute, not the "src" of the <browser id="sidebar">. The reason it // does that is that we want to delay sidebar load a bit when a browser // window opens. See delayedStartup(). // older code handled this case, so we do it too