From 7833ab0dcf9dfc6fae7f7c897fb70d33e7e54cc7 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 27 Aug 2019 17:16:17 +0200 Subject: [PATCH] add url parsing to sortt function --- sortt.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sortt.js b/sortt.js index 5113738..ca220c0 100644 --- a/sortt.js +++ b/sortt.js @@ -7,15 +7,7 @@ */ //safe url sort param global -window.sortt_url=window.location.search; -if (window.sortt_url.indexOf("sort=") < 0) { - //no sort url argument found - window.sortt_url=""; -} else { - window.sortt_url=window.sortt_url.substr(window.sortt_url.indexOf("sort=")+5); - window.sortt_url=window.sortt_url.substr(0,window.sortt_url.indexOf("&")); -} //creat global function with main routine window.sortt=function(normsort,revsort,isdefault){ //sortTable [normsort] (revsort) (isdefault) @@ -26,8 +18,22 @@ window.sortt=function(normsort,revsort,isdefault){ //default values of optinal parameters if (typeof revsort === 'undefined') revsort = ""; if (typeof isdefault === 'undefined') isdefault = false; + if (!(typeof isdefault === 'boolean')) isdefault = false; // look at ReadMe console.log("sortTable() normsort:\"" + normsort + "\" revsort:\"" + revsort + "\" sortdefault:\"" + sortdefault + "\""); + // parse URL + url_sort=""; + if (window.location.search.indexOf("sort=") < 0) { + if ( isdefault ) url_sort = normsort; + } else { + url_sort=window.location.search.substr(window.location.search.indexOf("sort=")+5); + url_sort=url_sort.substr(0,url_sort.indexOf("&")); + } + + + + + };