646 lines
22 KiB
JavaScript
646 lines
22 KiB
JavaScript
/**
|
|
* OTS Signage Modern Theme - Client-Side Utilities
|
|
* Sidebar toggle, dropdown menus, and UI interactions
|
|
*/
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
const STORAGE_KEYS = {
|
|
sidebarCollapsed: 'otsTheme:sidebarCollapsed'
|
|
};
|
|
|
|
/**
|
|
* Initialize sidebar toggle functionality
|
|
*/
|
|
function initSidebarToggle() {
|
|
const toggleBtn = document.querySelector('[data-action="toggle-sidebar"]');
|
|
const sidebar = document.querySelector('.ots-sidebar');
|
|
const closeBtn = document.querySelector('.ots-sidebar-close');
|
|
const collapseBtn = document.querySelector('.sidebar-collapse-btn-visible');
|
|
const expandBtn = document.querySelector('.sidebar-expand-btn');
|
|
const body = document.body;
|
|
|
|
if (!sidebar) return;
|
|
|
|
// Handle sidebar close button
|
|
if (closeBtn) {
|
|
closeBtn.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
sidebar.classList.remove('active');
|
|
});
|
|
}
|
|
|
|
// Mobile-aware toggle: add backdrop, aria-expanded, and focus management
|
|
if (toggleBtn) {
|
|
let lastFocus = null;
|
|
function ensureBackdrop() {
|
|
let bd = document.querySelector('.ots-backdrop');
|
|
if (!bd) {
|
|
bd = document.createElement('div');
|
|
bd.className = 'ots-backdrop';
|
|
bd.addEventListener('click', function() {
|
|
sidebar.classList.remove('active');
|
|
bd.classList.remove('show');
|
|
toggleBtn.setAttribute('aria-expanded', 'false');
|
|
if (lastFocus) lastFocus.focus();
|
|
});
|
|
document.body.appendChild(bd);
|
|
}
|
|
return bd;
|
|
}
|
|
|
|
toggleBtn.setAttribute('role', 'button');
|
|
toggleBtn.setAttribute('aria-controls', 'ots-sidebar');
|
|
toggleBtn.setAttribute('aria-expanded', 'false');
|
|
|
|
toggleBtn.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
const isNowActive = !sidebar.classList.contains('active');
|
|
sidebar.classList.toggle('active');
|
|
// On small screens show backdrop and manage focus
|
|
if (window.innerWidth <= 768) {
|
|
const bd = ensureBackdrop();
|
|
if (isNowActive) {
|
|
bd.classList.add('show');
|
|
toggleBtn.setAttribute('aria-expanded', 'true');
|
|
lastFocus = document.activeElement;
|
|
// move focus into the sidebar
|
|
const firstFocusable = sidebar.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
|
|
if (firstFocusable) firstFocusable.focus(); else sidebar.setAttribute('tabindex', '-1'), sidebar.focus();
|
|
// add escape handler
|
|
document.addEventListener('keydown', escHandler);
|
|
} else {
|
|
bd.classList.remove('show');
|
|
toggleBtn.setAttribute('aria-expanded', 'false');
|
|
if (lastFocus) lastFocus.focus();
|
|
document.removeEventListener('keydown', escHandler);
|
|
}
|
|
}
|
|
});
|
|
|
|
function escHandler(e) {
|
|
if (e.key === 'Escape' || e.key === 'Esc') {
|
|
const bd = document.querySelector('.ots-backdrop');
|
|
if (sidebar.classList.contains('active')) {
|
|
sidebar.classList.remove('active');
|
|
if (bd) bd.classList.remove('show');
|
|
toggleBtn.setAttribute('aria-expanded', 'false');
|
|
if (lastFocus) lastFocus.focus();
|
|
document.removeEventListener('keydown', escHandler);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (collapseBtn) {
|
|
const isCollapsed = localStorage.getItem(STORAGE_KEYS.sidebarCollapsed) === 'true';
|
|
if (isCollapsed) {
|
|
sidebar.classList.add('collapsed');
|
|
body.classList.add('ots-sidebar-collapsed');
|
|
document.documentElement.classList.add('ots-sidebar-collapsed');
|
|
updateSidebarStateClass();
|
|
}
|
|
|
|
collapseBtn.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
const nowCollapsed = !sidebar.classList.contains('collapsed');
|
|
sidebar.classList.toggle('collapsed');
|
|
body.classList.toggle('ots-sidebar-collapsed', nowCollapsed);
|
|
document.documentElement.classList.toggle('ots-sidebar-collapsed', nowCollapsed);
|
|
localStorage.setItem(STORAGE_KEYS.sidebarCollapsed, nowCollapsed ? 'true' : 'false');
|
|
updateSidebarNavOffset();
|
|
updateSidebarStateClass();
|
|
});
|
|
}
|
|
|
|
if (expandBtn) {
|
|
expandBtn.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
sidebar.classList.remove('collapsed');
|
|
body.classList.remove('ots-sidebar-collapsed');
|
|
document.documentElement.classList.remove('ots-sidebar-collapsed');
|
|
localStorage.setItem(STORAGE_KEYS.sidebarCollapsed, 'false');
|
|
updateSidebarNavOffset();
|
|
updateSidebarStateClass();
|
|
});
|
|
}
|
|
|
|
// Initialize sidebar section toggles
|
|
initSidebarSectionToggles();
|
|
|
|
// Close sidebar when clicking outside on mobile
|
|
document.addEventListener('click', function(e) {
|
|
if (window.innerWidth <= 768) {
|
|
const isClickInsideSidebar = sidebar.contains(e.target);
|
|
const isClickOnToggle = toggleBtn && toggleBtn.contains(e.target);
|
|
|
|
if (!isClickInsideSidebar && !isClickOnToggle && sidebar.classList.contains('active')) {
|
|
sidebar.classList.remove('active');
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Sidebar width is now handled purely by CSS classes (.ots-sidebar-collapsed).
|
|
* This function is kept as a no-op for backward compatibility.
|
|
*/
|
|
function updateSidebarWidth() {
|
|
// No-op: CSS handles layout via body.ots-sidebar-collapsed class
|
|
if (window.__otsDebug) {
|
|
const sidebar = document.querySelector('.ots-sidebar');
|
|
const collapsed = sidebar ? sidebar.classList.contains('collapsed') : false;
|
|
console.log('[OTS] updateSidebarWidth (no-op, CSS-driven)', { collapsed });
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Measure the sidebar header bottom and set the top padding of the nav list
|
|
* so nav items always begin below the header (logo + buttons).
|
|
*/
|
|
function updateSidebarNavOffset() {
|
|
const sidebar = document.querySelector('.ots-sidebar');
|
|
if (!sidebar) return;
|
|
const header = sidebar.querySelector('.sidebar-header');
|
|
const nav = sidebar.querySelector('.sidebar-nav, .ots-sidebar-nav');
|
|
if (!nav) return;
|
|
// Calculate header bottom relative to the sidebar top (so it works with scrolling)
|
|
const sidebarRect = sidebar.getBoundingClientRect();
|
|
const headerRect = header ? header.getBoundingClientRect() : null;
|
|
let offset = 0;
|
|
if (headerRect) {
|
|
offset = Math.max(0, Math.ceil(headerRect.bottom - sidebarRect.top));
|
|
} else if (header) {
|
|
offset = header.offsetHeight || 0;
|
|
}
|
|
// Add a small gap so nav doesn't touch the header edge
|
|
const gap = 8;
|
|
const paddingTop = offset > 0 ? offset + gap : '';
|
|
// apply as inline style to ensure it overrides static CSS rules
|
|
if (paddingTop) {
|
|
// Use setProperty with priority so it overrides stylesheet !important rules
|
|
try {
|
|
nav.style.setProperty('padding-top', `${paddingTop}px`, 'important');
|
|
} catch (err) {
|
|
// fallback
|
|
nav.style.paddingTop = `${paddingTop}px`;
|
|
}
|
|
} else {
|
|
// remove inline override
|
|
try {
|
|
nav.style.removeProperty('padding-top');
|
|
} catch (err) {
|
|
nav.style.paddingTop = '';
|
|
}
|
|
}
|
|
}
|
|
|
|
// simple debounce helper
|
|
function debounce(fn, wait) {
|
|
let t;
|
|
return function () {
|
|
clearTimeout(t);
|
|
t = setTimeout(() => fn.apply(this, arguments), wait);
|
|
};
|
|
}
|
|
|
|
function updateSidebarStateClass() {
|
|
const sidebar = document.querySelector('.ots-sidebar');
|
|
if (!sidebar) return;
|
|
const body = document.body;
|
|
const isCollapsed = sidebar.classList.contains('collapsed');
|
|
if (!isCollapsed) {
|
|
body.classList.add('ots-sidebar-open');
|
|
} else {
|
|
body.classList.remove('ots-sidebar-open');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize sidebar section collapse/expand functionality
|
|
*/
|
|
function initSidebarSectionToggles() {
|
|
const groupToggles = document.querySelectorAll('.sidebar-group-toggle');
|
|
|
|
syncSidebarActiveStates();
|
|
|
|
groupToggles.forEach(toggle => {
|
|
const group = toggle.closest('.sidebar-group');
|
|
const submenu = group ? group.querySelector('.sidebar-submenu') : null;
|
|
const caret = toggle.querySelector('.sidebar-group-caret');
|
|
if (submenu) {
|
|
const isOpen = group.classList.contains('is-open');
|
|
submenu.style.display = isOpen ? 'block' : 'none';
|
|
toggle.setAttribute('aria-expanded', isOpen.toString());
|
|
}
|
|
|
|
toggle.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
|
|
const group = toggle.closest('.sidebar-group');
|
|
const submenu = group ? group.querySelector('.sidebar-submenu') : null;
|
|
if (!submenu) return;
|
|
|
|
const isOpen = group.classList.contains('is-open');
|
|
group.classList.toggle('is-open', !isOpen);
|
|
toggle.setAttribute('aria-expanded', (!isOpen).toString());
|
|
submenu.style.display = isOpen ? 'none' : 'block';
|
|
syncSidebarActiveStates();
|
|
});
|
|
|
|
if (caret) {
|
|
caret.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
toggle.click();
|
|
});
|
|
}
|
|
});
|
|
|
|
// Capture-phase handler to override any conflicting listeners
|
|
document.addEventListener('click', function(e) {
|
|
const caret = e.target.closest('.sidebar-group-caret');
|
|
const toggle = e.target.closest('.sidebar-group-toggle');
|
|
const target = toggle || (caret ? caret.closest('.sidebar-group-toggle') : null);
|
|
if (!target) return;
|
|
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
const group = target.closest('.sidebar-group');
|
|
const submenu = group ? group.querySelector('.sidebar-submenu') : null;
|
|
if (!submenu) return;
|
|
|
|
const isOpen = group.classList.contains('is-open');
|
|
group.classList.toggle('is-open', !isOpen);
|
|
target.setAttribute('aria-expanded', (!isOpen).toString());
|
|
submenu.style.display = isOpen ? 'none' : 'block';
|
|
syncSidebarActiveStates();
|
|
}, true);
|
|
}
|
|
|
|
function syncSidebarActiveStates() {
|
|
const groups = document.querySelectorAll('.sidebar-group');
|
|
groups.forEach(group => {
|
|
const toggle = group.querySelector('.sidebar-group-toggle');
|
|
if (!toggle) return;
|
|
|
|
const hasActiveChild = Boolean(
|
|
group.querySelector('.sidebar-list.active') ||
|
|
group.querySelector('.sidebar-list > a.active')
|
|
);
|
|
|
|
toggle.classList.toggle('active', hasActiveChild);
|
|
|
|
if (hasActiveChild) {
|
|
group.classList.add('is-open');
|
|
const submenu = group.querySelector('.sidebar-submenu');
|
|
if (submenu) submenu.style.display = 'block';
|
|
toggle.setAttribute('aria-expanded', 'true');
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Initialize dropdown menus
|
|
*/
|
|
function initDropdowns() {
|
|
// Only handle OTS-specific dropdowns (user menu, notifications).
|
|
// Let Bootstrap handle topbar nav dropdowns (Schedule, Design, etc.) natively
|
|
// so that links like Dayparting can navigate normally.
|
|
const otsDropdowns = document.querySelectorAll('.ots-topbar-action .dropdown, .ots-page-actions .dropdown');
|
|
|
|
otsDropdowns.forEach(dropdown => {
|
|
const toggle = dropdown.querySelector('.dropdown-toggle, [data-toggle="dropdown"]');
|
|
const menu = dropdown.querySelector('.dropdown-menu');
|
|
|
|
if (!toggle || !menu) return;
|
|
|
|
// Toggle menu on toggle click
|
|
toggle.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
const isNowActive = dropdown.classList.toggle('active');
|
|
|
|
// Close other OTS dropdowns
|
|
otsDropdowns.forEach(other => {
|
|
if (other !== dropdown) other.classList.remove('active');
|
|
});
|
|
});
|
|
|
|
// Close menu when clicking outside
|
|
document.addEventListener('click', function(e) {
|
|
if (!dropdown.contains(e.target)) {
|
|
dropdown.classList.remove('active');
|
|
}
|
|
});
|
|
});
|
|
// Support DataTables Buttons collections which are not wrapped by .dropdown
|
|
document.addEventListener('click', function(e) {
|
|
const btn = e.target.closest('.dt-button');
|
|
|
|
if (btn) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
const wrapper = btn.closest('.dt-buttons') || btn.parentElement;
|
|
|
|
// close other open dt-buttons collections
|
|
document.querySelectorAll('.dt-buttons.active').forEach(w => {
|
|
if (w !== wrapper) w.classList.remove('active');
|
|
});
|
|
|
|
wrapper.classList.toggle('active');
|
|
|
|
// If DataTables placed the collection on the body, find it and position it under the clicked button
|
|
const allCollections = Array.from(document.querySelectorAll('.dt-button-collection'));
|
|
let collection = wrapper.querySelector('.dt-button-collection') || allCollections.find(c => !wrapper.contains(c));
|
|
|
|
// If DataTables didn't create a collection element, create one as a fallback
|
|
if (!collection) {
|
|
collection = document.createElement('div');
|
|
collection.className = 'dt-button-collection';
|
|
// prefer to append near wrapper for positioning; fallback to body
|
|
(wrapper || document.body).appendChild(collection);
|
|
}
|
|
|
|
if (collection) {
|
|
// hide other collections
|
|
allCollections.forEach(c => { if (c !== collection) { c.classList.remove('show'); c.style.display = 'none'; } });
|
|
|
|
const rect = btn.getBoundingClientRect();
|
|
const top = rect.bottom + window.scrollY;
|
|
const left = rect.left + window.scrollX;
|
|
|
|
collection.style.position = 'absolute';
|
|
collection.style.top = `${top}px`;
|
|
collection.style.left = `${left}px`;
|
|
collection.style.display = 'block';
|
|
collection.classList.add('show');
|
|
// DEBUG: log collection contents
|
|
try {
|
|
console.log('dt-button-collection opened, children:', collection.children.length, collection);
|
|
} catch (err) {}
|
|
|
|
// If the collection is empty or visually empty, build a fallback column list from the nearest table
|
|
const isEmpty = collection.children.length === 0 || collection.textContent.trim() === '' || collection.offsetHeight < 10;
|
|
if (isEmpty) {
|
|
try {
|
|
let table = btn.closest('table') || wrapper.querySelector('table') || document.querySelector('table');
|
|
if (table && window.jQuery && jQuery.fn && jQuery.fn.dataTable && jQuery.fn.dataTable.isDataTable(table)) {
|
|
const dt = jQuery(table).DataTable();
|
|
// clear existing
|
|
collection.innerHTML = '';
|
|
const thead = table.querySelectorAll('thead th');
|
|
thead.forEach((th, idx) => {
|
|
const text = (th.textContent || th.innerText || `Column ${idx+1}`).trim();
|
|
const item = document.createElement('div');
|
|
item.style.padding = '6px 12px';
|
|
item.style.display = 'flex';
|
|
item.style.alignItems = 'center';
|
|
item.style.gap = '8px';
|
|
const checkbox = document.createElement('input');
|
|
checkbox.type = 'checkbox';
|
|
checkbox.checked = dt.column(idx).visible();
|
|
checkbox.addEventListener('change', function() {
|
|
dt.column(idx).visible(this.checked);
|
|
});
|
|
const label = document.createElement('span');
|
|
label.textContent = text;
|
|
label.style.color = 'var(--color-text-primary)';
|
|
item.appendChild(checkbox);
|
|
item.appendChild(label);
|
|
collection.appendChild(item);
|
|
});
|
|
console.log('Fallback: populated collection with', collection.children.length, 'items');
|
|
} else {
|
|
console.log('Fallback: no DataTable instance found to populate column visibility');
|
|
}
|
|
} catch (err) {
|
|
console.warn('Error building fallback column list', err);
|
|
}
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
// click outside dt-button -> close any open collections
|
|
document.querySelectorAll('.dt-buttons.active').forEach(w => w.classList.remove('active'));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Initialize search functionality
|
|
*/
|
|
function initSearch() {
|
|
const searchForm = document.querySelector('.topbar-search');
|
|
if (!searchForm) return;
|
|
|
|
const input = searchForm.querySelector('.search-input');
|
|
if (input) {
|
|
input.addEventListener('focus', function() {
|
|
searchForm.style.borderColor = 'var(--color-primary)';
|
|
});
|
|
input.addEventListener('blur', function() {
|
|
searchForm.style.borderColor = 'var(--color-border)';
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize page specific interactions
|
|
*/
|
|
function initPageInteractions() {
|
|
// Displays page - folder selection
|
|
const folderItems = document.querySelectorAll('.folder-item');
|
|
folderItems.forEach(item => {
|
|
item.addEventListener('click', function() {
|
|
folderItems.forEach(f => f.classList.remove('active'));
|
|
this.classList.add('active');
|
|
});
|
|
});
|
|
|
|
// Media page - item selection
|
|
const mediaItems = document.querySelectorAll('.media-item');
|
|
mediaItems.forEach(item => {
|
|
item.addEventListener('click', function() {
|
|
this.style.opacity = '0.7';
|
|
setTimeout(() => this.style.opacity = '1', 200);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make sidebar responsive
|
|
*/
|
|
function makeResponsive() {
|
|
const sidebar = document.querySelector('.ots-sidebar');
|
|
const main = document.querySelector('.ots-main');
|
|
|
|
if (!sidebar) return;
|
|
|
|
// Add toggle button for mobile
|
|
if (window.innerWidth <= 768) {
|
|
sidebar.classList.add('mobile');
|
|
}
|
|
|
|
window.addEventListener('resize', function() {
|
|
if (window.innerWidth > 768) {
|
|
sidebar.classList.remove('mobile', 'active');
|
|
} else {
|
|
sidebar.classList.add('mobile');
|
|
}
|
|
// Recompute sidebar width on resize
|
|
updateSidebarWidth();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Prevent Chart.js errors when chart elements are missing
|
|
*/
|
|
function initChartSafeguard() {
|
|
if (!window.Chart) return;
|
|
|
|
if (typeof window.Chart.acquireContext === 'function') {
|
|
window.Chart.acquireContext = function(item) {
|
|
if (!item) return null;
|
|
|
|
const candidate = item.length ? item[0] : item;
|
|
if (candidate && typeof candidate.getContext === 'function') {
|
|
return candidate.getContext('2d');
|
|
}
|
|
|
|
return null;
|
|
};
|
|
return;
|
|
}
|
|
|
|
if (window.Chart.prototype && typeof window.Chart.prototype.acquireContext === 'function') {
|
|
window.Chart.prototype.acquireContext = function(item) {
|
|
if (!item) return null;
|
|
|
|
const candidate = item.length ? item[0] : item;
|
|
if (candidate && typeof candidate.getContext === 'function') {
|
|
return candidate.getContext('2d');
|
|
}
|
|
|
|
return null;
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Enhance tables: wrap in card, add per-table search box, client-side filtering
|
|
* Non-destructive: skips tables already enhanced
|
|
*/
|
|
function enhanceTables() {
|
|
const selector = '.ots-content table, .content table, .container table, .card table, table';
|
|
const tables = Array.from(document.querySelectorAll(selector));
|
|
let counter = 0;
|
|
|
|
tables.forEach(table => {
|
|
// only enhance tables that have a thead and tbody
|
|
if (!table || table.classList.contains('modern-table')) return;
|
|
if (!table.querySelector('thead') || !table.querySelector('tbody')) return;
|
|
|
|
counter += 1;
|
|
table.classList.add('modern-table');
|
|
|
|
// Build wrapper structure
|
|
const wrapper = document.createElement('div');
|
|
wrapper.className = 'modern-table-card';
|
|
|
|
const controls = document.createElement('div');
|
|
controls.className = 'table-controls';
|
|
|
|
const input = document.createElement('input');
|
|
input.type = 'search';
|
|
input.placeholder = 'Search…';
|
|
input.className = 'table-search-input';
|
|
input.setAttribute('aria-label', 'Table search');
|
|
input.style.minWidth = '180px';
|
|
|
|
controls.appendChild(input);
|
|
|
|
const tableWrapper = document.createElement('div');
|
|
tableWrapper.className = 'table-wrapper';
|
|
tableWrapper.style.overflow = 'auto';
|
|
|
|
// Insert wrapper into DOM in place of the table
|
|
const parent = table.parentNode;
|
|
parent.replaceChild(wrapper, table);
|
|
wrapper.appendChild(controls);
|
|
wrapper.appendChild(tableWrapper);
|
|
tableWrapper.appendChild(table);
|
|
|
|
// Simple, light-weight search filtering for this table only
|
|
input.addEventListener('input', function (e) {
|
|
const term = (e.target.value || '').toLowerCase();
|
|
table.querySelectorAll('tbody tr').forEach(tr => {
|
|
const text = tr.textContent.toLowerCase();
|
|
tr.style.display = term === '' || text.includes(term) ? '' : 'none';
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Initialize DataTables for enhanced behavior when available.
|
|
* Falls back gracefully if DataTables or jQuery are not present.
|
|
*/
|
|
function initDataTables() {
|
|
if (!window.jQuery) return;
|
|
const $ = window.jQuery;
|
|
if (!$.fn || !$.fn.dataTable) return;
|
|
|
|
$('.modern-table, table').each(function () {
|
|
try {
|
|
if (!$.fn.dataTable.isDataTable(this)) {
|
|
$(this).DataTable({
|
|
responsive: true,
|
|
lengthChange: false,
|
|
pageLength: 10,
|
|
autoWidth: false,
|
|
dom: '<"table-controls"f>rt<"table-meta"ip>',
|
|
language: { search: '' }
|
|
});
|
|
}
|
|
} catch (err) {
|
|
// If initialization fails, ignore and allow fallback enhancer
|
|
console.warn('DataTables init failed for table', this, err);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Initialize all features when DOM is ready
|
|
*/
|
|
function init() {
|
|
initSidebarToggle();
|
|
initDropdowns();
|
|
initSearch();
|
|
initPageInteractions();
|
|
initDataTables();
|
|
enhanceTables();
|
|
makeResponsive();
|
|
initChartSafeguard();
|
|
// Set initial sidebar width variable and keep it updated
|
|
updateSidebarWidth();
|
|
// Set initial nav offset and keep it updated on resize
|
|
updateSidebarNavOffset();
|
|
const debouncedUpdateNavOffset = debounce(function() {
|
|
updateSidebarNavOffset();
|
|
updateSidebarWidth();
|
|
}, 120);
|
|
window.addEventListener('resize', debouncedUpdateNavOffset);
|
|
}
|
|
|
|
// Wait for DOM to be ready
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
} else {
|
|
init();
|
|
}
|
|
})(); |