Skip to content
Permalink
Browse files

Keep the button position when it's placed right before space, flexibl…

…e space or separator
  • Loading branch information...
JustOff committed Apr 16, 2019
1 parent 70fd0bb commit e1142b62065e72aeaeadd834e8ea19868e573059
Showing with 24 additions and 5 deletions.
  1. +24 −5 bootstrap.js
@@ -55,9 +55,17 @@ let button = {
toolbox.palette.appendChild(b);

let {toolbarId, nextItemId} = this.getPrefs(),
toolbar = toolbarId && $(doc, toolbarId),
nextItem = toolbar && $(doc, nextItemId);
toolbar = toolbarId && $(doc, 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, nextItemId);
if (nextItem && nextItem.parentNode && nextItem.parentNode.id.replace("-customization-target", "") == toolbarId) {
toolbar.insertItem(this.meta.id, nextItem);
} else {
@@ -90,15 +98,26 @@ let button = {
afterCustomize : function (e) {
let toolbox = e.target,
b = $(toolbox.parentNode, button.meta.id),
toolbarId, nextItemId;
toolbarId, nextItem, nextItemId;
if (b) {
let parent = b.parentNode,
nextItem = b.nextSibling;
let parent = b.parentNode;
nextItem = b.nextSibling;
if (parent && (parent.localName == "toolbar" || parent.classList.contains("customization-target"))) {
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;
}
}
}
button.setPrefs(toolbarId, nextItemId);
},
getPrefs : function () {

0 comments on commit e1142b6

Please sign in to comment.
You can’t perform that action at this time.