gibney.org : Technology : Javascript : Experiments : New Mover : Mover08


just a logo :)

search:


See as: raw | code

terms of service | imprint

gibney.org
is powered by m1d1





Mover08
(Entry Nr. 278, by user 70 | edit)
/* www.gibney.org entry nr. 278: Mover */ if ('undefined'==typeof(ge_included)) { ge_included_left2load=0; ge_included=new Object(); ge_included["http://javascript.gibney.org/standards.js"]=true; function ge_require_once(src) { if(ge_included[src]) return; ge_included_left2load++; var sn=document.createElement("script"); sn.onload=function(){ ge_included_left2load--; } sn.onreadystatechange=function(){ if(this.readyState=='loaded' || this.readyState=='complete'){ ge_included_left2load--;this.onreadystatechange=null; } } sn.type="text/javascript"; sn.src=src; document.body.appendChild(sn); var obj=document.body.appendChild(sn); ge_included[src]=true; } function startMain() { if (ge_included_left2load==0) main(); else setTimeout("startMain()",250); } } ge_require_once('http://javascript.gibney.org/dynamic_html_elements.js'); /* Folgende zwei Funktionen entnommen aus 2d.js und modifiziert, sollte man ggf. wieder in die Library integrieren */ /**/ function mg_getElementX(obj) // modifiziert von cm: übergeben wird das Objekt selbst anstatt der id (weil nicht jedes Element zwangsläufig eine hat) { var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft obj = obj.offsetParent; } } else if (obj.x) curleft += obj.x; return curleft; } function mg_getElementY(obj) // modifiziert von cm: übergeben wird das Objekt selbst anstatt der id (weil nicht jedes Element zwangsläufig eine hat) { var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop obj = obj.offsetParent; } } else if (obj.y) curtop += obj.y; return curtop; } /**/ /* -///----------------------------------------- */ function DragAll() { var DragObject = null; var OffsetX = null; var OffsetY = null; var key = null; this.onmousedown=function(e) { if (!e) e=window.event; // bei IE in dieser Objekteigenschaft zu finden DragAllInstance.DragObject = isDOM ? e.target : event.srcElement; /* static -> absolute */ //alert (DragAllInstance.DragObject.style.position); if (DragAllInstance.DragObject.style.position=="static" || DragAllInstance.DragObject.style.position=="") { //alert ("static alarm!"); DragAllInstance.DragObject.style.left=mg_getElementX(DragAllInstance.DragObject); DragAllInstance.DragObject.style.top=mg_getElementY(DragAllInstance.DragObject); DragAllInstance.DragObject.style.position = "absolute"; } /* Cloning */ if (key=="ctrl") { DragObjectClone=DragAllInstance.DragObject.cloneNode(true); // Clone erzeugen DragAllInstance.DragObject.parentNode.appendChild(DragObjectClone); // Clone als Sibling appenden if (DragAllInstance.DragObject.style.position=="relative") { DragObjectClone.style.left=mg_getElementX(DragAllInstance.DragObject); DragObjectClone.style.top=mg_getElementY(DragAllInstance.DragObject); } DragAllInstance.DragObject=DragObjectClone; DragAllInstance.DragObject.style.position = "absolute"; } x=parseInt(DragAllInstance.DragObject.style.left); y=parseInt(DragAllInstance.DragObject.style.top); originalHeight=parseInt(DragAllInstance.DragObject.height); originalWidth=parseInt(DragAllInstance.DragObject.width); //if (originalHeight==null) alert ("originalHeight==null"); if (isNaN(x)) x=0; if (isNaN(y)) y=0; originalFontUnit="%"; originalFontSize=null; // gleichzeitig Flag if (isNaN(originalHeight)) // in diesem Fall wahrscheinlich CDATA, also FontSize ändern { originalFontSize=parseInt(DragAllInstance.DragObject.style.fontSize); if (isNaN(originalFontSize)) // hat keinen Style oder zumindest keine Größe im Style definiert? { originalFontSize="100"; // soll es haben originalFontUnit="%"; DragAllInstance.DragObject.style.fontSize=originalFontSize+originalFontUnit; } } if (isNaN(originalWidth)) originalWidth=1; DragAllInstance.OffsetX = e.clientX-x; DragAllInstance.OffsetY = e.clientY-y; DragStartX=e.clientX DragStartY=e.clientY document.onmousemove = DragAllInstance.onmousemove; document.onmouseup = DragAllInstance.onmouseup; document.onkeydown = DragAllInstance.onkeydown; document.onkeyup = DragAllInstance.onkeyup; return false; } this.onmousemove=function(e) { if (!e) e=window.event; // bei IE in dieser Objekteigenschaft zu finden if (key=="shift") /* scaling */ { if (originalFontSize==null) // current element is non-CDATA { DragAllInstance.DragObject.style.height=Math.max(originalHeight+(e.clientY-DragStartY),1)+"px"; DragAllInstance.DragObject.style.width=Math.max(originalWidth+(e.clientX-DragStartX),1)+"px"; } else { DragAllInstance.DragObject.style.fontSize=Math.max(originalFontSize+(e.clientY-DragStartY),1)+originalFontUnit; } } else // ordinary mode (move) { DragAllInstance.DragObject.style.left = e.clientX-DragAllInstance.OffsetX; DragAllInstance.DragObject.style.top = e.clientY-DragAllInstance.OffsetY; } return false; } this.onmouseup=function(e) { document.onmousemove = null; document.onmouseup = null; DragAllInstance.DragObject = null; return (DragStartX==e.clientX&&DragStartY==e.clientY); // Nur bei Klick ohne Drag wird ein Anchor ausgeführt } this.onclick=function(e) { if (!e) e=window.event; // bei IE in dieser Objekteigenschaft zu finden return (DragStartX==e.clientX&&DragStartY==e.clientY); // Nur bei Klick ohne Drag wird ein Anchor ausgeführt } this.onkeydown=function(e) { if (!e) e=window.event; if (e.which) code=e.which; else code=e.keyCode; code==16 ? key="shift" : code==17 ? key="ctrl" : key=null } this.onkeyup=function(e) { key = null; } } function main() { DragAllInstance=new DragAll(); document.onmousedown=DragAllInstance.onmousedown; document.onclick=DragAllInstance.onclick; message=createDiv('cm1',10,10,'
The Mover V0.8 is active.
You can drag and drop anything now.
Hold SHIFT to size elements.
Hold CTRL to clone elements.
'); message.style.zIndex=9999; } var isDOM=document.getElementById&&!document.all; startMain();
Create a new entry at this position