~jonas-drange/online-services-common-js/navbar-autocomplete

« back to all changes in this revision

Viewing changes to build/tablescroll/tablescroll-min.js

  • Committer: Stephen Stewart
  • Date: 2014-02-22 23:57:25 UTC
  • mfrom: (18.1.2 trunk)
  • Revision ID: stephen.stewart@canonical.com-20140222235725-iw6f15t9umws19xd
mergeĀ lp:~stephen-stewart/online-services-common-js/remove-u1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add("tablescroll",function(e,t){"use strict";e.namespace("u1"),e.u1.TableScroll=e.Base.create("TableScroll",e.Widget,[],{initializer:function(){this.set("nScrollbarWidth",this.getScrollbarWidth());var t=this.get("oNodeContainer"),n=this.get("oRowSpec");this.set("oNodeTable",t.one("table")),this.set("oNodeTbody",t.one("tbody")),this.set("oNodeThead",t.one("thead")),this.set("oNodeTfoot",t.one("tfoot")),this.styleNode=new e.u1.StyleNode,this.rows={},this.timer=null,this.dataCache=new e.Cache({max:this.get("nMaxDataCacheItems"),uniqueKeys:!0});if(!n||!n.preDataTemplate||!n.postDataTemplate){window.alert("Please define oRowSpec attribute as an object with 'preDataTemplate' and 'postDataTemplate' template node properties.");return}this.set("sRowPreDataTemplate",e.one(n.preDataTemplate).getContent()),this.set("sRowPostDataTemplate",e.one(n.postDataTemplate).getContent())},debugInit:function(){var t=e.Node.create("<div class='isroll-debug'><dl></dl></div>"),n=t.one("dl"),r=e.Node.create('<dt>Number Trs: </dt><dd id="tablescroll-ntrs"></dd>'),i=e.Node.create('<dt>Total No. of Records: </dt><dd id="tablescroll-totrs"></dd>'),s=e.Node.create('<dt>Number Data Pages: </dt><dd id="tablescroll-ndps"></dd>'),o=e.Node.create('<dt>Current Data Page: </dt><dd id="tablescroll-cdp"></dd>'),u=e.Node.create('<dt>LastScrollTop: </dt><dd id="tablescroll-lst"></dd>'),a=e.Node.create('<dt>Total Scroll Height: </dt><dd id="tablescroll-th"></dd>'),f=e.Node.create('<dt>Range visible Top: </dt><dd id="tablescroll-orv-top"></dd>'),l=e.Node.create('<dt>Range visible Middle: </dt><dd id="tablescroll-orv-middle"></dd>'),c=e.Node.create('<dt>Range visible Bottom: </dt><dd id="tablescroll-orv-bottom"></dd>'),h=[r,s,o,u,i,a,f,l,c],p;for(p in h)n.append(h[p]);e.Node.one("body").append(t),t.setStyles({position:"fixed","z-index":10,top:"5px",left:"5px",width:"300px",height:"250px",background:"#ccc"}),this.after("nLastScrollTopChange",function(t){e.Node.one("#tablescroll-lst").setContent(t.newVal)},this),this.after("aCurrentDataPageChange",function(t){e.Node.one("#tablescroll-cdp").setContent(t.newVal)},this),this.after("nNumTrsChange",function(t){e.Node.one("#tablescroll-ntrs").setContent(t.newVal)},this),this.after("nTotalDataPagesChange",function(t){e.Node.one("#tablescroll-ndps").setContent(t.newVal)},this),this.after("nScrollbarHeightChange",function(t){e.Node.one("#tablescroll-th").setContent(t.newVal)},this),this.after("nTotalRecordsChange",function(t){e.Node.one("#tablescroll-totrs").setContent(t.newVal)},this),this.after("nRangeVisibleTopChange",function(t){e.Node.one("#tablescroll-orv-top").setContent(t.newVal)},this),this.after("nRangeVisibleMiddleChange",function(t){e.Node.one("#tablescroll-orv-middle").setContent(t.newVal)},this),this.after("nRangeVisibleBottomChange",function(t){e.Node.one("#tablescroll-orv-bottom").setContent(t.newVal)},this),this.set("nNumTrs",this.get("oNodeContainer").all("tbody tr").size())},renderUI:function(){var t=this.get("bDebugMode"),n,r=this.get("oNodeContainer"),i,s,o,u,a;t===!0&&this.debugInit(),u=this.get("oNodeThead"),a=this.get("oNodeTable"),r.get("id")||r.set("id",e.guid()),i=u.cloneNode(!0),this.set("oNodeTheadClone",i),n=u.get("offsetHeight"),s=e.Node.create("<div class='tablescroll-thead'><table></table></div>"),e.UA.ie===7&&s.setStyle("zoom",1),o=s.one("table"),o.append(i),r.insertBefore(s,r),u.remove(),r.setStyles({height:this.get("nContainerHeight"),position:"relative",overflowX:"hidden",overflowY:"scroll"}),a.setStyles({height:-n,display:"block"})},bindUI:function(){var t=this.get("oNodeContainer"),n;e.UA.mobile>0?n=e.throttle(e.bind(this.onScroll,this),100):n=e.bind(this.onScroll,this),e.on("mousewheel",n),t.on("scroll",n),this.after("nTotalRecordsChange",this.onTotalRecordsChange,this),this.after("aCurrentDataPageChange",this.onDataPageChange,this),this.after("visibleChange",this.afterVisibleChange,this),e.on("windowresize",e.bind(this.syncUI,this))},syncUI:function(){this.get("visible")===!0&&(this.renderWidget(),this.setColumnWidths())},setColumnWidths:function(){var t=this.get("aColumnSpec"),n,r,i,s,o,u,a=0,f=0,l=0,c,h,p=null,d=this.get("oNodeTable"),v=d.get("offsetWidth"),m,g,y,b,w=this.get("oNodeContainer").get("id"),E,S,x,T;for(x=0,T=t.length;x<T;x++)c=t[x].width,o=t[x].flexwidth,typeof c!="undefined"&&(a+=parseInt(c,10)),typeof o!="undefined"&&(l+=parseInt(o,10));u=v-a,m=this.get("oNodeTbody").all("tr:first-child td");if(m.size()===0)return;y=m.item(0),S=y.getContent(),y.setContent(e.Node.create("<div style='height:"+this.get("nRowHeight")+"px'></div>")),h=y.get("offsetHeight")-parseInt(y.getComputedStyle("height"),10),y.setContent(S),n=["white-space: nowrap;","position: absolute;","overflow: hidden;","height: "+(this.get("nRowHeight")-h)+"px;"],i=["#"+w+" table"+"{ table-layout:fixed }","#"+w+" tr"+"{ width: "+v+"px; }","#"+w+" td { "+n.join(" ")+"}"],r=["text-overflow: ellipsis;","-o-text-overflow: ellipsis;","-ms-text-overflow: ellipsis;"];for(x=0,T=t.length;x<T;x++)c=t[x].width,g=m.item(x),o=t[x].flexwidth,typeof c!="undefined"&&(p=c),typeof o!="undefined"&&(p=u/100*o),s=g.get("offsetWidth")-parseInt(g.getComputedStyle("width"),10),p-=s,E="",t[x].ellipsis===!0&&(E=r.join(" ")),i.push("#"+w+" .c"+(x+1)+"{ left: "+f+"px; width:"+p+"px; "+E+"}"),f+=p+s;b=this.styleNode.get("styleNode"),b!==null&&b.remove(),this.styleNode.create(i),this.updateThWidths()},updateThWidths:function(){var e=this.get("oNodeTbody").all("tr:first-child td"),t=this.get("oNodeTheadClone").all("th"),n,r=e.size();e.each(function(e,i){if(i+1===r)return;n=e.get("offsetWidth"),n>0&&t.item(i).set("offsetWidth",n)},this)},onTotalRecordsChange:function(e){if(e.newVal===e.prevVal)return;var t=e.newVal*this.get("nRowHeight");this.get("oNodeTable").setStyle("height",t),this.set("nScrollbarHeight",t),this.set("nTotalDataPages",Math.ceil(t/(this.get("nRowHeight")*this.get("nRecordLimit")))),typeof e.prevVal!="undefined"&&(this.dataCache.flush(),this.syncUI())},onDataPageChange:function(t){if(t.prevVal===
2
 
t.newVal)return;var n=t.newVal;this.timer!==null&&clearTimeout(this.timer),this.timer=setTimeout(e.bind(function(e){var t=[],n=this.get("nRecordLimit"),r=e.currentPage,i,s,o,u,a;if(this.get("aCurrentDataPage")===r){for(u=0,a=r.length;u<a;u++)o=r[u],this.dataCache.retrieve("is-"+o)===null&&t.push(o);if(t.length===0)return;i=(t[0]-1)*n,s=n*t.length;for(u=0,a=t.length;u<a;u++)this.dataCache.add("is-"+t[u],"pending");this.fetchData(i,s)}this.timer=null},this,{currentPage:n}),this.get("nDataFetchDelay"))},onInitialData:function(){this.onScroll()},fetchData:function(t,n){this.get("oDataSource")[this.get("sDataSourceMethod")]({success:e.rbind(this.onIOSuccess,this,t,n),failure:e.rbind(this.onIOFailure,this,t,n),offset:t,limit:n})},onIOSuccess:function(e,t,n){var r=this.get("nRecordLimit"),i=this.get("fRecordListSchema")(e),s=Math.ceil(t/r+1),o;o=this.get("fRecordTotalSchema")(e),this.set("nTotalRecords",o),this.set("nTotalPages",o/this.get("nRecordLimit")),this.get("bLoadedInitialData")||this.onInitialData(e),n>r?(this.dataCache.add("is-"+s,i.slice(0,r)),this.dataCache.add("is-"+(s+1),i.slice(r,n))):this.dataCache.add("is-"+s,i),this.clearRows(),this.renderWidget(),this.get("bLoadedInitialData")||(this.setColumnWidths(),this.set("bLoadedInitialData",!0))},onIOFailure:function(){},clearDataCache:function(){this.dataCache.flush()},clearRows:function(){for(var e in this.rows)this.removeRow(e)},removeRow:function(e){this.rows[e].remove(!0),delete this.rows[e]},getRowData:function(e){var t=this.get("nRecordLimit"),n=Math.ceil((e+1)/t),r=e,i;n=n>0?n:1,n>1&&(r=Math.floor(e-(n-1)*t)),i=this.dataCache.retrieve("is-"+n);if(i&&i.response!=="pending"&&i.response[r])return i.response[r]},renderWidget:function(){var e=this.get("oNodeContainer"),t=this.get("nRowHeight"),n=e.get("scrollTop"),r=this.get("nContainerHeight"),i=r,s=this.get("oNodeTbody"),o=this.get("bDebugMode"),u=this.get("nTotalRecords"),a=Math.floor((n-i)/t),f=Math.ceil((n+r+i)/t),l,c,h;this.top=a=Math.max(0,a),this.bottom=f=Math.min(this.get("nScrollbarHeight")/t,f),l=Math.ceil(a+(f-a)/2),this.set("aCurrentDataPage",this.getCurrentDataPage()),o&&(this.set("nRangeVisibleTop",a),this.set("nRangeVisibleMiddle",l),this.set("nRangeVisibleBottom",f));for(h in this.rows)if(h<a||h>f)this.fire("preRowDestroyed",{node:this.rows[h]}),this.rows[h].remove(!0),delete this.rows[h];for(h=a;h<=f;h++){if(h>u-1)continue;this.rows[h]?c=this.rows[h]:c=this.rows[h]=this.renderRow(h),s.append(c)}o&&this.set("nNumTrs",this.get("oNodeContainer").all("tbody tr").size())},renderRow:function(t){var n={"tablescroll-rownum":t+1},r=this.get("nRowHeight"),i,s,o,u;return s=this.getRowData(t),s?(o=e.merge(s,n),u=this.get("fCustomRowRenderer"),u&&typeof u=="function"?i=u(o,t,this):i=e.Node.create(e.substitute(this.get("sRowPostDataTemplate"),o,function(t,n){return e.Escape.html(n)})),this.fire("rowDataRendered",{node:i,data:s})):(i=e.Node.create(e.substitute(this.get("sRowPreDataTemplate"),n,function(t,n){return e.Escape.html(n)})),this.fire("rowRendered",{node:i})),i.setStyles({top:t*r+"px",height:r+"px",position:"absolute"}),i},getCurrentDataPage:function(){var e=this.get("nRowHeight"),t=this.get("nRecordLimit"),n=t*e,r,i,s;return r=Math.ceil(this.top*e/n),r=r>0?r:1,i=Math.ceil(this.bottom*e/n),r=r>0?r:1,i=i>0?i:1,r===i?s=[r]:s=[r,i],s},onScroll:function(){if(this.get("visible")===!0){var e=this.get("oNodeContainer").get("scrollTop");this.get("nLastScrollTop")!==e&&this.renderWidget(),this.set("nLastScrollTop",e)}},getScrollbarWidth:function(){var t=0,n=e.Node.create('<div style="width:50px;height:50px;position:absolute;top:-999em;left:999em;"><div style="height:100px; width: 100%"></div></div>'),r,i;return e.one("body").append(n),r=parseInt(n.one("div").get("offsetWidth"),10),n.setStyle("overflow-y","scroll"),i=parseInt(n.one("div").get("offsetWidth"),10),n.remove(),t=r-i,t!==0?t:18}},{NAME:"tablescroll",ATTRS:{aColumnSpec:{value:null},oRowSpec:{value:null},bDebugMode:{value:!1},bLoadedInitialData:{value:!1},fRecordListSchema:{value:null},fRecordTotalSchema:{value:null},fCustomRowRenderer:{value:null},nContainerHeight:{value:400},aCurrentDataPage:{value:[1,1]},nDataFetchDelay:{value:250},nLastScrollTop:{value:null},nRecordLimit:{value:50},nRowHeight:{value:50},nScrollbarWidth:{value:null},nScrollbarHeight:{value:null},nNumTrs:{value:null},nMaxDataCacheItems:{value:10},nTotalDataPages:{value:null},nRangeVisibleTop:{value:null},nRangeVisibleMiddle:{value:null},nRangeVisibleBottom:{value:null},oNodeContainer:{setter:function(t){var n=e.one(t);return n}},oNodeTable:{writeOnce:!0},oNodeTbody:{writeOnce:!0},oNodeTfoot:{writeOnce:!0},oNodeThead:{writeOnce:!0},oNodeTheadClone:{writeOnce:!0},oDataSource:{value:null},sDataSourceMethod:{value:null},sRowPreDataTemplate:{value:null},sRowPostDataTemplate:{value:null}}})},"@VERSION@",{requires:["base-base","base-pluginhost","base-build","cache-base","cache-offline","cache-plugin","escape","stylenode","widget-base","widget-htmlparser","widget-uievents","widget-skin","event-resize"]});