1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is Mozilla Communicator client code, released
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2001
20 * the Initial Developer. All Rights Reserved.
23 * Daniel Glazman <daniel.glazman@disruptive-innovations.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 function CustomizeToolbar(id)
42 // Disable the toolbar context menu items
43 var menubar = document.getElementById("composer-main-menubar");
44 for (var i = 0; i < menubar.childNodes.length; ++i)
45 menubar.childNodes[i].setAttribute("disabled", true);
47 var customizePopup = document.getElementById("CustomizeMainToolbar");
49 customizePopup.setAttribute("disabled", "true");
50 customizePopup = document.getElementById("CustomizeFormatToolbar");
52 customizePopup.setAttribute("disabled", "true");
54 var customizeURL = "chrome://global/content/customizeToolbar.xul";
55 #ifdef TOOLBAR_CUSTOMIZATION_SHEET
56 var sheetFrame = document.getElementById("customizeToolbarSheetIFrame");
57 sheetFrame.hidden = false;
59 // The document might not have been loaded yet, if this is the first time.
60 // If it is already loaded, reload it so that the onload initialization code
62 if (sheetFrame.getAttribute("src") == customizeURL)
63 sheetFrame.contentWindow.location.reload()
65 sheetFrame.setAttribute("src", customizeURL);
67 // XXXmano: there's apparently no better way to get this when the iframe is
69 var sheetWidth = sheetFrame.style.width.match(/([0-9]+)px/)[1];
70 var popup = document.getElementById("customizeToolbarSheetPopup");
71 popup.setAttribute("refid", id);
72 popup.openPopup(document.getElementById(id), "after_start", (window.innerWidth - sheetWidth) / 2, 0);
74 window.openDialog(customizeURL,
76 "chrome,titlebar,toolbar,resizable,dependent",
77 document.getElementById(id));
81 function ToolboxCustomizeDone(aToolboxChanged)
83 #ifdef TOOLBAR_CUSTOMIZATION_SHEET
84 document.getElementById("customizeToolbarSheetIFrame").hidden = true;
85 document.getElementById("customizeToolbarSheetPopup").hidePopup();
88 // Re-enable parts of the UI we disabled during the dialog
89 var menubar = document.getElementById("composer-main-menubar");
90 for (var i = 0; i < menubar.childNodes.length; ++i)
91 menubar.childNodes[i].removeAttribute("disabled");
93 var customizePopup = document.getElementById("CustomizeMainToolbar");
95 customizePopup.removeAttribute("disabled");
96 customizePopup = document.getElementById("CustomizeFormatToolbar");
98 customizePopup.removeAttribute("disabled");
100 // make sure our toolbar buttons have the correct enabled state restored to them...
101 if (this.UpdateMainToolbar != undefined)
102 UpdateMainToolbar(focus);
105 function onViewToolbarCommand(aToolbarId, aMenuItemId)
107 var toolbar = document.getElementById(aToolbarId);
108 var menuItem = document.getElementById(aMenuItemId);
110 if (!toolbar || !menuItem) return;
112 var toolbarCollapsed = toolbar.collapsed;
114 // toggle the checkbox
115 menuItem.setAttribute('checked', toolbarCollapsed);
117 // toggle visibility of the toolbar
118 toolbar.collapsed = !toolbarCollapsed;
120 document.persist(aToolbarId, 'collapsed');
121 document.persist(aMenuItemId, 'checked');
124 function UpdateMainToolbar(caller)
126 dump("===> UPDATING TOOLBAR\n");
129 function UpdateCustomizeMenuPopup(aPopup)
131 while (aPopup.hasChildNodes())
132 aPopup.removeChild(aPopup.lastChild);
134 var toolboxes = document.getElementsByTagName("toolbox");
138 function InstallCustomizationDoneCallbacks()
140 gDialog.MainToolbox.customizeDone = ToolboxCustomizeDone;
141 gDialog.FormatToolbox.customizeDone = ToolboxCustomizeDone;