// ScrollBar Object
// experimental scrollbar widget being built for a new Scroll Object
// 19990416
// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynduo/
function ScrollBar(x,y,width,height,boxW,boxH) {
this.name = "ScrollBar"+(ScrollBar.count++)
this.x = x
this.y = y
this.w = width
this.h = height
this.boxW = boxW
this.boxH = boxH
this.offsetHeight = this.h-this.boxH
this.offsetWidth = this.w-this.boxW
this.inc = 10
this.speed = 20
this.active = false
this.obj = this.name+"Object"
eval(this.obj+"=this")
this.dragActive = false
this.build = ScrollBarBuild
this.activate = ScrollBarActivate
this.mousedown = ScrollBarMouseDown
this.mousemove = ScrollBarMouseMove
this.mouseup = ScrollBarMouseUp
this.finishSlide = ScrollBarFinishSlide
this.getXfactor = ScrollBarGetXfactor
this.getYfactor = ScrollBarGetYfactor
this.onScroll = new Function()
this.setImages = ScrollBarSetImages
}
function ScrollBarSetImages(bg,box,dir) {
if (!dir) dir = ''
this.bgImgs = (bg!=null)? true:false
this.bgImg = dir+bg
this.boxImgs = (box!=null)? true:false
this.boxImg = new Image()
this.boxImg.src = dir+box
}
function ScrollBarBuild() {
var bg = this.bgImgs? 'background-image:URL('+this.bgImg+'); layer-background-image:URL('+this.bgImg+'); repeat:yes; ' : ''
var box = this.boxImgs? '' : ''
this.css = css(this.name,this.x,this.y,this.w,this.h,null,null,null,bg)+
css(this.name+'Box',0,0,this.boxW,this.boxH)+
css(this.name+'C',0,0,this.w,this.h)
this.div = '
\n'+
'
'+box+'
\n'+
'
\n'+
'
'
}
function ScrollBarActivate() {
this.lyr = new DynLayer(this.name)
this.boxlyr = new DynLayer(this.name+'Box')
this.boxlyr.slideInit()
this.boxlyr.onSlide = new Function(this.obj+'.onScroll()')
this.lyrc = new DynLayer(this.name+'C')
this.lyrc.elm.scrollbar = this.obj
if (is.ns) this.lyrc.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
this.lyrc.elm.onmousedown = ScrollBarMouseSDown
this.lyrc.elm.onmousemove = ScrollBarMouseSMove
this.lyrc.elm.onmouseup = ScrollBarMouseSUp
this.lyrc.elm.onmouseover = new Function(this.obj+'.active=true')
this.lyrc.elm.onmouseout = new Function(this.obj+'.active=false')
}
function ScrollBarMouseSDown(e) {
var x = (is.ns)? e.layerX : event.offsetX
var y = (is.ns)? e.layerY : event.offsetY
eval(this.scrollbar+'.mousedown('+x+','+y+')')
return false
}
function ScrollBarMouseSMove(e) {
var x = (is.ns)? e.layerX : event.offsetX
var y = (is.ns)? e.layerY : event.offsetY
eval(this.scrollbar+'.mousemove('+x+','+y+')')
return false
}
function ScrollBarMouseSUp(e) {
eval(this.scrollbar+'.mouseup()')
return false
}
function ScrollBarMouseDown(x,y) {
this.mouseIsDown = true
if (x>this.boxlyr.x && x<=this.boxlyr.x+this.boxlyr.w && y>this.boxlyr.y && y<=this.boxlyr.y+this.boxlyr.h) {
this.dragX = x-this.boxlyr.x
this.dragY = y-this.boxlyr.y
this.dragActive = true
}
else if (!this.boxlyr.slideActive) {
newx = x-this.boxW/2
newy = y-this.boxH/2
if (newx<0) newx = 0
if (newx>=this.offsetWidth) newx = this.offsetWidth
if (newy<0) newy = 0
if (newy>=this.offsetHeight) newy = this.offsetHeight
this.boxlyr.slideTo(newx,newy,this.inc,this.speed,this.obj+'.finishSlide()')
}
else {
this.boxlyr.dragActive = true
}
return false
}
function ScrollBarFinishSlide() {
if (this.mouseIsDown) {
this.dragX = this.boxW/2
this.dragY = this.boxH/2
this.dragActive = true
}
}
function ScrollBarMouseMove(x,y) {
if (!this.dragActive || this.boxlyr.slideActive) return
var newx = x-this.dragX
var newy = y-this.dragY
if (x-this.dragX<0) newx = 0
if (x-this.dragX>=this.offsetWidth) newx = this.offsetWidth
if (y-this.dragY<0) newy = 0
if (y-this.dragY>=this.offsetHeight) newy = this.offsetHeight
this.boxlyr.moveTo(newx,newy)
this.onScroll()
}
function ScrollBarMouseUp() {
this.mouseIsDown = false
this.dragActive = false
this.boxlyr.slideActive = false
}
function ScrollBarGetXfactor() {
return 1-(this.offsetWidth-this.boxlyr.x)/this.offsetWidth
}
function ScrollBarGetYfactor() {
return 1-(this.offsetHeight-this.boxlyr.y)/this.offsetHeight
}
ScrollBar.count = 0