/ext-4.0.7/docs/source/DDProxy.html

https://bitbucket.org/srogerf/javascript · HTML · 230 lines · 196 code · 34 blank · 0 comment · 0 complexity · 19fc0ca429091861da7594ff4113eecd MD5 · raw file

  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">/*
  19. * This is a derivative of the similarly named class in the YUI Library.
  20. * The original license:
  21. * Copyright (c) 2006, Yahoo! Inc. All rights reserved.
  22. * Code licensed under the BSD License:
  23. * http://developer.yahoo.net/yui/license.txt
  24. */
  25. <span id='Ext-dd-DDProxy'>/**
  26. </span> * @class Ext.dd.DDProxy
  27. * @extends Ext.dd.DD
  28. * A DragDrop implementation that inserts an empty, bordered div into
  29. * the document that follows the cursor during drag operations. At the time of
  30. * the click, the frame div is resized to the dimensions of the linked html
  31. * element, and moved to the exact location of the linked element.
  32. *
  33. * References to the &quot;frame&quot; element refer to the single proxy element that
  34. * was created to be dragged in place of all DDProxy elements on the
  35. * page.
  36. */
  37. Ext.define('Ext.dd.DDProxy', {
  38. extend: 'Ext.dd.DD',
  39. statics: {
  40. <span id='Ext-dd-DDProxy-static-property-dragElId'> /**
  41. </span> * The default drag frame div id
  42. * @static
  43. */
  44. dragElId: &quot;ygddfdiv&quot;
  45. },
  46. <span id='Ext-dd-DDProxy-method-constructor'> /**
  47. </span> * Creates new DDProxy.
  48. * @param {String} id the id of the linked html element
  49. * @param {String} sGroup the group of related DragDrop objects
  50. * @param {Object} config an object containing configurable attributes.
  51. * Valid properties for DDProxy in addition to those in DragDrop:
  52. *
  53. * - resizeFrame
  54. * - centerFrame
  55. * - dragElId
  56. */
  57. constructor: function(id, sGroup, config) {
  58. if (id) {
  59. this.init(id, sGroup, config);
  60. this.initFrame();
  61. }
  62. },
  63. <span id='Ext-dd-DDProxy-property-resizeFrame'> /**
  64. </span> * By default we resize the drag frame to be the same size as the element
  65. * we want to drag (this is to get the frame effect). We can turn it off
  66. * if we want a different behavior.
  67. * @property resizeFrame
  68. * @type Boolean
  69. */
  70. resizeFrame: true,
  71. <span id='Ext-dd-DDProxy-property-centerFrame'> /**
  72. </span> * By default the frame is positioned exactly where the drag element is, so
  73. * we use the cursor offset provided by Ext.dd.DD. Another option that works only if
  74. * you do not have constraints on the obj is to have the drag frame centered
  75. * around the cursor. Set centerFrame to true for this effect.
  76. * @property centerFrame
  77. * @type Boolean
  78. */
  79. centerFrame: false,
  80. <span id='Ext-dd-DDProxy-method-createFrame'> /**
  81. </span> * Creates the proxy element if it does not yet exist
  82. * @method createFrame
  83. */
  84. createFrame: function() {
  85. var self = this;
  86. var body = document.body;
  87. if (!body || !body.firstChild) {
  88. setTimeout( function() { self.createFrame(); }, 50 );
  89. return;
  90. }
  91. var div = this.getDragEl();
  92. if (!div) {
  93. div = document.createElement(&quot;div&quot;);
  94. div.id = this.dragElId;
  95. var s = div.style;
  96. s.position = &quot;absolute&quot;;
  97. s.visibility = &quot;hidden&quot;;
  98. s.cursor = &quot;move&quot;;
  99. s.border = &quot;2px solid #aaa&quot;;
  100. s.zIndex = 999;
  101. // appendChild can blow up IE if invoked prior to the window load event
  102. // while rendering a table. It is possible there are other scenarios
  103. // that would cause this to happen as well.
  104. body.insertBefore(div, body.firstChild);
  105. }
  106. },
  107. <span id='Ext-dd-DDProxy-method-initFrame'> /**
  108. </span> * Initialization for the drag frame element. Must be called in the
  109. * constructor of all subclasses
  110. * @method initFrame
  111. */
  112. initFrame: function() {
  113. this.createFrame();
  114. },
  115. applyConfig: function() {
  116. this.callParent();
  117. this.resizeFrame = (this.config.resizeFrame !== false);
  118. this.centerFrame = (this.config.centerFrame);
  119. this.setDragElId(this.config.dragElId || Ext.dd.DDProxy.dragElId);
  120. },
  121. <span id='Ext-dd-DDProxy-method-showFrame'> /**
  122. </span> * Resizes the drag frame to the dimensions of the clicked object, positions
  123. * it over the object, and finally displays it
  124. * @method showFrame
  125. * @param {Number} iPageX X click position
  126. * @param {Number} iPageY Y click position
  127. * @private
  128. */
  129. showFrame: function(iPageX, iPageY) {
  130. var el = this.getEl();
  131. var dragEl = this.getDragEl();
  132. var s = dragEl.style;
  133. this._resizeProxy();
  134. if (this.centerFrame) {
  135. this.setDelta( Math.round(parseInt(s.width, 10)/2),
  136. Math.round(parseInt(s.height, 10)/2) );
  137. }
  138. this.setDragElPos(iPageX, iPageY);
  139. Ext.fly(dragEl).show();
  140. },
  141. <span id='Ext-dd-DDProxy-method-_resizeProxy'> /**
  142. </span> * The proxy is automatically resized to the dimensions of the linked
  143. * element when a drag is initiated, unless resizeFrame is set to false
  144. * @method _resizeProxy
  145. * @private
  146. */
  147. _resizeProxy: function() {
  148. if (this.resizeFrame) {
  149. var el = this.getEl();
  150. Ext.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
  151. }
  152. },
  153. // overrides Ext.dd.DragDrop
  154. b4MouseDown: function(e) {
  155. var x = e.getPageX();
  156. var y = e.getPageY();
  157. this.autoOffset(x, y);
  158. this.setDragElPos(x, y);
  159. },
  160. // overrides Ext.dd.DragDrop
  161. b4StartDrag: function(x, y) {
  162. // show the drag frame
  163. this.showFrame(x, y);
  164. },
  165. // overrides Ext.dd.DragDrop
  166. b4EndDrag: function(e) {
  167. Ext.fly(this.getDragEl()).hide();
  168. },
  169. // overrides Ext.dd.DragDrop
  170. // By default we try to move the element to the last location of the frame.
  171. // This is so that the default behavior mirrors that of Ext.dd.DD.
  172. endDrag: function(e) {
  173. var lel = this.getEl();
  174. var del = this.getDragEl();
  175. // Show the drag frame briefly so we can get its position
  176. del.style.visibility = &quot;&quot;;
  177. this.beforeMove();
  178. // Hide the linked element before the move to get around a Safari
  179. // rendering bug.
  180. lel.style.visibility = &quot;hidden&quot;;
  181. Ext.dd.DDM.moveToEl(lel, del);
  182. del.style.visibility = &quot;hidden&quot;;
  183. lel.style.visibility = &quot;&quot;;
  184. this.afterDrag();
  185. },
  186. beforeMove : function(){
  187. },
  188. afterDrag : function(){
  189. },
  190. toString: function() {
  191. return (&quot;DDProxy &quot; + this.id);
  192. }
  193. });
  194. </pre>
  195. </body>
  196. </html>