diff options
author | Alessio Vanni <vannilla@firemail.cc> | 2019-03-04 20:45:12 +0100 |
---|---|---|
committer | Alessio Vanni <vannilla@firemail.cc> | 2019-03-04 20:45:12 +0100 |
commit | 09547344faaa66a7d38b96550d6be5d2b68eaaab (patch) | |
tree | 7658b4f1b4812406770f101f867016150f7a586d /js | |
parent | fb6ac758bee7d5a1bdea19a055d5b5137208d348 (diff) | |
download | ematrix-09547344faaa66a7d38b96550d6be5d2b68eaaab.tar.lz ematrix-09547344faaa66a7d38b96550d6be5d2b68eaaab.tar.xz ematrix-09547344faaa66a7d38b96550d6be5d2b68eaaab.zip |
Improve space elements detection
Diffstat (limited to 'js')
-rw-r--r-- | js/vapi-background.js | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/js/vapi-background.js b/js/vapi-background.js index 55ce363..cca47c6 100644 --- a/js/vapi-background.js +++ b/js/vapi-background.js @@ -2476,11 +2476,27 @@ vAPI.toolbarButton = { // Found our button on this toolbar - but where on it? var before = null; for ( var i = index + 1; i < currentset.length; i++ ) { - if (currentset[i] === 'spacer') { - // The [id=...] notation doesn't work on - // 'toolbarspacer' elements. - // https://gitlab.com/vannilla/ematrix/issues/5 - before = toolbar.querySelector('toolbarspacer'); + // The [id=...] notation doesn't work on + // space elements as they get a random ID each session + // (or something like that) + // https://gitlab.com/vannilla/ematrix/issues/5 + // https://gitlab.com/vannilla/ematrix/issues/6 + + // Based on JustOff's snippet from the Pale Moon forum. + // It was reorganized because I find it more readable like this, + // but he did most of the work. + let space = /^(spring|spacer|separator)$/.exec(currentset[i]); + if (space !== null) { + let elems = toolbar.querySelectorAll('toolbar'+space[1]); + + let count = currentset.slice(i-currentset.length) + .filter(function (x) {return x == space[1];}) + .length; + + before = + toolbar.querySelector('[id="' + + elems[elems.length-count].id + + '"]'); } else { before = toolbar.querySelector('[id="'+currentset[i]+'"]'); } |