Parser: header checkbox properly updates row classnames. See #1199

This commit is contained in:
Rob Garrison 2016-04-26 12:11:13 -05:00
parent 7fdde11342
commit e03d4b24dc
No known key found for this signature in database
GPG Key ID: 0A42D160D71978E1
2 changed files with 14 additions and 15 deletions

View File

@ -1,2 +1,2 @@
/*! Parser: input & select - updated 1/15/2016 (v2.25.2) */ /*! Parser: input & select - updated 1/15/2016 (v2.25.2) */
!function(a){"use strict";var b=function(a,b,c){};a.tablesorter.addParser({id:"inputs",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input");return e.length?e.val():b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"inputs-numeric",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input"),f=e.length?e.val():b,g=a.tablesorter.formatFloat((f||"").replace(/[^\w,. \-()]/g,""),c);return b&&"number"==typeof g?g:b?a.trim(b&&c.config.ignoreCase?b.toLocaleLowerCase():b):b},parsed:!0,type:"numeric"}),a.tablesorter.addParser({id:"checkbox",is:function(){return!1},format:function(b,c,d,e){var f=a(d),g=c.config.widgetOptions,h=g.group_checkbox?g.group_checkbox:["checked","unchecked"],i=f.find('input[type="checkbox"]'),j=i.length?i[0].checked:"";return i.length?h[j?0:1]:b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.val():b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select-text",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.find("option:selected").text()||"":b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"textarea",is:function(){return!1},format:function(b,c,d){var e=a(d).find("textarea");return e.length?e.val():b},parsed:!0,type:"text"}),a(function(){if(a.fn.on){var c=function(a,b,c,d){a.toggleClass(b+"-"+c,d),(a[0].className||"").match(b+"-")?a.addClass(b):a.removeClass(b)},d=function(b,c){var d=b.children("tbody").children(":visible"),e=d.length;b.children("thead").find('input[type="checkbox"]').each(function(){var b=a(this).closest("td, th").attr("data-column"),f=d.filter("."+c+"-"+b).length,g=f===e;0===f||g?(this.checked=g,this.indeterminate=!1):this.indeterminate=!0})};a("table").on("tablesorter-initialized updateComplete",function(){this.tablesorterBusy=!1;var e=".parser-forms";a(this).children("tbody").off(e).on("mouseleave"+e,function(b){"TBODY"===b.target.nodeName&&a(":focus").blur()}).on("focus"+e,"select, input:not([type=checkbox]), textarea",function(){a(this).data("ts-original-value",this.value)}).on("blur"+e,"input:not([type=checkbox]), textarea",function(){this.value=a(this).data("ts-original-value")}).on("change keyup ".split(" ").join(e+" "),"select, input, textarea",function(e){if(27===e.which&&("INPUT"!==this.nodeName||"checkbox"!==this.type))return void(this.value=a(this).data("ts-original-value"));if("change"===e.type||"keyup"===e.type&&13===e.which&&("INPUT"===e.target.nodeName||"TEXTAREA"===e.target.nodeName&&e.altKey)){var f,g,h=a(e.target),i="checkbox"===e.target.type,j=h.closest("td"),k=j.closest("table"),l=j[0].cellIndex,m=k[0].config||!1,n=k.length&&k[0].tablesorterBusy,o=m&&m.$headerIndexed&&m.$headerIndexed[l]||[],p=i?e.target.checked:h.val();if(a.isEmptyObject(m)||n!==!1)return;if(i&&(g=m.checkboxClass||"checked",c(j.closest("tr"),g,l,p),d(k,g)),o.length&&(o.hasClass("parser-false")||o.hasClass("sorter-false")&&o.hasClass("filter-false"))||"change"===e.type&&m.table.isUpdating)return;(m&&p!==h.data("ts-original-value")||i)&&(h.data("ts-original-value",p),k[0].tablesorterBusy=!0,a.tablesorter.updateCell(m,j,f,function(){b(e,k,h),k[0].tablesorterBusy=!1}))}}),a(this).children("thead").find('input[type="checkbox"]')&&a(this).off(e).on("tablesorter-ready"+e,function(){var b,c=a(this),e=c.length&&c[0].config;a.isEmptyObject(e)||(this.tablesorterBusy=!0,b=e&&e.checkboxClass||"checked",d(c,b),this.tablesorterBusy=!1)}).children("thead").off(e).on("change"+e,'input[type="checkbox"]',function(e){var f,g,h,i,j,k,l,m=a(this),n=m.closest("table"),o=n.length&&n[0].config,p=this.checked;return n.length&&o&&!n[0].tablesorterBusy?(h=parseInt(m.closest("td, th").attr("data-column"),10),j="checkbox"===o.parsers[h].id,g=n.length&&o.checkboxVisible,n[0].tablesorterBusy=!0,i=n.children("tbody").children("tr"+("undefined"==typeof g||g===!0?":visible":"")).children(":nth-child("+(h+1)+")").find('input[type="checkbox"]').prop("checked",p),j?a.tablesorter.update(o,f,function(){b(e,n,i),n[0].tablesorterBusy=!1}):(l=o.checkboxClass||"checked",i.each(function(){k=a(this).closest("tr"),c(a(this).closest("tr"),l,h,p)}),d(n,l),b(e,n,i),n[0].tablesorterBusy=!1),!0):!1})})}})}(jQuery); !function(a){"use strict";var b=function(a,b,c){};a.tablesorter.addParser({id:"inputs",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input");return e.length?e.val():b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"inputs-numeric",is:function(){return!1},format:function(b,c,d){var e=a(d).find("input"),f=e.length?e.val():b,g=a.tablesorter.formatFloat((f||"").replace(/[^\w,. \-()]/g,""),c);return b&&"number"==typeof g?g:b?a.trim(b&&c.config.ignoreCase?b.toLocaleLowerCase():b):b},parsed:!0,type:"numeric"}),a.tablesorter.addParser({id:"checkbox",is:function(){return!1},format:function(b,c,d){var e=a(d),f=c.config.widgetOptions,g=f.group_checkbox?f.group_checkbox:["checked","unchecked"],h=e.find('input[type="checkbox"]'),i=h.length?h[0].checked:"";return h.length?g[i?0:1]:b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.val():b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"select-text",is:function(){return!1},format:function(b,c,d){var e=a(d).find("select");return e.length?e.find("option:selected").text()||"":b},parsed:!0,type:"text"}),a.tablesorter.addParser({id:"textarea",is:function(){return!1},format:function(b,c,d){var e=a(d).find("textarea");return e.length?e.val():b},parsed:!0,type:"text"}),a(function(){if(a.fn.on){var c=function(a,b,c,d){a.toggleClass(b+"-"+c,d),(a[0].className||"").match(b+"-")?a.addClass(b):a.removeClass(b)},d=function(b,c){var d=b.children("tbody").children(":visible"),e=d.length;b.children("thead").find('input[type="checkbox"]').each(function(){var b=a(this).closest("td, th").attr("data-column"),f=d.filter("."+c+"-"+b).length,g=f===e;0===f||g?(this.checked=g,this.indeterminate=!1):this.indeterminate=!0})};a("table").on("tablesorter-initialized updateComplete",function(){this.tablesorterBusy=!1;var e=".parser-forms";a(this).children("tbody").off(e).on("mouseleave"+e,function(b){"TBODY"===b.target.nodeName&&a(":focus").blur()}).on("focus"+e,"select, input:not([type=checkbox]), textarea",function(){a(this).data("ts-original-value",this.value)}).on("blur"+e,"input:not([type=checkbox]), textarea",function(){this.value=a(this).data("ts-original-value")}).on("change keyup ".split(" ").join(e+" "),"select, input, textarea",function(e){if(27===e.which&&("INPUT"!==this.nodeName||"checkbox"!==this.type))return void(this.value=a(this).data("ts-original-value"));if("change"===e.type||"keyup"===e.type&&13===e.which&&("INPUT"===e.target.nodeName||"TEXTAREA"===e.target.nodeName&&e.altKey)){var f,g,h=a(e.target),i="checkbox"===e.target.type,j=h.closest("td"),k=j.closest("table"),l=j[0].cellIndex,m=k[0].config||!1,n=k.length&&k[0].tablesorterBusy,o=m&&m.$headerIndexed&&m.$headerIndexed[l]||[],p=i?e.target.checked:h.val();if(a.isEmptyObject(m)||n!==!1)return;if(i&&(g=m.checkboxClass||"checked",c(j.closest("tr"),g,l,p),d(k,g)),o.length&&(o.hasClass("parser-false")||o.hasClass("sorter-false")&&o.hasClass("filter-false"))||"change"===e.type&&m.table.isUpdating)return;(m&&p!==h.data("ts-original-value")||i)&&(h.data("ts-original-value",p),k[0].tablesorterBusy=!0,a.tablesorter.updateCell(m,j,f,function(){b(e,k,h),k[0].tablesorterBusy=!1}))}}),a(this).children("thead").find('input[type="checkbox"]')&&a(this).off(e).on("tablesorter-ready"+e,function(){var b,c=a(this),e=c.length&&c[0].config;a.isEmptyObject(e)||(this.tablesorterBusy=!0,b=e&&e.checkboxClass||"checked",d(c,b),this.tablesorterBusy=!1)}).children("thead").off(e).on("change"+e,'input[type="checkbox"]',function(e){var f,g,h,i,j,k,l=a(this),m=l.closest("table"),n=m.length&&m[0].config,o=this.checked;return m.length&&n&&!m[0].tablesorterBusy?(h=parseInt(l.closest("td, th").attr("data-column"),10),j="checkbox"===n.parsers[h].id,g=m.length&&n.checkboxVisible,m[0].tablesorterBusy=!0,i=m.children("tbody").children("tr"+("undefined"==typeof g||g===!0?":visible":"")).children(":nth-child("+(h+1)+")").find('input[type="checkbox"]').prop("checked",o),k=n.checkboxClass||"checked",i.each(function(){c(a(this).closest("tr"),k,h,o)}),d(m,k),j?a.tablesorter.update(n,f,function(){b(e,m,i),m[0].tablesorterBusy=!1}):(b(e,m,i),m[0].tablesorterBusy=!1),!0):!1})})}})}(jQuery);

