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

1 line
7.2 KiB
JavaScript
Raw Normal View History

!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(b,e,f){var g,h;return g=a(f.columnSelector_layout),g.find("input").add(g.filter("input")).length?(e.$table.addClass(e.namespace.slice(1)+"columnselector"),h=e.selector={$container:a(f.columnSelector_container||"<div>")},h.$style=a("<style></style>").prop("disabled",!0).appendTo("head"),h.$breakpoints=a("<style></style>").prop("disabled",!0).appendTo("head"),h.isInitializing=!0,d.setupSelector(e,f),f.columnSelector_mediaquery&&d.setupBreakpoints(e,f),h.isInitializing=!1,h.$container.length?d.updateCols(e,f):e.debug&&console.warn("ColumnSelector: >> container not found"),void e.$table.off("refreshColumnSelector"+c).on("refreshColumnSelector"+c,function(a,b,c){d.refreshColumns(this.config,b,c)})):void(e.debug&&console.error("ColumnSelector: >> ERROR: Column Selector aborting, no input found in the layout! ***"))},refreshColumns:function(b,c,e){var f,g,h=a.isArray(e||c),i=b.widgetOptions;if("undefined"!=typeof c&&b.selector.$container.length){if("selectors"===c&&(b.selector.$container.empty(),d.setupSelector(b,i),d.setupBreakpoints(b,i),"undefined"==typeof e&&(e=b.selector.auto)),h)for(g=e||c,a.each(g,function(a,b){g[a]=parseInt(b,10)}),f=0;f<b.columns;f++)b.selector.$container.find("input[data-column="+f+"]").prop("checked",a.inArray(f,g)>=0);d.updateAuto(b,i,b.selector.$container.find('input[data-column="auto"]').prop("checked",e===!0||c===!0||"auto"===c&&e!==!1))}else d.updateBreakpoints(b,i),d.updateCols(b,i)},setupSelector:function(c,e){var f,g=c.selector,h=g.$container,i=e.columnSelector_saveColumns&&b.storage,j=i?b.storage(c.table,"tablesorter-columnSelector"):[],k=i?b.storage(c.table,"tablesorter-columnSelector-auto"):{};g.auto=a.isEmptyObject(k)||"boolean"!==a.type(k.auto)?e.columnSelector_mediaqueryState:k.auto,g.states=[],g.$column=[],g.$wrapper=[],g.$checkbox=[],c.$table.children("thead").find("tr:first th",c.table).each(function(){var i=a(this),k=i.attr(e.columnSelector_priority)||1,l=i.attr("data-column"),m=b.getData(this,c.headers[l],"columnSelector");return isNaN(k)&&k.length>0||"disable"===m||e.columnSelector_columns[l]&&"disable"===e.columnSelector_columns[l]?!0:(g.states[l]=j&&"undefined"!=typeof j[l]?j[l]:"undefined"!=typeof e.columnSelector_columns[l]?e.columnSelector_columns[l]:"true"===m||"false"!==m,g.$column[l]=a(this),f=i.attr(e.columnSelector_name)||i.text(),void(h.length&&(g.$wrapper[l]=a(e.columnSelector_layout.replace(/\{name\}/g,f)).appendTo(h),g.$checkbox[l]=g.$wrapper[l].find("input").add(g.$wrapper[l].filter("input")).attr("data-column",l).toggleClass(e.columnSelector_cssChecked,g.states[l]).prop("checked",g.states[l]).on("change",function(){g.states[l]=this.checked,d.updateCols(c,e)}).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.stora