//»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» //-------------------------------------------------------------------------- // JavaScript Drag Constructor for Objects in Dynamic Html. // // Usage: // Use with Mouse Event Functions: // drag.mouseDown(x,y) // Methods: // add() external: makes object dragable // remove() external: makes object no longer dragable // mouseDown(x,y) internal: if object, this.obj = object, this.active = true, set offsets // mouseMove(x,y) internal: if this.active, this.obj.moveTo(x-offset,y-offset) // mouseUp() internal: this.active = false // within() internal: checks if mouse is pointing at object // Bugs: // None? // Notes: // drag is initialized as new Drag() and is an object of of // type "Drag". Use add() to add objects to the drag object. // Use remove() to remove objects from the drag object. // "drag = new Drag()", this initiaizes drag for use in mouse // constructor as drag.object. //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- ns4 = (document.layers)?1:0 ie4 = (document.all)?1:0 function Drag() { this.obj = null this.array = new Array() this.active = false this.offsetX = 0 this.offsetY = 0 this.zIndex = 0 this.resort = true this.add = drag_add this.remove = drag_remove this.mouseDown = mouse_down this.mouseMove = mouse_move this.mouseUp = mouse_up } drag = new Drag() function drag_add() { for (var i=0; i<arguments.length; i++) { this.array[this.array.length] = arguments[i] this.zIndex += 1 } } function drag_remove() { for (var i=0; i<arguments.length; i++) { for (var j=0; j<this.array.length; j++) { if (this.array[j]==arguments[i]) { for (var k=j;k<=this.array.length-2;k++) this.array[k] = this.array[k+1] this.array[this.array.length-1] = null this.array.length -= 1 break } } } } function mouse_down(x,y) { for (var i=this.array.length-1;i>=0;i--) { var layer = this.array[i] if (within(x,y,layer.x,layer.x+layer.w,layer.y,layer.y+layer.h)) { this.obj = this.array[i] this.offsetX = x-this.obj.x this.offsetY = y-this.obj.y this.active = true break } } if (this.active && this.resort) { this.obj.css.zIndex = this.zIndex++ for (var j=i;j<=this.array.length-2;j++) this.array[j] = this.array[j+1] this.array[this.array.length-1] = this.obj } } function mouse_move(x,y) { if (this.active) this.obj.moveTo(x-this.offsetX,y-this.offsetY) } function mouse_up() { this.active = false } function within(x,y,lf,rt,tp,bt) { if (x>=lf && x<rt && y>=tp && y<bt) return true else return false } //-------------------------------------------------------------------------- // End of JavaScript Object Drag Constructor. //«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« //-------------------------------------------------------------------------- //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» //-------------------------------------------------------------------------- // JavaScript Mouse Event Functions for Dynamic Html. // // Usage: // Internal // Internal Methods: // mouseDown(e) gets (x,y) and allows events // mouseMove(e) gets (x,y) and allows events // mouseUp(e) gets (x,y) and allows events // mouseInit() initializes mouse functions // Bugs: // None? //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- function mouseDown(e) { if ((ns4 && e.which == 1) || ie4) { var x = (ns4)? e.pageX : event.x var y = (ns4)? e.pageY : event.y+document.body.scrollTop drag.mouseDown(x,y) if (drag.active) { return false } else return true } } function mouseMove(e) { var x = (ns4)? e.pageX : event.x var y = (ns4)? e.pageY : event.y+document.body.scrollTop if (drag.active) { drag.mouseMove(x,y) return false } else return true } function mouseUp(e) { var x = (ns4)? e.pageX : event.x var y = (ns4)? e.pageY : event.y+document.body.scrollTop if (drag.active) { drag.mouseUp() return false } else return true } function mouseInit() { document.onmousedown = mouseDown document.onmousemove = mouseMove document.onmouseup = mouseUp if (ns4) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP) } mouseInit(); //-------------------------------------------------------------------------- // End of JavaScript Mouse Event Functions. //««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««