/* Sortt @License MIT @Author 6543 @Repository https://gitea.com/6543/gitea_sortt @Version 1.2.1 */ // test if jQuery is available if(!window.jQuery) { console.log("sortt.js: ERROR no jQuery found!"); } else { //use JQuery to bind event on each with a "data-sortt" attribute $('th').each(function() { if ($(this)[0].dataset.sortt) $(this).on('click', function(e) { var data = $(this)[0].dataset.sortt; data = data.split(","); sortt(data[0],data[1],data[2]); }); }); } //create global function with main routine window.sortt=function(normsort,revsort,isdefault){ //sortTable [normsort] (revsort) (isdefault) //normsort is needed if (!(normsort)) return false; //default values of optinal parameters if (!(revsort)) revsort = ""; // parse URL /* script check if url has already a sort= NO: if sort=“” indikates default (with * prefix) set url_sort= YES: set url_sort variable */ let url = new URL(window.location); let url_sort = url.searchParams.get("sort"); if ((url_sort === null) && isdefault) url_sort = normsort; // generate new URL /* script check if url_sort and sort attribute is same NO: generate URL with sort param YES: check if reverse attribute exist -> YES: generate URL with reverse sort param */ if (url_sort != normsort) { url.searchParams.set("sort",normsort); } else if (revsort != "") { url.searchParams.set("sort",revsort); } //open url window.location.replace(url.href); };