/* [Discuz!] (C)2001-2099 Comsenz Inc. This is NOT a freeware, use is subject to license terms $Id: home_drag.js 32655 2013-02-28 04:08:00Z zhengqingpeng $ */ var Drags = []; var nDrags = 1; var mouseOffset = null; var iMouseDown = false; var lMouseState = false; var dragObject = null; var DragDrops = []; var curTarget = null; var lastTarget = null; var dragHelper = null; var tempDiv = null; var rootParent = null; var rootSibling = null; var D1Target = null; Number.prototype.NaN0=function(){return isNaN(this)?0:this;}; function CreateDragContainer(){ var cDrag = DragDrops.length; DragDrops[cDrag] = []; for(var i=0; i xPos) && ((parseInt(getAttribute('startTop')) + parseInt(getAttribute('startHeight'))) > yPos)){ activeCont = dragConts[i]; break; } } } if(activeCont){ if(activeCont!=curTarget.parentNode){ writeHistory(curTarget, 'Moved into '+activeCont.id); } var beforeNode = null; for(var i=activeCont.childNodes.length-1; i>=0; i--){ with(activeCont.childNodes[i]){ if(nodeName=='#text') continue; if(curTarget != activeCont.childNodes[i] && ((parseInt(getAttribute('startLeft')) + parseInt(getAttribute('startWidth'))) > xPos) && ((parseInt(getAttribute('startTop')) + parseInt(getAttribute('startHeight'))) > yPos)){ beforeNode = activeCont.childNodes[i]; } } } if(beforeNode){ if(beforeNode!=curTarget.nextSibling){ writeHistory(curTarget, 'Inserted Before '+beforeNode.id); activeCont.insertBefore(curTarget, beforeNode); } } else { if((curTarget.nextSibling) || (curTarget.parentNode!=activeCont)){ writeHistory(curTarget, 'Inserted at end of '+activeCont.id); activeCont.appendChild(curTarget); } } setTimeout(function(){ var contPos = getPosition(activeCont); activeCont.setAttribute('startWidth', parseInt(activeCont.offsetWidth)); activeCont.setAttribute('startHeight', parseInt(activeCont.offsetHeight)); activeCont.setAttribute('startLeft', contPos.x); activeCont.setAttribute('startTop', contPos.y);}, 5); if(curTarget.style.display!=''){ writeHistory(curTarget, 'Made Visible'); curTarget.style.display = ''; curTarget.style.visibility = 'hidden'; } } else { if(curTarget.style.display!='none'){ writeHistory(curTarget, 'Hidden'); curTarget.style.display = 'none'; } } } lMouseState = iMouseDown; lastTarget = target; } if(dragObject){ dragObject.style.position = 'absolute'; dragObject.style.top = mousePos.y - mouseOffset.y; dragObject.style.left = mousePos.x - mouseOffset.x; } lMouseState = iMouseDown; if(curTarget || dragObject) return false; } function mouseUp(ev){ if(Drags[0]){ if(curTarget){ writeHistory(curTarget, 'Mouse Up Fired'); dragHelper.style.display = 'none'; if(curTarget.style.display == 'none'){ if(rootSibling){ rootParent.insertBefore(curTarget, rootSibling); } else { rootParent.appendChild(curTarget); } } curTarget.style.display = ''; curTarget.style.visibility = 'visible'; } curTarget = null; } dragObject = null; iMouseDown = false; } function mouseDown(ev){ mousedown(ev); ev = ev || window.event; var target = ev.target || ev.srcElement; iMouseDown = true; if(Drags[0]){ if(lastTarget){ writeHistory(lastTarget, 'Mouse Down Fired'); } } if(target.onmousedown || target.getAttribute('DragObj')){ return false; } } function makeDraggable(item){ if(!item) return; item.onmousedown = function(ev){ dragObject = this; mouseOffset = getMouseOffset(this, ev); return false; } } function init_drag2(){ document.onmousemove = mouseMove; document.onmousedown = mouseDown; document.onmouseup = mouseUp; Drags[0] = $('Drags0'); if(Drags[0]){ CreateDragContainer($('DragContainer0')); } if(Drags[0]){ var cObj = $('applistcontent'); dragHelper = document.createElement('div'); dragHelper.style.cssName = "apps dragable"; dragHelper.style.cssText = 'position:absolute;display:none;width:777px;'; cObj.parentNode.insertBefore(dragHelper, cObj); } } function mousedown(evnt){ }