logo

blog

My website can't be that messy, right? git clone https://anongit.hacktivis.me/git/blog.git/
commit: 7c55c3b9ab5562d9062309d310c0c75477c2590d
parent a04e1c566ceb0d6b4378a2dc66521c24f6af4c1e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 16 Sep 2025 05:39:23 +0200

javascript/sorttable.js: use querySelectorAll instead getElementsByClassName + filtering

Diffstat:

Manimelist.xhtml.in2+-
Mjavascript/sorttable.js15++++++---------
Mmangalist.xhtml.in2+-
Mnginx_autoindex.xsl.in2+-
Mnotes_index.pm2+-
5 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/animelist.xhtml.in b/animelist.xhtml.in @@ -408,7 +408,7 @@ </table> </section> <!-- needs to be at the end… --> - <script defer="" src="javascript/sorttable.js?serial=2023030901"></script> + <script defer="" src="javascript/sorttable.js?serial=2025091600"></script> <xi:include href="templates/en/footer.shtml" parse="xml"/> </body> </html> diff --git a/javascript/sorttable.js b/javascript/sorttable.js @@ -1,6 +1,6 @@ /* * Copyright 2007 Stuart Langridge http://www.kryogenix.org/code/browser/sorttable/ - * Copyright 2018, 2023 Haelwenn (lanodan) Monnier <contact@hacktivis.me> + * Copyright 2018, 2023, 2025 Haelwenn (lanodan) Monnier <contact@hacktivis.me> * SPDX-License-Identifier: X11 */ @@ -20,12 +20,8 @@ sorttable.init = function() { // flag this function so we don't do the same thing twice sorttable.done = true; - var sortableElements = document.getElementsByClassName("sortable"); - Array.prototype.filter.call(sortableElements, function(sortableElement) { - if(sortableElement.nodeName == "TABLE" || sortableElement.nodeName == "table") - { - sorttable.makeSortable(sortableElement); - } + document.querySelectorAll("table.sortable").forEach((e) => { + sorttable.makeSortable(e); }); }; @@ -82,8 +78,9 @@ sorttable.innerSortFunction = function(tr) { { // remove sorttable_sorted classes theadRow = tr.parentNode; - theadRow.childNodes.forEach(function( - cell) { cell.classList.remove('sorttable_sorted_reverse', 'sorttable_sorted'); }); + theadRow.childNodes.forEach(function(cell) { + cell.classList.remove('sorttable_sorted_reverse', 'sorttable_sorted'); + }); // build an array to sort. This is a Schwartzian transform thing, // i.e., we "decorate" each row with the actual sort key, // sort based on the sort keys, and then put the rows back in order diff --git a/mangalist.xhtml.in b/mangalist.xhtml.in @@ -71,7 +71,7 @@ </table> </section> <!-- needs to be at the end… --> - <script defer="" src="javascript/sorttable.js?serial=2023030901"></script> + <script defer="" src="javascript/sorttable.js?serial=2025091600"></script> <xi:include href="templates/en/footer.shtml" parse="xml"/> </body> </html> diff --git a/nginx_autoindex.xsl.in b/nginx_autoindex.xsl.in @@ -34,7 +34,7 @@ </table> </main> <xi:include href="templates/en/footer.shtml" parse="xml"/> - <script src="/javascript/sorttable.js?serial=2023030902"></script> + <script src="/javascript/sorttable.js?serial=2025091600"></script> </body> </html></xsl:template> <!-- diff --git a/notes_index.pm b/notes_index.pm @@ -66,7 +66,7 @@ print ' </tbody> </table> </main> <!--#include file="/templates/en/footer.shtml" --> - <script src="/javascript/sorttable.js?serial=2023030902"></script> + <script src="/javascript/sorttable.js?serial=2025091600"></script> </body> </html> ';