StatusProxy.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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-StatusProxy'>/**
  19. </span> * A specialized floating Component that supports a drop status icon, {@link Ext.Layer} styles
  20. * and auto-repair. This is the default drag proxy used by all Ext.dd components.
  21. */
  22. Ext.define('Ext.dd.StatusProxy', {
  23. extend: 'Ext.Component',
  24. animRepair: false,
  25. childEls: [
  26. 'ghost'
  27. ],
  28. renderTpl: [
  29. '&lt;div class=&quot;' + Ext.baseCSSPrefix + 'dd-drop-icon&quot;&gt;&lt;/div&gt;' +
  30. '&lt;div id=&quot;{id}-ghost&quot; class=&quot;' + Ext.baseCSSPrefix + 'dd-drag-ghost&quot;&gt;&lt;/div&gt;'
  31. ],
  32. <span id='Ext-dd-StatusProxy-method-constructor'> /**
  33. </span> * Creates new StatusProxy.
  34. * @param {Object} [config] Config object.
  35. */
  36. constructor: function(config) {
  37. var me = this;
  38. config = config || {};
  39. Ext.apply(me, {
  40. hideMode: 'visibility',
  41. hidden: true,
  42. floating: true,
  43. id: me.id || Ext.id(),
  44. cls: Ext.baseCSSPrefix + 'dd-drag-proxy ' + this.dropNotAllowed,
  45. shadow: config.shadow || false,
  46. renderTo: Ext.getDetachedBody()
  47. });
  48. me.callParent(arguments);
  49. this.dropStatus = this.dropNotAllowed;
  50. },
  51. <span id='Ext-dd-StatusProxy-cfg-dropAllowed'> /**
  52. </span> * @cfg {String} dropAllowed
  53. * The CSS class to apply to the status element when drop is allowed.
  54. */
  55. dropAllowed : Ext.baseCSSPrefix + 'dd-drop-ok',
  56. <span id='Ext-dd-StatusProxy-cfg-dropNotAllowed'> /**
  57. </span> * @cfg {String} dropNotAllowed
  58. * The CSS class to apply to the status element when drop is not allowed.
  59. */
  60. dropNotAllowed : Ext.baseCSSPrefix + 'dd-drop-nodrop',
  61. <span id='Ext-dd-StatusProxy-method-setStatus'> /**
  62. </span> * Updates the proxy's visual element to indicate the status of whether or not drop is allowed
  63. * over the current target element.
  64. * @param {String} cssClass The css class for the new drop status indicator image
  65. */
  66. setStatus : function(cssClass){
  67. cssClass = cssClass || this.dropNotAllowed;
  68. if (this.dropStatus != cssClass) {
  69. this.el.replaceCls(this.dropStatus, cssClass);
  70. this.dropStatus = cssClass;
  71. }
  72. },
  73. <span id='Ext-dd-StatusProxy-method-reset'> /**
  74. </span> * Resets the status indicator to the default dropNotAllowed value
  75. * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
  76. */
  77. reset : function(clearGhost){
  78. var me = this,
  79. clsPrefix = Ext.baseCSSPrefix + 'dd-drag-proxy ';
  80. me.el.replaceCls(clsPrefix + me.dropAllowed, clsPrefix + me.dropNotAllowed);
  81. me.dropStatus = me.dropNotAllowed;
  82. if (clearGhost) {
  83. me.ghost.update('');
  84. }
  85. },
  86. <span id='Ext-dd-StatusProxy-method-update'> /**
  87. </span> * Updates the contents of the ghost element
  88. * @param {String/HTMLElement} html The html that will replace the current innerHTML of the ghost element, or a
  89. * DOM node to append as the child of the ghost element (in which case the innerHTML will be cleared first).
  90. */
  91. update : function(html){
  92. if (typeof html == &quot;string&quot;) {
  93. this.ghost.update(html);
  94. } else {
  95. this.ghost.update(&quot;&quot;);
  96. html.style.margin = &quot;0&quot;;
  97. this.ghost.dom.appendChild(html);
  98. }
  99. var el = this.ghost.dom.firstChild;
  100. if (el) {
  101. Ext.fly(el).setStyle('float', 'none');
  102. }
  103. },
  104. <span id='Ext-dd-StatusProxy-method-getGhost'> /**
  105. </span> * Returns the ghost element
  106. * @return {Ext.Element} el
  107. */
  108. getGhost : function(){
  109. return this.ghost;
  110. },
  111. <span id='Ext-dd-StatusProxy-method-hide'> /**
  112. </span> * Hides the proxy
  113. * @param {Boolean} clear True to reset the status and clear the ghost contents,
  114. * false to preserve them
  115. */
  116. hide : function(clear) {
  117. this.callParent();
  118. if (clear) {
  119. this.reset(true);
  120. }
  121. },
  122. <span id='Ext-dd-StatusProxy-method-stop'> /**
  123. </span> * Stops the repair animation if it's currently running
  124. */
  125. stop : function(){
  126. if (this.anim &amp;&amp; this.anim.isAnimated &amp;&amp; this.anim.isAnimated()) {
  127. this.anim.stop();
  128. }
  129. },
  130. <span id='Ext-dd-StatusProxy-method-sync'> /**
  131. </span> * Force the Layer to sync its shadow and shim positions to the element
  132. */
  133. sync : function(){
  134. this.el.sync();
  135. },
  136. <span id='Ext-dd-StatusProxy-method-repair'> /**
  137. </span> * Causes the proxy to return to its position of origin via an animation.
  138. * Should be called after an invalid drop operation by the item being dragged.
  139. * @param {Number[]} xy The XY position of the element ([x, y])
  140. * @param {Function} callback The function to call after the repair is complete.
  141. * @param {Object} scope The scope (`this` reference) in which the callback function is executed.
  142. * Defaults to the browser window.
  143. */
  144. repair : function(xy, callback, scope) {
  145. var me = this;
  146. me.callback = callback;
  147. me.scope = scope;
  148. if (xy &amp;&amp; me.animRepair !== false) {
  149. me.el.addCls(Ext.baseCSSPrefix + 'dd-drag-repair');
  150. me.el.hideUnders(true);
  151. me.anim = me.el.animate({
  152. duration: me.repairDuration || 500,
  153. easing: 'ease-out',
  154. to: {
  155. x: xy[0],
  156. y: xy[1]
  157. },
  158. stopAnimation: true,
  159. callback: me.afterRepair,
  160. scope: me
  161. });
  162. } else {
  163. me.afterRepair();
  164. }
  165. },
  166. // private
  167. afterRepair : function() {
  168. var me = this;
  169. me.hide(true);
  170. me.el.removeCls(Ext.baseCSSPrefix + 'dd-drag-repair');
  171. if (typeof me.callback == &quot;function&quot;) {
  172. me.callback.call(me.scope || me);
  173. }
  174. delete me.callback;
  175. delete me.scope;
  176. }
  177. });
  178. </pre>
  179. </body>
  180. </html>