/* * File: ColVis.js * Version: 1.1.0-dev * CVS: $Id$ * Description: Controls for column visiblity in DataTables * Author: Allan Jardine (www.sprymedia.co.uk) * Created: Wed Sep 15 18:23:29 BST 2010 * Modified: $Date$ by $Author$ * Language: Javascript * License: GPL v2 or BSD 3 point style * Project: Just a little bit of fun :-) * Contact: www.sprymedia.co.uk/contact * * Copyright 2010-2011 Allan Jardine, all rights reserved. * * This source file is free software, under either the GPL v2 license or a * BSD style license, available at: * http://datatables.net/license_gpl2 * http://datatables.net/license_bsd */(function(e){var t=function(e,n){(!this.CLASS||this.CLASS!="ColVis")&&alert("Warning: ColVis must be initialised with the keyword 'new'");typeof n=="undefined"&&(n={});this.s={dt:null,oInit:n,fnStateChange:null,activate:"click",sAlign:"left",buttonText:"Show / hide columns",hidden:!0,aiExclude:[],aoGroups:[],abOriginal:[],bShowAll:!1,sShowAll:"Show All",bRestore:!1,sRestore:"Restore original",iOverlayFade:500,fnLabel:null,sSize:"auto",bCssPosition:!1};this.dom={wrapper:null,button:null,collection:null,background:null,catcher:null,buttons:[],groupButtons:[],restore:null};t.aInstances.push(this);this.s.dt=e;this._fnConstruct();return this};t.prototype={fnRebuild:function(){for(var e=this.dom.buttons.length-1;e>=0;e--)this.dom.buttons[e]!==null&&this.dom.collection.removeChild(this.dom.buttons[e]);this.dom.buttons.splice(0,this.dom.buttons.length);this.dom.restore&&this.dom.restore.parentNode(this.dom.restore);this._fnAddGroups();this._fnAddButtons();this._fnDrawCallback()},_fnConstruct:function(){this._fnApplyCustomisation();var t=this,n,r;this.dom.wrapper=document.createElement("div");this.dom.wrapper.className="ColVis TableTools";this.dom.button=this._fnDomBaseButton(this.s.buttonText);this.dom.button.className+=" ColVis_MasterButton";this.dom.wrapper.appendChild(this.dom.button);this.dom.catcher=this._fnDomCatcher();this.dom.collection=this._fnDomCollection();this.dom.background=this._fnDomBackground();this._fnAddGroups();this._fnAddButtons();for(n=0,r=this.s.dt.aoColumns.length;n'+this.s.sRestore+"");e(n).click(function(e){for(var n=0,r=t.s.abOriginal.length;n'+this.s.sShowAll+"");e(n).click(function(e){for(var n=0,r=t.s.abOriginal.length;n'+a+"");e(s).click(function(t){var i=!e("input",this).is(":checked");t.target.nodeName.toLowerCase()=="input"&&(i=e("input",this).is(":checked"));for(var s=0;s'+u+"");e(i).click(function(r){var i=!e("input",this).is(":checked");r.target.nodeName.toLowerCase()=="input"&&(i=e("input",this).is(":checked"));var s=e.fn.dataTableExt.iApiIndex;e.fn.dataTableExt.iApiIndex=n._fnDataTablesApiIndex.call(n);if(!o.oFeatures.bServerSide||o.oScroll.sX===""&&o.oScroll.sY==="")n.s.dt.oInstance.fnSetColumnVis(t,i);else{n.s.dt.oInstance.fnSetColumnVis(t,i,!1);n.s.dt.oInstance.fnAdjustColumnSizing(!1);n.s.dt.oInstance.oApi._fnScrollDraw(n.s.dt);n._fnDrawCallback()}e.fn.dataTableExt.iApiIndex=s;n.s.fnStateChange!==null&&n.s.fnStateChange.call(n,t,i)});return i},_fnDataTablesApiIndex:function(){for(var e=0,t=this.s.dt.oInstance.length;e").addClass("ColVis_collectionBackground TableTools_collectionBackground").css("opacity",0).click(function(){t._fnCollectionHide.call(t,null,null)});this.s.activate=="mouseover"&&n.mouseover(function(){t.s.overcollection=!1;t._fnCollectionHide.call(t,null,null)});return n[0]},_fnCollectionShow:function(){var t=this,n,r,i,s=e(this.dom.button).offset(),o=this.dom.collection,u=this.dom.background,a=parseInt(s.left,10),f=parseInt(s.top+e(this.dom.button).outerHeight(),10);if(!this.s.bCssPosition){o.style.top=f+"px";o.style.left=a+"px"}e(o).css({display:"block",opacity:0});u.style.bottom="0px";u.style.right="0px";var l=this.dom.catcher.style;l.height=e(this.dom.button).outerHeight()+"px";l.width=e(this.dom.button).outerWidth()+"px";l.top=s.top+"px";l.left=a+"px";document.body.appendChild(u);document.body.appendChild(o);document.body.appendChild(this.dom.catcher);if(this.s.sSize=="auto"){var c=[];this.dom.collection.style.width="auto";for(n=0,r=this.dom.buttons.length;nv&&(o.style.left=v-p+"px")}this.s.hidden=!1},_fnCollectionHide:function(){var t=this;if(!this.s.hidden&&this.dom.collection!==null){this.s.hidden=!0;e(this.dom.collection).animate({opacity:0},t.s.iOverlayFade,function(e){this.style.display="none"});e(this.dom.background).animate({opacity:0},t.s.iOverlayFade,function(e){document.body.removeChild(t.dom.background);document.body.removeChild(t.dom.catcher)})}},_fnAdjustOpenRows:function(){var e=this.s.dt.aoOpenRows,t=this.s.dt.oApi._fnVisbleColumns(this.s.dt);for(var n=0,r=e.length;n