| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
;( function( $ ) { |
| 7 |
'use strict'; |
| 8 |
|
| 9 |
var updateServer = function( ) { |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
}; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
$.tablesorter.addParser({ |
| 20 |
id : 'inputs', |
| 21 |
is : function() { |
| 22 |
return false; |
| 23 |
}, |
| 24 |
format : function( txt, table, cell ) { |
| 25 |
var $input = $( cell ).find( 'input' ); |
| 26 |
return $input.length ? $input.val() : txt; |
| 27 |
}, |
| 28 |
parsed : true, |
| 29 |
type : 'text' |
| 30 |
}); |
| 31 |
|
| 32 |
$.tablesorter.addParser({ |
| 33 |
id : 'inputs-numeric', |
| 34 |
is : function() { |
| 35 |
return false; |
| 36 |
}, |
| 37 |
format : function( txt, table, cell ) { |
| 38 |
var $input = $( cell ).find( 'input' ); |
| 39 |
var val = $input.length ? $input.val() : txt, |
| 40 |
num = $.tablesorter.formatFloat( ( val || '' ).replace( /[^\w,. \-()]/g, '' ), table ); |
| 41 |
return txt && typeof num === 'number' ? num : |
| 42 |
txt ? $.trim( txt && table.config.ignoreCase ? txt.toLocaleLowerCase() : txt ) : txt; |
| 43 |
}, |
| 44 |
parsed : true, |
| 45 |
type : 'numeric' |
| 46 |
}); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
$.tablesorter.addParser({ |
| 51 |
id : 'checkbox', |
| 52 |
is : function() { |
| 53 |
return false; |
| 54 |
}, |
| 55 |
format : function( txt, table, cell ) { |
| 56 |
var $cell = $( cell ), |
| 57 |
wo = table.config.widgetOptions, |
| 58 |
|
| 59 |
|
| 60 |
status = wo.group_checkbox ? wo.group_checkbox : [ 'checked', 'unchecked' ], |
| 61 |
$input = $cell.find( 'input[type="checkbox"]' ), |
| 62 |
isChecked = $input.length ? $input[ 0 ].checked : ''; |
| 63 |
return $input.length ? status[ isChecked ? 0 : 1 ] : txt; |
| 64 |
}, |
| 65 |
parsed : true, |
| 66 |
type : 'text' |
| 67 |
}); |
| 68 |
|
| 69 |
$.tablesorter.addParser({ |
| 70 |
id: 'radio', |
| 71 |
is: function() { |
| 72 |
return false; |
| 73 |
}, |
| 74 |
format: function(txt, table, cell) { |
| 75 |
var $input = $(cell).find('input:checked'); |
| 76 |
return $input.length ? $input.val() : txt; |
| 77 |
}, |
| 78 |
parsed: true, |
| 79 |
type: 'text' |
| 80 |
}); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
$.tablesorter.addParser({ |
| 85 |
id : 'select', |
| 86 |
is : function() { |
| 87 |
return false; |
| 88 |
}, |
| 89 |
format : function( txt, table, cell ) { |
| 90 |
var $select = $( cell ).find( 'select' ); |
| 91 |
return $select.length ? $select.val() : txt; |
| 92 |
}, |
| 93 |
parsed : true, |
| 94 |
type : 'text' |
| 95 |
}); |
| 96 |
|
| 97 |
|
| 98 |
$.tablesorter.addParser({ |
| 99 |
id : 'select-text', |
| 100 |
is : function() { |
| 101 |
return false; |
| 102 |
}, |
| 103 |
format : function( txt, table, cell ) { |
| 104 |
var $select = $( cell ).find( 'select' ); |
| 105 |
return $select.length ? $select.find( 'option:selected' ).text() || '' : txt; |
| 106 |
}, |
| 107 |
parsed : true, |
| 108 |
type : 'text' |
| 109 |
}); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
$.tablesorter.addParser({ |
| 114 |
id : 'textarea', |
| 115 |
is : function() { |
| 116 |
return false; |
| 117 |
}, |
| 118 |
format : function( txt, table, cell ) { |
| 119 |
var $textarea = $( cell ).find( 'textarea' ); |
| 120 |
return $textarea.length ? $textarea.val() : txt; |
| 121 |
}, |
| 122 |
parsed : true, |
| 123 |
type : 'text' |
| 124 |
}); |
| 125 |
|
| 126 |
|
| 127 |
$.tablesorter.defaults.checkboxClass = ''; |
| 128 |
$.tablesorter.defaults.checkboxVisible = ''; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
$( function() { |
| 135 |
if ( !$.fn.on ) { return; } |
| 136 |
var toggleRowClass = function( $row, checkboxClass, indx, isChecked ) { |
| 137 |
|
| 138 |
|
| 139 |
$row.toggleClass( checkboxClass + '-' + indx, isChecked ); |
| 140 |
|
| 141 |
if ( ( $row[0].className || '' ).match( checkboxClass + '-' ) ) { |
| 142 |
$row.addClass( checkboxClass ); |
| 143 |
} else { |
| 144 |
$row.removeClass( checkboxClass ); |
| 145 |
} |
| 146 |
}, |
| 147 |
updateCheckbox = function($el, state) { |
| 148 |
if ($el.length && $el[0].nodeName !== 'INPUT') { |
| 149 |
$el = $el.find( 'input[type="checkbox"]' ); |
| 150 |
} |
| 151 |
if ($el.length) { |
| 152 |
var ua = window.navigator.userAgent; |
| 153 |
if (state === 'indeterminate') { |
| 154 |
|
| 155 |
$el.prop('checked', !(ua.indexOf('Trident/') > -1 || ua.indexOf('Edge/') > -1)); |
| 156 |
$el.prop('indeterminate', true); |
| 157 |
} else { |
| 158 |
$el.prop('checked', state); |
| 159 |
$el.prop('indeterminate', false); |
| 160 |
} |
| 161 |
} |
| 162 |
}, |
| 163 |
updateHeaderCheckbox = function( $table, checkboxClass ) { |
| 164 |
var $sticky, |
| 165 |
$rows = $table.children( 'tbody' ).children( ':visible' ), |
| 166 |
len = $rows.length, |
| 167 |
c = $table[0].config, |
| 168 |
wo = c && c.widgetOptions, |
| 169 |
$headers = c && c.$headers.add( $( c.namespace + '_extra_headers' ) ) || $table.children( 'thead' ), |
| 170 |
hasSticky = wo && wo.$sticky; |
| 171 |
|
| 172 |
$headers.find( 'input[type="checkbox"]' ).each( function() { |
| 173 |
if (hasSticky) { |
| 174 |
$sticky = hasSticky.find( '[data-column="' + column + '"]' ); |
| 175 |
} |
| 176 |
var column = $( this ).closest( 'td, th' ).attr( 'data-column' ), |
| 177 |
vis = $rows.filter( '.' + checkboxClass + '-' + column ).length, |
| 178 |
allChecked = vis === len && len > 0; |
| 179 |
if ( vis === 0 || allChecked ) { |
| 180 |
updateCheckbox($(this), allChecked); |
| 181 |
if ($sticky) { |
| 182 |
updateCheckbox($sticky, allChecked); |
| 183 |
} |
| 184 |
} else { |
| 185 |
updateCheckbox($(this), 'indeterminate'); |
| 186 |
if ($sticky) { |
| 187 |
updateCheckbox($sticky, 'indeterminate'); |
| 188 |
} |
| 189 |
} |
| 190 |
}); |
| 191 |
|
| 192 |
}; |
| 193 |
|
| 194 |
$( 'table' ).on( 'tablesorter-initialized updateComplete', function() { |
| 195 |
this.tablesorterBusy = false; |
| 196 |
var namespace = '.parser-forms'; |
| 197 |
$( this ) |
| 198 |
|
| 199 |
.addClass( this.config.namespace.slice(1) ) |
| 200 |
.children( 'tbody' ) |
| 201 |
.off( namespace ) |
| 202 |
.on( 'mouseleave' + namespace, function( event ) { |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
if ( event.target.nodeName === 'TBODY' ) { |
| 207 |
$( ':focus' ).blur(); |
| 208 |
} |
| 209 |
}) |
| 210 |
.on( 'focus' + namespace, 'select, input:not([type=checkbox]), textarea', function( event ) { |
| 211 |
var $row = $( event.target ).closest( 'tr' ), |
| 212 |
c = $row.closest( 'table' )[0].config; |
| 213 |
if ( !c || c && c.ignoreChildRow && $row.hasClass( c.cssChildRow ) ) { |
| 214 |
return; |
| 215 |
} |
| 216 |
$( this ).data( 'ts-original-value', this.value ); |
| 217 |
}) |
| 218 |
.on( 'blur' + namespace, 'input:not([type=checkbox]), textarea', function( event ) { |
| 219 |
var $row = $( event.target ).closest( 'tr' ), |
| 220 |
c = $row.closest( 'table' )[0].config; |
| 221 |
if ( !c || c && c.ignoreChildRow && $row.hasClass( c.cssChildRow ) ) { |
| 222 |
return; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
this.value = $( this ).data( 'ts-original-value' ); |
| 227 |
}) |
| 228 |
.on( 'change keyup '.split( ' ' ).join( namespace + ' ' ), 'select, input, textarea', function( event ) { |
| 229 |
var $row = $( this ).closest( 'tr' ), |
| 230 |
c = $row.closest( 'table' )[0].config; |
| 231 |
if ( !c || c && c.ignoreChildRow && $row.hasClass( c.cssChildRow ) ) { |
| 232 |
return; |
| 233 |
} |
| 234 |
if ( event.which === 27 && !( this.nodeName === 'INPUT' && this.type === 'checkbox' ) ) { |
| 235 |
|
| 236 |
this.value = $( this ).data( 'ts-original-value' ); |
| 237 |
return; |
| 238 |
} |
| 239 |
|
| 240 |
if ( event.type === 'change' || |
| 241 |
( event.type === 'keyup' && event.which === 13 && |
| 242 |
( event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA' && event.altKey ) ) ) { |
| 243 |
var undef, checkboxClass, |
| 244 |
$target = $( event.target ), |
| 245 |
isCheckbox = event.target.type === 'checkbox', |
| 246 |
$cell = $target.closest( 'td' ), |
| 247 |
indx = $cell[ 0 ].cellIndex, |
| 248 |
busy = c.table.tablesorterBusy, |
| 249 |
$hdr = c.$headerIndexed && c.$headerIndexed[ indx ] || [], |
| 250 |
val = isCheckbox ? event.target.checked : $target.val(); |
| 251 |
|
| 252 |
if ( $.isEmptyObject( c ) || busy !== false ) { |
| 253 |
return; |
| 254 |
} |
| 255 |
if ( isCheckbox ) { |
| 256 |
checkboxClass = c.checkboxClass || 'checked'; |
| 257 |
toggleRowClass( $cell.closest( 'tr' ), checkboxClass, indx, val ); |
| 258 |
updateHeaderCheckbox( c.$table, checkboxClass ); |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
if ( $hdr.length && ( $hdr.hasClass( 'parser-false' ) || |
| 263 |
( $hdr.hasClass( 'sorter-false' ) && $hdr.hasClass( 'filter-false' ) ) ) || |
| 264 |
|
| 265 |
( event.type === 'change' && c.table.isUpdating ) ) { |
| 266 |
return; |
| 267 |
} |
| 268 |
|
| 269 |
if ( c && val !== $target.data( 'ts-original-value' ) || isCheckbox ) { |
| 270 |
$target.data( 'ts-original-value', val ); |
| 271 |
c.table.tablesorterBusy = true; |
| 272 |
|
| 273 |
$.tablesorter.updateCell( c, $cell, undef, function() { |
| 274 |
updateServer( event, c.$table, $target ); |
| 275 |
c.table.tablesorterBusy = false; |
| 276 |
}); |
| 277 |
} |
| 278 |
} |
| 279 |
}); |
| 280 |
|
| 281 |
|
| 282 |
if ( $( this ).children( 'thead' ).find( 'input[type="checkbox"]' ) ) { |
| 283 |
$( this ) |
| 284 |
.off( namespace ) |
| 285 |
.on( 'tablesorter-ready' + namespace, function() { |
| 286 |
var checkboxClass, |
| 287 |
$table = $( this ), |
| 288 |
c = $table.length && $table[ 0 ].config; |
| 289 |
if ( !$.isEmptyObject( c ) ) { |
| 290 |
this.tablesorterBusy = true; |
| 291 |
checkboxClass = c && c.checkboxClass || 'checked'; |
| 292 |
|
| 293 |
updateHeaderCheckbox( $table, checkboxClass ); |
| 294 |
this.tablesorterBusy = false; |
| 295 |
} |
| 296 |
}) |
| 297 |
.children( 'thead' ) |
| 298 |
.add( this.config.widgetOptions.$sticky ) |
| 299 |
.off( namespace ) |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
.on( 'click' + namespace + ' change' + namespace, 'input[type="checkbox"]', function( event ) { |
| 304 |
var c, undef, onlyVisible, column, $target, isParsed, checkboxClass, |
| 305 |
$checkbox = $( this ), |
| 306 |
isChecked = this.checked, |
| 307 |
$table = $checkbox.closest( 'table' ), |
| 308 |
isSticky = $table.length && $table[0].className.match(/(tablesorter\w+)_extra_table/); |
| 309 |
if (isSticky) { |
| 310 |
isSticky = isSticky[1]; |
| 311 |
$table = $('.' + isSticky + ':not(.' + isSticky + '_extra_table)'); |
| 312 |
} |
| 313 |
c = $table.length && $table[ 0 ].config; |
| 314 |
if ( $table.length && c && !$table[ 0 ].tablesorterBusy ) { |
| 315 |
column = parseInt( $checkbox.closest( 'td, th' ).attr( 'data-column' ), 10 ); |
| 316 |
isParsed = c.parsers[ column ].id === 'checkbox'; |
| 317 |
onlyVisible = c.checkboxVisible; |
| 318 |
$table[ 0 ].tablesorterBusy = true; |
| 319 |
updateCheckbox( |
| 320 |
$target = $table |
| 321 |
.children( 'tbody' ) |
| 322 |
.children( 'tr' + ( typeof onlyVisible === 'undefined' || onlyVisible === true ? ':visible' : '' ) ) |
| 323 |
.children( ':nth-child(' + ( column + 1 ) + ')' ), |
| 324 |
isChecked |
| 325 |
); |
| 326 |
|
| 327 |
checkboxClass = c.checkboxClass || 'checked'; |
| 328 |
$target.each( function() { |
| 329 |
toggleRowClass( $( this ).closest( 'tr' ), checkboxClass, column, isChecked ); |
| 330 |
}); |
| 331 |
if (isSticky) { |
| 332 |
|
| 333 |
updateCheckbox($table.children( 'thead' ).find( '[data-column="' + column + '"]' ), isChecked); |
| 334 |
} else if (c.widgetOptions.$sticky) { |
| 335 |
updateCheckbox(c.widgetOptions.$sticky.find( 'thead' ).find( '[data-column="' + column + '"]' ), isChecked); |
| 336 |
} |
| 337 |
updateHeaderCheckbox( $table, checkboxClass ); |
| 338 |
if ( isParsed ) { |
| 339 |
|
| 340 |
$.tablesorter.update( c, undef, function() { |
| 341 |
updateServer( event, $table, $target ); |
| 342 |
$table[ 0 ].tablesorterBusy = false; |
| 343 |
}); |
| 344 |
} else { |
| 345 |
updateServer( event, $table, $target ); |
| 346 |
$table[ 0 ].tablesorterBusy = false; |
| 347 |
} |
| 348 |
|
| 349 |
return true; |
| 350 |
} |
| 351 |
|
| 352 |
return false; |
| 353 |
}); |
| 354 |
} |
| 355 |
|
| 356 |
}); |
| 357 |
}); |
| 358 |
|
| 359 |
})( jQuery ); |