/********************************* scrollbar.js for EA.com js code for EA.com redesign code by Byron Tredwell (byron(AT)blastradius.com) *********************************/ function scrollbar(parentElm,target) { this.sb = getElm(parentElm); this.dir = 0; this.aniSpeed = 10; this.height = this.sb.className.split(" ")[1]; this.target = getElm(target); if(isNaN(parseInt(this.height)) == true){ this.height = this.target.parentNode.offsetHeight; } this.sb.style.height = this.height+"px"; this.arrowTop = createElm("DIV",this.sb.id+"_aTop",this.sb); this.arrowTop.className = "arrow arrowTop"; this.arrowTop.sbRef = this; this.arrowBot = createElm("DIV",this.sb.id+"_aBot",this.sb); this.arrowBot.className = "arrow arrowBot"; this.arrowBot.sbRef = this; this.track = createElm("DIV",this.sb.id+"_track",this.sb); this.track.className = "track"; this.trackHeight = (this.height) - (this.arrowTop.offsetHeight + this.arrowBot.offsetHeight); this.track.style.height = this.trackHeight+"px"; this.track.sbRef = this; this.arrowTop.style.top = (this.trackHeight)+"px"; this.arrowBot.style.top = (this.trackHeight+this.arrowBot.offsetHeight)+"px"; this.thumb = createElm("DIV",this.sb.id+"_thumb",this.track); this.thumb.className = "thumb"; this.thumb.sbRef = this; this.visibleArea = this.target.parentNode.offsetHeight; this.targetHeight = this.target.offsetHeight; this.targetScrollDistance = this.visibleArea - this.targetHeight; if(this.targetScrollDistance >= 0) { this.targetHeight = 0 } if(this.targetHeight == 0) { this.thumbHeight = 0; this.targetScrollDistance = 0; //this.sb.style.display = "none"; }else{ this.thumbHeight = Math.floor(Math.abs( (this.visibleArea/this.targetHeight)*this.trackHeight ) ); } this.thumb.style.height = this.thumbHeight+"px"; this.maxH = this.trackHeight - this.thumbHeight; addListener(this.thumb,"mousedown",passDragEventCall); addListener(this.arrowTop,"mousedown",this.arrowDown); addListener(this.arrowBot,"mousedown",this.arrowDown); addListener(this.arrowTop,"mouseup",this.arrowUp); addListener(this.arrowBot,"mouseup",this.arrowUp); addListener(this.arrowTop,"mouseout",this.arrowUp); addListener(this.arrowBot,"mouseout",this.arrowUp); addListener(this.track,"mousedown",this.trackDown); } scrollbar.prototype.setScrollPerc = function() { if(window.activeScrollBar) { var sb = window.activeScrollBar; sb.scrollPerc = (sb.thumb.offsetTop/(sb.maxH)); setY(sb.target, sb.targetScrollDistance*sb.scrollPerc); } } scrollbar.prototype.arrowDown = function(e) { if(!e) var e = window.event; var tg = (e.target) ? e.target : e.srcElement; window.activeScrollBar = tg.sbRef; if(window.activeScrollBar.targetScrollDistance == 0) return; if(tg.id.indexOf("_aBot") >= 0){ tg.sbRef.dir = 1; tg.className = "arrow arrowBotOn"; }else{ tg.sbRef.dir = -1; tg.className = "arrow arrowTopOn"; } window.sbTimer = setInterval("moveThumb()",50); } scrollbar.prototype.arrowUp = function() { if(window.activeScrollBar) { if(window.activeScrollBar.dir == 1) { window.activeScrollBar.arrowBot.className = "arrow arrowBot"; }else{ window.activeScrollBar.arrowTop.className = "arrow arrowTop"; } window.activeScrollBar.dir = 0; window.activeScrollBar.setScrollPerc(); } window.activeScrollBar = null; if(window.sbTimer) clearInterval(window.sbTimer); } scrollbar.prototype.trackDown = function(e) { if(!e) var e = window.event; var tg = (e.target) ? e.target : e.srcElement; if(tg.id.indexOf("_track") >= 0) { window.activeScrollBar = tg.sbRef; tg.sbRef.scrollPerc = ( (e.clientY+ ( (isSafari) ? 0 : getScrollTop(window) ) ) - getOffsetProperty(tg, "Top") )/tg.sbRef.trackHeight; setY(tg.sbRef.thumb, tg.sbRef.maxH * tg.sbRef.scrollPerc); setY(tg.sbRef.target, tg.sbRef.targetScrollDistance*tg.sbRef.scrollPerc); } } scrollbar.prototype.reset = function(target) { if(typeof target != "object") target = getElm(target); this.target = target; this.visibleArea = this.target.parentNode.offsetHeight; this.targetHeight = this.target.offsetHeight; this.targetScrollDistance = this.visibleArea - this.targetHeight; if(this.targetScrollDistance >= 0) { this.targetHeight = 0 } if(this.targetHeight == 0) { this.thumbHeight = 0; this.targetScrollDistance = 0; //this.sb.style.display = "none"; }else{ this.thumbHeight = Math.floor(Math.abs( (this.visibleArea/this.targetHeight)*this.trackHeight ) ); this.sb.style.display = "block"; } this.thumb.style.height = this.thumbHeight+"px"; this.thumb.style.top = "0px"; this.target.style.top = "0px"; this.arrowTop.style.top = (this.trackHeight)+"px"; this.arrowBot.style.top = (this.trackHeight+this.arrowBot.offsetHeight)+"px"; this.maxH = this.trackHeight - this.thumbHeight; } scrollbar.prototype.scrollIntoView = function(itemTop, itemHeight) { var adjustScroll = false; var newTargetTop; var targetTop = this.target.offsetTop; if (itemTop > this.height - itemHeight - targetTop) { newTargetTop = -itemTop + (this.height - itemHeight); adjustScroll = true; } else if (itemTop < -targetTop) { newTargetTop = -itemTop; adjustScroll = true; } if (adjustScroll == true) { setY(this.target, newTargetTop); this.scrollPerc = (-this.target.offsetTop / (this.target.offsetHeight - this.height)); setY(this.thumb, this.maxH * this.scrollPerc); } } function moveThumb() { var sb = window.activeScrollBar; var thumb = sb.thumb; if(isNaN(parseInt(thumb.style.top)) == true) thumb.style.top = "0px"; moveBy(thumb,0,sb.dir*sb.aniSpeed,0); correctThumbPos(sb,sb.arrowUp); sb.setScrollPerc(); } function correctThumbPos(sb,func) { if(getY(sb.thumb) < 0){ setY(sb.thumb, 0); if(func) func(); } if(getY(sb.thumb) > sb.maxH){ setY(sb.thumb, sb.maxH); if(func) func(); } } function passDragEventCall(e) { if(!e) var e = window.event; var tg = (e.target) ? e.target : e.srcElement; window.activeScrollBar = tg.sbRef; dragable(e,tg,tg.sbRef.track,tg.sbRef.setScrollPerc,function(){window.activeScrollBar=null}); }