Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

/*
 * File:        Scroller.min.js
 * Version:     1.0.0
 * Author:      Allan Jardine (www.sprymedia.co.uk)
 * 
 * Copyright 2011 Allan Jardine, all rights reserved.
 *
 * This source file is free software, under either the GPL v2 license or a
 * BSD (3 point) style license, as supplied with this software.
 * 
 * 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
*/
(function(d,i,g){var e=function(a,c){if(!this instanceof e)alert("Scroller warning: Scroller must be initialised with the 'new' keyword.");else{if(typeof c=="undefined")c={};this.s=d.extend({dt:a,tableTop:0,tableBottom:0,redrawTop:0,redrawBottom:0,rowHeight:null,viewportHeight:0,viewportRows:0,stateTO:null,drawTO:null},e.oDefaults,c);this.dom={force:g.createElement("div"),scroller:null,table:null};this.s.dt.oInstance.oScroller=this;this._fnConstruct()}};e.prototype={fnRowToPixels:function(a){return a*
this.s.rowHeight},fnPixelsToRow:function(a){return parseInt(a/this.s.rowHeight,10)},fnScrollToRow:function(a,c){a=this.fnRowToPixels(a);typeof c=="undefined"||c?d(this.dom.scroller).animate({scrollTop:a}):d(this.dom.scroller).scrollTop(a)},_fnConstruct:function(){var a=this;this.dom.force.style.position="absolute";this.dom.force.style.top="0px";this.dom.force.style.left="0px";this.dom.force.style.width="1px";this.dom.scroller=d("div.dataTables_scrollBody",this.s.dt.nTableWrapper)[0];this.dom.scroller.appendChild(this.dom.force);
this.dom.scroller.style.position="relative";this.dom.table=d(">table",this.dom.scroller)[0];this.dom.table.style.position="absolute";this.dom.table.style.top="0px";this.dom.table.style.left="0px";this.s.rowHeight=="auto"&&this._fnCalcRowHeight();this.s.viewportHeight=d(this.dom.scroller).height();this.s.viewportRows=parseInt(this.s.viewportHeight/this.s.rowHeight,10)+1;this.s.dt._iDisplayLength=this.s.viewportRows*3;d(this.dom.scroller).scroll(function(){a._fnScroll.call(a)});this.s.dt.aoDrawCallback.push({fn:function(){a._fnDrawCallback.call(a)},
sName:"Scroller"});this.s.dt.aoStateSave.push({fn:function(c,b){return b+',"iScroller":'+a.dom.scroller.scrollTop},sName:"Scroller_State"})},_fnScroll:function(){var a=this,c=this.dom.scroller.scrollTop,b;this.s.trace&&console.log("Scroll: "+c+"px - boundaries: "+this.s.redrawTop+" / "+this.s.redrawBottom+".  Showing rows "+this.fnPixelsToRow(c)+" to "+this.fnPixelsToRow(c+d(this.dom.scroller).height())+" in the viewport, with rows "+this.s.dt._iDisplayStart+" to "+this.s.dt._iDisplayEnd+" rendered by the DataTable");
this._fnInfo();clearTimeout(this.s.stateTO);this.s.stateTO=setTimeout(function(){a.s.dt.oApi._fnSaveState(a.s.dt)},250);if(c<this.s.redrawTop||c>this.s.redrawBottom){b=parseInt(c/this.s.rowHeight,10)-this.s.viewportRows;if(b<0)b=0;else if(b+this.s.dt._iDisplayLength>this.s.dt.fnRecordsDisplay())b=this.s.dt.fnRecordsDisplay()-this.s.dt._iDisplayLength;else b%2!==0&&b++;if(b!=this.s.dt._iDisplayStart){this.s.tableTop=d(this.s.dt.nTable).offset().top;this.s.tableBottom=d(this.s.dt.nTable).height()+this.s.tableTop;
if(this.s.dt.oFeatures.bServerSide){clearTimeout(this.s.drawTO);this.s.drawTO=setTimeout(function(){a.s.dt._iDisplayStart=b;a.s.dt.oApi._fnCalculateEnd(a.s.dt);a.s.dt.oApi._fnDraw(a.s.dt)},this.s.serverWait)}else{this.s.dt._iDisplayStart=b;this.s.dt.oApi._fnCalculateEnd(this.s.dt);this.s.dt.oApi._fnDraw(this.s.dt)}this.s.trace&&console.log("Scroll forcing redraw - top DT render row: "+b)}}},_fnDrawCallback:function(){var a=this,c=this.dom.scroller.scrollTop;this.dom.force.style.height=this.s.rowHeight*
this.s.dt.fnRecordsDisplay()+"px";var b=this.s.rowHeight*this.s.dt._iDisplayStart;if(this.s.dt._iDisplayStart===0)b=0;else if(this.s.dt._iDisplayStart===this.s.dt.fnRecordsDisplay()-this.s.dt._iDisplayLength)b=this.s.rowHeight*this.s.dt._iDisplayStart;this.dom.table.style.top=b+"px";this.s.tableTop=b;this.s.tableBottom=d(this.s.dt.nTable).height()+this.s.tableTop;this.s.redrawTop=c-this.s.viewportHeight/2;this.s.redrawBottom=this.s.tableBottom-1.5*this.s.viewportHeight;this.s.trace&&console.log("Table redraw. Table top: "+
b+"px. Table bottom: "+this.s.tableBottom+". Scroll boundary top: "+this.s.redrawTop+". Scroll boundary bottom: "+this.s.redrawBottom);setTimeout(function(){a._fnInfo.call(a)},0);if(this.s.dt.oFeatures.bStateSave&&this.s.dt.oLoadedState!==null&&typeof this.s.dt.oLoadedState.iScroller!="undefined")if(this.s.dt.sAjaxSource!==null&&this.s.dt.iDraw==2||this.s.dt.sAjaxSource===null&&this.s.dt.iDraw==1)setTimeout(function(){d(a.dom.scroller).scrollTop(a.s.dt.oLoadedState.iScroller);a.s.redrawTop=a.s.dt.oLoadedState.iScroller-
a.s.viewportHeight/2},0)},_fnCalcRowHeight:function(){var a=this.s.dt.nTable.cloneNode(false),c=g.createElement("tbody"),b=g.createElement("tr"),f=g.createElement("td");f.innerHTML="&nbsp;";b.appendChild(f);c.appendChild(b);a.appendChild(c);g.body.appendChild(a);this.s.rowHeight=d(b).height();g.body.removeChild(a)},_fnInfo:function(){var a=this.s.dt,c=this.dom.scroller.scrollTop,b=this.fnPixelsToRow(c)+1,f=this.fnPixelsToRow(c+d(this.dom.scroller).height()),h=a.fnRecordsTotal();c=a.fnRecordsDisplay();
b=a.fnFormatNumber(b);f=a.fnFormatNumber(f);h=a.fnFormatNumber(h);c=a.fnFormatNumber(c);c=a.fnRecordsDisplay()===0&&a.fnRecordsDisplay()==a.fnRecordsTotal()?a.oLanguage.sInfoEmpty+a.oLanguage.sInfoPostFix:a.fnRecordsDisplay()===0?a.oLanguage.sInfoEmpty+" "+a.oLanguage.sInfoFiltered.replace("_MAX_",h)+a.oLanguage.sInfoPostFix:a.fnRecordsDisplay()==a.fnRecordsTotal()?a.oLanguage.sInfo.replace("_START_",b).replace("_END_",f).replace("_TOTAL_",c)+a.oLanguage.sInfoPostFix:a.oLanguage.sInfo.replace("_START_",
b).replace("_END_",f).replace("_TOTAL_",c)+" "+a.oLanguage.sInfoFiltered.replace("_MAX_",a.fnFormatNumber(a.fnRecordsTotal()))+a.oLanguage.sInfoPostFix;a=a.aanFeatures.i;b=0;for(h=a.length;b<h;b++)d(a[b]).html(c)}};e.oDefaults={trace:false,rowHeight:"auto",serverWait:200};e.prototype.CLASS="Scroller";e.VERSION="1.0.0";e.prototype.CLASS=e.VERSION;typeof d.fn.dataTable=="function"&&typeof d.fn.dataTableExt.fnVersionCheck=="function"&&d.fn.dataTableExt.fnVersionCheck("1.8.0")?d.fn.dataTableExt.aoFeatures.push({fnInit:function(a){return(new e(a,
typeof a.oInit.oScroller=="undefined"?{}:a.oInit.oScroller)).dom.wrapper},cFeature:"S",sFeature:"Scroller"}):alert("Warning: Scroller requires DataTables 1.8.0 or greater - www.datatables.net/download")})(jQuery,window,document);