AreaManager.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.mdnd.AreaManager"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.mdnd.AreaManager"] = true;
  8. dojo.provide("dojox.mdnd.AreaManager");
  9. dojo.require("dojox.mdnd.Moveable");
  10. dojo.declare(
  11. "dojox.mdnd.AreaManager",
  12. null,
  13. {
  14. // summary:
  15. // Drag And Drop manager
  16. // autoRefresh: Boolean
  17. // Enable the refresh of registered areas on drag start.
  18. autoRefresh: true,
  19. // areaClass: String
  20. // CSS class enabled an area if areaClass is defined
  21. areaClass: "dojoxDndArea",
  22. // dragHandleClass: String
  23. // CSS class enabled a drag handle.
  24. dragHandleClass: "dojoxDragHandle",
  25. constructor: function(){
  26. // summary:
  27. // Constructor of AreaManager class.
  28. // Initialize arrays, connects and subscribes.
  29. //console.log("dojox.mdnd.AreaManager ::: constructor");
  30. this._areaList = [];
  31. this.resizeHandler = dojo.connect(dojo.global,"onresize", this, function(){
  32. this._dropMode.updateAreas(this._areaList);
  33. });
  34. this._oldIndexArea = this._currentIndexArea = this._oldDropIndex = this._currentDropIndex = this._sourceIndexArea = this._sourceDropIndex = -1;
  35. },
  36. init: function(){
  37. // summary:
  38. // Initialize the manager by calling the registerByClass method
  39. //console.log("dojox.mdnd.AreaManager ::: init");
  40. this.registerByClass();
  41. },
  42. registerByNode: function(/*DOMNode*/area, /*Boolean*/notInitAreas){
  43. // summary:
  44. // To register Dnd Area : insert the DndArea using the specific sort of dropMode.
  45. // area:
  46. // a DOM node corresponding to the Dnd Area
  47. // notInitAreas:
  48. // if false or undefined, init the areas.
  49. //console.log("dojox.mdnd.AreaManager ::: registerByNode", area);
  50. var index = this._getIndexArea(area);
  51. if(area && index == -1){
  52. var acceptType = area.getAttribute("accept");
  53. var accept = (acceptType) ? acceptType.split(/\s*,\s*/) : ["text"];
  54. var obj = {
  55. 'node': area,
  56. 'items': [],
  57. 'coords': {},
  58. 'margin': null,
  59. 'accept': accept,
  60. 'initItems': false
  61. };
  62. dojo.forEach(this._getChildren(area), function(item){
  63. this._setMarginArea(obj, item);
  64. obj.items.push(this._addMoveableItem(item));
  65. }, this);
  66. this._areaList = this._dropMode.addArea(this._areaList, obj);
  67. if(!notInitAreas){
  68. this._dropMode.updateAreas(this._areaList);
  69. }
  70. dojo.publish("/dojox/mdnd/manager/register",[area]);
  71. }
  72. },
  73. registerByClass: function(){
  74. // summary:
  75. // Register all Dnd Areas identified by the attribute areaClass :
  76. // insert Dnd Areas using the specific sort of dropMode.
  77. //console.log("dojox.mdnd.AreaManager ::: registerByClass");
  78. dojo.query('.'+this.areaClass).forEach(function(area){
  79. this.registerByNode(area, true);
  80. }, this);
  81. this._dropMode.updateAreas(this._areaList);
  82. },
  83. unregister: function(/*DOMNode*/area){
  84. // summary:
  85. // Unregister a D&D Area and its children into the AreaManager.
  86. // area:
  87. // A node corresponding to the D&D Area.
  88. // returns:
  89. // True if the area is found and unregistered.
  90. //console.log("dojox.mdnd.AreaManager ::: unregister");
  91. var index = this._getIndexArea(area);
  92. if(index != -1){
  93. dojo.forEach(this._areaList[index].items, function(item){
  94. this._deleteMoveableItem(item);
  95. }, this);
  96. this._areaList.splice(index,1);
  97. // refresh target area
  98. this._dropMode.updateAreas(this._areaList);
  99. return true; // Boolean
  100. }
  101. return false; // Boolean
  102. },
  103. _addMoveableItem: function(/*DOMNode*/node){
  104. // summary:
  105. // Create a draggable item with a DOM node.
  106. // node:
  107. // A child of the D&D Area.
  108. // returns:
  109. // The draggable item.
  110. // tags:
  111. // protected
  112. //console.log("dojox.mdnd.AreaManager ::: _addMoveableItem");
  113. node.setAttribute("tabIndex", "0");
  114. var handle = this._searchDragHandle(node);
  115. var moveable = new dojox.mdnd.Moveable({ 'handle': handle, 'skip': true }, node);
  116. // add a css style :
  117. dojo.addClass(handle || node, "dragHandle");
  118. var type = node.getAttribute("dndType");
  119. var item = {
  120. 'item': moveable,
  121. 'type': type ? type.split(/\s*,\s*/) : ["text"],
  122. 'handlers': [dojo.connect(moveable, "onDragStart", this, "onDragStart")]
  123. }
  124. // connect to the uninitialize method of dijit._Widget to delete a moveable before a destruct
  125. if(dijit && dijit.byNode){
  126. var widget = dijit.byNode(node);
  127. if(widget){
  128. item.type = widget.dndType ? widget.dndType.split(/\s*,\s*/) : ["text"];
  129. item.handlers.push(
  130. dojo.connect(widget, "uninitialize", this, function(){
  131. this.removeDragItem(node.parentNode, moveable.node);
  132. })
  133. );
  134. }
  135. }
  136. return item; // Object
  137. },
  138. _deleteMoveableItem: function(/*Object*/ objItem){
  139. // summary:
  140. // Delete the Moveable object associated with a node.
  141. // item:
  142. // A moveable Object.
  143. // tags:
  144. // protected
  145. //console.log("dojox.mdnd.AreaManager ::: _deleteMoveableItem", objItem);
  146. // disconnect the handle
  147. dojo.forEach(objItem.handlers, function(handler){
  148. dojo.disconnect(handler);
  149. });
  150. // delete css style :
  151. var node = objItem.item.node,
  152. handle = this._searchDragHandle(node);
  153. dojo.removeClass(handle || node, "dragHandle");
  154. // call destroy of Moveable class
  155. objItem.item.destroy();
  156. },
  157. _getIndexArea: function(/*DOMNode*/area){
  158. // summary:
  159. // Get the index of an area.
  160. // area:
  161. // A moveable Object.
  162. // returns:
  163. // area index or -1
  164. // tags:
  165. // protected
  166. //console.log("dojox.mdnd.AreaManager ::: _getIndexArea");
  167. if(area){
  168. for(var i = 0; i < this._areaList.length; i++){
  169. if(this._areaList[i].node === area){
  170. return i; // Integer
  171. }
  172. }
  173. }
  174. return -1; // Integer
  175. },
  176. _searchDragHandle: function(/*DOMNode*/node){
  177. // summary:
  178. // Return the node which contains the first specific CSS class handle.
  179. // node:
  180. // A child of the D&D Area.
  181. // returns:
  182. // The drag handle node.
  183. // tags:
  184. // protected
  185. //console.log("dojox.mdnd.AreaManager ::: _searchDragHandle");
  186. if(node){
  187. var cssArray = this.dragHandleClass.split(' '),
  188. length = cssArray.length,
  189. queryCss = "";
  190. dojo.forEach(cssArray, function(css, i){
  191. queryCss += "." + css;
  192. if(i != length - 1){
  193. queryCss += ", ";
  194. }
  195. });
  196. return dojo.query(queryCss, node)[0]; // DomNode
  197. }
  198. },
  199. addDragItem: function(/*DOMNode*/area, /*DOMNode*/node, /*Integer*/index, /*Boolean*/notCheckParent){
  200. // summary:
  201. // To add an item programmatically.
  202. // area:
  203. // a node corresponding to the D&D Area
  204. // node:
  205. // the node which has to be treated.
  206. // index:
  207. // the place in the area
  208. // noCheckParent:
  209. // if true, doesn't check if node has a parent.
  210. // returns:
  211. // True if the node has been inserted else false.
  212. //console.log("dojox.mdnd.AreaManager ::: addDragItem");
  213. var add = true;
  214. if(!notCheckParent){
  215. add = area && node && (node.parentNode === null || (node.parentNode && node.parentNode.nodeType !== 1));
  216. }
  217. if(add){
  218. var indexArea = this._getIndexArea(area);
  219. if(indexArea !== -1){
  220. var item = this._addMoveableItem(node),
  221. items = this._areaList[indexArea].items;
  222. if(0 <= index && index < items.length){
  223. var firstListChild = items.slice(0, index),
  224. lastListChild = items.slice(index, items.length);
  225. firstListChild[firstListChild.length] = item;
  226. this._areaList[indexArea].items = firstListChild.concat(lastListChild);
  227. area.insertBefore(node, items[index].item.node);
  228. }
  229. else{
  230. this._areaList[indexArea].items.push(item);
  231. area.appendChild(node);
  232. }
  233. this._setMarginArea(this._areaList[indexArea], node);
  234. this._areaList[indexArea].initItems = false;
  235. return true; // Boolean
  236. }
  237. }
  238. return false; // Boolean
  239. },
  240. removeDragItem: function(/*DOMNode*/area, /*DOMNode*/node){
  241. // summary:
  242. // Delete a moveable item programmatically. The node is removed from the area.
  243. // area:
  244. // A node corresponding to the DndArea.
  245. // node:
  246. // The node which has to be treated.
  247. // returns:
  248. // the removed node
  249. //console.log("dojox.mdnd.AreaManager ::: removeDragItem");
  250. var index = this._getIndexArea(area);
  251. if(area && index !== -1){
  252. var items = this._areaList[index].items;
  253. for(var j = 0; j < items.length; j++){
  254. if(items[j].item.node === node){
  255. this._deleteMoveableItem(items[j]);
  256. // delete item of the array
  257. items.splice(j, 1);
  258. return area.removeChild(node); // Object
  259. }
  260. }
  261. }
  262. return null;
  263. },
  264. _getChildren: function(/*DOMNode*/area){
  265. // summary:
  266. // Get the children of a D&D area.
  267. // area:
  268. // A DnD area.
  269. // returns:
  270. // The children of a DnD area
  271. // tags:
  272. // protected
  273. //console.log("dojox.mdnd.AreaManager ::: _getChildren");
  274. var children = [];
  275. dojo.forEach(area.childNodes, function(child){
  276. // delete \n
  277. if(child.nodeType == 1){
  278. if(dijit && dijit.byNode){
  279. var widget = dijit.byNode(child);
  280. if(widget){
  281. if(!widget.dragRestriction){
  282. children.push(child);
  283. }
  284. }
  285. else{
  286. children.push(child);
  287. }
  288. }
  289. else{
  290. children.push(child);
  291. }
  292. }
  293. });
  294. return children; //Array
  295. },
  296. _setMarginArea: function(/*Object*/area,/*DOMNode*/node){
  297. // summary:
  298. // Set the value of margin in the data type of areaManager
  299. // only when the margin has never been computed.
  300. // area:
  301. // The object of a D&D Area.
  302. // node:
  303. // The node which contains margins
  304. // tags:
  305. // protected
  306. //console.log("dojox.mdnd.AreaManager ::: _setMarginArea");
  307. if(area && area.margin === null && node){
  308. area.margin = dojo._getMarginExtents(node);
  309. }
  310. },
  311. findCurrentIndexArea: function(/*Object*/coords, /*Object*/size){
  312. // summary:
  313. // find the nearest target area according to coordinates.
  314. // Coordinates are representing by an object : for example, {'x':10,'y':10}
  315. // coords:
  316. // an object encapsulating X and Y position
  317. // size:
  318. // an object encapsulating the area size
  319. // returns:
  320. // an index of area
  321. //console.log("dojox.mdnd.AreaManager ::: findCurrentIndexArea");
  322. this._oldIndexArea = this._currentIndexArea;
  323. this._currentIndexArea = this._dropMode.getTargetArea(this._areaList, coords, this._currentIndexArea);
  324. if(this._currentIndexArea != this._oldIndexArea){
  325. if(this._oldIndexArea != -1){
  326. this.onDragExit(coords, size);
  327. }
  328. if(this._currentIndexArea != -1){
  329. this.onDragEnter(coords, size);
  330. }
  331. }
  332. return this._currentIndexArea; //Integer
  333. },
  334. _isAccepted: function(/*Array*/ type, /*Array*/ accept){
  335. // summary:
  336. // True if user can drop widget on this node.
  337. // type:
  338. // Array containing item type
  339. // accept:
  340. // Array containing types
  341. this._accept = false;
  342. for(var i = 0; i < accept.length; ++i){
  343. for(var j = 0; j < type.length;++j){
  344. if(type[j] == accept[i]){
  345. this._accept = true;
  346. break;
  347. }
  348. }
  349. }
  350. },
  351. onDragStart: function(/*DOMNode*/node, /*Object*/coords, /*Object*/size){
  352. // summary:
  353. // Initialize the drag (see dojox.mdnd.Moveable.initOffsetDrag())
  354. // node:
  355. // The node which is about to be dragged
  356. // coords:
  357. // an object encapsulating X and Y position
  358. // size:
  359. // an object encapsulating width and height values
  360. // tags:
  361. // callback
  362. //console.log("dojox.mdnd.AreaManager ::: onDragStart");
  363. if(this.autoRefresh){
  364. this._dropMode.updateAreas(this._areaList);
  365. }
  366. // Create the cover :
  367. var _html = (dojo.isWebKit) ? dojo.body() : dojo.body().parentNode;
  368. if(!this._cover){
  369. this._cover = dojo.create('div', {
  370. 'class': "dndCover"
  371. });
  372. this._cover2 = dojo.clone(this._cover);
  373. dojo.addClass(this._cover2, "dndCover2");
  374. }
  375. var h = _html.scrollHeight+"px";
  376. this._cover.style.height = this._cover2.style.height = h;
  377. dojo.body().appendChild(this._cover);
  378. dojo.body().appendChild(this._cover2);
  379. this._dragStartHandler = dojo.connect(node.ownerDocument, "ondragstart", dojo, "stopEvent");
  380. // to know the source
  381. this._sourceIndexArea = this._lastValidIndexArea = this._currentIndexArea = this._getIndexArea(node.parentNode);
  382. // delete the dragItem into the source area
  383. var sourceArea = this._areaList[this._sourceIndexArea];
  384. var children = sourceArea.items;
  385. for(var i = 0; i < children.length; i++){
  386. if(children[i].item.node == node){
  387. this._dragItem = children[i];
  388. this._dragItem.handlers.push(dojo.connect(this._dragItem.item, "onDrag", this, "onDrag"));
  389. this._dragItem.handlers.push(dojo.connect(this._dragItem.item, "onDragEnd", this, "onDrop"));
  390. children.splice(i,1);
  391. this._currentDropIndex = this._sourceDropIndex = i;
  392. break;
  393. }
  394. }
  395. var nodeRef = null;
  396. if(this._sourceDropIndex !== sourceArea.items.length){
  397. nodeRef = sourceArea.items[this._sourceDropIndex].item.node;
  398. }
  399. // IE7 OPTIMIZATION
  400. if(dojo.isIE > 7){
  401. // connect these events on the cover
  402. this._eventsIE7 = [
  403. dojo.connect(this._cover, "onmouseover", dojo, "stopEvent"),
  404. dojo.connect(this._cover, "onmouseout", dojo, "stopEvent"),
  405. dojo.connect(this._cover, "onmouseenter", dojo, "stopEvent"),
  406. dojo.connect(this._cover, "onmouseleave", dojo, "stopEvent")
  407. ];
  408. }
  409. var s = node.style;
  410. s.left = coords.x+"px";
  411. s.top = coords.y+"px";
  412. // attach the node to the cover
  413. if(s.position == "relative" || s.position == ""){
  414. s.position = "absolute"; // enforcing the absolute mode
  415. }
  416. this._cover.appendChild(node);
  417. this._dropIndicator.place(sourceArea.node, nodeRef, size);
  418. // add a style to place the _dragNode in foreground
  419. dojo.addClass(node, "dragNode");
  420. // A dragged node is always draggable in this source area.
  421. this._accept = true;
  422. dojo.publish("/dojox/mdnd/drag/start",[node, sourceArea, this._sourceDropIndex]);
  423. },
  424. onDragEnter: function(/*Object*/coords, /*Object*/size){
  425. // summary:
  426. // Optionally called by the getTargetArea method of TargetFinder class.
  427. // coords:
  428. // coordinates of the dragged Node.
  429. // size:
  430. // size of the dragged Node.
  431. // tags:
  432. // callback
  433. //console.log("dojox.mdnd.AreaManager ::: onDragEnter", coords, size);
  434. if(this._currentIndexArea === this._sourceIndexArea){
  435. this._accept = true;
  436. }
  437. else{
  438. this._isAccepted(this._dragItem.type, this._areaList[this._currentIndexArea].accept);
  439. }
  440. },
  441. onDragExit: function(/*Object*/coords, /*Object*/size){
  442. // summary:
  443. // Optionally called by the getTargetArea method of TargetFinder class.
  444. // coords:
  445. // coordinates of the dragged Node.
  446. // size:
  447. // size of the dragged Node.
  448. // tags:
  449. // callback
  450. //console.log("dojox.mdnd.AreaManager ::: onDragExit");
  451. this._accept = false;
  452. },
  453. onDrag: function(/*DOMNode*/node, /*Object*/coords, /*Object*/size, /*Object*/mousePosition){
  454. // summary:
  455. // Occurs when the dojo.dnd.Moveable.onDrag is fired.
  456. // Search the nearest target area and called the placeDropIndicator
  457. // node:
  458. // The node which is dragged
  459. // coords:
  460. // an object encapsulating X and Y position
  461. // size:
  462. // an object encapsulating width and height values
  463. // mousePosition:
  464. // coordinates of mouse
  465. // tags:
  466. // callback
  467. //console.log("dojox.mdnd.AreaManager ::: onDrag", node, ",", coords,size);
  468. var coordinates = this._dropMode.getDragPoint(coords, size, mousePosition);
  469. this.findCurrentIndexArea(coordinates, size);
  470. if(this._currentIndexArea !== -1 && this._accept){
  471. this.placeDropIndicator(coordinates, size);
  472. }
  473. },
  474. placeDropIndicator: function(/*Object*/coords, /*Object*/size){
  475. // summary:
  476. // Search the right place to insert the dropIndicator and display the dropIndicator.
  477. // coords:
  478. // an object encapsulating X and Y position
  479. // size:
  480. // an object encapsulating width and height values
  481. // returns:
  482. // the current drop index
  483. //console.log("dojox.mdnd.AreaManager ::: placeDropIndicator");
  484. //keep old drop Index
  485. this._oldDropIndex = this._currentDropIndex;
  486. // calculate all children marker (see VerticalDropMode.initItems())
  487. var area = this._areaList[this._currentIndexArea];
  488. if(!area.initItems){
  489. this._dropMode.initItems(area);
  490. }
  491. //get the index where the drop has to be placed.
  492. this._currentDropIndex = this._dropMode.getDropIndex(area, coords);
  493. if(!(this._currentIndexArea === this._oldIndexArea && this._oldDropIndex === this._currentDropIndex)){
  494. this._placeDropIndicator(size);
  495. }
  496. return this._currentDropIndex; //Integer
  497. },
  498. _placeDropIndicator: function(/*Object*/size){
  499. // summary:
  500. // place the dropIndicator
  501. // size:
  502. // an object encapsulating width and height values
  503. // tags:
  504. // protected
  505. var oldArea = this._areaList[this._lastValidIndexArea];
  506. var currentArea = this._areaList[this._currentIndexArea];
  507. //refresh the previous area after moving out the drop indicator
  508. this._dropMode.refreshItems(oldArea, this._oldDropIndex, size, false);
  509. // place dropIndicator
  510. var node = null;
  511. if(this._currentDropIndex != -1){
  512. node = currentArea.items[this._currentDropIndex].item.node;
  513. }
  514. this._dropIndicator.place(currentArea.node, node);
  515. this._lastValidIndexArea = this._currentIndexArea;
  516. //refresh the current area after placing the drop indicator
  517. this._dropMode.refreshItems(currentArea, this._currentDropIndex, size, true);
  518. },
  519. onDropCancel: function(){
  520. // summary:
  521. // Cancel the drop.
  522. // The dragNode returns into the source.
  523. // tags:
  524. // callback
  525. //console.log("dojox.mdnd.AreaManager ::: onDropCancel");
  526. if(!this._accept){
  527. var index = this._getIndexArea(this._dropIndicator.node.parentNode);
  528. if(index != -1){
  529. this._currentIndexArea = index;
  530. }
  531. else{
  532. // case if the dropIndicator is in the area which has been unregistered during the drag.
  533. // chose by default the first area.
  534. this._currentIndexArea = 0;
  535. }
  536. }
  537. },
  538. onDrop: function(/*DOMNode*/node){
  539. // summary:
  540. // Drop the dragged item where the dropIndicator is displayed.
  541. // node:
  542. // The node which is about to be dropped
  543. // tags:
  544. // callback
  545. //console.log("dojox.mdnd.AreaManager ::: onDrop");
  546. //dropCancel
  547. this.onDropCancel();
  548. var targetArea = this._areaList[this._currentIndexArea];
  549. dojo.removeClass(node, "dragNode");
  550. var style = node.style;
  551. style.position = "relative";
  552. style.left = "0";
  553. style.top = "0";
  554. style.width = "auto";
  555. if(targetArea.node == this._dropIndicator.node.parentNode){
  556. targetArea.node.insertBefore(node, this._dropIndicator.node);
  557. }
  558. else{
  559. // case if the dropIndicator is in the area which has been unregistered during the drag.
  560. targetArea.node.appendChild(node);
  561. this._currentDropIndex = targetArea.items.length;
  562. }
  563. // add child into the new target area.
  564. var indexChild = this._currentDropIndex;
  565. if(indexChild == -1){
  566. indexChild = targetArea.items.length;
  567. }
  568. var children = targetArea.items;
  569. var firstListArea = children.slice(0, indexChild);
  570. var lastListArea = children.slice(indexChild, children.length);
  571. firstListArea[firstListArea.length] = this._dragItem;
  572. targetArea.items = firstListArea.concat(lastListArea);
  573. this._setMarginArea(targetArea, node);
  574. dojo.forEach(this._areaList, function(obj){
  575. obj.initItems = false;
  576. });
  577. // disconnect onDrop handler
  578. dojo.disconnect(this._dragItem.handlers.pop());
  579. dojo.disconnect(this._dragItem.handlers.pop());
  580. this._resetAfterDrop();
  581. // remove the cover
  582. if(this._cover){
  583. dojo.body().removeChild(this._cover);
  584. dojo.body().removeChild(this._cover2);
  585. }
  586. dojo.publish("/dojox/mdnd/drop",[node, targetArea, indexChild]);
  587. },
  588. _resetAfterDrop: function(){
  589. // summary:
  590. // reset manager properties after dropping an item
  591. // tags:
  592. // protected
  593. this._accept = false;
  594. this._dragItem = null;
  595. this._currentDropIndex = -1;
  596. this._currentIndexArea = -1;
  597. this._oldDropIndex = -1;
  598. this._sourceIndexArea = -1;
  599. this._sourceDropIndex = -1;
  600. this._dropIndicator.remove();
  601. if(this._dragStartHandler){
  602. dojo.disconnect(this._dragStartHandler);
  603. }
  604. if(dojo.isIE > 7){
  605. dojo.forEach(this._eventsIE7, dojo.disconnect);
  606. }
  607. },
  608. destroy: function(){
  609. // summary:
  610. // Destroy the component.
  611. //console.log("dojox.mdnd.AreaManager ::: destroy");
  612. //see implementation of unregister()
  613. while(this._areaList.length > 0){
  614. if(!this.unregister(this._areaList[0].node)){
  615. throw new Error("Error while destroying AreaManager");
  616. }
  617. }
  618. dojo.disconnect(this.resizeHandler);
  619. this._dropIndicator.destroy();
  620. this._dropMode.destroy();
  621. if(dojox.mdnd.autoScroll){
  622. dojox.mdnd.autoScroll.destroy();
  623. }
  624. if(this.refreshListener){
  625. dojo.unsubscribe(this.refreshListener);
  626. }
  627. // destroy the cover
  628. if(this._cover){
  629. dojo._destroyElement(this._cover);
  630. dojo._destroyElement(this._cover2);
  631. delete this._cover;
  632. delete this._cover2;
  633. }
  634. }
  635. });
  636. if(dijit && dijit._Widget){
  637. // Add a new property to widget
  638. dojo.extend(dijit._Widget, {
  639. // dndType: String
  640. // Defines a type of widget.
  641. dndType : "text"
  642. });
  643. }
  644. dojox.mdnd._areaManager = null;
  645. dojox.mdnd.areaManager = function(){
  646. // summary:
  647. // Returns the current areaManager, creates one if it is not created yet.
  648. if(!dojox.mdnd._areaManager){
  649. dojox.mdnd._areaManager = new dojox.mdnd.AreaManager();
  650. }
  651. return dojox.mdnd._areaManager; // Object
  652. };
  653. }