Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

/*
 * File:        FixedColumns.min.js
 * Version:     2.0.1
 * Author:      Allan Jardine (www.sprymedia.co.uk)
 * 
 * Copyright 2010-2010 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
 * 
 * This source file is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
 */
/*
     GPL v2 or BSD 3 point style
*/
var FixedColumns;
(function(c,q){FixedColumns=function(a,d){if(!this instanceof FixedColumns)alert("FixedColumns warning: FixedColumns must be initialised with the 'new' keyword.");else{if(typeof d=="undefined")d={};this.s={dt:a.fnSettings(),iTableColumns:a.fnSettings().aoColumns.length,aiWidths:[],bOldIE:c.browser.msie&&(c.browser.version=="6.0"||c.browser.version=="7.0")};this.dom={scroller:null,header:null,body:null,footer:null,grid:{wrapper:null,dt:null,left:{wrapper:null,head:null,body:null,foot:null},right:{wrapper:null,
head:null,body:null,foot:null}},clone:{left:{header:null,body:null,footer:null},right:{header:null,body:null,footer:null}}};this.s.dt.oFixedColumns=this;this._fnConstruct(d)}};FixedColumns.prototype={fnUpdate:function(){this._fnDraw(true)},fnRedrawLayout:function(){this.__fnGridLayout()},fnRecalculateHeight:function(a){a._DTTC_iHeight=null;a.style.height="auto"},fnSetRowHeight:function(a,d){var b=c(a).children(":first");b=b.outerHeight()-b.height();if(c.browser.mozilla||c.browser.opera)a.style.height=
d+"px";else c(a).children().height(d-b)},_fnConstruct:function(a){var d,b=this;if(typeof this.s.dt.oInstance.fnVersionCheck!="function"||this.s.dt.oInstance.fnVersionCheck("1.8.0")!==true)alert("FixedColumns "+FixedColumns.VERSION+" required DataTables 1.8.0 or later. Please upgrade your DataTables installation");else if(this.s.dt.oScroll.sX==="")this.s.dt.oInstance.oApi._fnLog(this.s.dt,1,"FixedColumns is not needed (no x-scrolling in DataTables enabled), so no action will be taken. Use 'FixedHeader' for column fixing when scrolling is not enabled");
else{this.s=c.extend(true,this.s,FixedColumns.defaults,a);this.dom.grid.dt=c(this.s.dt.nTable).parents("div.dataTables_scroll")[0];this.dom.scroller=c("div.dataTables_scrollBody",this.dom.grid.dt)[0];a=c(this.dom.grid.dt).width();var f=0,g=0;c("tbody>tr:eq(0)>td",this.s.dt.nTable).each(function(j){d=c(this).outerWidth();b.s.aiWidths.push(d);if(j<b.s.iLeftColumns)f+=d;if(b.s.iTableColumns-b.s.iRightColumns<=j)g+=d});if(this.s.iLeftWidth===null)this.s.iLeftWidth=this.s.sLeftWidth=="fixed"?f:f/a*100;
if(this.s.iRightWidth===null)this.s.iRightWidth=this.s.sRightWidth=="fixed"?g:g/a*100;this._fnGridSetup();for(a=0;a<this.s.iLeftColumns;a++)this.s.dt.oInstance.fnSetColumnVis(a,false);for(a=this.s.iTableColumns-this.s.iRightColumns;a<this.s.iTableColumns;a++)this.s.dt.oInstance.fnSetColumnVis(a,false);c(this.dom.scroller).scroll(function(){b.dom.grid.left.body.scrollTop=b.dom.scroller.scrollTop;if(b.s.iRightColumns>0)b.dom.grid.right.body.scrollTop=b.dom.scroller.scrollTop});c(q).resize(function(){b._fnGridLayout.call(b)});
var e=true;this.s.dt.aoDrawCallback=[{fn:function(){b._fnDraw.call(b,e);b._fnGridHeight(b);e=false},sName:"FixedColumns"}].concat(this.s.dt.aoDrawCallback);this._fnGridLayout();this._fnGridHeight();this.s.dt.oInstance.fnDraw(false)}},_fnGridSetup:function(){this.dom.body=this.s.dt.nTable;this.dom.header=this.s.dt.nTHead.parentNode;this.dom.header.parentNode.parentNode.style.position="relative";var a=c('<div class="DTFC_ScrollWrapper" style="position:relative; clear:both;"><div class="DTFC_LeftWrapper" style="position:absolute; top:0; left:0;"><div class="DTFC_LeftHeadWrapper" style="position:relative; top:0; left:0; overflow:hidden;"></div><div class="DTFC_LeftBodyWrapper" style="position:relative; top:0; left:0; overflow:hidden;"></div><div class="DTFC_LeftFootWrapper" style="position:relative; top:0; left:0; overflow:hidden;"></div></div><div class="DTFC_RightWrapper" style="position:absolute; top:0; left:0;"><div class="DTFC_RightHeadWrapper" style="position:relative; top:0; left:0; overflow:hidden;"></div><div class="DTFC_RightBodyWrapper" style="position:relative; top:0; left:0; overflow:hidden;"></div><div class="DTFC_RightFootWrapper" style="position:relative; top:0; left:0; overflow:hidden;"></div></div></div>')[0];
nLeft=a.childNodes[0];nRight=a.childNodes[1];this.dom.grid.wrapper=a;this.dom.grid.left.wrapper=nLeft;this.dom.grid.left.head=nLeft.childNodes[0];this.dom.grid.left.body=nLeft.childNodes[1];if(this.s.iRightColumns>0){this.dom.grid.right.wrapper=nRight;this.dom.grid.right.head=nRight.childNodes[0];this.dom.grid.right.body=nRight.childNodes[1]}if(this.s.dt.nTFoot){this.dom.footer=this.s.dt.nTFoot.parentNode;this.dom.grid.left.foot=nLeft.childNodes[2];if(this.s.iRightColumns>0)this.dom.grid.right.foot=
nRight.childNodes[2]}a.appendChild(nLeft);this.dom.grid.dt.parentNode.insertBefore(a,this.dom.grid.dt);a.appendChild(this.dom.grid.dt);this.dom.grid.dt.style.position="absolute";this.dom.grid.dt.style.top="0px";this.dom.grid.dt.style.left=this.s.iLeftWidth+"px";this.dom.grid.dt.style.width=c(this.dom.grid.dt).width()-this.s.iLeftWidth-this.s.iRightWidth+"px"},_fnGridLayout:function(){var a=this.dom.grid,d=c(a.wrapper).width(),b=0,f=0,g=0;b=this.s.sLeftWidth=="fixed"?this.s.iLeftWidth:this.s.iLeftWidth/
100*d;f=this.s.sRightWidth=="fixed"?this.s.iRightWidth:this.s.iRightWidth/100*d;g=d-b-f;a.left.wrapper.style.width=b+"px";a.dt.style.width=g+"px";a.dt.style.left=b+"px";if(this.s.iRightColumns>0){a.right.wrapper.style.width=f+"px";a.right.wrapper.style.left=d-f+"px"}},_fnGridHeight:function(){var a=this.dom.grid,d=c(this.dom.grid.dt).height();a.wrapper.style.height=d+"px";a.left.body.style.height=c(this.dom.scroller).height()+"px";a.left.wrapper.style.height=d+"px";if(this.s.iRightColumns>0){a.right.wrapper.style.height=
d+"px";a.right.body.style.height=c(this.dom.scroller).height()+"px"}},_fnDraw:function(a){this._fnCloneLeft(a);this._fnCloneRight(a);this.s.fnDrawCallback!==null&&this.s.fnDrawCallback.call(this,this.dom.clone.left,this.dom.clone.right);c(this).trigger("draw",{leftClone:this.dom.clone.left,rightClone:this.dom.clone.right})},_fnCloneRight:function(a){if(!(this.s.iRightColumns<=0)){var d,b=[];for(d=this.s.iTableColumns-this.s.iRightColumns;d<this.s.iTableColumns;d++)b.push(d);this._fnClone(this.dom.clone.right,
this.dom.grid.right,b,a)}},_fnCloneLeft:function(a){if(!(this.s.iLeftColumns<=0)){var d,b=[];for(d=0;d<this.s.iLeftColumns;d++)b.push(d);this._fnClone(this.dom.clone.left,this.dom.grid.left,b,a)}},_fnCopyLayout:function(a,d){for(var b=[],f=[],g=[],e=0,j=a.length;e<j;e++){var m=[];m.nTr=c(a[e].nTr).clone(true)[0];for(var i=0,h=this.s.iTableColumns;i<h;i++)if(c.inArray(i,d)!==-1){var k=c.inArray(a[e][i].cell,g);if(k===-1){k=c(a[e][i].cell).clone(true)[0];f.push(k);g.push(a[e][i].cell);m.push({cell:k,
unique:a[e][i].unique})}else m.push({cell:f[k],unique:a[e][i].unique})}b.push(m)}return b},_fnClone:function(a,d,b,f){var g=this,e,j,m,i,h;if(f){a.header!==null&&a.header.parentNode.removeChild(a.header);a.header=c(this.dom.header).clone(true)[0];a.header.className+=" DTFC_Cloned";a.header.style.width="100%";d.head.appendChild(a.header);var k=this._fnCopyLayout(this.s.dt.aoHeader,b),p=c(">thead",a.header);p.empty();e=0;for(j=k.length;e<j;e++)p[0].appendChild(k[e].nTr);this.s.dt.oApi._fnDrawHead(this.s.dt,
k,true)}else for(h=0;h<b.length;h++){c(">thead th:eq("+h+")",a.header)[0].className=this.s.dt.aoColumns[b[h]].nTh.className;c(">thead th:eq("+h+") span.DataTables_sort_icon",a.header).each(function(l){this.className=c("span.DataTables_sort_icon",g.s.dt.aoColumns[b[h]].nTh)[l].className})}this._fnEqualiseHeights("thead",this.dom.header,a.header);this.s.sHeightMatch=="auto"&&c(">tbody>tr",g.dom.body).css("height","auto");if(a.body!==null){a.body.parentNode.removeChild(a.body);a.body=null}a.body=c(this.dom.body).clone(true)[0];
a.body.className+=" DTFC_Cloned";a.body.style.paddingBottom=this.s.dt.oScroll.iBarWidth+"px";a.body.style.marginBottom=this.s.dt.oScroll.iBarWidth*2+"px";a.body.getAttribute("id")!==null&&a.body.removeAttribute("id");c(">thead>tr",a.body).empty();c(">tfoot",a.body).empty();var o=c("tbody",a.body)[0];c(o).empty();this.s.dt.aiDisplay.length>0?c(">tbody>tr",g.dom.body).each(function(l){var n=this.cloneNode(false);l=g.s.dt.oFeatures.bServerSide===false?g.s.dt.aiDisplay[g.s.dt._iDisplayStart+l]:l;for(h=
0;h<b.length;h++){m=b[h];if(typeof g.s.dt.aoData[l]._anHidden[m]!="undefined"){i=c(g.s.dt.aoData[l]._anHidden[m]).clone(true)[0];i.style.width=g.s.aiWidths[m]+"px";n.appendChild(i)}}o.appendChild(n)}):c(">tbody>tr",g.dom.body).each(function(){i=this.cloneNode(true);i.className+=" DTFC_NoData";c("td",i).html("");o.appendChild(i)});a.body.style.width="100%";d.body.appendChild(a.body);this._fnEqualiseHeights("tbody",g.dom.body,a.body);if(this.s.dt.nTFoot!==null){if(f){a.footer!==null&&a.footer.parentNode.removeChild(a.footer);
a.footer=c(this.dom.footer).clone(true)[0];a.footer.className+=" DTFC_Cloned";a.footer.style.width="100%";d.foot.appendChild(a.footer);k=this._fnCopyLayout(this.s.dt.aoFooter,b);d=c(">tfoot",a.footer);d.empty();e=0;for(j=k.length;e<j;e++)d[0].appendChild(k[e].nTr);this.s.dt.oApi._fnDrawHead(this.s.dt,k,true)}else for(h=0;h<b.length;h++)c(">tfoot th:eq("+h+")",a.footer)[0].className=this.s.dt.aoColumns[b[h]].nTf.className;this._fnEqualiseHeights("tfoot",this.dom.footer,a.footer)}e=c(">tbody>tr:eq(0)",
a.body);var r=c(">thead>tr:eq(0)",a.header);if(this.s.dt.nTFoot!==null)var s=c(">tfoot>tr:eq(0)",a.footer);e.children().each(function(l){var n=c(this).width();r.children(":eq("+l+")").width(n);g.s.dt.nTFoot!==null&&s.children(":eq("+l+")").width(n)})},_fnGetTrNodes:function(a){for(var d=[],b=0,f=a.childNodes.length;b<f;b++)a.childNodes[b].nodeName.toUpperCase()=="TR"&&d.push(a.childNodes[b]);return d},_fnEqualiseHeights:function(a,d,b){if(this.s.sHeightMatch!="none"){var f,g,e=d.getElementsByTagName(a)[0];
b=b.getElementsByTagName(a)[0];a=c(">"+a+">tr:eq(0)",d).children(":first");a=a.outerHeight()-a.height();e=this._fnGetTrNodes(e);var j=this._fnGetTrNodes(b);b=0;for(d=j.length;b<d;b++)if(this.s.sHeightMatch=="semiauto"&&typeof e[b]._DTTC_iHeight!="undefined"&&e[b]._DTTC_iHeight!==null)c.browser.msie&&c(j[b]).children().height(e[b]._DTTC_iHeight-a);else{f=e[b].offsetHeight;g=j[b].offsetHeight;f=g>f?g:f;if(this.s.sHeightMatch=="semiauto")e[b]._DTTC_iHeight=f;if(c.browser.msie){c(j[b]).children().height(f-
a);c(e[b]).children().height(f-a)}else{j[b].style.height=f+"px";e[b].style.height=f+"px"}}}}};FixedColumns.defaults={iLeftColumns:1,iRightColumns:0,fnDrawCallback:null,sLeftWidth:"fixed",iLeftWidth:null,sRightWidth:"fixed",iRightWidth:null,sHeightMatch:"semiauto"};FixedColumns.prototype.CLASS="FixedColumns";FixedColumns.VERSION="2.0.1"})(jQuery,window,document);