// Scroll Object // a widget that draws a JavaScript scrollbar to scroll a layer // 19990410 // Copyright (C) 1999 Dan Steinman // Distributed under the terms of the GNU Library General Public License // Available at http://www.dansteinman.com/dynapi/ // updated 20011228 by Bob Clary // to support Gecko function Scroll(x,y,width,height) { this.name = "Scroll"+(Scroll.count++) this.x = x this.y = y this.w = width this.h = height this.url = null this.active = false this.bar = new Function() this.arrow = new Function() this.arrow.active = false this.box = new Function() this.border = new Function() this.setH = false this.history = new Array() this.historyLoc = -1 this.historyLen = -1 this.visibility = null this.zIndex = null this.contentRef = null this.slideInc = 7 this.slideSpeed = 20 this.clipImages = true this.usebuffer = true this.obj = this.name+"ScrollObject" eval(this.obj+"=this") this.setMargins = ScrollSetMargins this.setMargins(10,10,10,10) this.setDimensions = ScrollSetDimensions this.setDimensions(0,0,15,this.h,15,15,30,1) this.setColors = ScrollSetColors // 1.Rahmen um Scroller 2. Hintergrund scrolllauffläche 3. Farbe Up Down 4.Rollbalken this.setColors(null,"#E4E6F5","#c5c5c5","#555555","#555555") // this.setColors(null,"#ffffff","#C5C5C5","#555555","#898989") #E4E6F5 this.preload = ScrollPreload this.setImages = ScrollSetImages this.setImages() this.setHeight = ScrollSetHeight this.build = ScrollBuild this.load = ScrollLoad this.writeContent = ScrollWriteContent this.back = ScrollBack this.forward = ScrollForward this.reload = ScrollReload this.activate = ScrollActivate this.jumpTo = ScrollJumpTo this.barDown = ScrollBarDown this.barMove = ScrollBarMove this.barUp = ScrollBarUp this.arrowDown = ScrollArrowDown this.arrowUp = ScrollArrowUp this.arrowSlide = ScrollArrowSlide } function ScrollSetDimensions(barX,barY,barW,barH,arrowuH,arrowdH,boxH,border) { this.arrow.uy = barY this.arrow.dy = barY+barH-arrowdH this.arrow.uh = arrowuH this.arrow.dh = arrowdH this.bar.x = barX+this.w this.bar.y = barY+this.arrow.uh this.bar.w = barW this.bar.h = barH-this.arrow.uh-this.arrow.dh this.box.h = boxH this.border.v = border } function ScrollSetColors(bg,border,bar,arrow,box) { this.bgcolor = bg this.border.color = border this.bar.color = bar this.arrow.color = arrow this.box.color = box } function ScrollSetMargins(l,r,t,b) { this.marginL = l this.marginR = r this.marginT = t this.marginB = b } function ScrollPreload(imgObj,imgSrc) { if (imgSrc) { eval(imgObj+' = new Image()') eval(imgObj+'.src = "'+imgSrc+'"') eval(imgObj+'s = true') } else eval(imgObj+'s = false') } function ScrollSetImages(box0,box1,up0,up1,dn0,dn1,bar,directory) { if (arguments.length<8) directory = '' for (var i=0;i\n' if ((is.ie || is.ns5) && this.usebuffer) this.divStart += '\n' this.divStart += '
\n'+ '
\n'+ '
\n'+ '
\n'+ '
\n'+ '
\n'+ '
\n' //bc:if (is.ie && !this.usebuffer) this.divStart += '\n' if ((is.ie || is.ns5) && !this.usebuffer) this.divStart += '\n' else this.divStart += '
\n' this.divEnd = '
\n' //bc:if (is.ns || this.usebuffer) this.divEnd += '
\n' if (is.ns4 || this.usebuffer) this.divEnd += '
\n' this.divEnd += '
\n' if (this.bar.images) this.divEnd += '\n' this.divEnd += '
' if (this.box.image0s) this.divEnd += '' this.divEnd += '
\n
\n
' if (this.arrow.upimage0s) this.divEnd += '' this.divEnd += '
\n
' if (this.arrow.dnimage0s) this.divEnd += '' this.divEnd += '
\n'+ '
\n'+ '
\n'+ '
\n'+ '\n' this.div = this.divStart+this.divEnd } function ScrollActivate(w,h) { if (h) { this.textHeight = h this.setH = true } //bc:if (is.ie && this.usebuffer && parent.frames[this.name+'Frame'].document.body.innerHTML) document.all[this.name+'TextT'].innerHTML = parent.frames[this.name+'Frame'].document.body.innerHTML if (is.ie && this.usebuffer && parent.frames[this.name+'Frame'].document.body.innerHTML) document.all[this.name+'TextT'].innerHTML = parent.frames[this.name+'Frame'].document.body.innerHTML if (is.ns5 && this.usebuffer && parent.frames[this.name+'Frame'].document.body.innerHTML) document.getElementById(this.name+'TextT').innerHTML = parent.frames[this.name+'Frame'].document.body.innerHTML this.lyr = new DynLayer(this.name) //bc:if (is.ie && !this.usebuffer) { if ((is.ie || is.ns5) && !this.usebuffer) { this.textlyr = new DynLayer('content',null,this.name+'Frame') this.contentRef = this.name+'content' } else { this.textlyr = new DynLayer(this.name+'TextT') this.contentRef = this.name+'.document.'+this.name+'TextC.document.'+this.name+'TextT' if (this.lyr.nestref) this.contentRef = this.lyr.nestref+'.document.'+this.contentRef } this.boxlyr = new DynLayer(this.name+'Box',DynLayer.nestRefArray[this.name+"Box"]) this.arrowur = new DynLayer(this.name+'ArrowU') this.arrowu = new DynLayer(this.name+'ArrowUC') this.arrowu.elm.onmousedown = new Function(this.obj+'.arrowDown(1); return false;') this.arrowu.elm.onmouseup = new Function(this.obj+'.arrowUp(); return false;') this.arrowu.elm.onmouseout = new Function(this.obj+'.arrowUp(); return false;') //bc:if (is.ns) this.arrowu.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP) if (is.ns4) this.arrowu.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP) this.arrowdr = new DynLayer(this.name+'ArrowD') this.arrowd = new DynLayer(this.name+'ArrowDC') this.arrowd.elm.onmousedown = new Function(this.obj+'.arrowDown(-1); return false;') this.arrowd.elm.onmouseup = new Function(this.obj+'.arrowUp(); return false;') this.arrowd.elm.onmouseout = new Function(this.obj+'.arrowUp(); return false;') //bc:if (is.ns) this.arrowd.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP) if (is.ns4) this.arrowd.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP) this.barlyr = new DynLayer(this.name+'BarC') this.barlyr.elm.scroll = this.obj this.barlyr.elm.onmousedown = ScrollBarDownStart this.barlyr.elm.onmousemove = ScrollBarMoveStart this.barlyr.elm.onmouseup = new Function(this.obj+'.barUp(); return false;') this.barlyr.elm.onmouseout = new Function(this.obj+'.arrowUp(); return false;') //bc:if (is.ns) this.barlyr.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEMOVE) if (is.ns4) this.barlyr.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEMOVE) //bc:if (!this.setH) this.textHeight = (is.ns)? this.textlyr.doc.height : this.textlyr.elm.scrollHeight if (!this.setH) this.textHeight = (is.ns4)? this.textlyr.doc.height : this.textlyr.elm.offsetHeight this.setH = false //bc:if (is.ns) { if (is.ns4) { this.textlyr.css.clip.bottom = Math.max(this.textHeight,this.h-2*this.border.v-this.marginT) this.textlyr.css.clip.right = this.w - this.border.v*2 } this.ratio = (this.textHeight+this.marginT+this.marginB-this.h+2*this.border.v)/(this.bar.h-this.box.h) this.jumpTo('top') if (this.ratio>0) this.boxlyr.css.visibility = 'inherit' else this.boxlyr.hide() } function ScrollLoad(url) { if (url != this.url) { this.historyLoc += 1 this.historyLen = this.historyLoc this.history[this.historyLen] = url this.reload() } } function ScrollBack() { if (this.historyLoc > 0) { this.historyLoc -= 1 this.reload() } } function ScrollForward() { if (this.historyLoc < this.historyLen) { this.historyLoc += 1 this.reload() } } function ScrollReload() { this.url = this.history[this.historyLoc] this.refresh = true //bc:if (is.ns) { if (is.ns4) { this.textlyr = new DynLayer(this.name+'TextT') this.textlyr.elm.src = this.url } //bc:else if (is.ie) parent.frames[this.name+'Frame'].document.location = this.url else if (is.ie || is.ns5) parent.frames[this.name+'Frame'].document.location = this.url } function ScrollJumpTo(y) { var by,ty if (y == "top") { by = 0 ty = this.marginT } else if (y=="bottom" && this.ratio>0) { by = this.bar.h-this.box.h ty = -this.ratio*by+this.marginT } else if (y=boxy && y=this.bar.h-boxh/2) this.boxlyr.moveTo(0,this.bar.h-boxh) else this.boxlyr.moveTo(0,y-boxh/2) if (this.box.image1s) this.boxlyr.doc.images[this.name+"BoxImg"].src = this.box.image1.src this.textlyr.moveTo(0,-this.ratio*(this.boxlyr.y)+this.marginT) this.clickYnew = y-this.boxlyr.y this.clickYold = y this.active = true } } function ScrollBarUp() { this.active = false if (this.box.image1s) this.boxlyr.doc.images[this.name+"BoxImg"].src = this.box.image0.src } function ScrollBarMoveStart(e) { //bc:var y = (is.ns)? e.layerY : event.offsetY var y; if (is.ns4) y = e.layerY; else if (is.ie) y = event.offsetY; else if (is.ns5) y = e.layerY; //bc: eval(this.scroll+'.barMove('+y+')') return false } function ScrollBarMove(y) { if (!this.active) return false var diff = y-this.clickYold var boxy = this.boxlyr.y var barh = this.bar.h-this.box.h if (boxy+diff<0 || boxy+diff>barh) { if (boxy+diff<0) this.boxlyr.moveTo(0,0) else this.boxlyr.moveTo(0,barh) this.clickYold = boxy+this.clickYnew } else { this.boxlyr.moveTo(0,y-this.clickYnew) this.clickYold = y } this.textlyr.moveTo(0,-this.ratio*(this.boxlyr.y)+this.marginT) return false } function ScrollArrowDown(dir) { if (this.ratio>0) { this.arrow.active = true if (dir==1 && this.arrow.upimage1s) this.arrowur.doc.images[this.name+"UpImg"].src = this.arrow.upimage1.src if (dir==-1 && this.arrow.dnimage1s) this.arrowdr.doc.images[this.name+"DnImg"].src = this.arrow.dnimage1.src this.arrowSlide(dir) } } function ScrollArrowUp() { if (this.ratio>0) { this.arrow.active = false this.active = false if (this.arrow.upimage1s) this.arrowur.doc.images[this.name+"UpImg"].src = this.arrow.upimage0.src if (this.arrow.dnimage1s) this.arrowdr.doc.images[this.name+"DnImg"].src = this.arrow.dnimage0.src if (this.box.image1s) this.boxlyr.doc.images[this.name+"BoxImg"].src = this.box.image0.src } } function ScrollArrowSlide(dir) { if (this.arrow.active) { if ((dir==1 && this.textlyr.y-(this.textHeight+2*this.border.v+this.marginB-this.h-this.slideInc))) { this.textlyr.moveBy(0,dir*this.slideInc) this.boxlyr.moveTo(0,(this.textlyr.y-this.marginT)/-this.ratio) setTimeout(this.obj+'.arrowSlide('+dir+')',this.slideSpeed) } else { if (dir==1) this.textlyr.moveTo(0,this.marginT) else if (dir==-1) this.textlyr.moveTo(0,-(this.textHeight+2*this.border.v+this.marginB-this.h)) this.boxlyr.moveTo(0,(this.textlyr.y-this.marginT)/-this.ratio) } } } function ScrollWriteContent(doc) { //bc:if (!this.usebuffer && is.ie) { if (!this.usebuffer && (is.ie||is.ns5)) { var str = '' doc.write(str) } } Scroll.count = 0