li{
MARGIN-BOTTOM:10px
}
ul{
MARGIN-TOP:5px
}
.DragContainer{
BORDER-RIGHT:#6699992pxsolid;PADDING-RIGHT:5px;BORDER-TOP:#6699992pxsolid;PADDING-LEFT:5px;FLOAT:left;PADDING-BOTTOM:0px;MARGIN:3px;BORDER-LEFT:#6699992pxsolid;WIDTH:100px;PADDING-TOP:5px;BORDER-BOTTOM:#6699992pxsolid
}
.OverDragContainer{
BORDER-RIGHT:#6699992pxsolid;PADDING-RIGHT:5px;BORDER-TOP:#6699992pxsolid;PADDING-LEFT:5px;FLOAT:left;PADDING-BOTTOM:0px;MARGIN:3px;BORDER-LEFT:#6699992pxsolid;WIDTH:100px;PADDING-TOP:5px;BORDER-BOTTOM:#6699992pxsolid
}
.OverDragContainer{
BACKGROUND-COLOR:#eee
}
.DragBox{
BORDER-RIGHT:#0001pxsolid;PADDING-RIGHT:2px;BORDER-TOP:#0001pxsolid;PADDING-LEFT:2px;FONT-SIZE:10px;MARGIN-BOTTOM:5px;PADDING-BOTTOM:2px;BORDER-LEFT:#0001pxsolid;WIDTH:94px;CURSOR:pointer;PADDING-TOP:2px;BORDER-BOTTOM:#0001pxsolid;FONT-FAMILY:verdana,tahoma,arial;BACKGROUND-COLOR:#eee
}
.OverDragBox{
BORDER-RIGHT:#0001pxsolid;PADDING-RIGHT:2px;BORDER-TOP:#0001pxsolid;PADDING-LEFT:2px;FONT-SIZE:10px;MARGIN-BOTTOM:5px;PADDING-BOTTOM:2px;BORDER-LEFT:#0001pxsolid;WIDTH:94px;CURSOR:pointer;PADDING-TOP:2px;BORDER-BOTTOM:#0001pxsolid;FONT-FAMILY:verdana,tahoma,arial;BACKGROUND-COLOR:#eee
}
.DragDragBox{
BORDER-RIGHT:#0001pxsolid;PADDING-RIGHT:2px;BORDER-TOP:#0001pxsolid;PADDING-LEFT:2px;FONT-SIZE:10px;MARGIN-BOTTOM:5px;PADDING-BOTTOM:2px;BORDER-LEFT:#0001pxsolid;WIDTH:94px;CURSOR:pointer;PADDING-TOP:2px;BORDER-BOTTOM:#0001pxsolid;FONT-FAMILY:verdana,tahoma,arial;BACKGROUND-COLOR:#eee
}
.miniDragBox{
BORDER-RIGHT:#0001pxsolid;PADDING-RIGHT:2px;BORDER-TOP:#0001pxsolid;PADDING-LEFT:2px;FONT-SIZE:10px;MARGIN-BOTTOM:5px;PADDING-BOTTOM:2px;BORDER-LEFT:#0001pxsolid;WIDTH:94px;CURSOR:pointer;PADDING-TOP:2px;BORDER-BOTTOM:#0001pxsolid;FONT-FAMILY:verdana,tahoma,arial;BACKGROUND-COLOR:#eee
}
.OverDragBox{
BACKGROUND-COLOR:#ffff99
}
.DragDragBox{
BACKGROUND-COLOR:#ffff99
}
.DragDragBox{
FILTER:alpha(opacity=50);BACKGROUND-COLOR:#ff99cc
}
LEGEND{
FONT-WEIGHT:bold;FONT-SIZE:12px;COLOR:#666699;FONT-FAMILY:verdana,tahoma,arial
}
FIELDSET{
PADDING-RIGHT:3px;PADDING-LEFT:3px;PADDING-BOTTOM:3px;PADDING-TOP:3px
}
.History{
FONT-SIZE:10px;OVERFLOW:auto;WIDTH:100%;FONT-FAMILY:verdana,tahoma,arial;HEIGHT:82px
}
#DragContainer8{
BORDER-RIGHT:#6699991pxsolid;PADDING-RIGHT:0px;BORDER-TOP:#6699991pxsolid;PADDING-LEFT:5px;PADDING-BOTTOM:0px;BORDER-LEFT:#6699991pxsolid;WIDTH:110px;PADDING-TOP:5px;BORDER-BOTTOM:#6699991pxsolid;HEIGHT:110px
}
.miniDragBox{
FLOAT:left;MARGIN:0px5px5px0px;WIDTH:20px;HEIGHT:20px
}
pre{border:1solid#CCC;background-color:#F8F8F0;padding:10px;}
//iMouseDownrepresentsthecurrentmousebuttonstate:upordown
/*
lMouseStaterepresentsthepreviousmousebuttonstatesothatwecan
checkforbuttonclicksandbuttonreleases:
if(iMouseDown&&!lMouseState)//buttonjustclicked!
if(!iMouseDown&&lMouseState)//buttonjustreleased!
*/
varmouseOffset=null;
variMouseDown=false;
varlMouseState=false;
vardragObject=null;
//Demo0variables
varDragDrops=[];
varcurTarget=null;
varlastTarget=null;
vardragHelper=null;
vartempDiv=null;
varrootParent=null;
varrootSibling=null;
Number.prototype.NaN0=function(){returnisNaN(this)?0:this;}
functionCreateDragContainer(){
/*
Createanew"ContainerInstance"sothatitemsfromone"Set"cannot
bedraggedintoitemsfromanother"Set"
*/
varcDrag=DragDrops.length;
DragDrops[cDrag]=[];
/*
Eachitempassedtothisfunctionshouldbea"container".Storeeach
oftheseitemsinourcurrentcontainer
*/
for(vari=0;i
DragDrops[cDrag].push(cObj);
cObj.setAttribute('DropObj',cDrag);
/* //Firefoxputsinlotsof#textnodes...skipthese cObj.childNodes[j].setAttribute('DragObj',cDrag); functionmouseCoords(ev){ functiongetMouseOffset(target,ev){ vardocPos=getPosition(target); functiongetPosition(e){ left+=e.offsetLeft+(e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0); return{x:left,y:top}; } functionmouseMove(ev){ /* Firefoxusesevent.targethere,MSIEusesevent.srcElement //mouseOutevent-firesiftheitemthemouseisonhaschanged /* //ifthemousewasmovedoveranelementthatisdraggable //mouseOverevent-Changetheitem'sclassifnecessary //iftheuserisjuststartingtodragtheelement //Recordthemousexandyoffsetfortheelement mouseOffset=getMouseOffset(target,ev); //WeremoveanythingthatisinourdragHelperDIVsowecanputanewiteminit. //Makeacopyofthecurrentitemandputitinourdraghelper. //settheclassonourhelperDIVifnecessary //disabledraggingfromourhelperDIV(it'salreadybeingdragged) /* /* //loopthrougheachpossibledropcontainer /* Eventhoughwearesavingthewidthandheightofeach Notethatthebiggestperformancegainhere,byfar,comes //loopthrougheachchildelementofeachcontainer varpos=getPosition(dragConts[i].childNodes[j]); //savethewidth,heightandpositionofeachelement //Ifwegetinherewearedraggingsomething vardragConts=DragDrops[curTarget.getAttribute('DragObj')]; varxPos=mousePos.x-mouseOffset.x+(parseInt(curTarget.getAttribute('startWidth'))/2); //checkeachdropcontainertoseeifourtargetobjectis"inside"thecontainer /* //exittheforloop //Ourtargetobjectisinoneofourcontainers.Checktoseewhereourdivbelongs //loopthrougheachchildnode(skippingtextnodes). //ifthecurrentitemis"After"theitembeingdragged //theitembeingdraggedbelongsbeforeanotheritem //theitembeingdraggedbelongsattheendofthecurrentcontainer //makeourdragitemvisible //ourdragitemisnotinacontainer,sohideit. //trackthecurrentmousestatesowecancompareagainstitnexttime //mouseMovetarget //trackthecurrentmousestatesowecancompareagainstitnexttime //thishelpspreventitemsonthepagefrombeinghighlightedwhiledragging functionmouseUp(ev){ //ifthedragitemisinvisibleputitbackwhereitwasbeforemovingit //makesurethedragitemisvisible functionmouseDown(){ document.onmousemove=mouseMove; window.onload=function(){ CreateDragContainer( document.body.appendChild(dragHelper);
Everytopleveliteminthesecontainersshouldbedraggable.Dothis
bysettingtheDragObjattributeoneachitemandthenlaterchecking
thisattributeinthemouseMovefunction
*/
for(varj=0;j
if(cObj.childNodes[j].nodeName=='#text')continue;
}
}
}
if(ev.pageX||ev.pageY){
return{x:ev.pageX,y:ev.pageY};
}
return{
x:ev.clientX+document.body.scrollLeft-document.body.clientLeft,
y:ev.clientY+document.body.scrollTop-document.body.clientTop
};
}
ev=ev||window.event;
varmousePos=mouseCoords(ev);
return{x:mousePos.x-docPos.x,y:mousePos.y-docPos.y};
}
varleft=0;
vartop=0;
while(e.offsetParent){
left+=e.offsetLeft+(e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
top+=e.offsetTop+(e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
e=e.offsetParent;
}
top+=e.offsetTop+(e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
ev=ev||window.event;
Wearesettingtargettowhateveritemthemouseiscurrentlyon
*/
vartarget=ev.target||ev.srcElement;
varmousePos=mouseCoords(ev);
if(lastTarget&&(target!==lastTarget)){
//resettheclassnameforthetargetelement
varorigClass=lastTarget.getAttribute('origClass');
if(origClass)lastTarget.className=origClass;
}
dragObjisthegroupingouritemisin(setfromthecreateDragContainerfunction).
iftheitemisnotinagroupingweignoreitsinceitcan'tbedraggedwiththis
script.
*/
vardragObj=target.getAttribute('DragObj');
if(dragObj!=null){
if(target!=lastTarget){
varoClass=target.getAttribute('overClass');
if(oClass){
target.setAttribute('origClass',target.className);
target.className=oClass;
}
}
if(iMouseDown&&!lMouseState){
//mouseDowntarget
curTarget=target;
rootParent=curTarget.parentNode;
rootSibling=curTarget.nextSibling;
for(vari=0;i
dragHelper.appendChild(curTarget.cloneNode(true));
dragHelper.style.display='block';
vardragClass=curTarget.getAttribute('dragClass');
if(dragClass){
dragHelper.firstChild.className=dragClass;
}
dragHelper.firstChild.removeAttribute('DragObj');
Recordthecurrentpositionofalldrag/droptargetsrelated
totheelement.Wedothisheresothatwedonothavetodo
itonthegeneralmousemoveeventwhichfireswhenthemouse
moveseven1pixel.Ifwedon'tdothisherethescript
wouldrunmuchslower.
*/
vardragConts=DragDrops[dragObj];
firstrecordthewidth/heightofourdragitem.Thenhideitsince
itisgoingto(potentially)bemovedoutofitsparent.
*/
curTarget.setAttribute('startWidth',parseInt(curTarget.offsetWidth));
curTarget.setAttribute('startHeight',parseInt(curTarget.offsetHeight));
curTarget.style.display='none';
for(vari=0;i
varpos=getPosition(dragConts[i]);
savethewidth,heightandpositionofeachcontainer.
containerbacktothecontainerthisismuchfasterbecause
wearesavingthenumberanddonothavetorunthrough
anycalculationsagain.Also,offsetHeightandoffsetWidth
arebothfairlyslow.Youwouldnevernormallynoticeany
performancehitfromthesetwofunctionsbutourcodeis
goingtoberunninghundredsoftimeseachsecondsoevery
littlebithelps!
fromnothavingtorunthroughthegetPositionfunction
hundredsoftimes.
*/
setAttribute('startWidth',parseInt(offsetWidth));
setAttribute('startHeight',parseInt(offsetHeight));
setAttribute('startLeft',pos.x);
setAttribute('startTop',pos.y);
}
for(varj=0;j
if((nodeName=='#text')||(dragConts[i].childNodes[j]==curTarget))continue;
setAttribute('startWidth',parseInt(offsetWidth));
setAttribute('startHeight',parseInt(offsetHeight));
setAttribute('startLeft',pos.x);
setAttribute('startTop',pos.y);
}
}
}
}
}
if(curTarget){
//moveourhelperdivtowhereverthemouseis(adjustedbymouseOffset)
dragHelper.style.top=mousePos.y-mouseOffset.y;
dragHelper.style.left=mousePos.x-mouseOffset.x;
varactiveCont=null;
varyPos=mousePos.y-mouseOffset.y+(parseInt(curTarget.getAttribute('startHeight'))/2);
for(vari=0;i
if(((getAttribute('startLeft'))
((getAttribute('startTop')+getAttribute('startHeight'))>yPos)){
ourtargetisinsideofourcontainersosavethecontainerinto
theactiveContvariableandthenexittheloopsincewenolonger
needtochecktherestofthecontainers
*/
activeCont=dragConts[i];
break;
}
}
}
if(activeCont){
//beforeNodewillholdthefirstnodeAFTERwhereourdivbelongs
varbeforeNode=null;
for(vari=activeCont.childNodes.length-1;i>=0;i--){
with(activeCont.childNodes[i]){
if(nodeName=='#text')continue;
if(
curTarget!=activeCont.childNodes[i]&&
((getAttribute('startLeft')+getAttribute('startWidth'))>xPos)&&
((getAttribute('startTop')+getAttribute('startHeight'))>yPos)){
beforeNode=activeCont.childNodes[i];
}
}
}
if(beforeNode){
if(beforeNode!=curTarget.nextSibling){
activeCont.insertBefore(curTarget,beforeNode);
}
}else{
if((curTarget.nextSibling)||(curTarget.parentNode!=activeCont)){
activeCont.appendChild(curTarget);
}
}
if(curTarget.style.display!=''){
curTarget.style.display='';
}
}else{
if(curTarget.style.display!='none'){
curTarget.style.display='none';
}
}
}
lMouseState=iMouseDown;
lastTarget=target;
lMouseState=iMouseDown;
returnfalse;
}
if(curTarget){
//hideourhelperobject-itisnolongerneeded
dragHelper.style.display='none';
if(curTarget.style.display=='none'){
if(rootSibling){
rootParent.insertBefore(curTarget,rootSibling);
}else{
rootParent.appendChild(curTarget);
}
}
curTarget.style.display='';
}
curTarget=null;
iMouseDown=false;
}
iMouseDown=true;
if(lastTarget){
returnfalse;
}
}
document.onmousedown=mouseDown;
document.onmouseup=mouseUp;
//Createourhelperobjectthatwillshowtheitemwhiledragging
dragHelper=document.createElement('DIV');
dragHelper.style.cssText='position:absolute;display:none;';
document.getElementById('DragContainer1'),
document.getElementById('DragContainer2'),
document.getElementById('DragContainer3')
);
}