tablesorter/dist/js/widgets/widget-columnSelector.min.js
Mottie c17aa829e6 Debug: update debug logging
pager, columnSelector & filter
2015-02-27 17:37:14 -06:00

1 line
6.7 KiB
JavaScript

!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.tableId="tablesorter"+(new Date).getTime(),f.$table.addClass(f.tableId),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=b.selector,i="."+b.tableId,j=[],k="";if(c.columnSelector_mediaquery&&!h.auto)return h.$breakpoints.prop("disabled",!0),void h.$style.prop("disabled",!1);for(e=0;6>e;e++)g=[],b.$headers.filter("["+c.columnSelector_priority+"="+(e+1)+"]").each(function(){f=parseInt(a(this).attr("data-column"),10)+1,g.push(i+" col:nth-child("+f+")"),g.push(i+" tr th:nth-child("+f+")"),g.push(i+" tr td:nth-child("+f+")")}),g.length&&(j=j.concat(g),k+=d.queryBreak.replace(/\[size\]/g,c.columnSelector_breakpoints[e]).replace(/\[columns\]/g,g.join(",")));h.$style&&h.$style.prop("disabled",!0),j.length&&h.$breakpoints.prop("disabled",!1).html(d.queryAll.replace(/\[columns\]/g,j.join(","))+k)},updateCols:function(c,d){if(!(d.columnSelector_mediaquery&&c.selector.auto||c.selector.isInitializing)){var e,f=c.selector,g=[],h="."+c.tableId;f.$container.find("input[data-column]").filter('[data-column!="auto"]').each(function(){this.checked||(e=parseInt(a(this).attr("data-column"),10)+1,g.push(h+" col:nth-child("+e+")"),g.push(h+" tr th:nth-child("+e+")"),g.push(h+" tr td:nth-child("+e+")")),a(this).toggleClass(d.columnSelector_cssChecked,this.checked)}),d.columnSelector_mediaquery&&f.$breakpoints.prop("disabled",!0),f.$style&&f.$style.prop("disabled",!1).html(g.length?g.join(",")+" { display: none; }":""),d.columnSelector_saveColumns&&b.storage&&b.storage(c.$table[0],"tablesorter-columnSelector",f.states),c.$table.trigger("columnUpdate")}},attachTo:function(b,c){b=a(b)[0];var d,e,f,g=b.config,h=a(c);h.length&&g&&(h.find(".tablesorter-column-selector").length||h.append('<span class="tablesorter-column-selector"></span>'),d=g.selector,e=g.widgetOptions,h.find(".tablesorter-column-selector").html(d.$container.html()).find("input").each(function(){var b=a(this).attr("data-column"),c="auto"===b?d.auto:d.states[b];a(this).toggleClass(e.columnSelector_cssChecked,c).prop("checked",c)}),d.$popup=h.on("change","input",function(){f=a(this).toggleClass(e.columnSelector_cssChecked,this.checked).attr("data-column"),d.$container.find('input[data-column="'+f+'"]').prop("checked",this.checked).trigger("change")}))}};b.addWidget({id:"columnSelector",priority:10,options:{columnSelector_container:null,columnSelector_columns:{},columnSelector_saveColumns:!0,columnSelector_layout:'<label><input type="checkbox">{name}</label>',columnSelector_name:"data-selector-name",columnSelector_mediaquery:!0,columnSelector_mediaqueryName:"Auto: ",columnSelector_mediaqueryState:!0,columnSelector_breakpoints:["20em","30em","40em","50em","60em","70em"],columnSelector_priority:"data-priority",columnSelector_cssChecked:"checked"},init:function(a,b,c,e){d.init(a,c,e)},remove:function(a,b,d,e){if(!e){var f=b.selector;f.$container.empty(),f.$popup&&f.$popup.empty(),f.$style.remove(),f.$breakpoints.remove(),b.$table.off("updateAll"+c+" update"+c)}}})}(jQuery);