@@ -139,8 +139,11 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
139139 table . hasClass = {
140140 noClassInfer : sortableTable . classList . contains ( "no-class-infer" ) ,
141141 cellsSort : sortableTable . classList . contains ( "cells-sort" ) ,
142- tableArrows : sortableTable . classList . contains ( "table-arrows" ) ,
143142 rememberSort : sortableTable . classList . contains ( "remember-sort" ) ,
143+ // tableArrows: sortableTable.classList.contains("table-arrows"),
144+ tableArrows : Array . from ( sortableTable . classList ) . filter ( ( item ) =>
145+ item . includes ( "table-arrows" )
146+ ) ,
144147 } ;
145148 for (
146149 let headerIndex = 0 ;
@@ -400,37 +403,26 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
400403 return ;
401404 }
402405
403- function changeTableArrow ( arrowDirection ) {
406+ function changeArrowAndSort ( arrowDirection , sortDirection ) {
404407 if ( table . hasClass . tableArrows ) {
405408 clearArrows ( arrow ) ;
406409 th . insertAdjacentText ( "beforeend" , arrowDirection ) ;
407410 }
408- }
409-
410- function sortColumn ( sortDirection ) {
411411 column . toBeSorted . sort ( sortDirection , {
412412 numeric : ! isAlphaSort ,
413413 ignorePunctuation : ! isPunctSort ,
414414 } ) ;
415415 }
416416
417417 if ( timesClickedColumn === 1 ) {
418- if ( desc ) {
419- changeTableArrow ( arrow . down ) ;
420- sortColumn ( sortDescending ) ;
421- } else {
422- changeTableArrow ( arrow . up ) ;
423- sortColumn ( sortAscending ) ;
424- }
418+ desc
419+ ? changeArrowAndSort ( arrow . down , sortDescending )
420+ : changeArrowAndSort ( arrow . up , sortAscending ) ;
425421 } else if ( timesClickedColumn === 2 ) {
426422 timesClickedColumn = 0 ;
427- if ( desc ) {
428- changeTableArrow ( arrow . up ) ;
429- sortColumn ( sortAscending ) ;
430- } else {
431- changeTableArrow ( arrow . down ) ;
432- sortColumn ( sortDescending ) ;
433- }
423+ desc
424+ ? changeArrowAndSort ( arrow . up , sortAscending )
425+ : changeArrowAndSort ( arrow . down , sortDescending ) ;
434426 }
435427 return timesClickedColumn ;
436428 }
@@ -524,20 +516,20 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
524516 columnIndexesClicked
525517 ) {
526518 const desc = th . classList . contains ( "order-by-desc" ) ;
527- const custom_arrows = th . classList . contains ( "custom-arrows" ) ;
528- // for (let word in th.classList) {
529- // console.log(word);
530- // }
531- let arrow = { neutral : " ↕" , up : " ↑" , down : " ↓" } ;
532519 let fillValue = "!X!Y!Z!" ;
533- if ( custom_arrows ) {
534- console . log ( custom_arrows ) ;
535- console . log ( custom_arrows . split ( "-" ) ) ;
536- [ arrow . up , arrow . neutral , arrow . down ] = custom_arrows . split ( ) ;
537- th . classList . add ( "table-arrows" ) ;
538- }
539-
540- if ( table . hasClass . tableArrows ) {
520+ let arrow = { up : " ↑" , neutral : " ↕" , down : " ↓" } ;
521+ if ( table . hasClass . tableArrows [ 0 ] ) {
522+ if ( table . hasClass . tableArrows [ 0 ] . split ( "-" ) . length > 2 ) {
523+ var customArrow = table . hasClass . tableArrows [ 0 ] . split ( "-" ) [ 2 ] ;
524+ if ( customArrow . length === 3 ) {
525+ console . log ( table . hasClass . tableArrows [ 0 ] . split ( "-" ) ) ;
526+ [ arrow . up , arrow . neutral , arrow . down ] = [
527+ " " + customArrow [ 0 ] ,
528+ " " + customArrow [ 1 ] ,
529+ " " + customArrow [ 2 ] ,
530+ ] ;
531+ }
532+ }
541533 th . insertAdjacentText ( "beforeend" , arrow . neutral ) ;
542534 }
543535
0 commit comments