4b881a97c3d3e3daffdd0d048a019733d25fc69c.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. /*
  7. * // Internal developer documentation -- will not show up in API docs @class
  8. * Ext.dd.PanelProxy A custom drag proxy implementation specific to
  9. * {@link Ext.Panel}s. This class is primarily used internally for the Panel's
  10. * drag drop implementation, and should never need to be created directly.
  11. * @constructor @param panel The {@link Ext.Panel} to proxy for @param config
  12. * Configuration options
  13. */
  14. Ext.dd.PanelProxy = function(panel, config) {
  15. this.panel = panel;
  16. this.id = this.panel.id + '-ddproxy';
  17. Ext.apply(this, config);
  18. };
  19. Ext.dd.PanelProxy.prototype = {
  20. /**
  21. * @cfg {Boolean} insertProxy True to insert a placeholder proxy element
  22. * while dragging the panel, false to drag with no proxy (defaults to
  23. * true).
  24. */
  25. insertProxy : true,
  26. // private overrides
  27. setStatus : Ext.emptyFn,
  28. reset : Ext.emptyFn,
  29. update : Ext.emptyFn,
  30. stop : Ext.emptyFn,
  31. sync : Ext.emptyFn,
  32. /**
  33. * Gets the proxy's element
  34. *
  35. * @return {Element} The proxy's element
  36. */
  37. getEl : function() {
  38. return this.ghost;
  39. },
  40. /**
  41. * Gets the proxy's ghost element
  42. *
  43. * @return {Element} The proxy's ghost element
  44. */
  45. getGhost : function() {
  46. return this.ghost;
  47. },
  48. /**
  49. * Gets the proxy's element
  50. *
  51. * @return {Element} The proxy's element
  52. */
  53. getProxy : function() {
  54. return this.proxy;
  55. },
  56. /**
  57. * Hides the proxy
  58. */
  59. hide : function() {
  60. if (this.ghost) {
  61. if (this.proxy) {
  62. this.proxy.remove();
  63. delete this.proxy;
  64. }
  65. this.panel.el.dom.style.display = '';
  66. this.ghost.remove();
  67. delete this.ghost;
  68. }
  69. },
  70. /**
  71. * Shows the proxy
  72. */
  73. show : function() {
  74. if (!this.ghost) {
  75. this.ghost = this.panel.createGhost(undefined, undefined, Ext
  76. .getBody());
  77. this.ghost.setXY(this.panel.el.getXY())
  78. if (this.insertProxy) {
  79. this.proxy = this.panel.el.insertSibling({
  80. cls : 'x-panel-dd-spacer'
  81. });
  82. this.proxy.setSize(this.panel.getSize());
  83. }
  84. this.panel.el.dom.style.display = 'none';
  85. }
  86. },
  87. // private
  88. repair : function(xy, callback, scope) {
  89. this.hide();
  90. if (typeof callback == "function") {
  91. callback.call(scope || this);
  92. }
  93. },
  94. /**
  95. * Moves the proxy to a different position in the DOM. This is typically
  96. * called while dragging the Panel to keep the proxy sync'd to the Panel's
  97. * location.
  98. *
  99. * @param {HTMLElement}
  100. * parentNode The proxy's parent DOM node
  101. * @param {HTMLElement}
  102. * before (optional) The sibling node before which the proxy
  103. * should be inserted (defaults to the parent's last child if not
  104. * specified)
  105. */
  106. moveProxy : function(parentNode, before) {
  107. if (this.proxy) {
  108. parentNode.insertBefore(this.proxy.dom, before);
  109. }
  110. }
  111. };
  112. // private - DD implementation for Panels
  113. Ext.Panel.DD = function(panel, cfg) {
  114. this.panel = panel;
  115. this.dragData = {
  116. panel : panel
  117. };
  118. this.proxy = new Ext.dd.PanelProxy(panel, cfg);
  119. Ext.Panel.DD.superclass.constructor.call(this, panel.el, cfg);
  120. this.setHandleElId(panel.header.id);
  121. panel.header.setStyle('cursor', 'move');
  122. this.scroll = false;
  123. };
  124. Ext.extend(Ext.Panel.DD, Ext.dd.DragSource, {
  125. showFrame : Ext.emptyFn,
  126. startDrag : Ext.emptyFn,
  127. b4StartDrag : function(x, y) {
  128. this.proxy.show();
  129. },
  130. b4MouseDown : function(e) {
  131. var x = e.getPageX();
  132. var y = e.getPageY();
  133. this.autoOffset(x, y);
  134. },
  135. onInitDrag : function(x, y) {
  136. this.onStartDrag(x, y);
  137. return true;
  138. },
  139. createFrame : Ext.emptyFn,
  140. getDragEl : function(e) {
  141. return this.proxy.ghost.dom;
  142. },
  143. endDrag : function(e) {
  144. this.proxy.hide();
  145. this.panel.saveState();
  146. },
  147. autoOffset : function(x, y) {
  148. x -= this.startPageX;
  149. y -= this.startPageY;
  150. this.setDelta(x, y);
  151. }
  152. });