分类: C/C++
2008-04-02 15:08:52
function DragControl() {
this.entity = null;
this.target = null;
this.origin = null;
this.enabled = false;
this.beginX = null;
this.beginY = null;
this.beginDrag = beginDrag;
this.endDrag = endDrag;
this.setTarget = setTarget;
this.setPosition = setPosition;
this.move = move;
this.reset = reset;
} 拖放控制涉及到的属性和方法包括: beginDrag()
定义:
function beginDrag(obj) {
if(window.event.button == 1)
{
document.onmousemove = function anonymous() { dragControl.move(obj) };
this.origin = obj.parentNode;
this.entity = obj;
this.beginX = window.event.x;
this.beginY = window.event.y;
window.event.cancelBubble = true;
}
}
此方法在XSLT式样页文件中使用。如图一所示:
endDrag()
定义:
function endDrag() {
if(this.entity != null) {
this.entity.style.position = "static";
this.entity.style.left = null;
this.entity.style.top = null;
this.entity = this.entity.removeNode(true);
if(this.target != null) {
dragControl.target.appendChild(this.entity);
if(this.target.open != "true") {
clickOnEntity(this.target);
}
}
else {
this.origin.appendChild(this.entity);
}
document.onmousemove = null;
document.onmouseup = null;
this.entity = null;
this.target = null;
this.enabled = false;
}
}此方法首先保证只有一个实体被选中。根据当前是否有选中的目的地,决定是将实体返回原位置(没有选择目的地)还是将实体移到新的位置(选择了一个目的地)。此方法在XSLT式样页文件中使用。如图二所示:
setTarget()
定义:
function setTarget(obj) {
if(this.entity != null && this.entity != obj) {
this.target = obj;
}
window.event.cancelBubble = true;
}
此方法保证存在一个当前的实体,并且选中的实体不是被移动的实体。然后设置DragControl 的target属性,然后在客户浏览器中进行cancelBubble 处理。此方法在XSLT式样页文件中使用。如图三所示:
setPosition()
定义:
function setPosition() {
this.entity.style.left = window.event.x;
this.entity.style.top = window.event.y - 10;
}此方法仅仅设置所选实体的X和Y坐标为当前鼠标事件的X和Y坐标。在move()中调用此方法。此方法在tree.js文件中使用。
move()
定义:
function move(obj) {
if(window.event.x < this.beginX - 5 || window.event.x > this.beginX + 5 ||
window.event.y < this.beginY -5 || window.event.y > this.beginY + 5 &&
this.enabled == false) {
obj.style.position = "absolute";
obj.style.filter = "alpha(opacity=''''60'''')";
this.setPosition();
this.enabled = true;
obj = obj.removeNode(true);
document.body.appendChild(obj);
document.onmouseup = function anonymous() { dragControl.endDrag() };
}
else if(this.enabled == true) {
this.setPosition();
}
} 这个方法保证用户在任何方向上拖拽对象至少5个象素时,他便将实体对象移到当前目录树之外,然后放进文档体中。在文档对象的"onmousemove"事件中它不断被调用,以便让实体总是显示在鼠标光标旁边。此方法在tree.js文件中使用。如图五所示:
reset()
定义:
function reset() {
document.onmouseup = null;
document.onmousemove = null;
this.entity = null;
this.origin = null;
this.target = null;
}此方法仅仅清除文档和DragControl对象。只要完成或取消拖拽都调用这个方法。此方法在XSLT式样页文件中使用。如图六所示: