Skip to content

Commit

Permalink
Merge pull request #653 from xscreach/feature/alphabetical-sorting-of…
Browse files Browse the repository at this point in the history
…-all-plugin-links-under-the-portal-details-panel
  • Loading branch information
modos189 authored Aug 1, 2023
2 parents 1c0d085 + 747f876 commit fc3cec2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions core/code/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,29 @@ function prepPluginsToLoad () {
};
}

function setupToolboxSort() {
var toolboxElement = $('#toolbox')[0];

function sortToolbox() {
var children = Array.prototype.slice.call(toolboxElement.children);
var sortedChildren = children.slice().sort(function (x, y) {
return x.innerText.localeCompare(y.innerText);
});
if (
sortedChildren.some(function (item, index) {
return item !== children[index];
})
) {
sortedChildren.forEach(function (child) {
toolboxElement.removeChild(child);
toolboxElement.appendChild(child);
});
}
}
sortToolbox();
window.observeDOMChildren(toolboxElement, sortToolbox);
}

function boot() {
log.log('loading done, booting. Built: '+'@build_date@');
if (window.deviceID) {
Expand Down Expand Up @@ -244,6 +267,8 @@ function boot() {

window.iitcLoaded = true;
window.runHooks('iitcLoaded');

setupToolboxSort();
}

try {
Expand Down
19 changes: 19 additions & 0 deletions core/code/utils_misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,22 @@ if (!Element.prototype.closest) {
return null;
};
}

var MutObserver = window.MutationObserver || window.WebKitMutationObserver;
window.observeDOMChildren = function (obj, callback) {
if (!obj || obj.nodeType !== 1) return;

if (MutObserver) {
// define a new observer
var mutationObserver = new MutObserver(callback);

// have the observer observe for changes in children
mutationObserver.observe(obj, { childList: true, subtree: true });
return mutationObserver;
}

// browser support fallback
else if (window.addEventListener) {
obj.addEventListener('DOMNodeInserted', callback, false);
}
};
1 change: 1 addition & 0 deletions core/total-conversion-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ window.script_info.changelog = [
'Improved info panel styling',
'Timestamp added to link and field data',
'Added scanner link to info panel',
'Sorted sidebar links',
],
},
];
Expand Down

0 comments on commit fc3cec2

Please sign in to comment.