tablesorter/dist/js/widgets/widget-columnSelector.min.js

1 line
6.8 KiB
JavaScript
Raw Normal View History

2015-05-30 20:07:37 +00:00
!function(a){"use strict";var b=a.tablesorter,c=".tscolsel",d=b.columnSelector={queryAll:"@media only all { [columns] { display: none; } } ",queryBreak:"@media all and (min-width: [size]) { [columns] { display: table-cell; } } ",init:function(e,f,g){var h,i;return h=a(g.columnSelector_layout),h.find("input").add(h.filter("input")).length?(f.$table.addClass(f.namespace.slice(1)+"columnselector"),i=f.selector={$container:a(g.columnSelector_container||"<div>")},i.$style=a("<style></style>").prop("disabled",!0).appendTo("head"),i.$breakpoints=a("<style></style>").prop("disabled",!0).appendTo("head"),i.isInitializing=!0,d.setupSelector(e,f,g),g.columnSelector_mediaquery&&d.setupBreakpoints(f,g),i.isInitializing=!1,i.$container.length?d.updateCols(f,g):f.debug&&b.log("ColumnSelector: >> container not found"),void f.$table.off("refreshColumnSelector"+c).on("refreshColumnSelector"+c,function(b,c){var e,f=a.isArray(c),g=this.config,h=g.widgetOptions;if(c&&g.selector.$container.length){if(f)for(a.each(c,function(a,b){c[a]=parseInt(b,10)}),e=0;e<g.columns;e++)g.selector.$container.find("input[data-column="+e+"]").prop("checked",a.inArray(e,c)>=0);d.updateAuto(g,h,i.$container.find('input[data-column="auto"]').prop("checked",!f))}else d.updateBreakpoints(g,h),d.updateCols(g,h)})):void(f.debug&&b.log("ColumnSelector: >> ERROR: Column Selector aborting, no input found in the layout! ***"))},setupSelector:function(c,e,f){var g,h=e.selector,i=h.$container,j=f.columnSelector_saveColumns&&b.storage,k=j?b.storage(c,"tablesorter-columnSelector"):[],l=j?b.storage(c,"tablesorter-columnSelector-auto"):{};h.auto=a.isEmptyObject(l)||"boolean"!==a.type(l.auto)?f.columnSelector_mediaqueryState:l.auto,h.states=[],h.$column=[],h.$wrapper=[],h.$checkbox=[],e.$table.children("thead").find("tr:first th",c).each(function(){var c=a(this),j=c.attr(f.columnSelector_priority)||1,l=c.attr("data-column"),m=b.getData(this,e.headers[l],"columnSelector");return isNaN(j)&&j.length>0||"disable"===m||f.columnSelector_columns[l]&&"disable"===f.columnSelector_columns[l]?!0:(h.states[l]=k&&"undefined"!=typeof k[l]?k[l]:"undefined"!=typeof f.columnSelector_columns[l]?f.columnSelector_columns[l]:"true"===m||"false"!==m,h.$column[l]=a(this),g=c.attr(f.columnSelector_name)||c.text(),void(i.length&&(h.$wrapper[l]=a(f.columnSelector_layout.replace(/\{name\}/g,g)).appendTo(i),h.$checkbox[l]=h.$wrapper[l].find("input").add(h.$wrapper[l].filter("input")).attr("data-column",l).toggleClass(f.columnSelector_cssChecked,h.states[l]).prop("checked",h.states[l]).on("change",function(){h.states[l]=this.checked,d.updateCols(e,f)}).change())))})},setupBreakpoints:function(b,e){var f=b.selector;e.columnSelector_mediaquery&&(f.lastIndex=-1,d.updateBreakpoints(b,e),b.$table.off("updateAll"+c).on("updateAll"+c,function(){d.updateBreakpoints(b,e),d.updateCols(b,e)})),f.$container.length&&(e.columnSelector_mediaquery&&(f.$auto=a(e.columnSelector_layout.replace(/\{name\}/g,e.columnSelector_mediaqueryName)).prependTo(f.$container),f.$auto.find("input").add(f.$auto.filter("input")).attr("data-column","auto").prop("checked",f.auto).toggleClass(e.columnSelector_cssChecked,f.auto).on("change",function(){d.updateAuto(b,e,a(this))}).change()),b.$table.off("update"+c).on("update"+c,function(){d.updateCols(b,e)}))},updateAuto:function(c,e,f){var g=c.selector;g.auto=f.prop("checked")||!1,a.each(g.$checkbox,function(a,b){b&&(b[0].disabled=g.auto,g.$wrapper[a].toggleClass("disabled",g.auto))}),e.columnSelector_mediaquery&&d.updateBreakpoints(c,e),d.updateCols(c,e),c.selector.$popup&&c.selector.$popup.find(".tablesorter-column-selector").html(g.$container.html()).find("input").each(function(){var b=a(this).attr("data-column");a(this).prop("checked","auto"===b?g.auto:g.states[b])}),e.columnSelector_saveColumns&&b.storage&&b.storage(c.$table[0],"tablesorter-columnSelector-auto",{auto:g.auto}),g.auto&&c.$table.trigger("columnUpdate")},updateBreakpoints:function(b,c){var e,f,g,h,i=b.selector,j=b.namespace+"columnselector",k=[],l="";if(c.columnSelector_mediaquery&&!i.auto)return i.$breakpoints.prop("disabled",