/**
* Advanced Taxonomy Reengineering - SJB Final Interceptor
* Optimized for AcademicCareers.com
*/
(function() {
const reengineerCategories = () => {
const selectNodes = document.querySelectorAll('select[name="categories[]"]');
selectNodes.forEach(selectElement => {
if (selectElement.dataset.reengineered === 'true') return;
const $select = window.jQuery ? jQuery(selectElement) : null;
// 1. Destroy existing widget to modify underlying DOM structure
if ($select && $select.data("ech-multiselect")) {
$select.multiselect('destroy');
}
const optionsArray = Array.from(selectElement.options);
let currentOptGroup = null;
optionsArray.forEach(option => {
const text = option.text;
// 2. Identify "Header" markers and create