Bug 885926 - [Australis] In file CustomizableUI.jsm, replace use of querySelector(idToSelector(id)) with getElementsByAttribute("id", id)[0] for palette queries; r=mconley

This commit is contained in:
Emma Sajic 2013-12-18 15:57:48 -05:00
parent a8c6523bfb
commit 3922bd4f55

View File

@ -883,7 +883,7 @@ let CustomizableUIInternal = {
} }
let nextNode = null; let nextNode = null;
if (aNextNodeId) { if (aNextNodeId) {
nextNode = aAreaNode.customizationTarget.querySelector(idToSelector(aNextNodeId)); nextNode = aAreaNode.customizationTarget.getElementsByAttribute("id", aNextNodeId)[0];
} }
return [aAreaNode.customizationTarget, nextNode]; return [aAreaNode.customizationTarget, nextNode];
}, },
@ -1004,7 +1004,7 @@ let CustomizableUIInternal = {
if (toolbox.palette) { if (toolbox.palette) {
// Attempt to locate a node with a matching ID within // Attempt to locate a node with a matching ID within
// the palette. // the palette.
let node = toolbox.palette.querySelector(idToSelector(aId)); let node = toolbox.palette.getElementsByAttribute("id", aId)[0];
if (node) { if (node) {
// Normalize the removable attribute. For backwards compat, this // Normalize the removable attribute. For backwards compat, this
// is optional if the widget is located in the toolbox palette, // is optional if the widget is located in the toolbox palette,
@ -1881,7 +1881,7 @@ let CustomizableUIInternal = {
windowCache.delete(aWidgetId); windowCache.delete(aWidgetId);
} }
let widgetNode = window.document.getElementById(aWidgetId) || let widgetNode = window.document.getElementById(aWidgetId) ||
window.gNavToolbox.palette.querySelector(idToSelector(aWidgetId)); window.gNavToolbox.palette.getElementsByAttribute("id", aWidgetId)[0];
if (widgetNode) { if (widgetNode) {
widgetNode.remove(); widgetNode.remove();
} }
@ -2014,7 +2014,7 @@ let CustomizableUIInternal = {
if (!container.length) { if (!container.length) {
return false; return false;
} }
let existingNode = container[0].querySelector(idToSelector(aWidgetId)); let existingNode = container[0].getElementsByAttribute("id", aWidgetId)[0];
if (existingNode) { if (existingNode) {
return true; return true;
} }
@ -2058,7 +2058,7 @@ let CustomizableUIInternal = {
// Clone the array so we don't modify the actual placements... // Clone the array so we don't modify the actual placements...
currentPlacements = [...currentPlacements]; currentPlacements = [...currentPlacements];
currentPlacements = currentPlacements.filter((item) => { currentPlacements = currentPlacements.filter((item) => {
let itemNode = container.querySelector(idToSelector(item)); let itemNode = container.getElementsByAttribute("id", item)[0];
return itemNode && removableOrDefault(itemNode || item); return itemNode && removableOrDefault(itemNode || item);
}); });
} }
@ -2972,7 +2972,7 @@ function XULWidgetGroupWrapper(aWidgetId) {
if (!instance) { if (!instance) {
// Toolbar palettes aren't part of the document, so elements in there // Toolbar palettes aren't part of the document, so elements in there
// won't be found via document.getElementById(). // won't be found via document.getElementById().
instance = aWindow.gNavToolbox.palette.querySelector(idToSelector(aWidgetId)); instance = aWindow.gNavToolbox.palette.getElementsByAttribute("id", aWidgetId)[0];
} }
let wrapper = new XULWidgetSingleWrapper(aWidgetId, instance); let wrapper = new XULWidgetSingleWrapper(aWidgetId, instance);
@ -3222,7 +3222,7 @@ OverflowableToolbar.prototype = {
} }
let inserted = false; let inserted = false;
for (; beforeNodeIndex < placements.length; beforeNodeIndex++) { for (; beforeNodeIndex < placements.length; beforeNodeIndex++) {
let beforeNode = this._target.querySelector(idToSelector(placements[beforeNodeIndex])); let beforeNode = this._target.getElementsByAttribute("id", placements[beforeNodeIndex])[0];
if (beforeNode) { if (beforeNode) {
this._target.insertBefore(child, beforeNode); this._target.insertBefore(child, beforeNode);
inserted = true; inserted = true;
@ -3355,7 +3355,7 @@ OverflowableToolbar.prototype = {
return [this._list, null]; return [this._list, null];
} }
let nextNode = this._list.querySelector(idToSelector(aNextNodeId)); let nextNode = this._list.getElementsByAttribute("id", aNextNodeId)[0];
// If this is the first item, we can actually just append the node // If this is the first item, we can actually just append the node
// to the end of the toolbar. If it results in an overflow event, we'll move // to the end of the toolbar. If it results in an overflow event, we'll move
// the new node to the overflow target. // the new node to the overflow target.
@ -3373,9 +3373,4 @@ OverflowableToolbar.prototype = {
}, },
}; };
// When IDs contain special characters, we need to escape them for use with querySelector:
function idToSelector(aId) {
return "#" + aId.replace(/[ !"'#$%&\(\)*+\-,.\/:;<=>?@\[\\\]^`{|}~]/g, '\\$&');
}
CustomizableUIInternal.initialize(); CustomizableUIInternal.initialize();