1 /* See license.txt for terms of usage */ 2 3 define([ 4 "firebug/lib/trace", 5 "firebug/lib/locale", 6 "firebug/lib/options", 7 "firebug/lib/css" 8 ], 9 function(FBTrace, Locale, Options, Css) { 10 11 // ********************************************************************************************* // 12 // Constants 13 14 var Toolbar = {}; 15 16 // ********************************************************************************************* // 17 // Implementation 18 19 Toolbar.createToolbarButton = function(toolbar, button, before) 20 { 21 if (typeof(button) == "string" && button.charAt(0) == "-") 22 return Toolbar.createToolbarSeparator(toolbar, before); 23 24 var toolbarButton = toolbar.ownerDocument.createElement("toolbarbutton"); 25 26 Toolbar.setItemIntoElement(toolbarButton, button); 27 28 if (before) 29 toolbar.insertBefore(toolbarButton, before); 30 else 31 toolbar.appendChild(toolbarButton); 32 33 return toolbarButton; 34 }; 35 36 Toolbar.setItemIntoElement = function(element, item) 37 { 38 if (item.label) 39 { 40 var label = item.nol10n ? item.label : Locale.$STR(item.label); 41 element.setAttribute("label", label); 42 } 43 44 if (item.id) 45 element.setAttribute("id", item.id); 46 47 if (item.type) 48 element.setAttribute("type", item.type); 49 50 if (item.checked) 51 element.setAttribute("checked", "true"); 52 53 if (item.disabled) 54 element.setAttribute("disabled", "true"); 55 56 if (item.image) 57 element.setAttribute("image", item.image); 58 59 if (item.command) 60 element.addEventListener("command", item.command, false); 61 62 if (item.commandID) 63 element.setAttribute("command", item.commandID); 64 65 if (item.option) 66 element.setAttribute("option", item.option); 67 68 if (item.tooltiptext) 69 { 70 var tooltiptext = item.nol10n ? item.tooltiptext : Locale.$STR(item.tooltiptext); 71 element.setAttribute("tooltiptext", tooltiptext); 72 } 73 74 if (item.className) 75 Css.setClass(element, item.className); 76 77 if (item.key) 78 element.setAttribute("accesskey", item.key); 79 80 if (item.name) 81 element.setAttribute("name", item.name); 82 83 return element; 84 } 85 86 Toolbar.createToolbarSeparator = function(toolbar, before) 87 { 88 if (!toolbar.firstChild) 89 return; 90 91 var separator = toolbar.ownerDocument.createElement("toolbarseparator"); 92 if (before) 93 toolbar.insertBefore(separator, before); 94 else 95 toolbar.appendChild(separator); 96 97 return separator; 98 }; 99 100 // ********************************************************************************************* // 101 // Registration 102 103 return Toolbar; 104 105 // ********************************************************************************************* // 106 }); 107