View File

@ -52,7 +52,7 @@
is : function() { is : function() {
return false; return false;
}, },
format : function( txt, table, cell, cellIndex ) { format : function( txt, table, cell ) {
var $cell = $( cell ), var $cell = $( cell ),
wo = table.config.widgetOptions, wo = table.config.widgetOptions,
// returning plain language here because this is what is shown in the // returning plain language here because this is what is shown in the
@ -221,7 +221,7 @@
$( this ) $( this )
.off( namespace ) .off( namespace )
.on( 'tablesorter-ready' + namespace, function() { .on( 'tablesorter-ready' + namespace, function() {
var checkboxClass, $rows, len, var checkboxClass,
$table = $( this ), $table = $( this ),
c = $table.length && $table[ 0 ].config; c = $table.length && $table[ 0 ].config;
if ( !$.isEmptyObject( c ) ) { if ( !$.isEmptyObject( c ) ) {
@ -236,7 +236,7 @@
.off( namespace ) .off( namespace )
// modified from http://jsfiddle.net/abkNM/6163/ // modified from http://jsfiddle.net/abkNM/6163/
.on( 'change' + namespace, 'input[type="checkbox"]', function( event ) { .on( 'change' + namespace, 'input[type="checkbox"]', function( event ) {
var undef, onlyVisible, column, $target, isParsed, $row, checkboxClass, var undef, onlyVisible, column, $target, isParsed, checkboxClass,
$checkbox = $( this ), $checkbox = $( this ),
$table = $checkbox.closest( 'table' ), $table = $checkbox.closest( 'table' ),
c = $table.length && $table[ 0 ].config, c = $table.length && $table[ 0 ].config,
@ -252,22 +252,21 @@
.children( ':nth-child(' + ( column + 1 ) + ')' ) .children( ':nth-child(' + ( column + 1 ) + ')' )
.find( 'input[type="checkbox"]' ) .find( 'input[type="checkbox"]' )
.prop( 'checked', isChecked ); .prop( 'checked', isChecked );
if ( !isParsed ) { // add checkbox class names to row
// add checkbox class names checkboxClass = c.checkboxClass || 'checked';
checkboxClass = c.checkboxClass || 'checked'; $target.each( function() {
$target.each(function(){ toggleRowClass( $( this ).closest( 'tr' ), checkboxClass, column, isChecked );
$row = $(this).closest('tr'); });
toggleRowClass( $(this).closest( 'tr' ), checkboxClass, column, isChecked ); updateHeaderCheckbox( $table, checkboxClass );
}); if ( isParsed ) {
updateHeaderCheckbox( $table, checkboxClass );
updateServer( event, $table, $target );
$table[ 0 ].tablesorterBusy = false;
} else {
// only update cache if checkboxes are being sorted // only update cache if checkboxes are being sorted
$.tablesorter.update( c, undef, function() { $.tablesorter.update( c, undef, function() {
updateServer( event, $table, $target ); updateServer( event, $table, $target );
$table[ 0 ].tablesorterBusy = false; $table[ 0 ].tablesorterBusy = false;
}); });
} else {
updateServer( event, $table, $target );
$table[ 0 ].tablesorterBusy = false;
} }
// needed for IE8 // needed for IE8
return true; return true;