tablesorter/dist/js/parsers/parser-input-select.min.js

5 lines
2.2 KiB
JavaScript

/*! input & select parsers for jQuery 1.7+ & tablesorter 2.7.11+
* Updated 3/5/2015 (v2.21.0)
* Demo: http://mottie.github.com/tablesorter/docs/example-widget-grouping.html
*/
!function(a){"use strict";var b=function(){};a.tablesorter.addParser({id:"inputs",is:function(){return!1},format:function(b,c,d){return a(d).find("input").val()||b},parsed:!0,type:"text"}),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 f.closest("tr").toggleClass("checked-"+e,j),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){return a(d).find("select").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){return a(d).find("textarea").val()||b},parsed:!0,type:"text"}),a(function(){a("table").on("tablesorter-initialized",function(){var c=function(b){b&&a(":focus").blur()};a(this).children("tbody").on("mouseleave",function(a){c("TBODY"===a.target.nodeName)}).on("focus","select, input, textarea",function(){a(this).data("ts-original-value",this.value)}).on("blur","input, textarea",function(){this.value=a(this).data("ts-original-value")}).on("change keyup","select, input, textarea",function(d){if(27===d.which)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=f.closest("td"),h=g.closest("table"),i=g[0].cellIndex,j=h[0].config||!1,k=j&&j.$headers&&j.$headers.eq(i);if(!j||k&&k.length&&(k.hasClass("parser-false")||k.hasClass("sorter-false")&&k.hasClass("filter-false")))return c();(f.val()!==f.data("ts-original-value")||"checkbox"===d.target.type)&&(f.data("ts-original-value",f.val()),h.trigger("updateCell",[f.closest("td"),e,function(){b(d,h,f)}]))}})})})}(jQuery);