/*!
 * Column visibility buttons for Buttons and DataTables.
 * 2016 SpryMedia Ltd - datatables.net/license
 */
!function(n){"function"==typeof define&&define.amd?define(["jquery","datatables.net","datatables.net-buttons"],(function(t){return n(t,window,document)})):"object"==typeof exports?module.exports=function(t,e){return t||(t=window),e&&e.fn.dataTable||(e=require("datatables.net")(t,e).$),e.fn.dataTable.Buttons||require("datatables.net-buttons")(t,e),n(e,t,t.document)}:n(jQuery,window,document)}((function(n,t,e,o){"use strict";var i=n.fn.dataTable;return n.extend(i.ext.buttons,{colvis:function(n,t){return{extend:"collection",text:function(n){return n.i18n("buttons.colvis","Column visibility")},className:"buttons-colvis",buttons:[{extend:"columnsToggle",columns:t.columns,columnText:t.columnText}]}},columnsToggle:function(n,t){return n.columns(t.columns).indexes().map((function(n){return{extend:"columnToggle",columns:n,columnText:t.columnText}})).toArray()},columnToggle:function(n,t){return{extend:"columnVisibility",columns:t.columns,columnText:t.columnText}},columnsVisibility:function(n,t){return n.columns(t.columns).indexes().map((function(n){return{extend:"columnVisibility",columns:n,visibility:t.visibility,columnText:t.columnText}})).toArray()},columnVisibility:{columns:o,text:function(n,t,e){return e._columnText(n,e)},className:"buttons-columnVisibility",action:function(n,t,e,i){var l=t.columns(i.columns),c=l.visible();l.visible(i.visibility!==o?i.visibility:!(c.length&&c[0]))},init:function(n,t,e){var o=this;t.attr("data-cv-idx",e.columns),n.on("column-visibility.dt"+e.namespace,(function(t,i){i.bDestroying||i.nTable!=n.settings()[0].nTable||o.active(n.column(e.columns).visible())})).on("column-reorder.dt"+e.namespace,(function(t,i,l){1===n.columns(e.columns).count()&&(o.text(e._columnText(n,e)),o.active(n.column(e.columns).visible()))})),this.active(n.column(e.columns).visible())},destroy:function(n,t,e){n.off("column-visibility.dt"+e.namespace).off("column-reorder.dt"+e.namespace)},_columnText:function(n,t){var e=n.column(t.columns).index(),o=n.settings()[0].aoColumns[e].sTitle;return o||(o=n.column(e).header().innerHTML),o=o.replace(/\n/g," ").replace(/<br\s*\/?>/gi," ").replace(/<select(.*?)<\/select>/g,"").replace(/<!\-\-.*?\-\->/g,"").replace(/<.*?>/g,"").replace(/^\s+|\s+$/g,""),t.columnText?t.columnText(n,e,o):o}},colvisRestore:{className:"buttons-colvisRestore",text:function(n){return n.i18n("buttons.colvisRestore","Restore visibility")},init:function(n,t,e){e._visOriginal=n.columns().indexes().map((function(t){return n.column(t).visible()})).toArray()},action:function(n,t,e,o){t.columns().every((function(n){var e=t.colReorder&&t.colReorder.transpose?t.colReorder.transpose(n,"toOriginal"):n;this.visible(o._visOriginal[e])}))}},colvisGroup:{className:"buttons-colvisGroup",action:function(n,t,e,o){t.columns(o.show).visible(!0,!1),t.columns(o.hide).visible(!1,!1),t.columns.adjust()},show:[],hide:[]}}),i.Buttons}));
