sonarr-repo-only/NzbDrone.Web/Scripts/DataTables-1.9.0/extras/FixedColumns/media/js/FixedColumns.min.js

48 lines
11 KiB
JavaScript

/*
* File: FixedColumns.min.js
* Version: 2.0.2
* 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
@contact www.sprymedia.co.uk/contact
@copyright 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
*/
var FixedColumns;
(function(c,m){FixedColumns=function(a,d){!this instanceof FixedColumns?alert("FixedColumns warning: FixedColumns must be initialised with the 'new' keyword."):("undefined"==typeof d&&(d={}),this.s={dt:a.fnSettings(),iTableColumns:a.fnSettings().aoColumns.length,aiWidths:[],bOldIE:c.browser.msie&&("6.0"==c.browser.version||"7.0"==c.browser.version)},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(!0)},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();c.browser.mozilla||c.browser.opera?a.style.height=d+
"px":c(a).children().height(d-b)},_fnConstruct:function(a){var d,b=this;if("function"!=typeof this.s.dt.oInstance.fnVersionCheck||!0!==this.s.dt.oInstance.fnVersionCheck("1.8.0"))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(!0,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];var a=c(this.dom.grid.dt).width(),f=0,g=0;c("tbody>tr:eq(0)>td",this.s.dt.nTable).each(function(a){d=c(this).outerWidth();b.s.aiWidths.push(d);a<b.s.iLeftColumns&&(f+=d);b.s.iTableColumns-b.s.iRightColumns<=a&&(g+=d)});if(null===this.s.iLeftWidth)this.s.iLeftWidth="fixed"==this.s.sLeftWidth?f:100*(f/a);
if(null===this.s.iRightWidth)this.s.iRightWidth="fixed"==this.s.sRightWidth?g:100*(g/a);this._fnGridSetup();for(a=0;a<this.s.iLeftColumns;a++)this.s.dt.oInstance.fnSetColumnVis(a,!1);for(a=this.s.iTableColumns-this.s.iRightColumns;a<this.s.iTableColumns;a++)this.s.dt.oInstance.fnSetColumnVis(a,!1);c(this.dom.scroller).scroll(function(){b.dom.grid.left.body.scrollTop=b.dom.scroller.scrollTop;if(0<b.s.iRightColumns)b.dom.grid.right.body.scrollTop=b.dom.scroller.scrollTop});c(m).resize(function(){b._fnGridLayout.call(b)});
var e=!0;this.s.dt.aoDrawCallback=[{fn:function(){b._fnDraw.call(b,e);b._fnGridHeight(b);e=!1},sName:"FixedColumns"}].concat(this.s.dt.aoDrawCallback);this._fnGridLayout();this._fnGridHeight();this.s.dt.oInstance.fnDraw(!1)}},_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(0<this.s.iRightColumns)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],0<this.s.iRightColumns))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,b=0,b="fixed"==this.s.sLeftWidth?this.s.iLeftWidth:this.s.iLeftWidth/
100*d,f="fixed"==this.s.sRightWidth?this.s.iRightWidth:this.s.iRightWidth/100*d;a.left.wrapper.style.width=b+"px";a.dt.style.width=d-b-f+"px";a.dt.style.left=b+"px";if(0<this.s.iRightColumns)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(0<this.s.iRightColumns)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);null!==this.s.fnDrawCallback&&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(!(0>=this.s.iRightColumns)){var c,b=[];for(c=this.s.iTableColumns-this.s.iRightColumns;c<this.s.iTableColumns;c++)b.push(c);this._fnClone(this.dom.clone.right,
this.dom.grid.right,b,a)}},_fnCloneLeft:function(a){if(!(0>=this.s.iLeftColumns)){var c,b=[];for(c=0;c<this.s.iLeftColumns;c++)b.push(c);this._fnClone(this.dom.clone.left,this.dom.grid.left,b,a)}},_fnCopyLayout:function(a,d){for(var b=[],f=[],g=[],e=0,k=a.length;e<k;e++){var l=[];l.nTr=c(a[e].nTr).clone(!0)[0];for(var i=0,h=this.s.iTableColumns;i<h;i++)if(-1!==c.inArray(i,d)){var j=c.inArray(a[e][i].cell,g);-1===j?(j=c(a[e][i].cell).clone(!0)[0],f.push(j),g.push(a[e][i].cell),l.push({cell:j,unique:a[e][i].unique})):
l.push({cell:f[j],unique:a[e][i].unique})}b.push(l)}return b},_fnClone:function(a,d,b,f){var g=this,e,k,l,i,h;if(f){null!==a.header&&a.header.parentNode.removeChild(a.header);a.header=c(this.dom.header).clone(!0)[0];a.header.className+=" DTFC_Cloned";a.header.style.width="100%";d.head.appendChild(a.header);var j=this._fnCopyLayout(this.s.dt.aoHeader,b),o=c(">thead",a.header);o.empty();for(e=0,k=j.length;e<k;e++)o[0].appendChild(j[e].nTr);this.s.dt.oApi._fnDrawHead(this.s.dt,j,!0)}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(a){this.className=c("span.DataTables_sort_icon",g.s.dt.aoColumns[b[h]].nTh)[a].className});this._fnEqualiseHeights("thead",this.dom.header,a.header);"auto"==this.s.sHeightMatch&&c(">tbody>tr",g.dom.body).css("height","auto");if(null!==a.body)a.body.parentNode.removeChild(a.body),a.body=null;a.body=c(this.dom.body).clone(!0)[0];a.body.className+=" DTFC_Cloned";
a.body.style.paddingBottom=this.s.dt.oScroll.iBarWidth+"px";a.body.style.marginBottom=2*this.s.dt.oScroll.iBarWidth+"px";null!==a.body.getAttribute("id")&&a.body.removeAttribute("id");c(">thead>tr",a.body).empty();c(">tfoot",a.body).empty();var n=c("tbody",a.body)[0];c(n).empty();0<this.s.dt.aiDisplay.length?c(">tbody>tr",g.dom.body).each(function(a){var d=this.cloneNode(!1),a=!1===g.s.dt.oFeatures.bServerSide?g.s.dt.aiDisplay[g.s.dt._iDisplayStart+a]:a;for(h=0;h<b.length;h++)if(l=b[h],"undefined"!=
typeof g.s.dt.aoData[a]._anHidden[l])i=c(g.s.dt.aoData[a]._anHidden[l]).clone(!0)[0],i.style.width=g.s.aiWidths[l]+"px",d.appendChild(i);n.appendChild(d)}):c(">tbody>tr",g.dom.body).each(function(){i=this.cloneNode(!0);i.className+=" DTFC_NoData";c("td",i).html("");n.appendChild(i)});a.body.style.width="100%";d.body.appendChild(a.body);this._fnEqualiseHeights("tbody",g.dom.body,a.body);if(null!==this.s.dt.nTFoot){if(f){null!==a.footer&&a.footer.parentNode.removeChild(a.footer);a.footer=c(this.dom.footer).clone(!0)[0];
a.footer.className+=" DTFC_Cloned";a.footer.style.width="100%";d.foot.appendChild(a.footer);j=this._fnCopyLayout(this.s.dt.aoFooter,b);d=c(">tfoot",a.footer);d.empty();for(e=0,k=j.length;e<k;e++)d[0].appendChild(j[e].nTr);this.s.dt.oApi._fnDrawHead(this.s.dt,j,!0)}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 m=c(">thead>tr:eq(0)",a.header);
if(null!==this.s.dt.nTFoot)var p=c(">tfoot>tr:eq(0)",a.footer);e.children().each(function(a){var b=c(this).width();m.children(":eq("+a+")").width(b);null!==g.s.dt.nTFoot&&p.children(":eq("+a+")").width(b)})},_fnGetTrNodes:function(a){for(var c=[],b=0,f=a.childNodes.length;b<f;b++)"TR"==a.childNodes[b].nodeName.toUpperCase()&&c.push(a.childNodes[b]);return c},_fnEqualiseHeights:function(a,d,b){if(!("none"==this.s.sHeightMatch&&"thead"!==a&&"tfoot"!==a)){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),k=this._fnGetTrNodes(b);for(b=0,d=k.length;b<d;b++)if("semiauto"==this.s.sHeightMatch&&"undefined"!=typeof e[b]._DTTC_iHeight&&null!==e[b]._DTTC_iHeight)c.browser.msie&&c(k[b]).children().height(e[b]._DTTC_iHeight-a);else{f=e[b].offsetHeight;g=k[b].offsetHeight;f=g>f?g:f;if("semiauto"==this.s.sHeightMatch)e[b]._DTTC_iHeight=f;c.browser.msie&&8>c.browser.version?(c(k[b]).children().height(f-a),c(e[b]).children().height(f-
a)):(k[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.2"})(jQuery,window,document);