LazyManager.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.LazyManager"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.mdnd.LazyManager"] = true;
  8. dojo.provide("dojox.mdnd.LazyManager");
  9. dojo.require("dojo.dnd.Manager");
  10. dojo.require("dojox.mdnd.PureSource");
  11. dojo.declare(
  12. "dojox.mdnd.LazyManager",
  13. null,
  14. {
  15. // summary:
  16. // This class allows to launch a drag and drop dojo on the fly.
  17. constructor: function(){
  18. //console.log("dojox.mdnd.LazyManager ::: constructor");
  19. this._registry = {};
  20. // initialization of the _fakeSource to enabled DragAndDrop :
  21. this._fakeSource = new dojox.mdnd.PureSource(dojo.create("div"), {
  22. 'copyOnly': false
  23. });
  24. this._fakeSource.startup();
  25. dojo.addOnUnload(dojo.hitch(this, "destroy"));
  26. this.manager = dojo.dnd.manager();
  27. },
  28. getItem: function(/*DOMNode*/draggedNode){
  29. //console.log("dojox.mdnd.LazyManager ::: getItem");
  30. var type = draggedNode.getAttribute("dndType");
  31. return {
  32. 'data' : draggedNode.getAttribute("dndData") || draggedNode.innerHTML,
  33. 'type' : type ? type.split(/\s*,\s*/) : ["text"]
  34. }
  35. },
  36. startDrag: function(/*Event*/e, /*DOMNode?*/draggedNode){
  37. // summary:
  38. // launch a dojo drag and drop on the fly.
  39. //console.log("dojox.mdnd.LazyManager ::: startDrag");
  40. draggedNode = draggedNode || e.target;
  41. if(draggedNode){
  42. var m = this.manager,
  43. object = this.getItem(draggedNode);
  44. if(draggedNode.id == ""){
  45. dojo.attr(draggedNode, "id", dojo.dnd.getUniqueId());
  46. }
  47. dojo.addClass(draggedNode, "dojoDndItem");
  48. this._fakeSource.setItem(draggedNode.id, object);
  49. m.startDrag(this._fakeSource, [draggedNode], false);
  50. m.onMouseMove(e);
  51. }
  52. },
  53. cancelDrag: function(){
  54. // summary:
  55. // cancel a drag and drop dojo on the fly.
  56. //console.log("dojox.mdnd.LazyManager ::: cancelDrag");
  57. var m = this.manager;
  58. m.target = null;
  59. m.onMouseUp();
  60. },
  61. destroy: function(){
  62. //console.log("dojox.mdnd.LazyManager ::: destroy");
  63. this._fakeSource.destroy();
  64. }
  65. });
  66. }