/* Notes default: top, left (0,0); requires width and height of viewable text area text area is sized to account for a scrollbar so -- we have the scrollbar region and the text region -- they always touch */ var _scroller_uniqueID = 0; document.currentScrollArea = null; function ScrollArea(w, h) { this.top = 0; this.left = 0; this.width = w; this.height = h; this.topInset = 0; this.leftInset = 2; this.rightInset = 2; this.scrollbarWidth = 23; this.scrollUpHeight = 24; this.scrollDnHeight = 25; this.scrollThumbHeight = 16; this.scrollTrackHeight = 1; this.scrollUpImage = ""; this.scrollDnImage = ""; this.scrollTrackImage = ""; this.scrollThumbImage = ""; this.scrollUpImageActive = ""; this.scrollDnImageActive = ""; this.doc = null; this.container = null; this.scrollRgn = null; this.trackRange = this.height - this.scrollUpHeight - this.scrollDnHeight - this.scrollThumbHeight; this.trackStart = this.scrollUpHeight; this.documentRange = 0; // offsetHeight - this.height; this.trackDirection = 0; this.trackOffset = 1; this.hitLocation = 0; this.hitOffset = 0; this.thumbMarker = 0; this.util = 0; this.override = false; this.useHeight = 0; this.actionTimer = null; this.holderDiv = null; this.changeText = function(srcTxt) { this.doc.innerHTML = srcTxt; this.useHeight = (arguments.length > 1) ? arguments[1] : this.doc.offsetHeight; if(/*this.doc.offsetHeight*/ this.useHeight < this.height) // if(this.container.offsetHeight < this.height) this.disableRgn.style.visibility = "inherit"; else this.disableRgn.style.visibility = "hidden"; } this.setStyle = function(attr, val) { with(this.doc.style) { eval(attr + " = '" + val + "'"); } } this.setTopLeft = function(t, l) { this.container.style.top = t; this.container.style.left = l; } this.setBackgroundColor = function(c) { this.container.style.backgroundColor = c; } this.setTextColor = function(c) { this.doc.style.color = c; } this.setBorder = function(borderAttr) { this.container.style.border = borderAttr; } this.handleButtonHit = function(evt) { if(evt) alert(evt.type + ": " + evt.target.name); else alert(window.event.type + ": " + window.event.srcElement.name); } // this.killAction = function(evt) { var e = document.all ? window.event : evt; var sa = document.all ? e.srcElement.owner : e.target.owner; if(sa.actionTimer != null) clearTimeout(sa.actionTimer); sa.actionTimer = null; if(sa.util == 1) { sa.scrollUp.style.backgroundImage = "url(" + sa.scrollUpImage + ")"; } if(sa.util == -1) { sa.scrollDn.style.backgroundImage = "url(" + sa.scrollDnImage + ")"; } sa.util = 0; } this.upAction = function(evt) { var e = document.all ? window.event : evt; var sa = document.all ? e.srcElement.owner : e.target.owner; var th = sa.scrollThumb; sa.util = 1; sa.scrollUp.style.backgroundImage = "url(" + sa.scrollUpImageActive + ")"; sa.documentRange = sa.useHeight/*doc.offsetHeight*/ - sa.height; document.currentScrollArea = sa; sa.trackDirection = -1; sa.moveAction(); return false; } this.moveAction = function() { var o = document.currentScrollArea; var dir = o.trackDirection; var th = o.scrollThumb; var newy = th.offsetTop + dir * 12; if(newy < o.trackStart) newy = o.trackStart; if(newy > o.trackStart + o.trackRange) newy = o.trackStart + o.trackRange; th.style.top = newy; o.doc.style.top = -Math.round(o.documentRange * (newy-o.trackStart)/o.trackRange); o.actionTimer = setTimeout( "document.currentScrollArea.moveAction()", 50); } this.dnAction = function(evt) { var e = document.all ? window.event : evt; var sa = document.all ? e.srcElement.owner : e.target.owner; var th = sa.scrollThumb; sa.util = -1; sa.scrollDn.style.backgroundImage = "url(" + sa.scrollDnImageActive + ")"; sa.documentRange = sa.useHeight/*doc.offsetHeight*/ - sa.height; document.currentScrollArea = sa; sa.trackDirection = 1; sa.moveAction(); return false; } /* grab page global coordinates -- calculate offset */ this.thumbAction = function(evt) { var e = document.all ? window.event : evt; var sa = document.all ? e.srcElement.owner : e.target.owner; var pt_y = document.all ? e.y : e.layerY; document.currentScrollArea = sa; sa.hitLocation = e.clientY; // good for IE5+/NN6+ sa.hitOffset = pt_y; sa.thumbMarker = sa.scrollThumb.offsetTop; sa.documentRange = sa.useHeight/*doc.offsetHeight*/ - sa.height; sa.storeMouseMove = document.onmousemove; sa.storeMouseUp = document.onmouseup; document.onmousemove = sa.handleDrag; document.onmouseup = function() { document.onmousemove = document.currentScrollArea.storeMouseMove; document.onmouseup = document.currentScrollArea.storeMouseUp; }; //showObj(e); return false; } this.handleDrag = function(evt) { var e = document.all ? window.event : evt; var sa = document.currentScrollArea; var th = sa.scrollThumb; var offset = sa.hitLocation - e.clientY; //window.status = sa.thumbMarker - offset; var set = sa.thumbMarker - offset; if(set < sa.trackStart) set = sa.trackStart; if(set > sa.trackRange + sa.trackStart) set = sa.trackRange + sa.trackStart; sa.scrollThumb.style.top = set; sa.doc.style.top = -Math.round(sa.documentRange * (set - sa.trackStart)/sa.trackRange); // window.status = window.defaultStatus = (document.all ? e.clientY : e.clientY) + " : " + (document.all ? e.srcElement.name : e.target.name); } this.trackAction = function(evt) { var e = document.all ? window.event : evt; var tr = document.all ? e.srcElement : e.target; var sa = tr.owner; var th = sa.scrollThumb; var pt_y = document.all ? e.offsetY : e.layerY; var pt_x = document.all ? e.offsetX : e.layerX; document.currentScrollArea = sa; sa.documentRange = sa.useHeight/*doc.offsetHeight*/ - sa.height; sa.trackOffset = Math.ceil(sa.documentRange * 0.1); sa.hitLocation = pt_y; if( pt_y > th.offsetTop - sa.scrollUpHeight ) sa.trackDirection = 1; if( pt_y < th.offsetTop - sa.scrollUpHeight ) sa.trackDirection = -1; sa.moveAction_trk(evt); return false; } this.moveAction_trk = function(evt) { var o = document.currentScrollArea; var e = document.all ? window.event : evt; var dir = o.trackDirection; var th = o.scrollThumb; //if(e) { var newy = th.offsetTop + dir*o.trackOffset; // relative to scrollrgn var loc = o.hitLocation; // relative to track! if(dir < 0 && newy < loc + o.trackStart) newy = loc + o.trackStart; if(dir > 0 && newy > loc + o.trackStart - o.scrollThumbHeight/*+ o.trackRange*/) newy = loc + o.trackStart - o.scrollThumbHeight/*+ o.trackRange*/; th.style.top = newy; o.doc.style.top = -Math.round(o.documentRange * (newy-o.trackStart)/o.trackRange); } o.actionTimer = setTimeout( "document.currentScrollArea.moveAction_trk()", 50); } // -------end experimentals - this.setScrollImage = function(part, src) { part = part.toLowerCase(); var the_part = ""; if(part.indexOf("act") != -1 && part.indexOf("u") != -1) the_part = "uh"; else if(part.indexOf("act") != -1 && part.indexOf("d") != -1) the_part = "dh"; else if(part.indexOf("up") != -1) the_part = "up"; else if(part.indexOf("d") != -1) the_part = "dn"; else if(part.indexOf("th") != -1) the_part = "th"; else if(part.indexOf("tr") != -1) the_part = "tr"; switch(the_part) { case "up" : this.scrollUpImage = src; break; case "dn" : this.scrollDnImage = src; break; case "th" : this.scrollThumbImage = src; break; case "tr" : this.scrollTrackImage = src; break; case "uh" : this.scrollUpImageActive = src; break; case "dh" : this.scrollDnImageActive = src; break; } } this.destroy = function() { // alert(this.container.id); // showObj(document.getElementById(this.container.id)); if(this.actionTimer != null) clearTimeout(this.actionTimer); if(this.holderDiv != null) { var theNode = this.holderDiv.removeNode(true); theNode = null; } //var oDiv = document.getElementById(this.container.id).removeNode(false); // showObj(oDiv); } this.create = function(parent) { var ref = this; // callback into ScrollArea this.container = document.createElement("DIV"); this.container.owner = this; this.container.id = "__scrollarea_" + _scroller_uniqueID++; with(this.container.style) { position = "absolute"; top = ref.top; left = ref.left; width = ref.width; height = ref.height; visibility = "hidden"; overflow = "hidden"; } this.doc = document.createElement("DIV"); this.doc.owner = this; this.doc.id = "doc"; with (this.doc.style) { position = "absolute"; top = ref.topInset; left = ref.leftInset; width = ref.width - ref.leftInset - ref.rightInset - ref.scrollbarWidth; height = "auto"; visibility = "inherit"; fontSize = "10px"; fontFamily = "Verdana"; } // god damn internet explorer!!! document.onselectstart = this.doc.onselectstart = function() { return false; } document.onmousedown = this.doc.onmousedown = function() { return false; } document.onfocus = this.doc.onfocus = function() { return false; } document.ondblclick = this.doc.ondblclick = function() { return false; } document.ondragstart = this.doc.ondragstart = function() {return false; } document.onactivate = this.doc.onactivate = function() { return false; } this.container.appendChild(this.doc); this.scrollRgn = document.createElement("DIV"); this.scrollRgn.owner = this; with(this.scrollRgn.style) { position = "absolute"; top = ref.topInset; left = ref.width - ref.scrollbarWidth; width = ref.scrollbarWidth; height = ref.height - 2 * ref.topInset; backgroundImage = "url(" + ref.scrollTrackImage + ")"; visibility = "inherit"; } // ------------ add scroll components this.scrollUp = document.createElement("DIV"); this.scrollUp.name = "upButton"; this.scrollUp.owner = this; with(this.scrollUp.style) { position = "absolute"; top = 0; left = 0; width = ref.scrollbarWidth; height = ref.scrollUpHeight; visibility = "inherit"; backgroundImage = "url(" + ref.scrollUpImage + ")"; } this.scrollUp.onmousedown = ref.upAction; //function() { alert("Up button"); } this.scrollUp.onmouseup = ref.killAction; this.scrollRgn.appendChild(this.scrollUp); this.scrollDn = document.createElement("DIV"); this.scrollDn.name = "dnButton"; this.scrollDn.owner = this; with(this.scrollDn.style) { position = "absolute"; top = ref.height - ref.scrollDnHeight; left = 0; width = ref.scrollbarWidth; height = ref.scrollUpHeight; visibility = "inherit"; backgroundImage = "url(" + ref.scrollDnImage + ")"; } this.scrollDn.onmousedown = ref.dnAction; //function() { alert("Down button"); } this.scrollDn.onmouseup = ref.killAction; this.scrollRgn.appendChild(this.scrollDn); this.scrollTrack = document.createElement("DIV"); this.scrollTrack.name = "track"; this.scrollTrack.owner = this; with(this.scrollTrack.style) { position = "absolute"; top = ref.trackStart; left = 0; width = ref.scrollbarWidth; height = ref.height - ref.scrollUpHeight - ref.scrollDnHeight; visibility = "inherit"; } this.scrollTrack.onmousedown = ref.trackAction; //function() { alert("Track"); } this.scrollTrack.onmouseup = ref.killAction; this.scrollRgn.appendChild(this.scrollTrack); this.scrollThumb = document.createElement("DIV"); this.scrollThumb.name = "thumb"; this.scrollThumb.owner = this; with(this.scrollThumb.style) { position = "absolute"; top = ref.trackStart; left = 0; width = ref.scrollbarWidth; height = ref.scrollThumbHeight; visibility = "inherit"; backgroundImage = "url(" + ref.scrollThumbImage + ")"; } this.scrollThumb.onmousedown = ref.thumbAction; //function() { alert("Thumb button"); } this.scrollThumb.onmouseup = ref.killAction; this.scrollRgn.appendChild(this.scrollThumb); this.disableRgn = document.createElement("DIV"); this.disableRgn.owner = this; with(this.disableRgn.style) { position = "absolute"; top = 0; left = 1; width = ref.scrollbarWidth-2; height = ref.height - 2 * ref.topInset; backgroundImage = "url(scrollbar/fadeout.gif)"; border = "1px solid white"; visibility = "hidden"; } this.scrollRgn.appendChild(this.disableRgn); // ------------- end add scroll components this.container.appendChild(this.scrollRgn); if(parent) { parent.appendChild(this.container); } else document.body.appendChild(this.container); } this.show = function() { this.container.style.visibility = "visible"; } this.hide = function() { this.container.style.visibility = "hidden"; } }