head 1.2; access; symbols; locks; strict; comment @# @; 1.2 date 2004.10.08.02.41.32; author aredridel; state Exp; branches; next 1.1; 1.1 date 2002.07.23.19.40.35; author aredridel; state Exp; branches; next ; desc @Code to drag divs around @ 1.2 log @fixed delete @ text @/* var debugWindow; function debugConsole() { debugWindow = window.open("","debugWin","toolbar=no,scrollbar=yes,width=300,height=400"); } function wdebug(msg) { debugWindow.document.writeln(msg+"
"); } //*/ var which; var ie = document.all ? 1 : 0 ; function doDrag(e) { /* Calculates the difference from the last stored * position to the current position. */ if(ie) { e = window.event; } var difX=e.clientX-window.lastX; var difY=e.clientY-window.lastY; // Retrieves the X and Y position of editcanvas. if(!ie) { var oldX = parseInt(which.style.getPropertyValue("left")); var oldY = parseInt(which.style.getPropertyValue("top")); } else { var oldX = parseInt(which.style.pixelLeft); var oldY = parseInt(which.style.pixelTop); } var newX = oldX+difX; var newY = oldY+difY; // Sets the new position for the div element. if(!ie) { which.style.left=newX+"px"; which.style.top=newY+"px"; } else { which.style.pixelLeft=newX; which.style.pixelTop=newY; } // Stores the current mouse position as last position. window.lastX=e.clientX; window.lastY=e.clientY; } // When drag begins, this function is called. function beginDrag(e) { if(!ie) { which = e.currentTarget; } else { which = window.event.srcElement; e = window.event; } if(which.className == 'element') which.style.backgroundColor = '#f88' // Store the current mouse position window.lastX=e.clientX; window.lastY=e.clientY; // Temporarily register event handlers if(!ie) { window.addEventListener("mousemove",doDrag,false); window.addEventListener("mouseup",endDrag,false); } else { document.onmousemove = doDrag; document.onmouseup = endDrag; } } // Called when the mouse button is released. function endDrag(e) { if(which.className == 'element') which.style.backgroundColor = '#fff'; // Release doDrag event handler assignment. if(!ie) { window.removeEventListener("mousemove",doDrag,false); window.removeEventListener("mouseup",doDrag,false); } else { document.onmousemove = null; document.onmouseup = null; } } function saveData() { elements = document.getElementsByTagName("div"); bucket = document.getElementById("data"); for(i = 0; i < elements.length; i++) { with(elements[i]) { if(className == "element" && innerHTML) { bucket.setAttribute("value", bucket.getAttribute("value")+innerHTML+"\t"+style.left+"\t"+style.top+"\n"); } } } } function mouseDown(e) { if(e.shiftKey) { if(!ie) { e.target.addEventListener("mouseup", showMenu, false); } else { e.srcElement.onmouseup = showMenuIE; } } else { beginDrag(e); } } function mouseDownIE() { mouseDown(window.event); } function showMenuIE() { with(window.event) { srcElement.onmouseup = null; srcElement.parentNode.removeChild(srcElement); } } function showMenu(e) { e.target.parentNode.removeChild(e.target); } function unselectAll() { document.selection.empty(); } function start() { /* Add event handler to all top-level nodes */ elements = document.getElementsByTagName("div"); if(!ie) { for(i = 0; i < elements.length; i++) { if(elements[i].className == "element") { elements[i].addEventListener("mousedown", mouseDown, false); } } document.getElementById("save").addEventListener("click", saveData, false); } else { document.getElementById("save").onclick = saveData; document.onmousedown = mouseDownIE; document.onselectionchange = unselectAll; } } @ 1.1 log @Initial revision @ text @d94 1 a94 2 for(i = 0; i < elements.length; i++) { d127 1 a127 1 e.target.parentNode.parentNode.removeChild(e.target.parentNode); @