Registry.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-dd-Registry'>/**
  19. </span> * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
  20. * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
  21. */
  22. Ext.define('Ext.dd.Registry', {
  23. singleton: true,
  24. constructor: function() {
  25. this.elements = {};
  26. this.handles = {};
  27. this.autoIdSeed = 0;
  28. },
  29. getId: function(el, autogen){
  30. if(typeof el == &quot;string&quot;){
  31. return el;
  32. }
  33. var id = el.id;
  34. if(!id &amp;&amp; autogen !== false){
  35. id = &quot;extdd-&quot; + (++this.autoIdSeed);
  36. el.id = id;
  37. }
  38. return id;
  39. },
  40. <span id='Ext-dd-Registry-method-register'> /**
  41. </span> * Registers a drag drop element.
  42. *
  43. * @param {String/HTMLElement} element The id or DOM node to register
  44. * @param {Object} data An custom data object that will be passed between the elements that are involved in drag
  45. * drop operations. You can populate this object with any arbitrary properties that your own code knows how to
  46. * interpret, plus there are some specific properties known to the Registry that should be populated in the data
  47. * object (if applicable):
  48. * @param {HTMLElement[]} data.handles Array of DOM nodes that trigger dragging for the element being registered.
  49. * @param {Boolean} data.isHandle True if the element passed in triggers dragging itself, else false.
  50. */
  51. register : function(el, data){
  52. data = data || {};
  53. if (typeof el == &quot;string&quot;) {
  54. el = document.getElementById(el);
  55. }
  56. data.ddel = el;
  57. this.elements[this.getId(el)] = data;
  58. if (data.isHandle !== false) {
  59. this.handles[data.ddel.id] = data;
  60. }
  61. if (data.handles) {
  62. var hs = data.handles,
  63. i, len;
  64. for (i = 0, len = hs.length; i &lt; len; i++) {
  65. this.handles[this.getId(hs[i])] = data;
  66. }
  67. }
  68. },
  69. <span id='Ext-dd-Registry-method-unregister'> /**
  70. </span> * Unregister a drag drop element
  71. * @param {String/HTMLElement} element The id or DOM node to unregister
  72. */
  73. unregister : function(el){
  74. var id = this.getId(el, false),
  75. data = this.elements[id],
  76. hs, i, len;
  77. if(data){
  78. delete this.elements[id];
  79. if(data.handles){
  80. hs = data.handles;
  81. for (i = 0, len = hs.length; i &lt; len; i++) {
  82. delete this.handles[this.getId(hs[i], false)];
  83. }
  84. }
  85. }
  86. },
  87. <span id='Ext-dd-Registry-method-getHandle'> /**
  88. </span> * Returns the handle registered for a DOM Node by id
  89. * @param {String/HTMLElement} id The DOM node or id to look up
  90. * @return {Object} handle The custom handle data
  91. */
  92. getHandle : function(id){
  93. if(typeof id != &quot;string&quot;){ // must be element?
  94. id = id.id;
  95. }
  96. return this.handles[id];
  97. },
  98. <span id='Ext-dd-Registry-method-getHandleFromEvent'> /**
  99. </span> * Returns the handle that is registered for the DOM node that is the target of the event
  100. * @param {Event} e The event
  101. * @return {Object} handle The custom handle data
  102. */
  103. getHandleFromEvent : function(e){
  104. var t = e.getTarget();
  105. return t ? this.handles[t.id] : null;
  106. },
  107. <span id='Ext-dd-Registry-method-getTarget'> /**
  108. </span> * Returns a custom data object that is registered for a DOM node by id
  109. * @param {String/HTMLElement} id The DOM node or id to look up
  110. * @return {Object} data The custom data
  111. */
  112. getTarget : function(id){
  113. if(typeof id != &quot;string&quot;){ // must be element?
  114. id = id.id;
  115. }
  116. return this.elements[id];
  117. },
  118. <span id='Ext-dd-Registry-method-getTargetFromEvent'> /**
  119. </span> * Returns a custom data object that is registered for the DOM node that is the target of the event
  120. * @param {Event} e The event
  121. * @return {Object} data The custom data
  122. */
  123. getTargetFromEvent : function(e){
  124. var t = e.getTarget();
  125. return t ? this.elements[t.id] || this.handles[t.id] : null;
  126. }
  127. });</pre>
  128. </body>
  129. </html>