Skip to content

Commit

Permalink
Keep the button position when it's placed right before space, flexibl…
Browse files Browse the repository at this point in the history
…e space or separator
  • Loading branch information
JustOff committed Apr 16, 2019
1 parent 95f9bf9 commit 356574b
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,17 @@ var button = {
toolbox.palette.appendChild(b);

var {toolbarId, nextItemId} = this.getPrefs(),
toolbar = toolbarId && $(doc, toolbarId),
nextItem = toolbar && $(doc, nextItemId);
toolbar = toolbarId && $(doc, toolbarId);
if (toolbar) {
// Handle special items with dynamic ids
var match = /^(separator|spacer|spring)\[(\d+)\]$/.exec(nextItemId);
if (match !== null) {
var dynItems = toolbar.querySelectorAll("toolbar" + match[1]);
if (match[2] < dynItems.length) {
nextItemId = dynItems[match[2]].id;
}
}
var nextItem = nextItemId && $(doc, nextItemId);
if (nextItem && nextItem.parentNode && nextItem.parentNode.id.replace("-customization-target", "") == toolbarId) {
toolbar.insertItem(this.meta.id, nextItem);
} else {
Expand Down Expand Up @@ -109,15 +117,26 @@ var button = {
afterCustomize : function(e) {
var toolbox = e.target,
b = $(toolbox.parentNode, button.meta.id),
toolbarId, nextItemId;
toolbarId, nextItem, nextItemId;
if (b) {
var parent = b.parentNode,
nextItem = b.nextSibling;
var 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
var match = /^(separator|spacer|spring)\d+$/.exec(nextItemId);
if (match !== null) {
var dynItems = nextItem.parentNode.querySelectorAll("toolbar" + match[1]);
for (var i = 0; i < dynItems.length; i++) {
if (dynItems[i].id == nextItemId) {
nextItemId = match[1] + "[" + i + "]";
break;
}
}
}
button.setPrefs(toolbarId, nextItemId);
},
getPrefs : function() {
Expand Down

0 comments on commit 356574b

Please sign in to comment.