tablesorter/dist/js/widgets/widget-filter-formatter-select2.min.js

2 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-07-11 12:42:19 +00:00
/*! Widget: filter, select2 formatter function - updated 7/11/2016 (v2.26.6) */
!function(a){"use strict";var b=a.tablesorter||{};b.filterFormatter=b.filterFormatter||{},b.filterFormatter.select2=function(c,d,e){var f,g,h=a.extend({cellText:"",match:!0,value:"",multiple:!0,width:"100%"},e),i=c.addClass("select2col"+d).closest("table")[0].config,j=i.widgetOptions,k=a('<input class="filter" type="hidden">').appendTo(c).bind("change"+i.namespace+"filter",function(){var a=q(this.value);i.$table.find(".select2col"+d+" .select2").select2("val",a),r()}),l=i.$headerIndexed[d],m=l.hasClass(j.filter_onlyAvail),n=h.match?"":"^",o=h.match?"":"$",p=j.filter_ignoreCase?"i":"",q=function(a){return a.replace(/^\/\(\^?/,"").replace(/\$\|\^/g,"|").replace(/\$?\)\/i?$/g,"").replace(/\\/g,"").split("|")},r=function(){var b=!1,c=i.$table.find(".select2col"+d+" .select2").select2("val")||h.value||"";a.isArray(c)&&(b=!0,c=c.join("\x00")),c=c.replace(/[-[\]{}()*+?.,\/\\^$|#\s]/g,"\\$&"),b&&(c=c.split("\x00")),k.val(a.isArray(c)&&c.length&&""!==c.join("")?"/("+n+(c||[]).join(o+"|"+n)+o+")/"+p:"").trigger("search").end().find(".select2").select2("val",c),i.widgetOptions.$sticky&&i.widgetOptions.$sticky.find(".select2col"+d+" .select2").select2("val",c)},s=function(){g=[],f=b.filter.getOptionSource(i.$table[0],d,m)||[],a.each(f,function(a,b){g.push({id:""+b.parsed,text:b.text})}),h.data=g};return l.toggleClass("filter-match",h.match),h.cellText&&c.prepend("<label>"+h.cellText+"</label>"),h.ajax&&!a.isEmptyObject(h.ajax)||h.data||(s(),i.$table.bind("filterEnd",function(){s(),i.$table.find(".select2col"+d).add(i.widgetOptions.$sticky&&i.widgetOptions.$sticky.find(".select2col"+d)).find(".select2").select2(h)})),a('<input class="select2 select2-'+d+'" type="hidden" />').val(h.value).appendTo(c).select2(h).bind("change",function(){r()}),i.$table.bind("filterFomatterUpdate",function(){var a=q(i.$table.data("lastSearch")[d]||"");c=i.$table.find(".select2col"+d),c.find(".select2").select2("val",a),r(),b.filter.formatterUpdated(c,d)}),i.$table.bind("stickyHeadersInit",function(){var b=i.widgetOptions.$sticky.find(".select2col"+d).empty();a('<input class="select2 select2-'+d+'" type="hidden">').val(h.value).appendTo(b).select2(h).bind("change",function(){i.$table.find(".select2col"+d).find(".select2").select2("val",i.widgetOptions.$sticky.find(".select2col"+d+" .select2").select2("val")),r()}),h.cellText&&b.prepend("<label>"+h.cellText+"</label>")}),i.$table.bind("filterReset",function(){i.$table.find(".select2col"+d).find(".select2").select2("val",h.value||""),setTimeout(function(){r()},0)}),r(),k}}(jQuery);