home *** CD-ROM | disk | FTP | other *** search
- /// Drag&Drop System
-
- var dragobj;
-
- function m_down(event, object)
- {
-
-
- dragobj = object;
-
- dragobj.style.zIndex = "100";
- if(!dragobj.style.left) dragobj.style.left = "0px";
- if(!dragobj.style.top) dragobj.style.top = "0px";
-
- // Zapamatuj pozici mysi pri klintuti
- dragobj.clickX = event.clientX;
- dragobj.clickY = event.clientY;
-
- // Zapamatuj pozici objektu pri klintuti
- dragobj.left = parseInt(dragobj.style.left);
- dragobj.top = parseInt(dragobj.style.top);
-
-
- // Zacni sledovat pohyb mysi
- if(IE)
- {
- document.attachEvent('onmousemove', m_move);
- document.attachEvent('onmouseup', m_up);
- }
-
- if(NS || OPERA)
- {
- document.addEventListener('mousemove', m_move, true);
- document.addEventListener('mouseup', m_up, true);
- }
-
- return stopEvent(event);
- }
-
-
- function m_move(event)
- {
- // Spocti rozdil mezi puvodni pozici mysi pri stisku a nynejsi pozici a zavolej proceduru objektu pro presun
- dragobj.ondragdrop(event.clientX-dragobj.clickX,event.clientY-dragobj.clickY, event);
- return stopEvent(event);
- }
-
- function m_up(event)
- {
- // Ukonci sledovani mysi
- if(IE)
- {
- document.detachEvent('onmousemove', m_move);
- document.detachEvent('onmouseup', m_up);
- if(dragobj.ondragend)dragobj.ondragend(event);
- }
-
- if(NS || OPERA)
- {
- document.removeEventListener('mousemove', m_move, true);
- document.removeEventListener('mouseup', m_up, true);
- if(dragobj.ondragend)dragobj.ondragend(event);
- }
-
- return stopEvent(event);
- }
-
-
- // Prirad objektu moznost presunu
- function startDrag(what)
- {
- if(what.style.position!="relative" && what.style.position!="absolute") {what.style.position="relative";}
- what.onmousedown = function(e) {if(e) {event=e;} m_down(event,what);}
- what.drag = 1;
- }
-
- // Odeber objektu moznost presunu
- function stopDrag(what)
- {
- what.onmousedown = null;
- what.drag = 0;
- }
-
- // Zastav sireni udalosti
- function stopEvent(event)
- {
- if(IE) {event.cancelBubble = true; return false;}
- if(NS || OPERA) {event.stopPropagation(); event.preventDefault(); return false;}
- }
-
-