tablesorter/dist/js/parsers/parser-input-select.min.js
Rob Garrison f006d8aa5f v2.28.6
2017-04-02 06:34:02 -05:00

2 lines
4.3 KiB
JavaScript

/*! Parser: input & select - updated 11/26/2016 (v2.28.0) */
!function(a){"use strict";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.tablesorter.defaults.checkboxClass="",a.tablesorter.defaults.checkboxVisible="",a(function(){if(a.fn.on){var b=function(a,b,c,d){a.toggleClass(b+"-"+c,d),(a[0].className||"").match(b+"-")?a.addClass(b):a.removeClass(b)},c=function(b,c){var d=window.navigator.userAgent,e=b.children("tbody").children(":visible"),f=e.length;b.children("thead").find('input[type="checkbox"]').each(function(){var b=a(this).closest("td, th").attr("data-column"),g=e.filter("."+c+"-"+b).length,h=g===f&&f>0;0===g||h?(this.checked=h,this.indeterminate=!1):(this.checked=!(d.indexOf("Trident/")>-1||d.indexOf("Edge/")>-1),this.indeterminate=!0)})};a("table").on("tablesorter-initialized updateComplete",function(){this.tablesorterBusy=!1;var d=".parser-forms";a(this).children("tbody").off(d).on("mouseleave"+d,function(b){"TBODY"===b.target.nodeName&&a(":focus").blur()}).on("focus"+d,"select, input:not([type=checkbox]), textarea",function(){a(this).data("ts-original-value",this.value)}).on("blur"+d,"input:not([type=checkbox]), textarea",function(){this.value=a(this).data("ts-original-value")}).on("change keyup ".split(" ").join(d+" "),"select, input, textarea",function(d){if(27===d.which&&("INPUT"!==this.nodeName||"checkbox"!==this.type))return void(this.value=a(this).data("ts-original-value"));if("change"===d.type||"keyup"===d.type&&13===d.which&&("INPUT"===d.target.nodeName||"TEXTAREA"===d.target.nodeName&&d.altKey)){var e,f=a(d.target),g="checkbox"===d.target.type,h=f.closest("td"),i=h.closest("table"),j=h[0].cellIndex,k=i[0].config||!1,l=i.length&&i[0].tablesorterBusy,m=k&&k.$headerIndexed&&k.$headerIndexed[j]||[],n=g?d.target.checked:f.val();if(a.isEmptyObject(k)||l!==!1)return;if(g&&(e=k.checkboxClass||"checked",b(h.closest("tr"),e,j,n),c(i,e)),m.length&&(m.hasClass("parser-false")||m.hasClass("sorter-false")&&m.hasClass("filter-false"))||"change"===d.type&&k.table.isUpdating)return;(k&&n!==f.data("ts-original-value")||g)&&(f.data("ts-original-value",n),i[0].tablesorterBusy=!0,a.tablesorter.updateCell(k,h,void 0,function(){i[0].tablesorterBusy=!1}))}}),a(this).children("thead").find('input[type="checkbox"]')&&a(this).off(d).on("tablesorter-ready"+d,function(){var b,d=a(this),e=d.length&&d[0].config;a.isEmptyObject(e)||(this.tablesorterBusy=!0,b=e&&e.checkboxClass||"checked",c(d,b),this.tablesorterBusy=!1)}).children("thead").off(d).on("click.parser-forms change"+d,'input[type="checkbox"]',function(d){var e,f,g,h,i,j=a(this),k=j.closest("table"),l=k.length&&k[0].config,m=this.checked;return!(!k.length||!l||k[0].tablesorterBusy)&&(f=parseInt(j.closest("td, th").attr("data-column"),10),h="checkbox"===l.parsers[f].id,e=k.length&&l.checkboxVisible,k[0].tablesorterBusy=!0,g=k.children("tbody").children("tr"+(void 0===e||e===!0?":visible":"")).children(":nth-child("+(f+1)+")").find('input[type="checkbox"]').prop("checked",m),i=l.checkboxClass||"checked",g.each(function(){b(a(this).closest("tr"),i,f,m)}),c(k,i),h?a.tablesorter.update(l,void 0,function(){k[0].tablesorterBusy=!1}):k[0].tablesorterBusy=!1,!0)})})}})}(jQuery);