dndContainer.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. if (!dojo._hasResource["dijit._tree.dndContainer"]) { // _hasResource checks
  2. // added by build. Do
  3. // not use _hasResource
  4. // directly in your
  5. // code.
  6. dojo._hasResource["dijit._tree.dndContainer"] = true;
  7. dojo.provide("dijit._tree.dndContainer");
  8. dojo.require("dojo.dnd.common");
  9. dojo.require("dojo.dnd.Container");
  10. dojo.declare("dijit._tree.dndContainer", null, {
  11. constructor : function(tree, params) {
  12. // summary: a constructor of the Container
  13. // tree: Node: node or node's id to build the container on
  14. // params: Object: a dict of parameters, which gets mixed into the
  15. // object
  16. this.tree = tree;
  17. this.node = tree.domNode;
  18. dojo.mixin(this, params);
  19. // class-specific variables
  20. this.map = {};
  21. this.current = null;
  22. // states
  23. this.ContainerState = "";
  24. dojo.addClass(this.node, "dojoDndContainer");
  25. // mark up children
  26. if (!(params && params._skipStartup)) {
  27. this.startup();
  28. }
  29. // set up events
  30. this.events = [
  31. dojo.connect(this.node, "onmouseover", this, "onMouseOver"),
  32. dojo.connect(this.node, "onmouseout", this, "onMouseOut"),
  33. // cancel text selection and text dragging
  34. dojo.connect(this.node, "ondragstart", dojo, "stopEvent"),
  35. dojo.connect(this.node, "onselectstart", dojo, "stopEvent")];
  36. },
  37. // abstract access to the map
  38. getItem : function(/* String */key) {
  39. // summary: returns a data item by its key (id)
  40. // console.log("Container getItem()", arguments,this.map,
  41. // this.map[key], this.selection[key]);
  42. return this.selection[key];
  43. // return this.map[key]; // Object
  44. },
  45. // mouse events
  46. onMouseOver : function(e) {
  47. // summary: event processor for onmouseover
  48. // e: Event: mouse event
  49. var n = e.relatedTarget;
  50. while (n) {
  51. if (n == this.node) {
  52. break;
  53. }
  54. try {
  55. n = n.parentNode;
  56. } catch (x) {
  57. n = null;
  58. }
  59. }
  60. if (!n) {
  61. this._changeState("Container", "Over");
  62. this.onOverEvent();
  63. }
  64. n = this._getChildByEvent(e);
  65. if (this.current == n) {
  66. return;
  67. }
  68. if (this.current) {
  69. this._removeItemClass(this.current, "Over");
  70. }
  71. if (n) {
  72. this._addItemClass(n, "Over");
  73. }
  74. this.current = n;
  75. },
  76. onMouseOut : function(e) {
  77. // summary: event processor for onmouseout
  78. // e: Event: mouse event
  79. for (var n = e.relatedTarget; n;) {
  80. if (n == this.node) {
  81. return;
  82. }
  83. try {
  84. n = n.parentNode;
  85. } catch (x) {
  86. n = null;
  87. }
  88. }
  89. if (this.current) {
  90. this._removeItemClass(this.current, "Over");
  91. this.current = null;
  92. }
  93. this._changeState("Container", "");
  94. this.onOutEvent();
  95. },
  96. _changeState : function(type, newState) {
  97. // summary: changes a named state to new state value
  98. // type: String: a name of the state to change
  99. // newState: String: new state
  100. var prefix = "dojoDnd" + type;
  101. var state = type.toLowerCase() + "State";
  102. // dojo.replaceClass(this.node, prefix + newState, prefix +
  103. // this[state]);
  104. dojo.removeClass(this.node, prefix + this[state]);
  105. dojo.addClass(this.node, prefix + newState);
  106. this[state] = newState;
  107. },
  108. _getChildByEvent : function(e) {
  109. // summary: gets a child, which is under the mouse at the moment, or
  110. // null
  111. // e: Event: a mouse event
  112. var node = e.target;
  113. if (node && dojo.hasClass(node, "dijitTreeLabel")) {
  114. return node;
  115. }
  116. return null;
  117. },
  118. markupFactory : function(tree, params) {
  119. params._skipStartup = true;
  120. return new dijit._tree.dndContainer(tree, params);
  121. },
  122. _addItemClass : function(node, type) {
  123. // summary: adds a class with prefix "dojoDndItem"
  124. // node: Node: a node
  125. // type: String: a variable suffix for a class name
  126. dojo.addClass(node, "dojoDndItem" + type);
  127. },
  128. _removeItemClass : function(node, type) {
  129. // summary: removes a class with prefix "dojoDndItem"
  130. // node: Node: a node
  131. // type: String: a variable suffix for a class name
  132. dojo.removeClass(node, "dojoDndItem" + type);
  133. },
  134. onOverEvent : function() {
  135. // summary: this function is called once, when mouse is over our
  136. // container
  137. console.log("onOverEvent parent");
  138. },
  139. onOutEvent : function() {
  140. // summary: this function is called once, when mouse is out of our
  141. // container
  142. }
  143. });
  144. }