PureSource.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. define("dojox/mdnd/PureSource", ["dojo/_base/kernel","dojo/_base/declare","dojo/_base/html","dojo/_base/connect",
  2. "dojo/_base/array","dojo/dnd/Selector","dojo/dnd/Manager"],function(dojo){
  3. return dojo.declare(
  4. "dojox.mdnd.PureSource",
  5. dojo.dnd.Selector,
  6. {
  7. // summary:
  8. // A Source Object, which can be used only as a DnD source.
  9. // A Source can contained several dnd items.
  10. // A dnd item is not a source.
  11. horizontal: false,
  12. copyOnly: true,
  13. skipForm: false,
  14. withHandles: false,
  15. isSource: true,
  16. targetState: "Disabled",
  17. generateText: true,
  18. constructor: function(/*DOMNode|String*/node, /*dojo.dnd.__SourceArgs?*/params){
  19. // summary:
  20. // Initialize a new PureSource.
  21. // node:
  22. // Node or node's id to build the source on.
  23. // params:
  24. // Any property of this class may be configured via the params
  25. // object which is mixed-in to the 'dojo.dnd.Source' instance.
  26. //console.log('dojox.mdnd.PureSource ::: constructor');
  27. dojo.mixin(this, dojo.mixin({}, params));
  28. var type = this.accept;
  29. // class-specific variables
  30. this.isDragging = false;
  31. this.mouseDown = false;
  32. // states
  33. this.sourceState = "";
  34. dojo.addClass(this.node, "dojoDndSource");
  35. if(this.horizontal){
  36. dojo.addClass(this.node, "dojoDndHorizontal");
  37. }
  38. // set up events
  39. this.topics = [
  40. dojo.subscribe("/dnd/cancel", this, "onDndCancel"),
  41. dojo.subscribe("/dnd/drop", this, "onDndCancel")
  42. ];
  43. },
  44. onDndCancel: function(){
  45. // summary:
  46. // Topic event processor for /dnd/cancel, called to cancel the Dnd
  47. // operation.
  48. // tags:
  49. // callback
  50. //console.log('dojox.mdnd.PureSource ::: onDndCancel');
  51. this.isDragging = false;
  52. this.mouseDown = false;
  53. delete this.mouseButton;
  54. },
  55. copyState: function(/*Boolean*/keyPressed){
  56. // summary:
  57. // Returns true, if we need to copy items, false to move.
  58. // It is separated to be overwritten dynamically, if needed.
  59. // keyPressed:
  60. // The "copy" was pressed.
  61. // returns:
  62. // True, if we need to copy items, false to move.
  63. //console.log('dojox.mdnd.PureSource ::: copyState');
  64. return this.copyOnly || keyPressed; // Boolean
  65. },
  66. destroy: function(){
  67. // summary:
  68. // Prepares the object to be garbage-collected.
  69. //console.log('dojox.mdnd.PureSource ::: destroy');
  70. dojox.mdnd.PureSource.superclass.destroy.call(this);
  71. dojo.forEach(this.topics, dojo.unsubscribe);
  72. this.targetAnchor = null;
  73. },
  74. markupFactory: function(/*Object*/params, /*DomNode*/node){
  75. // summary:
  76. // Markup methods.
  77. // params:
  78. // ???
  79. // node:
  80. // ???
  81. // returns:
  82. // New dojox.mdnd.PureSource instance.
  83. //console.log('dojox.mdnd.PureSource ::: markupFactory');
  84. params._skipStartup = true;
  85. return new dojox.mdnd.PureSource(node, params);
  86. },
  87. onMouseMove: function(/*Event*/e){
  88. // summary:
  89. // Event processor for onmousemove.
  90. // e:
  91. // Mouse event.
  92. //console.log('dojox.mdnd.PureSource ::: onMouseMove');
  93. if(this.isDragging){
  94. return;
  95. }
  96. dojox.mdnd.PureSource.superclass.onMouseMove.call(this, e);
  97. var m = dojo.dnd.manager();
  98. if(this.mouseDown && !this.isDragging && this.isSource){
  99. var nodes = this.getSelectedNodes();
  100. if(nodes.length){
  101. m.startDrag(this, nodes, this.copyState(dojo.isCopyKey(e)));
  102. this.isDragging = true;
  103. }
  104. }
  105. },
  106. onMouseDown: function(/*Event*/e){
  107. // summary:
  108. // Event processor for onmousedown.
  109. // e:
  110. // Mouse event.
  111. // tags:
  112. // callback
  113. //console.log('dojox.mdnd.PureSource ::: onMouseDown');
  114. if(this._legalMouseDown(e) && (!this.skipForm || !dojo.dnd.isFormElement(e))){
  115. this.mouseDown = true;
  116. this.mouseButton = e.button;
  117. dojox.mdnd.PureSource.superclass.onMouseDown.call(this, e);
  118. }
  119. },
  120. onMouseUp: function(/*Event*/e){
  121. // summary:
  122. // Event processor for onmouseup.
  123. // e:
  124. // Mouse event
  125. // tags:
  126. // callback
  127. //console.log('.dnd.PureSource ::: onMouseUp');
  128. if(this.mouseDown){
  129. this.mouseDown = false;
  130. dojox.mdnd.PureSource.superclass.onMouseUp.call(this, e);
  131. }
  132. },
  133. onOverEvent: function(){
  134. // summary:
  135. // Called once, when mouse is over our container.
  136. // tags:
  137. // callback
  138. //console.log('dojox.mdnd.PureSource ::: onOverEvent');
  139. dojox.mdnd.PureSource.superclass.onOverEvent.call(this);
  140. dojo.dnd.manager().overSource(this);
  141. },
  142. onOutEvent: function(){
  143. // summary:
  144. // Called once, when mouse is out our container.
  145. // tags:
  146. // callback
  147. //console.log('dojox.mdnd.PureSource ::: onOutEvent');
  148. dojox.mdnd.PureSource.superclass.onOutEvent.call(this);
  149. dojo.dnd.manager().outSource(this);
  150. },
  151. _markDndStatus: function(/*Boolean*/copy){
  152. // summary:
  153. // Changes source's state based on "copy" status.
  154. // copy:
  155. // Copy status.
  156. // tags:
  157. // protected
  158. //console.log('dojox.mdnd.PureSource ::: _markDndStatus');
  159. this._changeState("Source", copy ? "Copied" : "Moved");
  160. },
  161. _legalMouseDown: function(/*Event*/e){
  162. // summary:
  163. // Checks if user clicked on "approved" items.
  164. // e:
  165. // Mouse event.
  166. // returns:
  167. // True if user clicked on "approved" items.
  168. // tags:
  169. // protected
  170. //console.log('dojox.mdnd.PureSource ::: _legalMouseDown');
  171. if(!this.withHandles){ return true; }
  172. for(var node = e.target; node && !dojo.hasClass(node, "dojoDndItem"); node = node.parentNode){
  173. if(dojo.hasClass(node, "dojoDndHandle")){ return true; }
  174. }
  175. return false; // Boolean
  176. }
  177. });
  178. });