tablesorter/dist/js/parsers/parser-input-select.min.js
Rob Garrison 90f7326819 2.30.7
2018-07-10 08:32:19 -05:00

2 lines
5.5 KiB
JavaScript

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