_dndContainer.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.getObject lang.mixin lang.hitch
  7. "dojo/mouse", // mouse.enter, mouse.leave
  8. "dojo/on"
  9. ], function(aspect, declare, domClass, event, lang, mouse, on){
  10. // module:
  11. // dijit/tree/_dndContainer
  12. // summary:
  13. // This is a base class for `dijit.tree._dndSelector`, and isn't meant to be used directly.
  14. // It's modeled after `dojo.dnd.Container`.
  15. return declare("dijit.tree._dndContainer", null, {
  16. // summary:
  17. // This is a base class for `dijit.tree._dndSelector`, and isn't meant to be used directly.
  18. // It's modeled after `dojo.dnd.Container`.
  19. // tags:
  20. // protected
  21. /*=====
  22. // current: DomNode
  23. // The currently hovered TreeNode.rowNode (which is the DOM node
  24. // associated w/a given node in the tree, excluding it's descendants)
  25. current: null,
  26. =====*/
  27. constructor: function(tree, params){
  28. // summary:
  29. // A constructor of the Container
  30. // tree: Node
  31. // Node or node's id to build the container on
  32. // params: dijit.tree.__SourceArgs
  33. // A dict of parameters, which gets mixed into the object
  34. // tags:
  35. // private
  36. this.tree = tree;
  37. this.node = tree.domNode; // TODO: rename; it's not a TreeNode but the whole Tree
  38. lang.mixin(this, params);
  39. // class-specific variables
  40. this.current = null; // current TreeNode's DOM node
  41. // states
  42. this.containerState = "";
  43. domClass.add(this.node, "dojoDndContainer");
  44. // set up events
  45. this.events = [
  46. // container level events
  47. on(this.node, mouse.enter, lang.hitch(this, "onOverEvent")),
  48. on(this.node, mouse.leave, lang.hitch(this, "onOutEvent")),
  49. // switching between TreeNodes
  50. aspect.after(this.tree, "_onNodeMouseEnter", lang.hitch(this, "onMouseOver"), true),
  51. aspect.after(this.tree, "_onNodeMouseLeave", lang.hitch(this, "onMouseOut"), true),
  52. // cancel text selection and text dragging
  53. on(this.node, "dragstart", lang.hitch(event, "stop")),
  54. on(this.node, "selectstart", lang.hitch(event, "stop"))
  55. ];
  56. },
  57. destroy: function(){
  58. // summary:
  59. // Prepares this object to be garbage-collected
  60. var h;
  61. while(h = this.events.pop()){ h.remove(); }
  62. // this.clearItems();
  63. this.node = this.parent = null;
  64. },
  65. // mouse events
  66. onMouseOver: function(widget /*===== , evt =====*/){
  67. // summary:
  68. // Called when mouse is moved over a TreeNode
  69. // widget: TreeNode
  70. // evt: Event
  71. // tags:
  72. // protected
  73. this.current = widget;
  74. },
  75. onMouseOut: function(/*===== widget, evt =====*/){
  76. // summary:
  77. // Called when mouse is moved away from a TreeNode
  78. // widget: TreeNode
  79. // evt: Event
  80. // tags:
  81. // protected
  82. this.current = null;
  83. },
  84. _changeState: function(type, newState){
  85. // summary:
  86. // Changes a named state to new state value
  87. // type: String
  88. // A name of the state to change
  89. // newState: String
  90. // new state
  91. var prefix = "dojoDnd" + type;
  92. var state = type.toLowerCase() + "State";
  93. //domClass.replace(this.node, prefix + newState, prefix + this[state]);
  94. domClass.replace(this.node, prefix + newState, prefix + this[state]);
  95. this[state] = newState;
  96. },
  97. _addItemClass: function(node, type){
  98. // summary:
  99. // Adds a class with prefix "dojoDndItem"
  100. // node: Node
  101. // A node
  102. // type: String
  103. // A variable suffix for a class name
  104. domClass.add(node, "dojoDndItem" + type);
  105. },
  106. _removeItemClass: function(node, type){
  107. // summary:
  108. // Removes a class with prefix "dojoDndItem"
  109. // node: Node
  110. // A node
  111. // type: String
  112. // A variable suffix for a class name
  113. domClass.remove(node, "dojoDndItem" + type);
  114. },
  115. onOverEvent: function(){
  116. // summary:
  117. // This function is called once, when mouse is over our container
  118. // tags:
  119. // protected
  120. this._changeState("Container", "Over");
  121. },
  122. onOutEvent: function(){
  123. // summary:
  124. // This function is called once, when mouse is out of our container
  125. // tags:
  126. // protected
  127. this._changeState("Container", "");
  128. }
  129. });
  130. });