datatable-scroll-min.js revision 55468c0b0feefa0f7cf0bfd96efc5a84b17995e5
YUI.add("datatable-scroll",function(f){var d=f.Lang,a=d.isString,e=d.isNumber,c=d.isArray,b;f.DataTable.Scrollable=b=function(){};b.ATTRS={scrollable:{value:false,setter:"_setScrollable"}};f.mix(b.prototype,{scrollTo:function(h){var g;if(h&&this._tbodyNode&&(this._yScrollNode||this._xScrollNode)){if(c(h)){g=this.getCell(h);}else{if(e(h)){g=this.getRow(h);}else{if(a(h)){g=this._tbodyNode.one("#"+h);}else{if(h instanceof f.Node&&h.ancestor(".yui3-datatable")===this.get("boundingBox")){g=h;}}}}g&&g.scrollIntoView();}},_CAPTION_TABLE_TEMPLATE:'<table class="{className}" role="presentation"></table>',_SCROLLBAR_TEMPLATE:'<div class="{className}"><div></div></div>',_X_SCROLLER_TEMPLATE:'<div class="{className}"></div>',_Y_SCROLLER_TEMPLATE:'<div class="{className}"><table class="{tableClassName}" role="presentation"></table></div>',_addVirtualScrollbar:function(){var g=this._yScrollNode,h=f.DOM.getScrollbarWidth()+"px",i=f.Node.create(f.Lang.sub(this._SCROLLBAR_TEMPLATE,{className:this.getClassName("virtual","scrollbar")}));this._scrollbarNode=i;i.setStyles({height:g.get("clientHeight")+"px",width:h,bottom:h});i.one("div").setStyle("height",g.get("scrollHeight")+"px");this._virtualScrollHandle=new f.EventHandle([i.on("scroll",f.rbind("_syncVirtualScroll",this)),g.on("scroll",f.rbind("_syncVirtualScroll",this))]);this.get("contentBox").appendChild(i);},_afterContentChange:function(g){this._mergeXScrollContent();this._mergeYScrollContent();this._uiSetWidth(this.get("width"));this._syncScrollUI();},_afterScrollableChange:function(g){this._uiSetScrollable();this._syncScrollUI();},_afterScrollHeightChange:function(g){this._yScroll&&this._syncScrollUI();},_bindScrollUI:function(){this.after(["dataChange","columnsChange","captionChange","heightChange"],f.bind("_afterContentChange",this));this.data.after(["add","remove","reset","*:change"],f.bind("_afterContentChange",this));},_calcScrollHeight:function(){var g=this._yScrollNode;return this.get("contentBox").get("clientHeight")-g.get("offsetTop")-g.get("offsetHeight")+g.get("clientHeight");},_createXScrollNode:function(){if(!this._xScrollNode){this._xScrollNode=f.Node.create(f.Lang.sub(this._X_SCROLLER_TEMPLATE,{className:this.getClassName("x","scroller")}));}},_createYScrollNode:function(){if(!this._yScrollNode){this._yScrollNode=f.Node.create(f.Lang.sub(this._Y_SCROLLER_TEMPLATE,{className:this.getClassName("y","scroller"),tableClassName:this.getClassName("y","scroll","table")}));}},_fixColumnWidths:function(){var k=this._tbodyNode,n=k.get("parentNode"),h=k.one("tr"),o=h&&h.all("td"),p=f.DOM.getScrollbarWidth(),g=[],j,l,m;if(o){this._tableNode.appendChild(this._tbodyNode);j=o.size()-1;m=o.item(j);this._setColumnWidth(j,(m.get("offsetWidth")+p)+"px");o.pop();g=o.get("offsetWidth");for(j=0,l=g.length;j<l;++j){this._setColumnWidth(j,g[j]+"px");}n.appendChild(this._tbodyNode);}},initializer:function(){this._setScrollProperties();this.after(["scrollableChange","heightChange","widthChange"],this._setScrollProperties);f.Do.after(this._bindScrollUI,this,"bindUI");f.Do.after(this._syncScrollUI,this,"syncUI");},_mergeXScrollContent:function(){var g=this._xScrollNode,h;this.get("boundingBox").removeClass(this.getClassName("scrollable","x"));if(g){if(this._captionNode){h=this._captionNode&&this._captionNode.ancestor("."+this.getClassName("caption","table"));this._tableNode.insertBefore(this._captionNode,this._tableNode.get("firstChild"));if(h){h.remove().destroy(true);}}g.replace(g.get("childNodes").toFrag());this._xScrollNode=null;if(this._scrollbarNode){this._virtualScrollHandle.detach();this._virtualScrollHandle=null;this._scrollbarNode.remove().destroy(true);this._scrollbarNode=null;}}},_mergeYScrollContent:function(){this.get("boundingBox").removeClass(this.getClassName("scrollable","y"));if(this._yScrollNode){this._tableNode.append(this._tbodyNode);this._yScrollNode.remove().destroy(true);this._yScrollNode=null;this._removeHeaderScrollPadding();}this._uiSetColumns();},_removeHeaderScrollPadding:function(){var k=this._theadNode.all("> tr").getDOMNodes(),h,j,g;for(j=0,g=k.length;j<g;j+=(h.rowSpan||1)){h=f.one(k[j].cells[k[j].cells.length-1]).setStyle("paddingRight","");}},_setHeaderScrollPadding:function(){var k=this._theadNode.all("> tr").getDOMNodes(),l,h,j,g;h=f.one(k[0].cells[k[0].cells.length-1]);l=(f.DOM.getScrollbarWidth()+parseInt(h.getComputedStyle("paddingRight"),10))+"px";for(j=0,g=k.length;j<g;j+=(h.rowSpan||1)){h=f.one(k[j].cells[k[j].cells.length-1]).setStyle("paddingRight",l);}},_setScrollable:function(g){if(g===true){g="xy";}if(a(g)){g=g.toLowerCase();}return(g===false||g==="y"||g==="x"||g==="xy")?g:f.Attribute.INVALID_VALUE;},_setScrollProperties:function(){var i=this.get("scrollable")||"",h=this.get("width"),g=this.get("height");this._xScroll=h&&i.indexOf("x")>-1;this._yScroll=g&&i.indexOf("y")>-1;},_setYScrollColWidths:function(){var j=this._yScrollNode,i=j&&j.one("> table"),h,g;if(i){j.all("colgroup,col").remove();h=this._colgroupNode.cloneNode(true);h.set("id",f.stamp(h));if(!f.Features.test("table","badColWidth")){g=h.all("col").pop();g.setStyle("width",(parseInt(g.getStyle("width"),10)-1-f.DOM.getScrollbarWidth())+"px");}i.insertBefore(h,i.one("> thead, > tfoot, > tbody"));}},_splitXScrollContent:function(){var g;this._createXScrollNode();this._tableNode.wrap(this._xScrollNode);if(this._yScrollNode){this._xScrollNode.append(this._yScrollNode);}if(this._captionNode){g=f.Node.create(f.Lang.sub(this._CAPTION_TABLE_TEMPLATE,{className:this.getClassName("caption","table")}));g.setStyle("width",this.get("width"));g.insertBefore(this._captionNode,g.get("firstChild"));this.get("contentBox").insertBefore(g,this._xScrollNode);}},_splitYScrollContent:function(){var i=this._tableNode,j=this._yScrollTable,g,h;this.get("boundingBox").addClass(this.getClassName("scrollable","y"));if(!j){this._fixColumnWidths();this._setHeaderScrollPadding();h=parseInt(i.getComputedStyle("width"),10);i.setStyle("width",h+"px");this._createYScrollNode();j=this._yScrollNode;
g=j.one("table");g.append(this._tbodyNode);i.insert(j,"after");j.setStyles({height:this._calcScrollHeight()+"px",width:(h-2)+"px"});g.setStyle("width",j.get("clientWidth")+"px");}this._setYScrollColWidths();},_syncScrollUI:function(){var g=this.get("contentBox"),i=this._yScrollNode||g,h=i.one("table");this._uiSetDim("width","");this._tableNode.setStyle("width","");this._uiSetScrollable();if(this._yScroll){if(h.get("scrollHeight")>i.get("clientHeight")){this._splitYScrollContent();}else{this._mergeYScrollContent();}}else{this._mergeYScrollContent();}if(this._xScroll){if(h.get("scrollWidth")>parseInt(this.get("width"),10)){this._splitXScrollContent();if(this._yScrollNode){this._yScrollNode.setStyle("height",(this._yScrollNode.get("offsetHeight")-f.DOM.getScrollbarWidth())+"px");this._addVirtualScrollbar();}}else{this._mergeXScrollContent();}}else{this._mergeXScrollContent();}this._uiSetDim("width",this.get("width"));},_syncVirtualScroll:function(h){var g=(h.currentTarget===this._scrollbarNode)?this._yScrollNode:this._scrollbarNode;g.set("scrollTop",h.currentTarget.get("scrollTop"));},_uiSetWidth:function(g){var h=this._xScrollNode||this._yScrollNode;if(e(g)){g+=this.DEF_UNIT;}if(h){this._mergeXScrollContent();this._mergeYScrollContent();this._syncScrollUI();}else{this._uiSetDim("width",g);this._tableNode.setStyle("width",g);}},_uiSetScrollable:function(){this.get("boundingBox").toggleClass(this.getClassName("scrollable","x"),this._xScroll).toggleClass(this.getClassName("scrollable","y"),this._yScroll);}},true);f.Base.mix(f.DataTable,[b]);},"@VERSION@",{skinnable:true,requires:["datatable-base","dom-screen"]});