User:Zocky/Draglets.js

/* Draglets for Mediawiki HTML/CSS draggable popup windows (c)2005 en:User:Zocky Released under GPL

/*

Includes
document.write(' ');

document.write('');

// DRAGLETS

var dragletTop=100;

// Create new draglet function dragletNew(title,x,y,width) { dragletTop++; id = "draglet_" + dragletTop;

var w = width ? width + 'px' : 'auto'; var p; if (window.addEventListener) {   p = 'fixed' }  else {   p = 'absolute'; y+= document.documentElement.scrollTop; x+= document.documentElement.scrollLeft; }

dragletCode = '' +  '' +    '[×] ' +    ''+title+' ' +  ' '  +   ' ' + ' ';

new Insertion.Bottom($('globalWrapper'),dragletCode); Event.observe($(id+'_titlebar'),'mousedown',dragletPick, false); Event.observe($(id+'_titlebar'),'click',dragletClick, false); return (id); }

//Close draglet function dragletClose(id) { $('globalWrapper').removeChild($(id)); }

// drag and drop var dragletMouseX = 0; var dragletMouseY = 0; var dragletStartX = 0; var dragletStartY = 0; var dragletActive;

function dragletClick(e) { dragletActive && Event.stop(e); }

function dragletPick(e) { dragletActive = Event.findElementByClass(e,'draglet'); dragletTop++; dragletActive.style.zIndex = dragletTop; dragletMouseX = Event.pointerX(e); dragletMouseY = Event.pointerY(e); dragletStartX = parseInt(dragletActive.style.left); dragletStartY = parseInt(dragletActive.style.top);

Event.observe(document,"mousemove", dragletDrag, false); Event.observe(document,"mouseup", dragletDrop, false); Event.stop(e); }

function dragletDrag(e) { dragletActive.style.left = (Event.pointerX(e) - dragletMouseX + dragletStartX) + "px"; dragletActive.style.top = (Event.pointerY(e) - dragletMouseY + dragletStartY) + "px"; Event.stop(e); }

function dragletDrop(e) { Event.stopObserving(document,"mousemove", dragletDrag, false); Event.stopObserving(document,"mouseup", dragletDrop, false); dragletActive=null; Event.stop(e); }