87,910
社区成员
发帖
与我相关
我的任务
分享
/*
shawl.qiu code
class: DragSort
version: 1.0
date: 2008-x-x
updated: ver, name, date, summary.
updated x: ver, name, date, summary.
*/
var GCount = 1;
if(typeof __DragSort=="undefined")
{
__DragSort = {};
__DragSort.Set = {};
__DragSort.SourceEle = undefined;
__DragSort.TempEle = undefined;
__DragSort.DspDragEle = undefined;
__DragSort.GIndex = 999;
__DragSort.Pos = {x:0, y:0};
}
if(typeof HTMLElement!="undefined")
{
Event.prototype.__defineSetter__
(
"returnValue"
, function (bBool)
{
if(bBool) this.stopPropagation();
else this.preventDefault();
}
);
Event.prototype.__defineGetter__
(
"srcElement"
, function (bBool)
{
return this.target;
}
);
HTMLElement.prototype.attachEvent =
function(sEvtName, Func, bCaptures)
{
if(!bCaptures) bCaptures = false;
sEvtName = sEvtName.slice(2);
this.addEventListener(sEvtName, Func, bCaptures);
};
document.attachEvent = HTMLElement.prototype.attachEvent;
HTMLElement.prototype.detachEvent =
function(evt, fn, bCaptures)
{
evt = evt.slice(2);
this.removeEventListener(evt, fn, bCaptures);
};
document.detachEvent = HTMLElement.prototype.detachEvent;
}/* if(typeof HTMLElement!="undefined") */
function DragSort()
{
var This = this;
This.Set = [];
}
DragSort.prototype.Main = DragSort_Main;
function DragSort_Main()
{
var This = this;
for(var i=0, j=This.Set.length; i<j; i++)
{
var Item = This.Set[i];
Item.This = This;
//Item.attachEvent("onmousedown", DragSort_Mousedown);
Item.onmousedown = DragSort_Mousedown;
//Item.onmouseup = DragSort_Mouseup;
}
document.attachEvent("onmouseup", DragSort_Mouseup);
}/* function DragSort_Main() */
function DragSort_Mousedown(e)
{
e = e||window.event;
e.returnValue = true;
var TempEle = e.srcElement, XEle;
while(TempEle = TempEle.parentNode)
{
if(!TempEle.tagName) break;
if(TempEle.getAttribute("IsDrag")!=null)
{
XEle = TempEle;
}
}
if(!XEle) return true;
document.attachEvent("onmousemove", DragSort_Mousemove);
fSetCapture(e, XEle);
if(XEle.id in __DragSort.Set==false)
{
__DragSort.Set[XEle.id] = XEle;
}
__DragSort.SourceEle = XEle;
__DragSort.DspDragEle = XEle.cloneNode(true);
__DragSort.DspDragEle.id = "";
__DragSort.DspDragEle.This = XEle.This;
var Pos = fGetXYWH(__DragSort.SourceEle);
with(__DragSort.DspDragEle.style)
{
position = "absolute";
//top = "-100px";
zIndex = ++__DragSort.GIndex;
}
XEle.parentNode.appendChild(__DragSort.DspDragEle);
fAddClass(__DragSort.DspDragEle, "DragDspClass");
fAddClass(__DragSort.SourceEle, "DragDownClass");
__DragSort.Pos.y = e.clientY - parseInt(Pos.Top);
}
function DragSort_Mousemove(e)
{
e = e||window.event;
e.returnValue = true;
var TempEle = e.srcElement, XEle;
while(TempEle.tagName)
{
if(TempEle.getAttribute("IsDrag")!=null)
{
XEle = TempEle;
break;
}
TempEle = TempEle.parentNode
}
if(!XEle) return;
if(!__DragSort.DspDragEle) return;
var Left = e.clientX - __DragSort.Pos.x;
var Top = e.clientY - __DragSort.Pos.y;
__DragSort.DspDragEle.style.top = Top + "px";
var Pos1 = fGetXYWH(XEle);
var Pos2 = fGetXYWH(__DragSort.SourceEle);
var bBefore= true;
if(Pos2.Top<Pos1.Top) bBefore = false;
}
function DragSort_Mouseup(e)
{
e = e||window.event;
e.returnValue = true;
document.detachEvent("onmousemove", DragSort_Mousemove);
var ex = document.documentElement.scrollLeft+e.clientX;
var ey = document.documentElement.scrollTop+e.clientY;
var Pos1 = Pos2 = null, TempEle = e.srcElement, XEle;
while(TempEle.tagName)
{
if(TempEle.getAttribute("IsDrag")!=null)
{
XEle = TempEle;
break;
}
TempEle = TempEle.parentNode
}
if(!XEle) return;
var This = XEle.This;
if(__DragSort.DspDragEle)
{
try
{
}
catch(ex){}
__DragSort.DspDragEle.parentNode.removeChild(__DragSort.DspDragEle);
}
else
{
return;
}
fRemoveClass(__DragSort.SourceEle, "DragDownClass");
for(var i=0, j=This.Set.length; i<j; i++)
{
var Item = This.Set[i];
var Pos = fGetXYWH(Item);
var MaxTop = Pos.Top+Pos.Height;
if(Pos.Top<=ey&&MaxTop>=ey)
{
GetEle = Item;
break;
}
}
if(!GetEle) return;
Pos1 = fGetXYWH(__DragSort.SourceEle);
Pos2 = fGetXYWH(GetEle);
var bBefore= true;
if(Pos2.Top>Pos1.Top) bBefore = false;
fInsertNode(GetEle, __DragSort.SourceEle, bBefore);
__DragSort.Set = {};
__DragSort.SourceEle = undefined;
__DragSort.TempEle = undefined;
__DragSort.DspDragEle = undefined;
__DragSort.GIndex = 999;
__DragSort.Pos = {x:0, y:0};
}
function fSetCapture(EvtForFf, EleForIe)
{
if(typeof HTMLElement !="undefined")
{
EvtForFf.stopPropagation();
EvtForFf.preventDefault();
}
else try{EleForIe.setCapture()}catch(ex){};
}/* function fSetCapture(EvtForFf, EleForIe) */
function fReleaseCapture(EvtForFf, EleForIe)
{
if(typeof HTMLElement !="undefined")EvtForFf.stopPropagation();
else EleForIe.releaseCapture();
}/* function fReleaseCapture(EvtForFf, EleForIe) */
function fGetXYWH(Ele)
{/* shawl.qiu code, return object */
var a = new Array();
var t = Ele.offsetTop, l = Ele.offsetLeft, w = Ele.offsetWidth, h = Ele.offsetHeight;
while(Ele = Ele.offsetParent){ t += Ele.offsetTop; l += Ele.offsetLeft; }
return {Top:t, Left:l, Width:w, Height:h};
}/* end function fGetXYWH(Ele) */
function fInsertNode(OldNode, NewNode, bBefore)
{/* shawl.qiu script, return default */
var ParentNode = OldNode.parentNode;
if(!ParentNode){document.body.appendChild(NewNode); return false; };
if(bBefore){ ParentNode.insertBefore(NewNode,OldNode); return false; }
ParentNode.replaceChild(NewNode, OldNode);
return ParentNode.insertBefore(OldNode, NewNode);
}/* end function fInsertNode(OldNode, NewNode, bBefore) */
function fSetOpacity(XEle, iAlpha)
{/* shawl.qiu code, return void */
XEle.style.opacity = iAlpha/100;
XEle.style.filter = 'alpha(opacity=' + iAlpha + ')';
return;
}/* function fSetOpacity(XEle, iAlpha) */
function fAddClass(XEle, XClass)
{/* shawl.qiu code, void return */
if(!XClass) throw new Error("XClass 不能为空!");
if(XEle.className!="")
{
var Re = new RegExp("\\b"+XClass+"\\b\\s*", "");
XEle.className = XEle.className.replace(Re, "");
XEle.className = XClass+" "+XEle.className;
}
else XEle.className = XClass;
}/* end function fAddClass(XEle, XClass) */
function fRemoveClass(XEle, XClass)
{/* shawl.qiu code, void return */
if(!XClass) throw new Error("XClass 不能为空!");
if(XEle.className!="")
{
var Re = new RegExp("\\b"+XClass+"\\b\\s*", "");
XEle.className = XEle.className.replace(Re, "");
}
}/* function fRemoveClass(XEle, XClass) */
if(tag.getAttribute("IsDrag")=="false")return;//===================
function DragSort_Mousedown(e)
{
e = e||window.event;
e.returnValue = true;
var tag=e.srcElement;
if(tag.tagName!="TD"&&tag.tagName!="TR")return;//===================
//其他代码