diff options
Diffstat (limited to 'js/dojo/dojox/mdnd/adapter')
| -rw-r--r-- | js/dojo/dojox/mdnd/adapter/DndFromDojo.js | 365 | ||||
| -rw-r--r-- | js/dojo/dojox/mdnd/adapter/DndToDojo.js | 484 |
2 files changed, 849 insertions, 0 deletions
diff --git a/js/dojo/dojox/mdnd/adapter/DndFromDojo.js b/js/dojo/dojox/mdnd/adapter/DndFromDojo.js new file mode 100644 index 0000000..8f0a3f1 --- /dev/null +++ b/js/dojo/dojox/mdnd/adapter/DndFromDojo.js @@ -0,0 +1,365 @@ +//>>built +define("dojox/mdnd/adapter/DndFromDojo", ["dojo/_base/kernel","dojo/_base/declare","dojo/_base/connect","dojo/_base/array", + "dojo/_base/html","dojo/_base/window","dojox/mdnd/AreaManager","dojo/dnd/Manager"],function(dojo){ + var dfd = dojo.declare( + "dojox.mdnd.adapter.DndFromDojo", + null, + { + // summary + // Allow communication between Dojo dnd items and DojoX D&D areas + + // dropIndicatorSize: Object + // size by default of dropIndicator (display only into a D&D Area) + dropIndicatorSize : {'w':0,'h':50}, + + // dropIndicatorSize: Object + // size by default of dropIndicator (display only into a D&D Area) + dropIndicatorSize: {'w':0,'h':50}, + + // _areaManager: Object + // Reference to the current DojoX Dnd Manager + _areaManager: null, + + // _dojoManager + // Reference to the current Dojo Manager + _dojoManager: null, + + // _currentArea: Object + // The current Area on mouse over + _currentArea: null, + + // _oldArea: Object + // The old area the mouse has passed over + _oldArea: null, + + // _moveHandler: Object + // The handler of mouse connection + _moveHandler: null, + + // _subscribeHandler: Array + // The list of dojo dnd topics + _subscribeHandler: null, + + constructor: function(){ + this._areaManager = dojox.mdnd.areaManager(); + this._dojoManager = dojo.dnd.manager(); + this._currentArea = null; + this._moveHandler = null; + this.subscribeDnd(); + }, + + subscribeDnd: function(){ + // summary: + // Subscribe to somes topics of dojo drag and drop. + + //console.log(("dojox.mdnd.adapter.DndFromDojo ::: subscribeDnd"); + this._subscribeHandler = [ + dojo.subscribe("/dnd/start",this,"onDragStart"), + dojo.subscribe("/dnd/drop/before", this, "onDrop"), + dojo.subscribe("/dnd/cancel",this,"onDropCancel"), + dojo.subscribe("/dnd/source/over",this,"onDndSource") + ] + }, + + unsubscribeDnd: function(){ + // summary: + // Unsubscribe to some topics of dojo drag and drop. + + //console.log(("dojox.mdnd.adapter.DndFromDojo ::: unsubscribeDnd"); + dojo.forEach(this._subscribeHandler, dojo.unsubscribe); + }, + + _getHoverArea: function(/*Object*/ coords){ + // summary: + // Get a D&D dojoX area as a DOM node positioned under a specific point. + // coords: + // Object containing the coordinates x and y (mouse position) + // tags: + // protected + + //console.log("dojox.mdnd.adapter.DndFromDojo ::: _getHoverArea"); + var x = coords.x; + var y = coords.y; + this._oldArea = this._currentArea; + this._currentArea = null; + var areas = this._areaManager._areaList; + for(var i = 0; i < areas.length; i++){ + var area = areas[i]; + var startX = area.coords.x; + var endX = startX + area.node.offsetWidth; + var startY = area.coords.y; + var endY = startY + area.node.offsetHeight; + // check if the coordinates mouse is in a D&D Area + if(startX <= x && x <= endX && startY <= y && y <= endY){ + this._areaManager._oldIndexArea = this._areaManager._currentIndexArea; + this._areaManager._currentIndexArea = i; + this._currentArea = area.node; + break; + } + } + if(this._currentArea != this._oldArea){ + if(this._currentArea == null){ + // case when the dragNode was in a D&D area but it's out now. + this.onDragExit(); + } + else if(this._oldArea == null){ + // case when the dragNode was out a D&D area but it's in now. + this.onDragEnter(); + } + else{ + // case when the dragNode was in a D&D area and enter in an other D&D area directly. + this.onDragExit(); + this.onDragEnter(); + } + } + + //console.log("dojox.mdnd.adapter.DndFromDojo ::: _getHoverArea",this._dojoManager.avatar.node,this._currentArea,this._oldArea); + }, + + onDragStart: function(/*Object*/source, /*Array*/nodes, /*Boolean*/copy){ + // summary: + // Occurs when the "/dnd/start" topic is published. + // source: + // the source which provides items + // nodes: + // the list of transferred items + // copy: + // copy items, if true, move items otherwise + // tags: + // callback + + //console.log("dojox.mdnd.adapter.DndFromDojo ::: onDragStart"); + // catch the dragNode to get the type when it's necessary. + this._dragNode = nodes[0]; + this._copy = copy; this._source = source; + // Connect the onMouseMove : + // It's usefull to activate the detection of a D&D area and the dropIndicator place only if + // the dragNode is out of a the source dojo. The classic behaviour of the dojo source is kept. + this._outSourceHandler = dojo.connect(this._dojoManager, "outSource", this, function(){ + //dojo.disconnect(this._outSourceHandler); + if(this._moveHandler == null){ + this._moveHandler = dojo.connect(dojo.doc, "mousemove", this, "onMouseMove"); + } + }); + }, + + onMouseMove: function(/*DOMEvent*/e){ + // summary: + // Occurs when the user moves the mouse. + // e: + // the DOM event + // tags: + // callback + + //console.log("dojox.mdnd.adapter.DndFromDojo ::: onMouseMove"); + // calculate the coordonates of the mouse. + var coords = { + 'x': e.pageX, + 'y': e.pageY + }; + this._getHoverArea(coords); + // if a D&D area has been found and if it's accepted to drop this type of dragged node + if(this._currentArea && this._areaManager._accept){ + // specific case : a dropIndicator can be hidden (see onDndSource method) + if(this._areaManager._dropIndicator.node.style.visibility == "hidden"){ + this._areaManager._dropIndicator.node.style.visibility = ""; + dojo.addClass(this._dojoManager.avatar.node, "dojoDndAvatarCanDrop"); + } + // place the dropIndicator in D&D Area with a default size. + this._areaManager.placeDropIndicator(coords, this.dropIndicatorSize); + } + }, + + onDragEnter: function(){ + // summary: + // Occurs when the user drages an DOJO dnd item inside a D&D dojoX area. + // tags: + // callback + + //console.log("dojox.mdnd.adapter.DndFromDojo ::: onDragEnter"); + // Check if the type of dragged node is accepted in the selected D&D dojoX Area. + var _dndType = this._dragNode.getAttribute("dndType"); + // need to have an array as type + var type = (_dndType) ? _dndType.split(/\s*,\s*/) : ["text"]; + this._areaManager._isAccepted(type, this._areaManager._areaList[this._areaManager._currentIndexArea].accept); + // if the D&D dojoX Area accepts the drop, change the color of Avatar. + if(this._dojoManager.avatar){ + if(this._areaManager._accept){ + dojo.addClass(this._dojoManager.avatar.node, "dojoDndAvatarCanDrop"); + } + else{ + dojo.removeClass(this._dojoManager.avatar.node, "dojoDndAvatarCanDrop"); + } + } + }, + + onDragExit: function(){ + // summary: + // Occurs when the user leaves a D&D dojoX area after dragging an DOJO dnd item over it. + + //console.log("dojox.mdnd.adapter.DndFromDojo ::: onDragExit"); + // if the dragged node exits of a D&D dojoX Area : + this._areaManager._accept = false; + // change color of avatar + if(this._dojoManager.avatar){ + dojo.removeClass(this._dojoManager.avatar.node, "dojoDndAvatarCanDrop"); + } + // reset all variables and remove the dropIndicator. + if(this._currentArea == null){ + this._areaManager._dropMode.refreshItems(this._areaManager._areaList[this._areaManager._oldIndexArea], this._areaManager._oldDropIndex, this.dropIndicatorSize, false); + this._areaManager._resetAfterDrop(); + } + else{ + this._areaManager._dropIndicator.remove(); + } + }, + + isAccepted: function(/*Node*/node, /*Object*/accept){ + // summary: + // Check if a dragNode is accepted into a dojo target. + // node: + // The dragged node. + // accept: + // Object containing the type accepted for a target dojo. + // returns: + // true if the dragged node is accepted in the target dojo. + + //console.log("dojox.mdnd.adapter.DndFromDojo ::: isAccepted"); + var type = (node.getAttribute("dndType")) ? node.getAttribute("dndType") : "text"; + if(type && type in accept) + return true; // Boolean + else + return false; // Boolean + }, + + onDndSource: function(/*Object*/ source){ + // summary: + // Called when the mouse enters or exits of a source dojo. + // source: + // the dojo source/target + // tags: + // callback + + //console.log("dojox.mdnd.adapter.DndFromDojo ::: onDndSource",source); + // Only the case : "source dojo into a D&D dojoX Area" is treated. + if(this._currentArea == null){ + return; + } + if(source){ + // Enter in a source/target dojo. + // test if the type of draggedNode is accepted : + var accept = false; + if(this._dojoManager.target == source){ + accept = true; + } + else{ + accept = this.isAccepted(this._dragNode, source.accept); + } + if(accept){ + // disconnect the onMouseMove to disabled the search of a drop zone in the D&D dojoX Area. + dojo.disconnect(this._moveHandler); + this._currentArea = this._moveHandler = null; + // hidden the visibility of dojoX dropIndicator to prevent an offset when the dropIndicator disappears. + // test if drop indicator is visible before applaying hidden style. + var dropIndicator = this._areaManager._dropIndicator.node; + if(dropIndicator && dropIndicator.parentNode !== null && dropIndicator.parentNode.nodeType == 1) + dropIndicator.style.visibility = "hidden"; + } + else{ + // if the type of dragged node is not accepted in the target dojo, the color of avatar + // have to be the same that the color of D&D dojoX Area acceptance. + this._resetAvatar(); + } + } + else{ + // Exit of a source/target dojo. + // reconnect the onMouseMove to enabled the search of a drop zone in the D&D dojox Area. + if(!this._moveHandler) + this._moveHandler = dojo.connect(dojo.doc, "mousemove", this, "onMouseMove"); + + this._resetAvatar(); + } + }, + + _resetAvatar: function(){ + // summary: + // Function executed in onDndSource function to set the avatar + // acceptance according to the dojox DnD AreaManager Acceptance. + // It is used when The mouse exit a source/target dojo or if the + // dragged node is not accepted in dojo source / target. + // tags: + // protected + + //console.log("dojox.mdnd.adapter.DndFromDojo ::: _resetAvatar"); + if(this._dojoManager.avatar){ + if(this._areaManager._accept){ + dojo.addClass(this._dojoManager.avatar.node, "dojoDndAvatarCanDrop"); + } + else{ + dojo.removeClass(this._dojoManager.avatar.node, "dojoDndAvatarCanDrop"); + } + } + }, + + onDropCancel: function(){ + // summary: + // Occurs when the "/dnd/cancel" topic is published. + // tags: + // callback + + //console.log("dojox.mdnd.adapter.DndFromDojo ::: onDropCancel"); + if(this._currentArea == null){ + // the dragged node is not in the D&D dojox Area => Cancel + this._areaManager._resetAfterDrop(); + dojo.disconnect(this._moveHandler); + dojo.disconnect(this._outSourceHandler); + this._currentArea = this._moveHandler = this._outSourceHandler = null; + } + else{ + // the dragged node is in the D&D dojox Area + // (catch when dragged node exits of a source/target dojo and stays in the same D&D dojox Area) + // dojo cancel the drop but it's authorized in the D&D Area + if(this._areaManager._accept){ + this.onDrop(this._source, [this._dragNode], this._copy, this._currentArea); + } + else{ + this._currentArea = null; + dojo.disconnect(this._outSourceHandler); + dojo.disconnect(this._moveHandler); + this._moveHandler = this._outSourceHandler = null; + } + } + }, + + onDrop: function(/*Object*/source, /*Array*/nodes, /*Boolean*/copy){ + // summary: + // Occurs when the user leaves a D&D dojox area after dragging an DOJO dnd item over it. + // source: + // the source which provides items + // nodes: + // the list of transferred items + // copy: + // copy items, if true, move items otherwise + // tags: + // callback + + //console.log("dojox.mdnd.adapter.DndFromDojo ::: onDrop", this._currentArea); + dojo.disconnect(this._moveHandler); + dojo.disconnect(this._outSourceHandler); + this._moveHandler = this._outSourceHandler = null; + if(this._currentArea){ + var dropIndex = this._areaManager._currentDropIndex; + dojo.publish("/dnd/drop/after", [source, nodes, copy, this._currentArea, dropIndex]); + this._currentArea = null; + } + if(this._areaManager._dropIndicator.node.style.visibility == "hidden"){ + this._areaManager._dropIndicator.node.style.visibility = ""; + } + this._areaManager._resetAfterDrop(); + } + }); + + dojox.mdnd.adapter._dndFromDojo = null; + dojox.mdnd.adapter._dndFromDojo = new dojox.mdnd.adapter.DndFromDojo(); + return dfd; +}); diff --git a/js/dojo/dojox/mdnd/adapter/DndToDojo.js b/js/dojo/dojox/mdnd/adapter/DndToDojo.js new file mode 100644 index 0000000..baaf9b1 --- /dev/null +++ b/js/dojo/dojox/mdnd/adapter/DndToDojo.js @@ -0,0 +1,484 @@ +//>>built +define("dojox/mdnd/adapter/DndToDojo", ["dojo/_base/kernel","dojo/_base/declare","dojo/_base/html","dojo/_base/connect", + "dojo/_base/window","dojo/_base/array","dojox/mdnd/PureSource","dojox/mdnd/LazyManager"],function(dojo){ + var dtd = dojo.declare( + "dojox.mdnd.adapter.DndToDojo", + null, + { + // summary: + // Allow communication between an item of dojox D&D area to a target dojo. + + // _dojoList: Array + // Array containing object references the dojo Target list + _dojoList: null, + + // _currentDojoArea: DOMNode + // Representing the current dojo area + _currentDojoArea: null, + + // _dojoxManager: dojox.mdnd.AreaManager + // The reference to the dojox AreaManager + _dojoxManager: null, + + // _dragStartHandler: Object + // Handle to keep start subscribe + _dragStartHandler: null, + + // _dropHandler: Object + // Handle to keep drop subscribe + _dropHandler: null, + + // _moveHandler: Object + // Handle to keep move subscribe + _moveHandler: null, + + // _moveUpHandler: Object + // Handle to kee move up subscribe + _moveUpHandler: null, + + // _draggedNode: DOMNode + // The current dragged node + _draggedNode: null, + + constructor: function(){ + this._dojoList = []; + this._currentDojoArea = null; + this._dojoxManager = dojox.mdnd.areaManager(); + this._dragStartHandler = dojo.subscribe("/dojox/mdnd/drag/start", this, function(node, sourceArea, sourceDropIndex){ + this._draggedNode = node; + this._moveHandler = dojo.connect(dojo.doc, "onmousemove", this, "onMouseMove"); + }); + this._dropHandler = dojo.subscribe("/dojox/mdnd/drop", this, function(node, targetArea, indexChild){ + if(this._currentDojoArea){ + dojo.publish("/dojox/mdnd/adapter/dndToDojo/cancel", [this._currentDojoArea.node, this._currentDojoArea.type, this._draggedNode, this.accept]); + } + this._draggedNode = null; + this._currentDojoArea = null; + dojo.disconnect(this._moveHandler); + }); + }, + + _getIndexDojoArea: function(/*node*/area){ + // summary: + // Check if a dojo area is registered. + // area: DOMNode + // A node corresponding to the target dojo. + // returns: + // The index of area if it's registered else -1. + // tags: + // protected + + //console.log('dojox.mdnd.adapter.DndToDojo ::: _getIndexDojoArea'); + if(area){ + for(var i = 0, l = this._dojoList.length; i < l; i++){ + if(this._dojoList[i].node === area){ + return i; + } + } + } + return -1; + }, + + _initCoordinates: function(/*DOMNode*/area){ + // summary: + // Initialize the coordinates of the target dojo. + // area: + // A registered DOM node. + // returns: + // An object which contains coordinates : *{x:0,y:,x1:0,y1:0}* + // tags: + // protected + + //console.log('dojox.mdnd.adapter.DndToDojo ::: _initCoordinates'); + if(area){ + var position = dojo.position(area, true), + coords = {}; + coords.x = position.x + coords.y = position.y + coords.x1 = position.x + position.w; + coords.y1 = position.y + position.h; + return coords; // Object + } + return null; + }, + + register: function(/*DOMNode*/area, /*String*/ type,/*Boolean*/ dojoTarget){ + // summary: + // Register a target dojo. + // The target is represented by an object containing : + // - the dojo area node + // - the type reference to identify a group node + // - the coords of the area to enable refresh position + // area: + // The DOM node which has to be registered. + // type: + // A String to identify the node. + // dojoTarger: + // True if the dojo D&D have to be enable when mouse is hover the registered target dojo. + + //console.log("dojox.mdnd.adapter.DndToDojo ::: registerDojoArea", area, type, dojoTarget); + if(this._getIndexDojoArea(area) == -1){ + var coords = this._initCoordinates(area), + object = { + 'node': area, + 'type': type, + 'dojo': (dojoTarget)?dojoTarget:false, + 'coords': coords + }; + this._dojoList.push(object); + // initialization of the _fakeSource to allow Dnd switching + if(dojoTarget && !this._lazyManager){ + this._lazyManager = new dojox.mdnd.LazyManager(); + } + } + }, + + unregisterByNode: function(/*DOMNode*/area){ + // summary: + // Unregister a target dojo. + // area: + // The DOM node of target dojo. + + //console.log("dojox.mdnd.adapter.DndToDojo ::: unregisterByNode", area); + var index = this._getIndexDojoArea(area); + // if area is registered + if(index != -1){ + this._dojoList.splice(index, 1); + } + }, + + unregisterByType: function(/*String*/type){ + // summary: + // Unregister several targets dojo having the same type passing in parameter. + // type: + // A String to identify dojo targets. + + //console.log("dojox.mdnd.adapter.DndToDojo ::: unregisterByType", type); + if(type){ + var tempList = []; + dojo.forEach(this._dojoList, function(item, i){ + if(item.type != type){ + tempList.push(item); + } + }); + this._dojoList = tempList; + } + }, + + unregister: function(){ + // summary: + // Unregister all targets dojo. + + //console.log("dojox.mdnd.adapter.DndToDojo ::: unregister"); + this._dojoList = []; + }, + + refresh: function(){ + // summary: + // Refresh the coordinates of all registered dojo target. + + //console.log("dojox.mdnd.adapter.DndToDojo ::: refresh"); + var dojoList = this._dojoList; + this.unregister(); + dojo.forEach(dojoList, function(dojo){ + dojo.coords = this._initCoordinates(dojo.node); + }, this); + this._dojoList = dojoList; + }, + + refreshByType: function(/*String*/ type){ + // summary: + // Refresh the coordinates of registered dojo target with a specific type. + // type: + // A String to identify dojo targets. + + //console.log("dojox.mdnd.adapter.DndToDojo ::: refresh"); + var dojoList = this._dojoList; + this.unregister(); + dojo.forEach(dojoList, function(dojo){ + if(dojo.type == type){ + dojo.coords = this._initCoordinates(dojo.node); + } + }, this); + this._dojoList = dojoList; + }, + + _getHoverDojoArea: function(/*Object*/coords){ + // summary: + // Check if the coordinates of the mouse is in a dojo target. + // coords: + // Coordinates of the mouse. + // tags: + // protected + + //console.log("dojox.mdnd.adapter.DndToDojo ::: _getHoverDojoArea"); + this._oldDojoArea = this._currentDojoArea; + this._currentDojoArea = null; + var x = coords.x; + var y = coords.y; + var length = this._dojoList.length; + for(var i = 0; i < length; i++){ + var dojoArea = this._dojoList[i]; + var coordinates = dojoArea.coords; + if(coordinates.x <= x && x <= coordinates.x1 && coordinates.y <= y && y <= coordinates.y1){ + this._currentDojoArea = dojoArea; + break; + } + } + }, + + onMouseMove: function(/*DOMEvent*/e){ + // summary: + // Call when the mouse moving after an onStartDrag of AreaManger. + // Check if the coordinates of the mouse is in a dojo target. + // e: + // Event object. + // tags: + // callback + + //console.log("dojox.mdnd.adapter.DndToDojo ::: onMouseMove"); + var coords = { + 'x': e.pageX, + 'y': e.pageY + }; + this._getHoverDojoArea(coords); + if(this._currentDojoArea != this._oldDojoArea){ + if(this._currentDojoArea == null){ + this.onDragExit(e); + } + else if(this._oldDojoArea == null){ + this.onDragEnter(e); + } + else{ + this.onDragExit(e); + this.onDragEnter(e); + } + } + }, + + isAccepted: function(/*DOMNode*/draggedNode, /*Object*/ target){ + // summary: + // Return true if the dragged node is accepted. + // This method has to be overwritten according to registered target. + + //console.log("dojox.mdnd.adapter.DndToDojo ::: isAccepted"); + return true; + }, + + + onDragEnter: function(/*DOMEvent*/e){ + // summary: + // Call when the mouse enters in a registered dojo target. + // e: + // The current Javascript Event. + // tags: + // callback + + //console.log("dojox.mdnd.adapter.DndToDojo ::: onDragEnter"); + // specific for drag and drop switch + if(this._currentDojoArea.dojo){ + // disconnect + dojo.disconnect(this._dojoxManager._dragItem.handlers.pop()); + dojo.disconnect(this._dojoxManager._dragItem.handlers.pop()); + //disconnect onmousemove of moveable item + //console.info("before",this._dojoxManager._dragItem.item.events.pop()); + dojo.disconnect(this._dojoxManager._dragItem.item.events.pop()); + dojo.body().removeChild(this._dojoxManager._cover); + dojo.body().removeChild(this._dojoxManager._cover2); + var node = this._dojoxManager._dragItem.item.node; + // hide dragNode : + // disconnect the dojoDndAdapter if it's initialize + if(dojox.mdnd.adapter._dndFromDojo){ + dojox.mdnd.adapter._dndFromDojo.unsubscribeDnd(); + } + dojo.style(node, { + 'position': "relative", + 'top': '0', + 'left': '0' + }); + // launch the drag and drop Dojo. + this._lazyManager.startDrag(e, node); + var handle = dojo.connect(this._lazyManager.manager, "overSource", this, function(){ + dojo.disconnect(handle); + if(this._lazyManager.manager.canDropFlag){ + // remove dropIndicator + this._dojoxManager._dropIndicator.node.style.display = "none"; + } + }); + + this.cancelHandler = dojo.subscribe("/dnd/cancel", this, function(){ + var moveableItem = this._dojoxManager._dragItem.item; + // connect onmousemove of moveable item + // need to reconnect the onmousedown of movable class. + moveableItem.events = [ + dojo.connect(moveableItem.handle, "onmousedown", moveableItem, "onMouseDown") + ]; + // replace the cover and the dragNode in the cover. + dojo.body().appendChild(this._dojoxManager._cover); + dojo.body().appendChild(this._dojoxManager._cover2); + this._dojoxManager._cover.appendChild(moveableItem.node); + + var objectArea = this._dojoxManager._areaList[this._dojoxManager._sourceIndexArea]; + var dropIndex = this._dojoxManager._sourceDropIndex; + var nodeRef = null; + if(dropIndex != objectArea.items.length + && dropIndex != -1){ + nodeRef = objectArea.items[this._dojoxManager._sourceDropIndex].item.node; + } + if(this._dojoxManager._dropIndicator.node.style.display == "none"){ + this._dojoxManager._dropIndicator.node.style.display == ""; + } + this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item, "onDrag", this._dojoxManager, "onDrag")); + this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item, "onDragEnd", this._dojoxManager, "onDrop")); + this._draggedNode.style.display = ""; + this._dojoxManager.onDrop(this._draggedNode); + dojo.unsubscribe(this.cancelHandler); + dojo.unsubscribe(this.dropHandler); + if(dojox.mdnd.adapter._dndFromDojo){ + dojox.mdnd.adapter._dndFromDojo.subscribeDnd(); + } + }); + this.dropHandler = dojo.subscribe("/dnd/drop/before", this, function(params){ + dojo.unsubscribe(this.cancelHandler); + dojo.unsubscribe(this.dropHandler); + this.onDrop(); + }); + } + else{ + this.accept = this.isAccepted(this._dojoxManager._dragItem.item.node, this._currentDojoArea); + if(this.accept){ + // disconnect + dojo.disconnect(this._dojoxManager._dragItem.handlers.pop()); + dojo.disconnect(this._dojoxManager._dragItem.handlers.pop()); + // remove dropIndicator + this._dojoxManager._dropIndicator.node.style.display = "none"; + if(!this._moveUpHandler){ + this._moveUpHandler = dojo.connect(dojo.doc, "onmouseup", this, "onDrop"); + } + } + } + // publish a topic + dojo.publish("/dojox/mdnd/adapter/dndToDojo/over",[this._currentDojoArea.node, this._currentDojoArea.type, this._draggedNode, this.accept]); + }, + + onDragExit: function(/*DOMEvent*/e){ + // summary: + // Call when the mouse exit of a registered dojo target. + // e: + // current javscript event + + //console.log("dojox.mdnd.adapter.DndToDojo ::: onDragExit",e, this._dojoxManager._dragItem.item); + // set the old height of dropIndicator. + if(this._oldDojoArea.dojo){ + // unsubscribe the topic /dnd/cancel and /dnd/drop/before + dojo.unsubscribe(this.cancelHandler); + dojo.unsubscribe(this.dropHandler); + // launch Drag and Drop + var moveableItem = this._dojoxManager._dragItem.item; + // connect onmousemove of moveable item + this._dojoxManager._dragItem.item.events.push(dojo.connect( + moveableItem.node.ownerDocument, + "onmousemove", + moveableItem, + "onMove" + )); + // replace the cover and the dragNode in the cover. + dojo.body().appendChild(this._dojoxManager._cover); + dojo.body().appendChild(this._dojoxManager._cover2); + this._dojoxManager._cover.appendChild(moveableItem.node); + // fix style : + var style = moveableItem.node.style; + style.position = "absolute"; + style.left = (moveableItem.offsetDrag.l + e.pageX)+"px"; + style.top = (moveableItem.offsetDrag.t + e.pageX)+"px"; + style.display = ""; + // stop dojoDrag + this._lazyManager.cancelDrag(); + // reconnect the dndFromDojo + if(dojox.mdnd.adapter._dndFromDojo){ + dojox.mdnd.adapter._dndFromDojo.subscribeDnd(); + } + if(this._dojoxManager._dropIndicator.node.style.display == "none"){ + this._dojoxManager._dropIndicator.node.style.display = ""; + } + // reconnect the areaManager. + this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item, "onDrag", this._dojoxManager, "onDrag")); + this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item, "onDragEnd", this._dojoxManager, "onDrop")); + this._dojoxManager._dragItem.item.onMove(e); + } + else{ + if(this.accept){ + // disconnect the mouseUp event. + if(this._moveUpHandler){ + dojo.disconnect(this._moveUpHandler); + this._moveUpHandler = null; + } + // redisplay dropIndicator + if(this._dojoxManager._dropIndicator.node.style.display == "none"){ + this._dojoxManager._dropIndicator.node.style.display = ""; + } + // reconnect the areaManager. + this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item, "onDrag", this._dojoxManager, "onDrag")); + this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item, "onDragEnd", this._dojoxManager, "onDrop")); + this._dojoxManager._dragItem.item.onMove(e); + } + } + // publish a topic + dojo.publish("/dojox/mdnd/adapter/dndToDojo/out",[this._oldDojoArea.node, this._oldDojoArea.type, this._draggedNode, this.accept]); + }, + + onDrop: function(/*DOMEvent*/e){ + // summary: + // Called when an onmouseup event is loaded on a registered target dojo. + // e: + // Event object. + + // console.log("dojox.mdnd.adapter.DndToDojo ::: onDrop", this._currentDojoArea); + if(this._currentDojoArea.dojo){ + // reconnect the dojoDndAdapter + if(dojox.mdnd.adapter._dndFromDojo){ + dojox.mdnd.adapter._dndFromDojo.subscribeDnd(); + } + } + if(this._dojoxManager._dropIndicator.node.style.display == "none"){ + this._dojoxManager._dropIndicator.node.style.display = ""; + } + // remove the cover + if(this._dojoxManager._cover.parentNode && this._dojoxManager._cover.parentNode.nodeType == 1){ + dojo.body().removeChild(this._dojoxManager._cover); + dojo.body().removeChild(this._dojoxManager._cover2); + } + // remove draggedNode of target : + if(this._draggedNode.parentNode == this._dojoxManager._cover){ + this._dojoxManager._cover.removeChild(this._draggedNode); + } + dojo.disconnect(this._moveHandler); + dojo.disconnect(this._moveUpHandler); + this._moveHandler = this._moveUpHandler = null; + dojo.publish("/dojox/mdnd/adapter/dndToDojo/drop", [this._draggedNode, this._currentDojoArea.node, this._currentDojoArea.type]); + dojo.removeClass(this._draggedNode, "dragNode"); + var style = this._draggedNode.style; + style.position = "relative"; + style.left = "0"; + style.top = "0"; + style.width = "auto"; + dojo.forEach(this._dojoxManager._dragItem.handlers, dojo.disconnect); + this._dojoxManager._deleteMoveableItem(this._dojoxManager._dragItem); + this._draggedNode = null; + this._currentDojoArea = null; + // reset of area manager. + this._dojoxManager._resetAfterDrop(); + } + }); + + dojox.mdnd.adapter._dndToDojo = null; + dojox.mdnd.adapter.dndToDojo = function(){ + // summary: + // returns the current areaManager, creates one if it is not created yet + if(!dojox.mdnd.adapter._dndToDojo){ + dojox.mdnd.adapter._dndToDojo = new dojox.mdnd.adapter.DndToDojo(); + } + return dojox.mdnd.adapter._dndToDojo; // Object + }; + return dtd; +});
\ No newline at end of file |
