first fersion of algo finished

This commit is contained in:
6543 2019-08-27 17:39:58 +02:00
parent 4b59391a36
commit 2813577c4c
Signed by: 6543
GPG Key ID: A1CA74D27FD13271

View File

@ -20,6 +20,10 @@ window.sortt=function(normsort,revsort,isdefault){
if (!(typeof isdefault === 'boolean')) isdefault = false;

// 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
*/
url_sort="";
if (window.location.search.indexOf("sort=") < 0) {
if ( isdefault ) url_sort = normsort;
@ -28,8 +32,32 @@ window.sortt=function(normsort,revsort,isdefault){
url_sort=url_sort.substr(0,url_sort.indexOf("&"));
}

// generate new URL
/* script check if url_sort and sort attribute is same
YES: check if reverse attribute exist -> YES: generate URL with reverse sort param and open
NO: generate URL with sort param and open
*/
url_new = window.location.protocol + "//" + window.location.host + window.location.pathname;
if (window.location.search.length == 0) {
if (url_sort != normsort) {
url_new += "?sort=" + normsort
} else if (revsort != "") {
url_new += "?sort=" + revsort
}
} else {
tmp = window.location.search.substr(window.location.search.indexOf("sort=")+5);
if (tmp.indexOf("&") >= 0) {
tmp = tmp.substr(tmp.indexOf("&"));
} else {
tmp = "";
}

if (url_sort != normsort) {
url_new = tmp.substr(0,window.location.search.indexOf("sort=")+5) + normsort + tmp;
} else if (revsort != "") {
url_new = tmp.substr(0,window.location.search.indexOf("sort=")+5) + revsort + tmp;
}
}


//window.location.replace("http://localhost:3000/admin/repos?sort=feweststars&q=&tab=");
window.location.replace(url_new);
};