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