Compare commits

...

23 Commits
v1.0 ... 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
6543 f630cb10e3 Release 1.2
* use jQuery and data-sortt attribute if available
2019-09-18 00:36:09 +00:00
6543 ff002275ca
code format 2019-09-18 02:32:50 +02:00
6543 4e68338082
JS check if jQuery is available
and dont trust the user ;)
2019-09-18 02:29:57 +02:00
6543 f029789e11
use jQuery to bind event
-> use JQuery to bind event on each <th> with a "data-sortt" attribute
2019-09-18 02:24:52 +02:00
6543 d95a82e823
corect logic after short param checks 2019-09-18 00:43:09 +02:00
6543 38deca6a2c
unset arg is bool:false & spell corection
add improvements and sugestions of gary-kim

Co-Authored-By: Gary Kim <gary@garykim.dev>
2019-09-03 16:30:00 +02:00
2 changed files with 84 additions and 16 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

View File

@ -4,26 +4,26 @@
@License MIT
@Author 6543
@Repository https://gitea.com/6543/gitea_sortt
@Version 1.0
@Version 1.3.0

*/

//creat global function with main routine
window.sortt=function(normsort,revsort,isdefault){
//sortTable [normsort] (revsort) (isdefault)
//Declare Functions

//normsort is needet
if (typeof normsort === 'undefined') return false;
//create global function with main routine
window.sortt=function(normsort,revsort,isdefault){
//sortt [normsort] (revsort) (isdefault)

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

//default values of optinal parameters
if (typeof revsort === 'undefined') revsort = "";
if (typeof isdefault === 'undefined') isdefault = false;
if (!(typeof isdefault === 'boolean')) isdefault = false;
if (!(revsort)) revsort = "";

// 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,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 + " ");
}
}
});

}