'use strict';dotclear.ready(()=>{const enableTableSort=(tableId,offset=0,semver=-1,numeric=-1)=>{const table=document.getElementById(tableId);if(!table){return;}
table.classList.add('js-sortable');const headers=table.querySelectorAll('th');for(const header of headers){if(header.innerText)header.setAttribute('tabindex','0');}
const tableBody=table.querySelector('tbody');const rows=tableBody.querySelectorAll('tr');const directions=Array.from({length:headers.length});const sortColumn=(indexData,indexHead)=>{const direction=directions[indexHead]||'asc';const multiplier=direction==='asc'?1:-1;const newRows=Array.from(rows);function comparePartials(a,b){if(a===b){return 0;}
const splitA=a.split('.');const splitB=b.split('.');const length=Math.max(splitA.length,splitB.length);for(let i=0;i<length;i++){if(Number.parseInt(splitA[i],10)>Number.parseInt(splitB[i],10)||(splitA[i]===splitB[i]&&Number.isNaN(splitB[i+1]))){return 1*multiplier;}
if(Number.parseInt(splitA[i],10)<Number.parseInt(splitB[i],10)||(splitA[i]===splitB[i]&&Number.isNaN(splitA[i+1]))){return-1*multiplier;}}}
newRows.sort((rowA,rowB)=>{let cellA=rowA.querySelectorAll('td')[indexData].innerHTML;let cellB=rowB.querySelectorAll('td')[indexData].innerHTML;if(semver===indexHead)return comparePartials(cellA,cellB);if(numeric===indexHead){cellA=Number.parseInt(rowA.querySelectorAll('td')[indexData].innerText,10);cellB=Number.parseInt(rowB.querySelectorAll('td')[indexData].innerText,10);switch(true){case cellA>cellB:return 1*multiplier;case cellA<cellB:return-1*multiplier;case cellA===cellB:return 0;}}
return cellA.localeCompare(cellB)*multiplier;});for(const row of rows)row.remove();for(const row of newRows)tableBody.appendChild(row);for(const header of headers){header.classList.remove('sorted-asc','sorted-desc');}
headers[indexHead].classList.add(`sorted-${direction}`);directions[indexHead]=direction==='asc'?'desc':'asc';};if(headers.length)
for(let index=headers.length-1;index>=0;index--){headers[index].addEventListener('click',()=>sortColumn(index+offset,index));headers[index].addEventListener('keypress',(event)=>{if(event.key==='Enter'){event.target.click();event.preventDefault();}});}};enableTableSort('settings');dotclear.responsiveCellHeaders(document.querySelector('#settings'),'#settings',1);});