mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
8a9e52827e
- Prevent javascript error. - Include thead checkbox code to update tbody column checkboxes. - Add thead checkbox updating with indeterminate state.
2 lines
3.9 KiB
JavaScript
2 lines
3.9 KiB
JavaScript
/*! Parser: input & select - updated 10/31/2015 (v2.24.0) */
|
|
!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=f.closest("tr"),h=c.config.widgetOptions,i=c.config.checkboxClass||"checked",j=h.group_checkbox?h.group_checkbox:["checked","unchecked"],k=f.find('input[type="checkbox"]'),l=k.length?k[0].checked:"";return g.toggleClass(i+"-"+e,l),l?g.addClass(i):g.length&&!(g[0].className||"").match(i+"-")&&g.removeClass(i),k.length?j[l?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(){a.fn.on&&a("table").on("tablesorter-initialized updateComplete",function(){this.tablesorterBusy=!1;var c=".parser-forms";a(this).children("tbody").off(c).on("mouseleave"+c,function(b){"TBODY"===b.target.nodeName&&a(":focus").blur()}).on("focus"+c,"select, input, textarea",function(){a(this).data("ts-original-value",this.value)}).on("blur"+c,"input, textarea",function(){this.value=a(this).data("ts-original-value")}).on("change keyup ".split(" ").join(c+" "),"select, input, textarea",function(c){if(27===c.which)return void(this.value=a(this).data("ts-original-value"));if("change"===c.type||"keyup"===c.type&&13===c.which&&("INPUT"===c.target.nodeName||"TEXTAREA"===c.target.nodeName&&c.altKey)){var d,e=a(c.target),f="checkbox"===c.target.type,g=e.closest("td"),h=g.closest("table"),i=g[0].cellIndex,j=h[0].config||!1,k=h.length&&h[0].tablesorterBusy,l=j&&j.$headerIndexed&&j.$headerIndexed[i]||[],m=f?c.target.checked:e.val();if(a.isEmptyObject(j)||k!==!1||l.length&&(l.hasClass("parser-false")||l.hasClass("sorter-false")&&l.hasClass("filter-false"))||"change"===c.type&&j.table.isUpdating)return;(j&&m!==e.data("ts-original-value")||f)&&(e.data("ts-original-value",m),h[0].tablesorterBusy=!0,a.tablesorter.updateCell(j,g,d,function(){b(c,h,e),h[0].tablesorterBusy=!1}))}}),a(this).children("thead").find('input[type="checkbox"]')&&a(this).off(c).on("tablesorter-ready"+c,function(){var b,c,d,e=a(this),f=e.length&&e[0].config;a.isEmptyObject(f)||(this.tablesorterBusy=!0,b=f&&f.checkboxClass||"checked",c=e.children("tbody").children(":visible"),d=c.length,a(this).children("thead").find('input[type="checkbox"]').each(function(){var e=a(this).closest("td, th").attr("data-column"),f=c.filter("."+b+"-"+e).length,g=f===d;0===f||g?(this.checked=g,this.indeterminate=!1):this.indeterminate=!0}),this.tablesorterBusy=!1)}).children("thead").off(c).on("change"+c,'input[type="checkbox"]',function(c){var d,e,f,g,h=a(this),i=h.closest("table"),j=i.length&&i[0].config,k=this.checked;return i.length&&j&&!i[0].tablesorterBusy&&(f=parseInt(h.closest("td, th").attr("data-column"),10),e=i.length&&j.checkboxVisible,i[0].tablesorterBusy=!0,g=i.children("tbody").children("tr"+("undefined"==typeof e||e===!0?":visible":"")).children(":nth-child("+(f+1)+")").find('input[type="checkbox"]').prop("checked",k),a.tablesorter.update(j,d,function(){b(c,i,g),i[0].tablesorterBusy=!1})),!1})})})}(jQuery); |