| 1 |
define(["dojo/_base/kernel", |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/lang", |
| 4 |
"dojo/_base/connect", |
| 5 |
"dojo/_base/array", |
| 6 |
"dojo/dom-class", |
| 7 |
"dojo/dnd/common", |
| 8 |
"dojo/dnd/Selector", |
| 9 |
"dojo/dnd/Manager" |
| 10 |
],function(dojo, declare, lang, connect, array, domClass, dnd, Selector, Manager){ |
| 11 |
var PureSource = declare( |
| 12 |
"dojox.mdnd.PureSource", |
| 13 |
Selector, |
| 14 |
{ |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
horizontal: false, |
| 21 |
copyOnly: true, |
| 22 |
skipForm: false, |
| 23 |
withHandles: false, |
| 24 |
isSource: true, |
| 25 |
targetState: "Disabled", |
| 26 |
generateText: true, |
| 27 |
|
| 28 |
constructor: function(node, params){ |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
lang.mixin(this, lang.mixin({}, params)); |
| 39 |
var type = this.accept; |
| 40 |
|
| 41 |
|
| 42 |
this.isDragging = false; |
| 43 |
this.mouseDown = false; |
| 44 |
|
| 45 |
|
| 46 |
this.sourceState = ""; |
| 47 |
domClass.add(this.node, "dojoDndSource"); |
| 48 |
if(this.horizontal){ |
| 49 |
domClass.add(this.node, "dojoDndHorizontal"); |
| 50 |
} |
| 51 |
|
| 52 |
this.topics = [ |
| 53 |
connect.subscribe("/dnd/cancel", this, "onDndCancel"), |
| 54 |
connect.subscribe("/dnd/drop", this, "onDndCancel") |
| 55 |
]; |
| 56 |
}, |
| 57 |
|
| 58 |
onDndCancel: function(){ |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
this.isDragging = false; |
| 67 |
this.mouseDown = false; |
| 68 |
delete this.mouseButton; |
| 69 |
}, |
| 70 |
|
| 71 |
copyState: function(keyPressed){ |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
return this.copyOnly || keyPressed; |
| 82 |
}, |
| 83 |
|
| 84 |
destroy: function(){ |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
PureSource.superclass.destroy.call(this); |
| 90 |
array.forEach(this.topics, connect.unsubscribe); |
| 91 |
this.targetAnchor = null; |
| 92 |
}, |
| 93 |
|
| 94 |
markupFactory: function(params, node){ |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
params._skipStartup = true; |
| 106 |
return new PureSource(node, params); |
| 107 |
}, |
| 108 |
|
| 109 |
onMouseMove: function(e){ |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
if(this.isDragging){ |
| 117 |
return; |
| 118 |
} |
| 119 |
PureSource.superclass.onMouseMove.call(this, e); |
| 120 |
var m = Manager.manager(); |
| 121 |
if(this.mouseDown && !this.isDragging && this.isSource){ |
| 122 |
var nodes = this.getSelectedNodes(); |
| 123 |
if(nodes.length){ |
| 124 |
m.startDrag(this, nodes, this.copyState(connect.isCopyKey(e))); |
| 125 |
this.isDragging = true; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
}, |
| 130 |
|
| 131 |
onMouseDown: function(e){ |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
if(this._legalMouseDown(e) && (!this.skipForm || !dnd.isFormElement(e))){ |
| 141 |
this.mouseDown = true; |
| 142 |
this.mouseButton = e.button; |
| 143 |
PureSource.superclass.onMouseDown.call(this, e); |
| 144 |
} |
| 145 |
}, |
| 146 |
|
| 147 |
onMouseUp: function(e){ |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
if(this.mouseDown){ |
| 157 |
this.mouseDown = false; |
| 158 |
PureSource.superclass.onMouseUp.call(this, e); |
| 159 |
} |
| 160 |
}, |
| 161 |
|
| 162 |
onOverEvent: function(){ |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
PureSource.superclass.onOverEvent.call(this); |
| 170 |
Manager.manager().overSource(this); |
| 171 |
}, |
| 172 |
|
| 173 |
onOutEvent: function(){ |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
PureSource.superclass.onOutEvent.call(this); |
| 181 |
Manager.manager().outSource(this); |
| 182 |
}, |
| 183 |
|
| 184 |
_markDndStatus: function(copy){ |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
this._changeState("Source", copy ? "Copied" : "Moved"); |
| 194 |
}, |
| 195 |
|
| 196 |
_legalMouseDown: function(e){ |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
if(!this.withHandles){ return true; } |
| 208 |
for(var node = e.target; node && !domClass.contains(node, "dojoDndItem"); node = node.parentNode){ |
| 209 |
if(domClass.contains(node, "dojoDndHandle")){ return true; } |
| 210 |
} |
| 211 |
return false; |
| 212 |
} |
| 213 |
}); |
| 214 |
return PureSource; |
| 215 |
}); |