From fe10eabff8b16845da93cd0e57089a572b4304aa Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 27 Aug 2019 16:35:45 +0200 Subject: [PATCH] changes for onclick --- README.md | 1 + sortt.js | 23 +++++++---------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index cce686d..d8d5b91 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Java Script for https://github.com/go-gitea/gitea/pull/7980 (Sortable Tables) .. by header click +sortt( [normsort], (revsort), (isdefault) ) ## Routine Idear 1. add to table head colum onclick="sortt('sort parameters')" diff --git a/sortt.js b/sortt.js index bb457b6..5113738 100644 --- a/sortt.js +++ b/sortt.js @@ -17,24 +17,15 @@ if (window.sortt_url.indexOf("sort=") < 0) { window.sortt_url=window.sortt_url.substr(0,window.sortt_url.indexOf("&")); } //creat global function with main routine -window.sortt=function(sort_atr){ - //sortTable [sort attribute] +window.sortt=function(normsort,revsort,isdefault){ + //sortTable [normsort] (revsort) (isdefault) - if (sort_atr.length = 0) return; + //normsort is needet + if (typeof normsort === 'undefined') return false; - //split sort_atribute in its parts - sortdefault = false; - if ( sort_atr.indexOf("*") == 0 ) { - sortdefault = true; - sort_atr = sort_atr.substr(1); - } - if ( sort_atr.indexOf(",") == -1 ) { - revsort = ""; - normsort = sort_atr; - } else { - normsort = sort_atr.substr(0,sort_atr.indexOf(",")); - revsort = sort_atr.substr(sort_atr.indexOf(",")+1); - } + //default values of optinal parameters + if (typeof revsort === 'undefined') revsort = ""; + if (typeof isdefault === 'undefined') isdefault = false; // look at ReadMe console.log("sortTable() normsort:\"" + normsort + "\" revsort:\"" + revsort + "\" sortdefault:\"" + sortdefault + "\"");