_dndContainer.js.uncompressed.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. define("dijit/tree/_dndContainer", [
  2. "dojo/aspect", // aspect.after
  3. "dojo/_base/declare", // declare
  4. "dojo/dom-class", // domClass.add domClass.remove domClass.replace
  5. "dojo/_base/event", // event.stop
  6. "dojo/_base/lang", // lang.mixin lang.hitch
  7. "dojo/on",
  8. "dojo/touch"
  9. ], function(aspect, declare,domClass, event, lang, on, touch){
  10. // module:
  11. // dijit/tree/_dndContainer
  12. /*=====
  13. var __Args = {
  14. // summary:
  15. // A dict of parameters for Tree source configuration.
  16. // isSource: Boolean?
  17. // Can be used as a DnD source. Defaults to true.
  18. // accept: String[]
  19. // List of accepted types (text strings) for a target; defaults to
  20. // ["text", "treeNode"]
  21. // copyOnly: Boolean?
  22. // Copy items, if true, use a state of Ctrl key otherwise,
  23. // dragThreshold: Number
  24. // The move delay in pixels before detecting a drag; 0 by default
  25. // betweenThreshold: Integer
  26. // Distance from upper/lower edge of node to allow drop to reorder nodes
  27. };
  28. =====*/
  29. return declare("dijit.tree._dndContainer", null, {
  30. // summary:
  31. // This is a base class for `dijit/tree/_dndSelector`, and isn't meant to be used directly.
  32. // It's modeled after `dojo/dnd/Container`.
  33. // tags:
  34. // protected
  35. /*=====
  36. // current: DomNode
  37. // The currently hovered TreeNode.rowNode (which is the DOM node
  38. // associated w/a given node in the tree, excluding it's descendants)
  39. current: null,
  40. =====*/
  41. constructor: function(tree, params){
  42. // summary:
  43. // A constructor of the Container
  44. // tree: Node
  45. // Node or node's id to build the container on
  46. // params: __Args
  47. // A dict of parameters, which gets mixed into the object
  48. // tags:
  49. // private
  50. this.tree = tree;
  51. this.node = tree.domNode; // TODO: rename; it's not a TreeNode but the whole Tree
  52. lang.mixin(this, params);
  53. // class-specific variables
  54. this.current = null; // current TreeNode's DOM node
  55. // states
  56. this.containerState = "";
  57. domClass.add(this.node, "dojoDndContainer");
  58. // set up events
  59. this.events = [
  60. // Mouse (or touch) enter/leave on Tree itself
  61. on(this.node, touch.enter, lang.hitch(this, "onOverEvent")),
  62. on(this.node, touch.leave, lang.hitch(this, "onOutEvent")),
  63. // switching between TreeNodes
  64. aspect.after(this.tree, "_onNodeMouseEnter", lang.hitch(this, "onMouseOver"), true),
  65. aspect.after(this.tree, "_onNodeMouseLeave", lang.hitch(this, "onMouseOut"), true),
  66. // cancel text selection and text dragging
  67. on(this.node, "dragstart", lang.hitch(event, "stop")),
  68. on(this.node, "selectstart", lang.hitch(event, "stop"))
  69. ];
  70. },
  71. destroy: function(){
  72. // summary:
  73. // Prepares this object to be garbage-collected
  74. var h;
  75. while(h = this.events.pop()){ h.remove(); }
  76. // this.clearItems();
  77. this.node = this.parent = null;
  78. },
  79. // mouse events
  80. onMouseOver: function(widget /*===== , evt =====*/){
  81. // summary:
  82. // Called when mouse is moved over a TreeNode
  83. // widget: TreeNode
  84. // evt: Event
  85. // tags:
  86. // protected
  87. this.current = widget;
  88. },
  89. onMouseOut: function(/*===== widget, evt =====*/){
  90. // summary:
  91. // Called when mouse is moved away from a TreeNode
  92. // widget: TreeNode
  93. // evt: Event
  94. // tags:
  95. // protected
  96. this.current = null;
  97. },
  98. _changeState: function(type, newState){
  99. // summary:
  100. // Changes a named state to new state value
  101. // type: String
  102. // A name of the state to change
  103. // newState: String
  104. // new state
  105. var prefix = "dojoDnd" + type;
  106. var state = type.toLowerCase() + "State";
  107. //domClass.replace(this.node, prefix + newState, prefix + this[state]);
  108. domClass.replace(this.node, prefix + newState, prefix + this[state]);
  109. this[state] = newState;
  110. },
  111. _addItemClass: function(node, type){
  112. // summary:
  113. // Adds a class with prefix "dojoDndItem"
  114. // node: Node
  115. // A node
  116. // type: String
  117. // A variable suffix for a class name
  118. domClass.add(node, "dojoDndItem" + type);
  119. },
  120. _removeItemClass: function(node, type){
  121. // summary:
  122. // Removes a class with prefix "dojoDndItem"
  123. // node: Node
  124. // A node
  125. // type: String
  126. // A variable suffix for a class name
  127. domClass.remove(node, "dojoDndItem" + type);
  128. },
  129. onOverEvent: function(){
  130. // summary:
  131. // This function is called once, when mouse is over our container
  132. // tags:
  133. // protected
  134. this._changeState("Container", "Over");
  135. },
  136. onOutEvent: function(){
  137. // summary:
  138. // This function is called once, when mouse is out of our container
  139. // tags:
  140. // protected
  141. this._changeState("Container", "");
  142. }
  143. });
  144. });