Compare commits

...

17 Commits
v1.2 ... master

Author SHA1 Message Date
6543 d55d9a2789
README: add release shield 2019-09-19 00:33:04 +02:00
6543 c67f191bc6
add license shields to README 2019-09-18 22:46:16 +02:00
6543 d421210539
Release 1.3.0 2019-09-18 21:42:29 +02:00
6543 2dcf9a93e2
ready for release v1.3.0
* add arrow to active colum header
 * update docu
2019-09-18 21:41:24 +02:00
6543 4e47ba7367
activate new function 2019-09-18 21:36:39 +02:00
6543 9c23f35a9b Merge branch 'feature-add-arrow' into develop 2019-09-18 21:35:37 +02:00
6543 ae60f10523
move data var so other routines also can use it 2019-09-18 21:32:52 +02:00
6543 2f77862081
add coments for documentation 2019-09-18 21:17:41 +02:00
6543 35b566ed07
add func getArrow
this return a arrow char if colum header corelates with sort param in url
2019-09-18 21:14:34 +02:00
6543 4720a6d57c
corect comment 2019-09-18 21:12:16 +02:00
6543 9546772868
corect comment 2019-09-18 20:47:16 +02:00
6543 0ba4bb3e26
restruct code for additional features 2019-09-18 20:42:07 +02:00
6543 286c93ef56
first declare functions then use 2019-09-18 20:40:05 +02:00
6543 04054ff746 Release 1.2.1
* url.searchParams delete(), append() -> url.searchParams set()
 * right typo
 * add missing ";"
2019-09-18 10:35:42 +02:00
6543 66bc536ebb
update version to 1.2.1 2019-09-18 10:35:04 +02:00
6543 295f44fc9c
url.searchParams delete(), append() -> url.searchParams set() 2019-09-18 10:33:21 +02:00
6543 d6beaa8664
right typo & add missing ";" 2019-09-18 10:32:11 +02:00
2 changed files with 79 additions and 25 deletions

View File

@ -1,3 +1,7 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Release](https://img.shields.io/badge/Release-v1.3.0-brightgreen)](https://gitea.com/6543/gitea_sortt/releases)


# gitea_sortt

Java Script for https://github.com/go-gitea/gitea/pull/7980 (Sortable Tables) .. by header click

100
sortt.js
View File

@ -4,31 +4,17 @@
@License MIT
@Author 6543
@Repository https://gitea.com/6543/gitea_sortt
@Version 1.2
@Version 1.3.0

*/


// test if jQuery is available
if(!window.jQuery) {
console.log("sortt.js: ERROR no jQuery found!");
} else {

//use JQuery to bind event on each <th> 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){
//sortTable [normsort] (revsort) (isdefault)
//sortt [normsort] (revsort) (isdefault)

//normsort is needet
//normsort is needed
if (!(normsort)) return false;

//default values of optinal parameters
@ -36,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");
@ -48,15 +34,79 @@ 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.delete("sort");
url.searchParams.append("sort",normsort);
url.searchParams.set("sort",normsort);
} else if (revsort != "") {
url.searchParams.delete("sort");
url.searchParams.append("sort",revsort);
url.searchParams.set("sort",revsort);
}

//open url
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 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;
}
}
}


//USE Functions

// test if jQuery is available
if(!window.jQuery) {
console.log("sortt.js: ERROR no jQuery found!");
} else {

//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) {
//get data
var data = $(this)[0].dataset.sortt;
data = data.split(",");

//add onclick event
$(this).on('click', function() {
sortt(data[0],data[1],data[2]);
});

//add arrow to colume
var arrow = getArrow(data[0],data[1],data[2]);
// if function got a match ...
if (arrow != false ) {
$(this).prepend(arrow + " ");
}
}
});

}