2019-08-27 12:17:23 +00:00
|
|
|
/*
|
|
|
|
Sortt
|
|
|
|
|
|
|
|
@License MIT
|
|
|
|
@Author 6543
|
2019-08-28 00:38:36 +00:00
|
|
|
@Repository https://gitea.com/6543/gitea_sortt
|
2019-09-18 08:35:04 +00:00
|
|
|
@Version 1.2.1
|
2019-08-28 00:38:36 +00:00
|
|
|
|
2019-08-27 12:17:23 +00:00
|
|
|
*/
|
|
|
|
|
2019-09-18 18:40:05 +00:00
|
|
|
//Declare Functions
|
2019-09-18 00:24:52 +00:00
|
|
|
|
2019-09-03 14:30:00 +00:00
|
|
|
//create global function with main routine
|
2019-08-27 14:35:45 +00:00
|
|
|
window.sortt=function(normsort,revsort,isdefault){
|
2019-09-18 18:47:16 +00:00
|
|
|
//sortt [normsort] (revsort) (isdefault)
|
2019-08-27 14:17:53 +00:00
|
|
|
|
2019-09-18 08:32:11 +00:00
|
|
|
//normsort is needed
|
2019-09-17 22:43:09 +00:00
|
|
|
if (!(normsort)) return false;
|
2019-08-27 14:17:53 +00:00
|
|
|
|
2019-08-27 14:35:45 +00:00
|
|
|
//default values of optinal parameters
|
2019-09-17 22:43:09 +00:00
|
|
|
if (!(revsort)) revsort = "";
|
2019-08-27 14:17:53 +00:00
|
|
|
|
2019-08-27 15:16:17 +00:00
|
|
|
// parse URL
|
2019-08-27 15:39:58 +00:00
|
|
|
/* script check if url has already a sort=
|
|
|
|
NO: if sort=“” indikates default (with * prefix) set url_sort=
|
|
|
|
YES: set url_sort variable
|
|
|
|
*/
|
2019-08-28 00:34:37 +00:00
|
|
|
let url = new URL(window.location);
|
|
|
|
let url_sort = url.searchParams.get("sort");
|
|
|
|
if ((url_sort === null) && isdefault) url_sort = normsort;
|
2019-08-27 15:16:17 +00:00
|
|
|
|
2019-08-27 15:39:58 +00:00
|
|
|
// generate new URL
|
|
|
|
/* script check if url_sort and sort attribute is same
|
2019-08-28 00:34:37 +00:00
|
|
|
NO: generate URL with sort param
|
|
|
|
YES: check if reverse attribute exist -> YES: generate URL with reverse sort param
|
2019-08-27 15:39:58 +00:00
|
|
|
*/
|
|
|
|
|
2019-08-28 00:34:37 +00:00
|
|
|
if (url_sort != normsort) {
|
2019-09-18 08:33:21 +00:00
|
|
|
url.searchParams.set("sort",normsort);
|
2019-08-28 00:34:37 +00:00
|
|
|
} else if (revsort != "") {
|
2019-09-18 08:33:21 +00:00
|
|
|
url.searchParams.set("sort",revsort);
|
2019-08-27 15:39:58 +00:00
|
|
|
}
|
2019-08-27 15:16:17 +00:00
|
|
|
|
2019-08-28 00:34:37 +00:00
|
|
|
//open url
|
|
|
|
window.location.replace(url.href);
|
2019-08-27 14:17:53 +00:00
|
|
|
};
|
2019-09-18 18:40:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
//USE Functions
|
|
|
|
|
|
|
|
// test if jQuery is available
|
|
|
|
if(!window.jQuery) {
|
|
|
|
console.log("sortt.js: ERROR no jQuery found!");
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//use JQuery to bind event on each <th> with a "data-sortt" attribute
|
|
|
|
$('th').each(function() {
|
2019-09-18 18:42:07 +00:00
|
|
|
//if data attribute sortt is set
|
|
|
|
if ($(this)[0].dataset.sortt) {
|
|
|
|
//add onclick event
|
|
|
|
$(this).on('click', function() {
|
|
|
|
var data = $(this)[0].dataset.sortt;
|
|
|
|
data = data.split(",");
|
|
|
|
sortt(data[0],data[1],data[2]);
|
|
|
|
});
|
|
|
|
//add arrow to colume
|
|
|
|
// - place holder -
|
|
|
|
}
|
2019-09-18 18:40:05 +00:00
|
|
|
});
|
|
|
|
}
|