//Drag & Drop script for DHTML //Dennie Hoopingarner //September, 1999 //Updated August 27, 2001 the_offset = 100//Global variables for platform branching var isNav, isIE //Global Variables for repositioning var orig_x, orig_y; // Global Variables for referencing var my_name; if (parseInt(navigator.appVersion) >= 4) { if (navigator.appName == "Netscape") { isNav = true; } else { isIE = true; } } // Begin utility functions //set zIndex property function setZIndex(obj, zOrder) { if (obj) { obj.zIndex = zOrder } } //Position an object at a specific pixel coordinate function shiftTo(obj, x, y) { if (isNav) { obj.moveTo(x,y) } else { obj.pixelLeft = x obj.pixelTop = y } } //End utility functions //GLobal holds references to selected element var selectedObj //Globals hold location of click relative4 to selected element var offsetX, offsetY //Find out which element has been clicked on function setSelectedElem(evt) { if (isNav) { var clickX = evt.pageX var clickY = evt.pageY var testObj for (var i = document.layers.length - 1; i >= 0; i--) { testObj = document.layers[i] if ((clickX > testObj.left) && (clickX < testObj.left + testObj.clip.width) && (clickY > testObj.top) && (clickY < testObj.top + testObj.clip.height)) { selectedObj = testObj if (selectedObj) { setZIndex(selectedObj, 100) return } } } } else { // my_name = window.event.srcElement.parentElement.id my_name=window.event.srcElement.id var imgObj = window.event.srcElement selectedObj = imgObj.style if(selectedObj) { setZIndex(selectedObj, 100) return } } selectedObj = null return } // Drag an element function dragIt(evt) { if (selectedObj){ if (isNav) { shiftTo(selectedObj, (evt.pageX - offsetX), (evt.pageY - offsetY)) } else { //if (my_name.substr(0,5) =="float") { shiftTo(selectedObj, (window.event.clientX - offsetX), (window.event.clientY - offsetY)) //} //prevent further system response to dragging return false } } } //Turn selected element on function engage(evt) { setSelectedElem(evt) if (selectedObj) { if (isNav) { offsetX = evt.pageX - selectedObj.left offsetY = evt.pageY - selectedObj.top orig_x = selectedObj.left orig_y = selectedObj.top } else { offsetX = window.event.offsetX offsetY = window.event.offsetY orig_x = selectedObj.pixelLeft orig_y = selectedObj.pixelTop } } //Prevent further processing of MouseDOwn return false } //Turn selected element off // MOUSEUP function release(evt) { setZIndex(selectedObj, 0) // Netscape-Specific Code if (isNav) { if (selectedObj == null) { return } if (selectedObj.id.substr(0,5) == "solid") { selectedObj.left = orig_x selectedObj.top = orig_y } else { dest_left = eval("document.solid" + selectedObj.id.substr(5,2) + ".left") dest_top = eval("document.solid" + selectedObj.id.substr(5,2) + ".top") my_abs_left = Math.abs(dest_left - selectedObj.left) my_abs_top = Math.abs(dest_top - selectedObj.top) if ((my_abs_top <= 30) && (my_abs_left <= 30)) { selectedObj.left = dest_left + the_offset selectedObj.top = dest_top } else { selectedObj.left = orig_x selectedObj.top = orig_y } } // IE-Specific Code }