tablesorter/dist/js/widgets/widget-filter-formatter-select2.min.js
Mottie 263aa97e66 Build: add combined file with selected widgets & parsers. See #855
NOTE: the core js/jquery.tablesorter.js file is no longer UMD wrapped!; this is done by the build process now

Updated various parser & widget comments
2015-03-28 15:03:50 -05:00

2 lines
2.2 KiB
JavaScript

/*! Widget: filter, select2 formatter function - updated 3/26/2015 (v2.21.3) */
!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.closest("table")[0].config,j=i.widgetOptions,k=a('<input class="filter" type="hidden">').appendTo(c).bind("change"+i.namespace+"filter",function(){var a=this.value;a=a.replace(/[/()$^]/g,"").split("|"),c.find(".select2").select2("val",a),q()}),l=i.$headerIndexed[d],m=l.hasClass(j.filter_onlyAvail),n=[],o=h.match?"":"^",p=h.match?"":"$",q=function(){var b=!1,d=c.find(".select2").select2("val")||h.value||"";a.isArray(d)&&(b=!0,d=d.join("\x00")),d=d.replace(/[-[\]{}()*+?.,/\\^$|#\s]/g,"\\$&"),b&&(d=d.split("\x00")),k.val(a.isArray(d)&&d.length&&""!==d.join("")?"/("+o+(d||[]).join(p+"|"+o)+p+")/":"").trigger("search").end().find(".select2").select2("val",d),n.length&&n.find(".select2").select2("val",d)},r=function(){g=[],f=b.filter.getOptionSource(i.$table[0],d,m)||[],a.each(f,function(a,b){g.push({id:b,text:b})}),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||(r(),m&&i.$table.bind("filterEnd",function(){r(),c.add(n).find(".select2").select2(h)})),a('<input class="select2 select2-'+d+'" type="hidden" />').val(h.value).appendTo(c).select2(h).bind("change",function(){q()}),i.$table.bind("filterFomatterUpdate",function(){var a=i.$table.data("lastSearch")[d]||"";a=a.replace(/^\/\(\^?/,"").replace(/\$\|\^/g,"|").replace(/\$?\)\/$/g,"").split("|"),c.find(".select2").select2("val",a),q(),b.filter.formatterUpdated(c,d)}),i.$table.bind("stickyHeadersInit",function(){n=i.widgetOptions.$sticky.find(".tablesorter-filter-row").children().eq(d).empty(),a('<input class="select2 select2-'+d+'" type="hidden">').val(h.value).appendTo(n).select2(h).bind("change",function(){c.find(".select2").select2("val",n.find(".select2").select2("val")),q()}),h.cellText&&n.prepend("<label>"+h.cellText+"</label>")}),i.$table.bind("filterReset",function(){c.find(".select2").select2("val",h.value||""),setTimeout(function(){q()},0)}),q(),k}}(jQuery);