2019-08-27 12:17:23 +00:00
|
|
|
/*
|
|
|
|
Sortt
|
|
|
|
|
|
|
|
@License MIT
|
|
|
|
@Author 6543
|
|
|
|
*/
|
|
|
|
|
2019-08-27 14:17:53 +00:00
|
|
|
//creat global function with main routine
|
2019-08-27 14:35:45 +00:00
|
|
|
window.sortt=function(normsort,revsort,isdefault){
|
|
|
|
//sortTable [normsort] (revsort) (isdefault)
|
2019-08-27 14:17:53 +00:00
|
|
|
|
2019-08-27 14:35:45 +00:00
|
|
|
//normsort is needet
|
|
|
|
if (typeof normsort === 'undefined') return false;
|
2019-08-27 14:17:53 +00:00
|
|
|
|
2019-08-27 14:35:45 +00:00
|
|
|
//default values of optinal parameters
|
|
|
|
if (typeof revsort === 'undefined') revsort = "";
|
|
|
|
if (typeof isdefault === 'undefined') isdefault = false;
|
2019-08-27 15:16:17 +00:00
|
|
|
if (!(typeof isdefault === 'boolean')) isdefault = false;
|
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) {
|
|
|
|
url.searchParams.delete("sort");
|
|
|
|
url.searchParams.append("sort",normsort);
|
|
|
|
} else if (revsort != "") {
|
|
|
|
url.searchParams.delete("sort");
|
|
|
|
url.searchParams.append("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
|
|
|
};
|