Changeset 6476
- Timestamp:
- 09/07/06 19:22:41 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Wsp_Modeling/spaces/gen/modelBuilder/bs.doss/_common/sm/webSiteGenerator/scDragMgr.js
r6412 r6476 63 63 */ 64 64 var scDragMgr = { 65 66 // DRAGDROP interface ======================================================== 67 // Make a DragDrop container 68 makeContainer : function(pKey, pCatchment, pContainer, pIfEmpty) { 69 this.dragdrop.makeContainer(pKey, pCatchment, pContainer, pIfEmpty); return this 70 }, 71 72 // Set how the containter should react on drop 73 // pMode = ordered|append|inBulk 74 // pMax : max num of labels that the container can accept 75 setMode : function(pContainer, pMode, pMax) { 76 this.dragdrop.setMode(pContainer, pMode, pMax); return this 77 }, 78 79 // Retrieve an array of all containers of the specified key that are contained in pRootNode 80 getContainers : function (pKey, pRootNode) { 81 return this.dragdrop.getContainers(pKey, pRootNode) 82 }, 83 84 // Retrieve an array of draggable labels contained in pContainer 85 getLabels : function(pContainer) { 86 return this.dragdrop.getLabels(pContainer) 87 }, 88 89 // Resets the content of all containers with the labels ontained in 90 // vContainer.labelsToAdd = [{label:vLabel1}, {label:vLabel2, x:23, y:65}] - "x:23, y:65" issu de saveLabelPos((pLabel)) 91 repopulateContainers : function (pKey) { 92 //TODO 93 }, 94 95 // Make a dragdrop label 96 makeDragableLabel : function(pKey, pLabel, pHandle) { 97 this.dragdrop.makeDragableLabel(pKey, pLabel, pHandle); return this 98 }, 99 100 // Set the callback function to be called on any successfull drop action 101 setCallback : function(pLabel, pfunction) { 102 this.dragdrop.setCallback(pLabel, pfunction); return this 103 }, 104 105 // Turn the draggablilty of labels on and off 106 setDraggable : function (pLabel, pIsDraggable) { 107 this.dragdrop.setDraggable(pLabel, pIsDraggable); return this 108 }, 109 110 // Fix a constraint box in which the label can be dragged 111 setConstraintBox : function (pLabel, pNode) { 112 // FIXME: Disable on Konqueror type browsers as this they cannot support this for the moment 113 if (navigator.userAgent.toLowerCase().indexOf("khtml") != -1) return 114 this.dragdrop.setConstraintBox(pLabel, pNode); return this 115 }, 116 117 // Returns a string rep of the label's position 118 saveLabelPos : function (pLabel) { 119 //TODO 120 } 65 121 } 66 122 … … 68 124 69 125 isMouseInside : function(pDragEvent, pContainter) { 70 return ( pDragEvent.t opLeftOffset.inside( pContainter.topLeftPosition, pContainter.bottomRightPosition ) || pDragEvent.bottomRightOffset.inside( pContainter.topLeftPosition, pContainter.bottomRightPosition ) )126 return ( pDragEvent.transformedMouseOffset.inside( pContainter.topLeftPosition, pContainter.bottomRightPosition )) 71 127 }, 72 128 … … 146 202 }, 147 203 204 logError : function(pLog) { 205 if(window.console) { 206 window.console.log("scDragMgr ERROR - "+pLog) 207 } else { 208 alert("scDragMgr ERROR - "+pLog) 209 } 210 }, 211 212 213 148 214 restoreListOrder : function(listID) { 149 215 /* … … 278 344 topLeftOffset : function(element) { 279 345 var offset = this._offset(element) 280 281 346 var parent = element.offsetParent 282 347 while (parent) { … … 432 497 var group = this.createGroup(element) 433 498 group.setHandle(handle) 434 group.transparent drag499 group.transparentDrag() 435 500 group.onTopWhileDragging() 436 501 return group … … 447 512 scDragMgr.coordinates.topLeftOffset(element).reposition(element) 448 513 } 449 450 // TODO: only if scDragMgr.isDebugging()451 /* group.register('draginit', this._showDragEventStatus)452 group.register('dragmove', this._showDragEventStatus)453 group.register('dragend', this._showDragEventStatus)454 */455 514 return group 456 },457 458 _showDragEventStatus : function(dragEvent) {459 window.status = dragEvent.toString()460 515 }, 461 516 … … 473 528 this.element = element 474 529 this._handle = null 530 this._draggable = true 475 531 this._thresholdDistance = 0 476 532 this._transforms = new Array() … … 550 606 }, 551 607 608 setDraggable : function(draggable) { 609 this._draggable = draggable 610 }, 611 552 612 _dragInit : function(event) { 553 613 event = scDragMgr.events.fix(event) … … 555 615 var dragEvent = group.factory._createEvent('draginit', event, group) 556 616 557 group._isThresholdExceeded = false 558 group._initialMouseOffset = dragEvent.mouseOffset 559 group._grabOffset = dragEvent.mouseOffset.minus(dragEvent.topLeftOffset) 560 scDragMgr.events.register(document, 'mousemove', group._drag) 561 document.onmousemove = function() { return false } 562 scDragMgr.events.register(document, 'mouseup', group._dragEnd) 563 564 group._notifyListeners(dragEvent) 617 if (group._draggable) { 618 group._isThresholdExceeded = false 619 group._initialMouseOffset = dragEvent.mouseOffset 620 group._grabOffset = dragEvent.mouseOffset.minus(dragEvent.topLeftOffset) 621 scDragMgr.events.register(document, 'mousemove', group._drag) 622 document.onmousemove = function() { return false } 623 scDragMgr.events.register(document, 'mouseup', group._dragEnd) 624 625 group._notifyListeners(dragEvent) 626 } 565 627 }, 566 628 … … 665 727 /** 666 728 * ============================================================================= 667 * scDragMgr DRAGSORT668 */669 scDragMgr.dragsort = {670 671 makeSortable : function(pItem) {672 var vGroup = scDragMgr.drag.createSimpleGroup(pItem)673 vGroup.register('dragstart', this._onDragStart)674 vGroup.register('dragmove', this._onDragMove)675 vGroup.register('dragend', this._onDragEnd)676 return vGroup677 },678 679 makeListSortable : function(pList) {680 var vHelpers = scDragMgr.helpers681 var vCoordinates = scDragMgr.coordinates682 683 pList.getItems = function() {684 var vItems = this.getElementsByTagName("li")685 return vItems686 }687 688 var vItems = pList.getElementsByTagName("li")689 vHelpers.map(vItems, function(pItem) {690 var vDragGroup = scDragMgr.dragsort.makeSortable(pItem)691 vDragGroup.setThreshold(4)692 var vMin, vMax693 vDragGroup.addTransform(function(pCoordinate, pDragEvent) {694 return pCoordinate.constrainTo(vMin, vMax)695 })696 vDragGroup.register('dragstart', function() {697 var vItems = pList.getElementsByTagName("li")698 vMin = vMax = vCoordinates.topLeftOffset(vItems[0])699 for (var i = 1, n = vItems.length; i < n; i++) {700 var vOffset = vCoordinates.topLeftOffset(vItems[i])701 vMin = vMin.min(vOffset)702 vMax = vMax.max(vOffset)703 }704 })705 })706 for (var i = 1, n = arguments.length; i < n; i++)707 vHelpers.map(vItems, arguments[i])708 },709 710 _onDragStart : function(pDragEvent) {711 },712 _onDragMove : function(pDragEvent) {713 var vHelpers = scDragMgr.helpers714 var vCoordinates = scDragMgr.coordinates715 var vItem = pDragEvent.group.element716 var vXmouse = pDragEvent.transformedMouseOffset717 var vMoveTo = null718 719 var vPrevious = vHelpers.previousItem(vItem, vItem.nodeName)720 while (vPrevious != null) {721 var vBottomRight = vCoordinates.bottomRightOffset(vPrevious)722 if (vXmouse.y <= vBottomRight.y && vXmouse.x <= vBottomRight.x) {723 vMoveTo = vPrevious724 }725 vPrevious = vHelpers.previousItem(vPrevious, vItem.nodeName)726 }727 if (vMoveTo != null) {728 vHelpers.moveBefore(vItem, vMoveTo)729 return730 }731 732 var vNext = vHelpers.nextItem(vItem, vItem.nodeName)733 while (vNext != null) {734 var vTopLeft = vCoordinates.topLeftOffset(vNext)735 if (vTopLeft.y <= vXmouse.y && vTopLeft.x <= vXmouse.x) {736 vMoveTo = vNext737 }738 vNext = vHelpers.nextItem(vNext, vItem.nodeName)739 }740 if (vMoveTo != null) {741 vHelpers.moveBefore(vItem, vHelpers.nextItem(vMoveTo, vItem.nodeName))742 return743 }744 },745 _onDragEnd : function(pDragEvent) {746 scDragMgr.coordinates.create(0, 0).reposition(pDragEvent.group.element)747 },748 749 /**750 Multi-list support751 */752 fFirstContainers : new Array(),753 fLastContainers : new Array(),754 755 makeContainerItem : function(pItem) {756 var vGroup = scDragMgr.drag.createSimpleGroup(pItem)757 758 // tracks if the item is currently outside all containers759 vGroup.isOutside = false760 pItem.isDraggable = true761 vGroup.register('dragstart', this._onContainerItemDragStart)762 vGroup.register('dragmove', this._onContainerItemDragMove)763 vGroup.register('dragend', this._onContainerItemDragEnd)764 765 return vGroup766 },767 768 getContainers : function(pRootNode, pKey) {769 var vContainers = new Array()770 var vContainer = scDragMgr.dragsort.fFirstContainers[pKey]771 while (vContainer != null) {772 if (scDragMgr.helpers.isEltContainedByNode(vContainer, pRootNode)) vCatchments.push(vContainers)773 vContainer = vContainer.fNextContainer774 }775 return (vContainers)776 },777 778 makeListContainer : function(pList, pListID) {779 var vHelpers = scDragMgr.helpers780 var vCoordinates = scDragMgr.coordinates781 var vListID = (typeof pListID != scDragMgr.utilities.fUndef) ? pListID : 'defaultList'782 vListID = (vListID.length == 0) ? 'defaultList' : vListID783 784 pList.fListID = vListID785 pList.onDragOver = new Function()786 pList.onDragOut = new Function()787 pList.getKey = function() { return this.fListID }788 pList.getItems = function() {789 var vItems = this.getElementsByTagName("li")790 return vItems791 }792 793 // each container becomes a linked list node794 if (typeof this.fFirstContainers[pList.fListID] == scDragMgr.utilities.fUndef) {795 this.fFirstContainers[pList.fListID] = this.fLastContainers[pList.fListID] = pList796 pList.fPreviousContainer = null797 pList.fNextContainer = null798 } else {799 pList.fPreviousContainer = this.fLastContainers[pList.fListID]800 pList.fNextContainer = null801 this.fLastContainers[pList.fListID].fNextContainer = pList802 this.fLastContainers[pList.fListID] = pList803 }804 805 var vItems = pList.getElementsByTagName("li")806 807 vHelpers.map(vItems, function(pItem) {808 var vDragGroup = scDragMgr.dragsort.makeContainerItem(pItem)809 vDragGroup.setThreshold(4)810 })811 for (var i = 2, n = arguments.length; i < n; i++)812 vHelpers.map(vItems, arguments[i])813 },814 815 _onContainerItemDragStart : function(pDragEvent) {816 var vCoordinates = scDragMgr.coordinates817 // update all container bounds, since they may have changed on a previous drag818 //819 // could be more smart about when to do this820 var vContainer = scDragMgr.dragsort.fFirstContainers[pDragEvent.group.element.parentNode.fListID]821 while (vContainer != null) {822 vContainer.topLeftPosition = vCoordinates.topLeftOffset(vContainer)823 vContainer.bottomRightPosition = vCoordinates.bottomRightOffset( vContainer)824 vContainer = vContainer.fNextContainer825 }826 // item starts out over current parent827 pDragEvent.group.element.parentNode.onDragOver()828 },829 _onContainerItemDragMove : function(pDragEvent) {830 var vHelpers = scDragMgr.helpers831 var vCoordinates = scDragMgr.coordinates832 833 var vGroup = pDragEvent.group834 var vItem = pDragEvent.group.element835 var vXmouse = pDragEvent.transformedMouseOffset836 var vMoveTo = null837 838 // check if we were nowhere839 if (vGroup.isOutside) {840 // check each container to see if in its bounds841 var vContainer = scDragMgr.dragsort.fFirstContainers[pDragEvent.group.element.parentNode.fListID]842 while (vContainer != null) {843 if (vHelpers.isMouseInside(pDragEvent, vContainer)) {844 // we're inside this one845 vContainer.onDragOver()846 vGroup.isOutside = false847 }848 vContainer = vContainer.fNextContainer849 }850 // we're still not inside the bounds of any container851 if (vGroup.isOutside)852 return853 854 // check if we're outside our parent's bounds855 } else if (!(vHelpers.isMouseInside(pDragEvent, vItem.parentNode))) {856 vItem.parentNode.onDragOut()857 vGroup.isOutside = true858 859 // check if we're inside a new container's bounds860 var vContainer = scDragMgr.dragsort.fFirstContainers[pDragEvent.group.element.parentNode.fListID]861 while (vContainer != null) {862 if (vHelpers.isMouseInside(pDragEvent, vContainer)) {863 864 // we're inside this one865 vContainer.onDragOver()866 vGroup.isOutside = false867 vItem.parentNode.removeChild(vItem)868 vContainer.appendChild(vItem)869 vContainer.topLeftPosition = vCoordinates.topLeftOffset(vContainer)870 vContainer.bottomRightPosition = vCoordinates.bottomRightOffset( vContainer)871 break872 }873 vContainer = vContainer.fNextContainer874 }875 }876 877 // if we get here, we're inside some container bounds, so we do878 // everything the original dragsort script did to swap us into the879 // correct position880 var vPrevious = vHelpers.previousItem(vItem, vItem.nodeName)881 while (vPrevious != null) {882 var vBottomRight = vCoordinates.bottomRightOffset(vPrevious)883 if (vXmouse.y <= vBottomRight.y && vXmouse.x <= vBottomRight.x) {884 vMoveTo = vPrevious885 }886 vPrevious = vHelpers.previousItem(vPrevious, vItem.nodeName)887 }888 if (vMoveTo != null) {889 vHelpers.moveBefore(vItem, vMoveTo)890 return891 }892 893 var vNext = vHelpers.nextItem(vItem, vItem.nodeName)894 while (vNext != null) {895 var vTopLeft = vCoordinates.topLeftOffset(vNext)896 if (vTopLeft.y <= vXmouse.y && vTopLeft.x <= vXmouse.x) {897 vMoveTo = vNext898 }899 vNext = vHelpers.nextItem(vNext, vItem.nodeName)900 }901 if (vMoveTo != null) {902 vHelpers.moveBefore(vItem, vHelpers.nextItem(vMoveTo, vItem.nodeName))903 return904 }905 },906 _onContainerItemDragEnd : function(pDragEvent) {907 pDragEvent.group.element.parentNode.onDragOut()908 scDragMgr.coordinates.create(0, 0).reposition(pDragEvent.group.element)909 }910 }911 912 /**913 * =============================================================================914 729 * scDragMgr DRAGDROP 915 730 */ 916 731 scDragMgr.dragdrop = { 732 733 // Lib Fields ================================================================ 917 734 fFirstCatchments : new Array(), 918 735 fLastCatchments : new Array(), 919 736 fDragContainer : document.createElement("DIV"), 920 737 921 makeDragable : function(pElt) { 922 var vGroup = scDragMgr.drag.createSimpleGroup(pElt) 923 vGroup.fStartParent = null 924 vGroup.fLastParent = null 925 pElt.isDraggable = true 926 vGroup.register('dragstart', this._onDragStart) 927 vGroup.register('dragmove', this._onDragMove) 928 vGroup.register('dragend', this._onDragEnd) 929 return vGroup 930 }, 931 932 getZones : function(pRootNode, pKey) { 933 var vCatchments = new Array() 934 var vCatchment = scDragMgr.dragdrop.fFirstCatchments[pKey] 935 while (vCatchment != null) { 936 if (scDragMgr.helpers.isEltContainedByNode(vCatchment, pRootNode)) vCatchments.push(vCatchment) 937 vCatchment = vCatchment.fNextCatchment 938 } 939 return (vCatchments) 940 }, 941 942 makeSingleDragZone : function(pCatchment, pContainer, pIfEmpty, pKey) { 943 this._initSingleZone(pCatchment, pContainer, pIfEmpty, pKey) 944 }, 945 946 _initZone : function(pCatchment, pContainer, pIfEmpty, pKey) { 947 var vKey = (typeof pKey != scDragMgr.utilities.fUndef) ? pKey : 'defaultKey' 948 vKey = (vKey.length == 0) ? 'defaultKey' : vKey 949 950 //init... 951 pCatchment.fKey = vKey 952 pCatchment.fHasInitItems = false 953 pCatchment.onDragOver = new Function() 954 pCatchment.onDragOut = new Function() 955 pCatchment.getKey = function() { return this.fKey } 956 pCatchment.updateGui = function() { 957 if (typeof this.fContainer != scDragMgr.utilities.fUndef) { 958 var vChild = this.fContainer.lastChild 959 var vHasItems = false 960 while (vChild != null && !vHasItems) { 961 if (vChild.isDraggable) { 962 vHasItems = true 963 } 964 vChild = vChild.previousSibling 738 // EXTERNAL functions ======================================================== 739 // EXTERNAL - CONTAINER - Creates a drag/drop container 740 makeContainer : function (pKey, pCatchment, pContainer, pIfEmpty) { 741 try { 742 var vKey = (typeof pKey != scDragMgr.utilities.fUndef) ? pKey : 'defaultKey' 743 vKey = (vKey.length == 0) ? 'defaultKey' : vKey 744 if (typeof pCatchment.fKey != scDragMgr.utilities.fUndef) { 745 scDragMgr.utilities.logError("dragdrop.makeContainer: "+pCatchment.id+" is already init.") 746 return 747 } 748 //init... 749 pCatchment.fKey = vKey 750 pCatchment.onDragOver = new Function() // public dragover event (for styles etc) 751 pCatchment.onDragOut = new Function() //public dragout event (for styles etc) 752 pCatchment.xUpdateGui = this._UpdateGui 753 pCatchment.xIsDropable = this._IsDropable 754 pCatchment.xOnDragOver = this._onDragOver 755 pCatchment.xOnDragOut = this._onDragOut 756 757 // each catchment becomes a linked catchment node 758 if (typeof this.fFirstCatchments[pCatchment.fKey] == scDragMgr.utilities.fUndef) { 759 this.fFirstCatchments[pCatchment.fKey] = this.fLastCatchments[pCatchment.fKey] = pCatchment 760 pCatchment.fPreviousCatchment = null 761 pCatchment.fNextCatchment = null 762 } else { 763 pCatchment.fPreviousCatchment = this.fLastCatchments[pCatchment.fKey] 764 pCatchment.fNextCatchment = null 765 this.fLastCatchments[pCatchment.fKey].fNextCatchment = pCatchment 766 this.fLastCatchments[pCatchment.fKey] = pCatchment 767 } 768 // init Container elt 769 if (typeof pContainer != scDragMgr.utilities.fUndef) { 770 pContainer.fDelaultDisplay = scDragMgr.css.readStyle(pContainer, "display") 771 pContainer.fCatchment = pCatchment 772 pCatchment.fContainer = pContainer 773 this.setMode(pContainer, "ordered", -1) 774 } 775 // init IfEmpty elt 776 if (typeof pIfEmpty != scDragMgr.utilities.fUndef) { 777 pIfEmpty.fDelaultDisplay = scDragMgr.css.readStyle(pIfEmpty, "display") 778 pCatchment.fIfEmpty = pIfEmpty 779 } 780 pCatchment.fIsEmpty = pCatchment.xUpdateGui() 781 } catch (vError) { 782 scDragMgr.utilities.logError("dragdrop.makeContainer: "+vError) 783 } 784 }, 785 786 // EXTERNAL - CONTAINER - Set how the containter should react on drop (ordered, append, inBulk) 787 setMode : function(pContainer, pMode, pMax) { 788 try { 789 if (typeof pContainer.fCatchment != scDragMgr.utilities.fUndef) { 790 var vCatchment = pContainer.fCatchment 791 vCatchment.fDropMode = pMode 792 vCatchment.fMaxLabels = pMax 793 switch(vCatchment.fDropMode){ 794 case "ordered": 795 vCatchment.xOnDragPostProcess = this._onDragSort 796 vCatchment.xOnDragEndPostProcess = this._onDropReposition 797 break 798 case "append": 799 vCatchment.xOnDragPostProcess = new Function() 800 vCatchment.xOnDragEndPostProcess = this._onDropReposition 801 break 802 case "inBulk": 803 vCatchment.xOnDragPostProcess = new Function() 804 vCatchment.xOnDragEndPostProcess = new Function() 965 805 } 966 this.fContainer.style["display"] = (!vHasItems ? "none" : "") 967 if (typeof this.fIfEmpty != scDragMgr.utilities.fUndef) { 968 this.fIfEmpty.style["display"] = (vHasItems ? "none" : "") 969 } 970 } 971 } 972 pCatchment.getItems = function() { 973 var vItems = new Array() 974 if (typeof this.fContainer != scDragMgr.utilities.fUndef) { 975 var vChild = this.fContainer.firstChild 806 } 807 } catch (vError) { 808 scDragMgr.utilities.logError("dragdrop.setMode: "+vError) 809 } 810 }, 811 812 // EXTERNAL - CONTAINER - Retrieve an array of all containers of the specified key that are contained in pRootNode 813 getContainers : function(pKey, pRootNode) { 814 try { 815 var vContainers = new Array() 816 var vCatchment = scDragMgr.dragdrop.fFirstCatchments[pKey] 817 while (vCatchment != null) { 818 if (scDragMgr.helpers.isEltContainedByNode(vCatchment, pRootNode)) vContainers.push(vCatchment.fContainer) 819 vCatchment = vCatchment.fNextCatchment 820 } 821 return (vContainers) 822 } catch (vError) { 823 scDragMgr.utilities.logError("dragdrop.getContainers: "+vError) 824 } 825 }, 826 827 // EXTERNAL - CONTAINER - Retrieve an array of draggable labels contained in pContainer 828 getLabels : function(pContainer) { 829 try { 830 var vLabels = new Array() 831 if (typeof pContainer != scDragMgr.utilities.fUndef) { 832 var vChild = pContainer.firstChild 976 833 while (vChild != null) { 977 if (vChild. isDraggable) vItems.push(vChild)834 if (vChild.fIsDraggable) vLabels.push(vChild) 978 835 vChild = vChild.nextSibling 979 836 } 980 837 } 981 return (vItems) 982 } 983 984 // each container becomes a linked zone node 985 if (typeof this.fFirstCatchments[pCatchment.fKey] == scDragMgr.utilities.fUndef) { 986 this.fFirstCatchments[pCatchment.fKey] = this.fLastCatchments[pCatchment.fKey] = pCatchment 987 pCatchment.fPreviousCatchment = null 988 pCatchment.fNextCatchment = null 989 } else { 990 pCatchment.fPreviousCatchment = this.fLastCatchments[pCatchment.fKey] 991 pCatchment.fNextCatchment = null 992 this.fLastCatchments[pCatchment.fKey].fNextCatchment = pCatchment 993 this.fLastCatchments[pCatchment.fKey] = pCatchment 994 } 995 996 // make all children of pContainer draggable... 997 if (typeof pContainer != scDragMgr.utilities.fUndef) { 998 pCatchment.fContainer = pContainer 999 pContainer.fCatchment = pCatchment 1000 var vChild = pContainer.lastChild 1001 while (vChild != null) { 1002 if (vChild.nodeType != 3) { 1003 pCatchment.fHasInitItems = true 1004 var vDragGroup = this.makeDragable(vChild) 1005 vDragGroup.setThreshold(4) 1006 for (var i = 4, n = arguments.length; i < n; i++) arguments(vChild) 838 return (vLabels) 839 } catch (vError) { 840 scDragMgr.utilities.logError("dragdrop.getLabels: "+vError) 841 } 842 }, 843 844 // EXTERNAL - CONTAINER - Returns the number of current lables in a container 845 countLabels : function(pContainer) { 846 try { 847 var vCount = 0 848 if (typeof pContainer != scDragMgr.utilities.fUndef) { 849 var vChild = pContainer.firstChild 850 while (vChild != null) { 851 if (vChild.fIsDraggable) vCount++ 852 vChild = vChild.nextSibling 853 } 854 } 855 return (vCount) 856 } catch (vError) { 857 scDragMgr.utilities.logError("dragdrop.countLabels: "+vError) 858 } 859 }, 860 861 // EXTERNAL - LABEL - Make a dragdrop label 862 makeDragableLabel : function(pKey, pLabel, pHandle) { 863 try { 864 var vKey = (typeof pKey != scDragMgr.utilities.fUndef) ? pKey : 'defaultKey' 865 vKey = (vKey.length == 0) ? 'defaultKey' : vKey 866 if (typeof pLabel.fKey != scDragMgr.utilities.fUndef) { 867 scDragMgr.utilities.logError("dragdrop.makeDragableLabel: "+pLabel.id+" is already init.") 868 return 869 } 870 pLabel.fIsDraggable = true 871 // update container's GUI if needed 872 if (pLabel.parentNode.fCatchment && pLabel.parentNode.fCatchment.xUpdateGui) { 873 pLabel.parentNode.fCatchment.xUpdateGui() 874 } 875 pHandle = pHandle ? pHandle : pLabel 876 var vGroup = scDragMgr.drag.createGroup(pLabel) 877 vGroup.setHandle(pHandle) 878 vGroup.transparentDrag() 879 vGroup.setThreshold(4) 880 vGroup.onTopWhileDragging() 881 vGroup.register('dragstart', this._onDragStart) 882 vGroup.register('dragmove', this._onDragMove) 883 vGroup.register('dragend', this._onDragEnd) 884 pLabel.fStartParent = null 885 pLabel.fLastParent = null 886 pLabel.fKey = vKey 887 pLabel.fGroup = vGroup 888 pLabel.xDropCallback = new Function() 889 } catch (vError) { 890 scDragMgr.utilities.logError("dragdrop.makeDragableLabel: "+vError) 891 } 892 }, 893 894 // EXTERNAL - LABEL - Fix a constraint box in which the label can be dragged 895 setConstraintBox : function(pLabel, pNode) { 896 try { 897 var vCoords = scDragMgr.coordinates 898 var vMaxTopLeft = vCoords.topLeftOffset(pNode) 899 var vMaxBottomRight = vCoords.bottomRightOffset(pNode).minus(vCoords._size(pLabel)) 900 pLabel.fGroup.addTransform(function(pCoordinate, pDragEvent) { 901 return pCoordinate.constrainTo(vMaxTopLeft, vMaxBottomRight) 902 }) 903 } catch (vError) { 904 scDragMgr.utilities.logError("dragdrop.setConstraintBox: "+vError) 905 } 906 }, 907 908 // EXTERNAL - LABEL - Set the callback function to be called on any successfull drop action 909 setCallback : function(pLabel, pfunction) { 910 try { 911 pLabel.xDropCallback = pfunction 912 } catch (vError) { 913 scDragMgr.utilities.logError("dragdrop.setCallback: "+vError) 914 } 915 }, 916 917 // EXTERNAL - LABEL - Turn the draggablilty of labels on and off 918 setDraggable : function (pLabel, pIsDraggable) { 919 try { 920 pLabel.fGroup.setDraggable(pIsDraggable) 921 } catch (vError) { 922 scDragMgr.utilities.logError("dragdrop.setDraggable: "+vError) 923 } 924 }, 925 926 // INTERNAL functions ======================================================== 927 // INTERNAL update acontainer GUI (show/hide ifEmpty etc) 928 _UpdateGui : function() { 929 var vHasItems = false 930 if (typeof this.fContainer != scDragMgr.utilities.fUndef) { 931 var vChild = this.fContainer.lastChild 932 while (vChild != null && !vHasItems) { 933 if (vChild.fIsDraggable) { 934 vHasItems = true 1007 935 } 1008 936 vChild = vChild.previousSibling 1009 937 } 1010 } 1011 1012 // init IfEmpty elt 1013 if (typeof pIfEmpty != scDragMgr.utilities.fUndef) { 1014 pCatchment.fIfEmpty = pIfEmpty 1015 } 1016 pCatchment.updateGui() 1017 }, 938 if (typeof this.fContainer != scDragMgr.utilities.fUndef && this.fContainer != this) this.fContainer.style["display"] = (!vHasItems ? "none" : this.fContainer.fDelaultDisplay) 939 if (typeof this.fIfEmpty != scDragMgr.utilities.fUndef) this.fIfEmpty.style["display"] = (vHasItems ? "none" : this.fIfEmpty.fDelaultDisplay) 940 } 941 this.topLeftPosition = scDragMgr.coordinates.topLeftOffset(this) 942 this.bottomRightPosition = scDragMgr.coordinates.bottomRightOffset(this) 943 return vHasItems 944 }, 945 946 // INTERNAL remove Item from current container and keep in temp storage 1018 947 _floatItem : function(pDragEvent) { 1019 948 var vGroup = pDragEvent.group 1020 949 var vItem = pDragEvent.group.element 1021 var vCurrentC atchment = vItem.parentNode.fCatchment1022 1023 v Group.fLastContainer = null950 var vCurrentContainer = vItem.parentNode 951 var vCurrentCatchment = vCurrentContainer.fCatchment 952 vItem.fLastContainer = null 1024 953 vCurrentCatchment.onDragOut() 1025 954 vCurrentCatchment.fContainer.removeChild(vItem) 1026 vCurrentCatchment. updateGui()955 vCurrentCatchment.xUpdateGui() 1027 956 scDragMgr.dragdrop.fDragContainer.style["position"] = 'absolute' 1028 957 scDragMgr.dragdrop.fDragContainer.style["top"] = '0px' 958 scDragMgr.dragdrop.fDragContainer.className = vCurrentContainer.className 1029 959 document.body.appendChild(scDragMgr.dragdrop.fDragContainer) 1030 960 scDragMgr.dragdrop.fDragContainer.appendChild(vItem) 1031 961 }, 962 963 // INTERNAL remove Item from temp storage 1032 964 _unfloatItem : function(pDragEvent) { 1033 965 var vItem = pDragEvent.group.element 1034 1035 scDragMgr.dragdrop.fDragContainer.removeChild(vItem) 1036 document.body.removeChild(scDragMgr.dragdrop.fDragContainer) 1037 }, 1038 1039 _initSingleZone : function(pCatchment, pContainer, pIfEmpty, pKey) { 1040 this._initZone(pCatchment, pContainer, pIfEmpty, pKey) 1041 pCatchment.fIsSingleZone = true 1042 pCatchment.fFull = pCatchment.fHasInitItems 1043 pCatchment.xIsDropable = this._IsDropableSingleZone 1044 pCatchment.xOnDragOver = this._onDragOverSingleZone 1045 pCatchment.xOnDragOut = this._onDragOutSingleZone 1046 }, 1047 _IsDropableSingleZone : function(pDragEvent, pCatchment) { 1048 return( !pCatchment.fFull || pDragEvent.group.element.parentNode.fCatchment == pCatchment ) 1049 }, 1050 _onDragOverSingleZone : function(pDragEvent, pCatchment) { 966 if (vItem.parentNode == scDragMgr.dragdrop.fDragContainer){ 967 scDragMgr.dragdrop.fDragContainer.removeChild(vItem) 968 document.body.removeChild(scDragMgr.dragdrop.fDragContainer) 969 } 970 }, 971 972 // INTERNAL drag/drop functions 973 _IsDropable : function(pDragEvent, pCatchment) { 974 return( pCatchment.fMaxLabels =-1 || scDragMgr.dragdrop.countLabels(pCatchment.fContainer) < pCatchment.fMaxLabels || pDragEvent.group.element.parentNode.fCatchment == pCatchment ) 975 }, 976 _onDragOver : function(pDragEvent, pCatchment) { 1051 977 var vGroup = pDragEvent.group 1052 978 var vItem = pDragEvent.group.element 1053 1054 if(vGroup.fLastContainer == null){ 979 if(vItem.fLastContainer == null){ 1055 980 scDragMgr.dragdrop._unfloatItem(pDragEvent) 1056 981 }else{ … … 1058 983 vCurrentCatchment.onDragOut() 1059 984 vCurrentCatchment.fContainer.removeChild(vItem) 1060 vCurrentCatchment.fFull = false 1061 vCurrentCatchment.updateGui() 1062 } 985 vCurrentCatchment.xUpdateGui() 986 } 987 pCatchment.fContainer.appendChild(vItem) 988 vItem.fLastContainer = pCatchment.fContainer 989 pCatchment.xUpdateGui() 990 pCatchment.onDragOver() 991 }, 992 _onDragOut : function(pDragEvent) { 993 scDragMgr.dragdrop._floatItem(pDragEvent) 994 }, 995 _onDropReposition : function(pDragEvent) { 996 var vItem = pDragEvent.group.element 997 scDragMgr.coordinates.create(0, 0).reposition(vItem) 998 }, 999 // INTERNAL - sorting algorythm 1000 _onDragSort : function(pDragEvent, pCatchment) { 1001 var vHelpers = scDragMgr.helpers 1002 var vItem = pDragEvent.group.element 1003 var vMoveTo = null 1004 var vCoordinates = scDragMgr.coordinates 1005 var vXmouse = pDragEvent.transformedMouseOffset 1063 1006 1064 pCatchment.fFull = true 1065 pCatchment.fContainer.appendChild(vItem) 1066 vGroup.fLastContainer = pCatchment.fContainer 1067 pCatchment.updateGui() 1068 pCatchment.onDragOver() 1069 }, 1070 _onDragOutSingleZone : function(pDragEvent) { 1071 var vGroup = pDragEvent.group 1072 var vItem = pDragEvent.group.element 1073 var vCurrentCatchment = vItem.parentNode.fCatchment 1074 1075 vCurrentCatchment.fFull = false 1076 scDragMgr.dragdrop._floatItem(pDragEvent) 1077 }, 1078 1007 var vPrevious = vHelpers.previousItem(vItem, vItem.nodeName) 1008 while (vPrevious != null) { 1009 var vThreshold = vCoordinates.bottomRightOffset(vPrevious) 1010 // var vThreshold = vCoordinates.bottomRightOffset(vPrevious).minus(vCoordinates.create(vPrevious.offsetWidth/2, vPrevious.offsetHeight/2)) 1011 if (vXmouse.y <= vThreshold.y && vXmouse.x <= vThreshold.x) { 1012 vMoveTo = vPrevious 1013 } 1014 vPrevious = vHelpers.previousItem(vPrevious, vItem.nodeName) 1015 } 1016 if (vMoveTo != null) { 1017 vHelpers.moveBefore(vItem, vMoveTo) 1018 return 1019 } 1020 1021 var vNext = vHelpers.nextItem(vItem, vItem.nodeName) 1022 while (vNext != null) { 1023 // var vThreshold = vCoordinates.bottomRightOffset(vNext).minus(vCoordinates.create(vNext.offsetWidth/2, vNext.offsetHeight/2)) 1024 var vThreshold = vCoordinates.topLeftOffset(vNext) 1025 if (vThreshold.y <= vXmouse.y && vThreshold.x <= vXmouse.x) { 1026 vMoveTo = vNext 1027 } 1028 vNext = vHelpers.nextItem(vNext, vItem.nodeName) 1029 } 1030 if (vMoveTo != null) { 1031 vHelpers.moveBefore(vItem, vHelpers.nextItem(vMoveTo, vItem.nodeName)) 1032 return 1033 } 1034 }, 1035 1036 // INTERNAL Main drag/drop functions ========================================= 1079 1037 _onDragStart : function(pDragEvent) { 1080 1038 var vCoordinates = scDragMgr.coordinates 1039 var vItem = pDragEvent.group.element 1081 1040 1082 1041 // update all Catchment bounds, since they may have changed on a previous drag 1083 var vCatchment = scDragMgr.dragdrop.fFirstCatchments[ pDragEvent.group.element.parentNode.fCatchment.fKey]1042 var vCatchment = scDragMgr.dragdrop.fFirstCatchments[vItem.fKey] 1084 1043 while (vCatchment != null) { 1085 1044 vCatchment.topLeftPosition = vCoordinates.topLeftOffset(vCatchment) 1086 vCatchment.bottomRightPosition = vCoordinates.bottomRightOffset( vCatchment)1045 vCatchment.bottomRightPosition = vCoordinates.bottomRightOffset(vCatchment) 1087 1046 vCatchment = vCatchment.fNextCatchment 1088 1047 } 1089 1048 // item starts out over current parent 1090 pDragEvent.group.fStartContainer = pDragEvent.group.element.parentNode1091 pDragEvent.group.fLastContainer = pDragEvent.group.fStartContainer1092 pDragEvent.group.element.parentNode.fCatchment.onDragOver()1049 vItem.fStartContainer = vItem.parentNode 1050 vItem.fLastContainer = vItem.fStartContainer 1051 vItem.parentNode.fCatchment.onDragOver() 1093 1052 }, 1094 1053 _onDragMove : function(pDragEvent) { 1095 1054 var vHelpers = scDragMgr.helpers 1096 1055 var vGroup = pDragEvent.group 1097 var vItem = pDragEvent.group.element1056 var vItem = vGroup.element 1098 1057 1099 1058 // Check to see if we are in any catchment zone of our key 1100 1059 var vIsOutside = true 1101 var vCatchment = scDragMgr.dragdrop.fFirstCatchments[v Group.fStartContainer.fCatchment.fKey]1060 var vCatchment = scDragMgr.dragdrop.fFirstCatchments[vItem.fKey] 1102 1061 while (vCatchment != null) { 1103 1062 if (vHelpers.isMouseInside(pDragEvent, vCatchment) && vCatchment.xIsDropable(pDragEvent, vCatchment)) { … … 1109 1068 // If we are outside all catchment zones then float the item if needed 1110 1069 if (vIsOutside) { 1111 if (v Group.fLastContainer != null) {1112 v Group.fLastContainer.fCatchment.xOnDragOut(pDragEvent)1070 if (vItem.fLastContainer != null) { 1071 vItem.fLastContainer.fCatchment.xOnDragOut(pDragEvent) 1113 1072 } 1114 1073 1115 1074 // else if we are in a new catchment zone switch to the new one 1116 } else if (v Group.fLastContainer == null || vCatchment != vGroup.fLastContainer.fCatchment) {1075 } else if (vItem.fLastContainer == null || vCatchment != vItem.fLastContainer.fCatchment) { 1117 1076 vCatchment.xOnDragOver(pDragEvent, vCatchment) 1118 1077 } 1078 if (vCatchment) vCatchment.xOnDragPostProcess(pDragEvent, vCatchment) 1119 1079 }, 1120 1080 _onDragEnd : function(pDragEvent) { 1081 var vItem = pDragEvent.group.element 1121 1082 1122 1083 // If we are still floated (not in any catchment zone) then restore the item to it's original container 1123 if (pDragEvent.group.fLastContainer == null) { 1124 pDragEvent.group.fStartContainer.fCatchment.xOnDragOver(pDragEvent, pDragEvent.group.fStartContainer.fCatchment) 1125 } 1126 pDragEvent.group.element.parentNode.fCatchment.onDragOut() 1127 scDragMgr.coordinates.create(0, 0).reposition(pDragEvent.group.element) 1128 } 1129 } 1084 if (vItem.fLastContainer == null && vItem.fStartContainer) { 1085 vItem.fStartContainer.fCatchment.xOnDragOver(pDragEvent, vItem.fStartContainer.fCatchment) 1086 } 1087 vItem.parentNode.fCatchment.onDragOut() 1088 if (vItem.fStartContainer != vItem.parentNode) { 1089 try{ 1090 vItem.xDropCallback() 1091 } catch (e){} 1092 } 1093 vItem.parentNode.fCatchment.xOnDragEndPostProcess(pDragEvent) 1094 } 1095 }
Note: See TracChangeset
for help on using the changeset viewer.