diff options
author | JustOff <Off.Just.Off@gmail.com> | 2018-07-01 18:33:47 +0300 |
---|---|---|
committer | JustOff <Off.Just.Off@gmail.com> | 2018-07-01 18:33:47 +0300 |
commit | 51b321c7f4e3ac4fa7ed27931510aea39515f199 (patch) | |
tree | 1370ff6258e8fbca857f2ff91fa8c724e2d5206b /toolkit/jetpack/sdk/ui | |
parent | 5857b9d9d770882dca107f72a2adbe594b51a052 (diff) | |
download | UXP-51b321c7f4e3ac4fa7ed27931510aea39515f199.tar UXP-51b321c7f4e3ac4fa7ed27931510aea39515f199.tar.gz UXP-51b321c7f4e3ac4fa7ed27931510aea39515f199.tar.lz UXP-51b321c7f4e3ac4fa7ed27931510aea39515f199.tar.xz UXP-51b321c7f4e3ac4fa7ed27931510aea39515f199.zip |
[PMkit] Keep the buttons position when they are placed right before space, flexible space or separator
Diffstat (limited to 'toolkit/jetpack/sdk/ui')
-rw-r--r-- | toolkit/jetpack/sdk/ui/buttons.js | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/toolkit/jetpack/sdk/ui/buttons.js b/toolkit/jetpack/sdk/ui/buttons.js index 6aaed3865..450584ea7 100644 --- a/toolkit/jetpack/sdk/ui/buttons.js +++ b/toolkit/jetpack/sdk/ui/buttons.js @@ -50,6 +50,14 @@ function insertButton(aWindow, id, onBuild) { let toolbar = toolbarId != "" && doc.getElementById(toolbarId); if (toolbar) { + // Handle special items with dynamic ids + let match = /^(separator|spacer|spring)\[(\d+)\]$/.exec(nextItemId); + if (match !== null) { + let dynItems = toolbar.querySelectorAll("toolbar" + match[1]); + if (match[2] < dynItems.length) { + nextItemId = dynItems[match[2]].id; + } + } let nextItem = nextItemId != "" && doc.getElementById(nextItemId); // If nextItem not in toolbar then retrieve it by reading currentset attribute if (!(nextItem && nextItem.parentNode && nextItem.parentNode.id == toolbarId)) { @@ -82,15 +90,26 @@ function afterCustomize(e) { for (let [id] of buttonsList) { let toolbox = e.target; let b = toolbox.parentNode.querySelector("#" + id); - let toolbarId = null, nextItemId = null; + let toolbarId = null, nextItem = null, nextItemId = null; if (b) { let parent = b.parentNode; - let nextItem = b.nextSibling; + nextItem = b.nextSibling; if (parent && parent.localName == "toolbar") { toolbarId = parent.id; nextItemId = nextItem && nextItem.id; } } + // Handle special items with dynamic ids + let match = /^(separator|spacer|spring)\d+$/.exec(nextItemId); + if (match !== null) { + let dynItems = nextItem.parentNode.querySelectorAll("toolbar" + match[1]); + for (let i = 0; i < dynItems.length; i++) { + if (dynItems[i].id == nextItemId) { + nextItemId = match[1] + "[" + i + "]"; + break; + } + } + } saveLocation(id, toolbarId, nextItemId); } } |