From 286c93ef56652f59b79766b9298b434c07616982 Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Wed, 18 Sep 2019 20:40:05 +0200
Subject: [PATCH 1/9] first declare functions then use
---
sortt.js | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/sortt.js b/sortt.js
index 1943758..d85013d 100644
--- a/sortt.js
+++ b/sortt.js
@@ -8,21 +8,7 @@
*/
-
-// test if jQuery is available
-if(!window.jQuery) {
- console.log("sortt.js: ERROR no jQuery found!");
-} else {
-
- //use JQuery to bind event on each
with a "data-sortt" attribute
- $('th').each(function() {
- if ($(this)[0].dataset.sortt) $(this).on('click', function(e) {
- var data = $(this)[0].dataset.sortt;
- data = data.split(",");
- sortt(data[0],data[1],data[2]);
- });
- });
-}
+//Declare Functions
//create global function with main routine
window.sortt=function(normsort,revsort,isdefault){
@@ -58,3 +44,21 @@ window.sortt=function(normsort,revsort,isdefault){
//open url
window.location.replace(url.href);
};
+
+
+//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 | with a "data-sortt" attribute
+ $('th').each(function() {
+ if ($(this)[0].dataset.sortt) $(this).on('click', function(e) {
+ var data = $(this)[0].dataset.sortt;
+ data = data.split(",");
+ sortt(data[0],data[1],data[2]);
+ });
+ });
+}
From 0ba4bb3e26d5ccbcc1eaf1d2555b9ca2d78b9b59 Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Wed, 18 Sep 2019 20:42:07 +0200
Subject: [PATCH 2/9] restruct code for additional features
---
sortt.js | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/sortt.js b/sortt.js
index d85013d..d478b79 100644
--- a/sortt.js
+++ b/sortt.js
@@ -55,10 +55,16 @@ if(!window.jQuery) {
//use JQuery to bind event on each | with a "data-sortt" attribute
$('th').each(function() {
- if ($(this)[0].dataset.sortt) $(this).on('click', function(e) {
- var data = $(this)[0].dataset.sortt;
- data = data.split(",");
- sortt(data[0],data[1],data[2]);
- });
+ //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 -
+ }
});
}
From 9546772868678994016437a34726ec20c75a716d Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Wed, 18 Sep 2019 20:47:16 +0200
Subject: [PATCH 3/9] corect comment
---
sortt.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sortt.js b/sortt.js
index d478b79..f3c1f88 100644
--- a/sortt.js
+++ b/sortt.js
@@ -12,7 +12,7 @@
//create global function with main routine
window.sortt=function(normsort,revsort,isdefault){
- //sortTable [normsort] (revsort) (isdefault)
+ //sortt [normsort] (revsort) (isdefault)
//normsort is needed
if (!(normsort)) return false;
From 4720a6d57c839c809236f05e7a02482bff03bdca Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Wed, 18 Sep 2019 21:12:16 +0200
Subject: [PATCH 4/9] corect comment
---
sortt.js | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/sortt.js b/sortt.js
index f3c1f88..e181ec2 100644
--- a/sortt.js
+++ b/sortt.js
@@ -22,8 +22,8 @@ window.sortt=function(normsort,revsort,isdefault){
// 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
+ NO: if normsort is default set url_sort=
+ YES: set url_sort variable
*/
let url = new URL(window.location);
let url_sort = url.searchParams.get("sort");
@@ -34,7 +34,6 @@ window.sortt=function(normsort,revsort,isdefault){
NO: generate URL with sort param
YES: check if reverse attribute exist -> YES: generate URL with reverse sort param
*/
-
if (url_sort != normsort) {
url.searchParams.set("sort",normsort);
} else if (revsort != "") {
From 35b566ed072e14a5447751736a08e0f14b49af61 Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Wed, 18 Sep 2019 21:14:34 +0200
Subject: [PATCH 5/9] add func getArrow
this return a arrow char if colum header corelates with sort param in url
---
sortt.js | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/sortt.js b/sortt.js
index d478b79..31aee0a 100644
--- a/sortt.js
+++ b/sortt.js
@@ -45,6 +45,38 @@ window.sortt=function(normsort,revsort,isdefault){
window.location.replace(url.href);
};
+//create global function with main routine
+function getArrow(normsort,revsort,isdefault){
+ //sortt [normsort] (revsort) (isdefault)
+
+ //arrows
+ var arrow_down = '⯆'; // U+2BC6
+ var arrow_up = '⯅'; // U+2BC5
+
+ //normsort is needed
+ if (!(normsort)) return false;
+
+ //default values of optinal parameters
+ if (!(revsort)) revsort = "";
+
+ //get sort param from url
+ let url_sort = (new URL(window.location)).searchParams.get("sort");
+
+ if ((url_sort === null) && isdefault) {
+ //if sort is sorted as default add arrow tho this table header
+ if (isdefault) return arrow_down;
+ } else {
+
+ if (url_sort === normsort) {
+ return arrow_down;
+ } else if (url_sort === revsort) {
+ return arrow_up;
+ } else {
+ return false;
+ }
+ }
+}
+
//USE Functions
From 2f77862081be35fd5ef24c0bba21ae1cf931bb67 Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Wed, 18 Sep 2019 21:17:41 +0200
Subject: [PATCH 6/9] add coments for documentation
---
sortt.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/sortt.js b/sortt.js
index 31aee0a..cb8e942 100644
--- a/sortt.js
+++ b/sortt.js
@@ -66,12 +66,15 @@ function getArrow(normsort,revsort,isdefault){
//if sort is sorted as default add arrow tho this table header
if (isdefault) return arrow_down;
} else {
-
+ //if sort arg is in url test if it corelates with colum header sort arguments
if (url_sort === normsort) {
+ //the table is sorted with this header normal
return arrow_down;
} else if (url_sort === revsort) {
+ //the table is sorted with this header reverse
return arrow_up;
} else {
+ //the table is NOT sorted with this header
return false;
}
}
From ae60f10523864f5f347efc9084cf0a43f5804d02 Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Wed, 18 Sep 2019 21:32:52 +0200
Subject: [PATCH 7/9] move data var so other routines also can use it
---
sortt.js | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/sortt.js b/sortt.js
index e181ec2..75a4f0e 100644
--- a/sortt.js
+++ b/sortt.js
@@ -56,12 +56,15 @@ if(!window.jQuery) {
$('th').each(function() {
//if data attribute sortt is set
if ($(this)[0].dataset.sortt) {
+ //get data
+ var data = $(this)[0].dataset.sortt;
+ data = data.split(",");
+
//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 -
}
From 4e47ba73676580b143ab09ebdb3627bea03c8f79 Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Wed, 18 Sep 2019 21:36:39 +0200
Subject: [PATCH 8/9] activate new function
---
sortt.js | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/sortt.js b/sortt.js
index 511cd4c..fa36386 100644
--- a/sortt.js
+++ b/sortt.js
@@ -101,7 +101,11 @@ if(!window.jQuery) {
});
//add arrow to colume
- // - place holder -
+ var arrow = getArrow(data[0],data[1],data[2]);
+ // if function got a match ...
+ if (arrow != false ) {
+ $(this).prepend(arrow + " ");
+ }
}
});
}
From 2dcf9a93e2640d29e69458ec5eb22b160756039d Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Wed, 18 Sep 2019 21:41:24 +0200
Subject: [PATCH 9/9] ready for release v1.3.0
* add arrow to active colum header
* update docu
---
sortt.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sortt.js b/sortt.js
index fa36386..cd3c2fb 100644
--- a/sortt.js
+++ b/sortt.js
@@ -4,7 +4,7 @@
@License MIT
@Author 6543
@Repository https://gitea.com/6543/gitea_sortt
- @Version 1.2.1
+ @Version 1.3.0
*/
@@ -87,7 +87,7 @@ if(!window.jQuery) {
console.log("sortt.js: ERROR no jQuery found!");
} else {
- //use JQuery to bind event on each | with a "data-sortt" attribute
+ //use JQuery to go throu each table header with "data-sortt" attribute
$('th').each(function() {
//if data attribute sortt is set
if ($(this)[0].dataset.sortt) {
@@ -108,4 +108,5 @@ if(!window.jQuery) {
}
}
});
+
}
|