Your IP : 216.73.217.95


Current Path : /var/www/surf/TYPO3/vendor/typo3/cms-backend/Resources/Public/JavaScript/
Upload File :
Current File : //var/www/surf/TYPO3/vendor/typo3/cms-backend/Resources/Public/JavaScript/sortable-table.js

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */
import Tablesort from"tablesort";import"tablesort.dotsep.js";import"tablesort.number.js";import{IconElement}from"@typo3/backend/element/icon-element.js";import{Sizes}from"@typo3/backend/enum/icon-types.js";class TablesortWithButtons extends Tablesort{init(t,e){let o,r;if(this.table=t,this.thead=!1,this.options=e,t.rows&&t.rows.length>0)if(t.tHead&&t.tHead.rows.length>0){for(let e=0;e<t.tHead.rows.length;e++)if("thead"===t.tHead.rows[e].getAttribute("data-sort-method")){o=t.tHead.rows[e];break}o||(o=t.tHead.rows[t.tHead.rows.length-1]),this.thead=!0}else o=t.rows[0];if(!o)return;const n=t=>{t.preventDefault(),t.stopImmediatePropagation();const e=t.currentTarget.parentNode;this.current&&this.current!==e&&this.current.removeAttribute("aria-sort"),this.current=e,this.sortTable(e)};for(let t=0;t<o.cells.length;t++){const e=o.cells[t];if(e.setAttribute("role","columnheader"),"none"!==e.getAttribute("data-sort-method")){const t=document.createElement("button");t.classList.add("table-sorting-button");const o=document.createElement("span");o.classList.add("table-sorting-label"),o.textContent=e.textContent,t.appendChild(o);const s=document.createElement("span");s.classList.add("table-sorting-icon");const a=new IconElement;a.identifier="actions-sort-amount",a.size=Sizes.small,s.appendChild(a),t.appendChild(s),t.addEventListener("click",n,!1),e.replaceChildren(t),null!==e.getAttribute("data-sort-default")&&(r=e)}}r&&(this.current=r,this.sortTable(r))}}export default class SortableTable{constructor(t){new TablesortWithButtons(t),t.addEventListener("afterSort",(t=>{const e=t.target;e.tHead.querySelectorAll(".table-sorting-button").forEach((t=>{t.classList.remove("table-sorting-button-active");t.querySelector("typo3-backend-icon").identifier="actions-sort-amount"}));const o=e.tHead.querySelector("th[aria-sort]"),r=o.querySelector(".table-sorting-button");r.classList.add("table-sorting-button-active");const n=r.querySelector("typo3-backend-icon");"ascending"===o.ariaSort?n.identifier="actions-sort-amount-down":n.identifier="actions-sort-amount-up"}))}}