scroll_manager.js



/*scroll_manager class*/
var scroll_manager = function(){
this.viewLength = 0; //int
this.contentLength = 0; //int
this.currentContentPosition = 0; //int
this.contentPositionMax = 0; //int

this.scrollLength = 0; //int
this.buttonLength = 0; //int
this.currentButtonPosition = 0; //int
this.buttonPositionMax = 0; //int

this.contentMoveHandler = null;
this.buttonMoveHandler = null;
this.showScrollHandler = null;
this.hideScrollHandler = null;
}

/*set viewLength attribute. contentPositionMax is calculated*/
scroll_manager.prototype.setViewLength = function(pPiewLength){
this.viewLength = pPiewLength;
this.contentPositionMax = this.contentLength - this.viewLength;
if(this.contentPositionMax < 0){this.contentPositionMax = 0;}
if(this.contentPositionMax > 0){
if(this.showScrollHandler){this.showScrollHandler();}
}else{
if(this.hideScrollHandler){this.hideScrollHandler();}
}
}

/*set contentLength attribute. contentPositionMax is calculated*/
scroll_manager.prototype.setContentLength = function(pContentLength){
  this.contentLength = pContentLength;
this.contentPositionMax = this.contentLength - this.viewLength;
if(this.contentPositionMax < 0){this.contentPositionMax = 0;}
if(this.contentPositionMax > 0){
if(this.showScrollHandler){this.showScrollHandler();}
}else{
if(this.hideScrollHandler){this.hideScrollHandler();}
}
}

/*set currentContentPosition attribute*/
scroll_manager.prototype.setContentPosition = function(pContentPosition){
  this.currentContentPosition = pContentPosition;
if(this.currentContentPosition < 0){this.currentContentPosition = 0;}
if(this.currentContentPosition > this.contentPositionMax){this.currentContentPosition = this.contentPositionMax;}
if(this.contentMoveHandler){this.contentMoveHandler(this.currentContentPosition);}
this.adjustButtonPosition();
}

/*move contentPosition*/
scroll_manager.prototype.moveContentPosition = function(pMoveMargin){
this.setContentPosition(this.currentContentPosition + pMoveMargin);
}

/*Adjust content position according to scroll button position*/
scroll_manager.prototype.adjustContentPosition = function(){
if(this.buttonPositionMax != 0){
this.currentContentPosition = Math.ceil(this.contentPositionMax * this.currentButtonPosition / this.buttonPositionMax);
 if(this.contentMoveHandler){this.contentMoveHandler(this.currentContentPosition);}
  }
}

/*set scrollLength attribute. buttonPositionMax is calculated*/
scroll_manager.prototype.setScrollLength = function(pScrollLength){
this.scrollLength = pScrollLength;
this.buttonPositionMax = this.scrollLength - this.buttonLength;
}

/*set buttonLength attribute. buttonPositionMax is calculated*/
scroll_manager.prototype.setButtonLength = function(pButtonLength){
this.buttonLength = pButtonLength;
this.buttonPositionMax = this.scrollLength - this.buttonLength;
}

/*set currentButtonPosition attribute*/
scroll_manager.prototype.setButtonPosition = function(pButtonPosition){
  this.currentButtonPosition = pButtonPosition;
if(this.currentButtonPosition < 0){this.currentButtonPosition = 0;}
if(this.currentButtonPosition > this.buttonPositionMax){this.currentButtonPosition = this.buttonPositionMax;}
if(this.buttonMoveHandler){this.buttonMoveHandler(this.currentButtonPosition);}
this.adjustContentPosition();
}

/*move buttonPosition*/
scroll_manager.prototype.moveButtonPosition = function(pMoveMargin){
this.setButtonPosition(this.currentButtonPosition + pMoveMargin);
}

/*Adjust scroll Button position according to content position*/
scroll_manager.prototype.adjustButtonPosition = function(){
if(this.contentPositionMax != 0){
 this.currentButtonPosition = Math.ceil(this.buttonPositionMax * this.currentContentPosition / this.contentPositionMax);
 if(this.buttonMoveHandler){this.buttonMoveHandler(this.currentButtonPosition);}
  }
}
s

Comments