sort.js
上传用户:shjgzm
上传日期:2017-08-31
资源大小:2757k
文件大小:5k
- /************************************************************************************************************
- (C) www.dhtmlgoodies.com, October 2005
- This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.
- Terms of use:
- You are free to use this script as long as the copyright message is kept intact. However, you may not
- redistribute, sell or repost it without our permission.
- Thank you!
- www.dhtmlgoodies.com
- Alf Magne Kalleland
- ************************************************************************************************************/
- var offsetYInsertDiv = -3; // Y offset for the little arrow indicating where the node should be inserted.
- if(!document.all)offsetYInsertDiv = offsetYInsertDiv - 7; // No IE
- var arrParent = false;
- var arrMoveCont = false;
- var arrMoveCounter = -1;
- var arrTarget = false;
- var arrNextSibling = false;
- var leftPosArrangableNodes = false;
- var widthArrangableNodes = false;
- var nodePositionsY = new Array();
- var nodeHeights = new Array();
- var arrInsertDiv = false;
- var insertAsFirstNode = false;
- var arrNodesDestination = false;
- function cancelEvent()
- {
- return false;
- }
- function getTopPos(inputObj)
- {
- var returnValue = inputObj.offsetTop;
- while((inputObj = inputObj.offsetParent) != null){
- returnValue += inputObj.offsetTop;
- }
- return returnValue;
- }
- function getLeftPos(inputObj)
- {
- var returnValue = inputObj.offsetLeft;
- while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
- return returnValue;
- }
- function clearMovableDiv()
- {
- if(arrMoveCont.getElementsByTagName('LI').length>0){
- if(arrNextSibling)arrParent.insertBefore(arrTarget,arrNextSibling); else arrParent.appendChild(arrTarget);
- }
- }
- function initMoveNode(e)
- {
- clearMovableDiv();
- if(document.all)e = event;
- arrMoveCounter = 0;
- arrTarget = this;
- if(this.nextSibling)arrNextSibling = this.nextSibling; else arrNextSibling = false;
- timerMoveNode();
- arrMoveCont.parentNode.style.left = e.clientX + 'px';
- arrMoveCont.parentNode.style.top = (e.clientY + Math.max(document.body.scrollTop,document.documentElement.scrollTop)) + 'px';
- return false;
- }
- function timerMoveNode()
- {
- if(arrMoveCounter>=0 && arrMoveCounter<10){
- arrMoveCounter = arrMoveCounter +1;
- setTimeout('timerMoveNode()',20);
- }
- if(arrMoveCounter>=10){
- arrMoveCont.appendChild(arrTarget);
- }
- }
- function arrangeNodeMove(e)
- {
- if(document.all)e = event;
- if(arrMoveCounter<10)return;
- if(document.all && arrMoveCounter>=10 && e.button!=1){
- arrangeNodeStopMove();
- }
- arrMoveCont.parentNode.style.left = e.clientX + 'px';
- arrMoveCont.parentNode.style.top = (e.clientY + Math.max(document.body.scrollTop,document.documentElement.scrollTop)) + 'px';
- var tmpY = e.clientY + Math.max(document.body.scrollTop,document.documentElement.scrollTop);
- arrInsertDiv.style.display='none';
- arrNodesDestination = false;
- if(e.clientX<leftPosArrangableNodes || e.clientX>leftPosArrangableNodes + widthArrangableNodes)return;
- var subs = arrParent.getElementsByTagName('LI');
- for(var no=0;no<subs.length;no++){
- var topPos =getTopPos(subs[no]);
- var tmpHeight = subs[no].offsetHeight;
- if(no==0){
- if(tmpY<=topPos && tmpY>=topPos-5){
- arrInsertDiv.style.top = (topPos + offsetYInsertDiv) + 'px';
- arrInsertDiv.style.display = 'block';
- arrNodesDestination = subs[no];
- insertAsFirstNode=true;
- return;
- }
- }
- if(tmpY>=topPos && tmpY<=(topPos+tmpHeight)){
- arrInsertDiv.style.top = (topPos+tmpHeight + offsetYInsertDiv) + 'px';
- arrInsertDiv.style.display = 'block';
- arrNodesDestination = subs[no];
- insertAsFirstNode = false;
- return;
- }
- }
- }
- function arrangeNodeStopMove()
- {
- arrMoveCounter = -1;
- arrInsertDiv.style.display='none';
- if(arrNodesDestination){
- var subs = arrParent.getElementsByTagName('LI');
- if(arrNodesDestination==subs[0] && insertAsFirstNode){
- arrParent.insertBefore(arrTarget,arrNodesDestination);
- }else{
- if(arrNodesDestination.nextSibling){
- arrParent.insertBefore(arrTarget,arrNodesDestination.nextSibling);
- }else{
- arrParent.appendChild(arrTarget);
- }
- }
- }
- arrNodesDestination = false;
- clearMovableDiv();
- }
- function initArrangableNodes()
- {
- arrParent = document.getElementById('arrangableNodes');
- arrMoveCont = document.getElementById('movableNode').getElementsByTagName('UL')[0];
- arrInsertDiv = document.getElementById('arrDestInditcator');
- leftPosArrangableNodes = getLeftPos(arrParent);
- arrInsertDiv.style.left = leftPosArrangableNodes - 5 + 'px';
- widthArrangableNodes = arrParent.offsetWidth;
- var subs = arrParent.getElementsByTagName('LI');
- for(var no=0;no<subs.length;no++){
- subs[no].onmousedown = initMoveNode;
- subs[no].onselectstart = cancelEvent;
- }
- document.documentElement.onmouseup = arrangeNodeStopMove;
- document.documentElement.onmousemove = arrangeNodeMove;
- document.documentElement.onselectstart = cancelEvent;
- }
- window.onload = initArrangableNodes;