AreaManager.js 21 KB

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