4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
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
26 <span id='Ext-dd-DDProxy-method-constructor'><span id='Ext-dd-DDProxy'>/**
27 </span></span> * @class Ext.dd.DDProxy
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.
33 * References to the "frame" element refer to the single proxy element that
34 * was created to be dragged in place of all DDProxy elements on the
39 * @param {String} id the id of the linked html element
40 * @param {String} sGroup the group of related DragDrop objects
41 * @param {object} config an object containing configurable attributes
42 * Valid properties for DDProxy in addition to those in DragDrop:
43 * resizeFrame, centerFrame, dragElId
45 Ext.define('Ext.dd.DDProxy', {
49 <span id='Ext-dd-DDProxy-property-Ext'> /**
50 </span> * The default drag frame div id
51 * @property Ext.dd.DDProxy.dragElId
55 dragElId: "ygddfdiv"
58 constructor: function(id, sGroup, config) {
60 this.init(id, sGroup, config);
65 <span id='Ext-dd-DDProxy-property-resizeFrame'> /**
66 </span> * By default we resize the drag frame to be the same size as the element
67 * we want to drag (this is to get the frame effect). We can turn it off
68 * if we want a different behavior.
69 * @property resizeFrame
74 <span id='Ext-dd-DDProxy-property-centerFrame'> /**
75 </span> * By default the frame is positioned exactly where the drag element is, so
76 * we use the cursor offset provided by Ext.dd.DD. Another option that works only if
77 * you do not have constraints on the obj is to have the drag frame centered
78 * around the cursor. Set centerFrame to true for this effect.
79 * @property centerFrame
84 <span id='Ext-dd-DDProxy-method-createFrame'> /**
85 </span> * Creates the proxy element if it does not yet exist
88 createFrame: function() {
90 var body = document.body;
92 if (!body || !body.firstChild) {
93 setTimeout( function() { self.createFrame(); }, 50 );
97 var div = this.getDragEl();
100 div = document.createElement("div");
101 div.id = this.dragElId;
104 s.position = "absolute";
105 s.visibility = "hidden";
106 s.cursor = "move";
107 s.border = "2px solid #aaa";
110 // appendChild can blow up IE if invoked prior to the window load event
111 // while rendering a table. It is possible there are other scenarios
112 // that would cause this to happen as well.
113 body.insertBefore(div, body.firstChild);
117 <span id='Ext-dd-DDProxy-method-initFrame'> /**
118 </span> * Initialization for the drag frame element. Must be called in the
119 * constructor of all subclasses
122 initFrame: function() {
126 applyConfig: function() {
129 this.resizeFrame = (this.config.resizeFrame !== false);
130 this.centerFrame = (this.config.centerFrame);
131 this.setDragElId(this.config.dragElId || Ext.dd.DDProxy.dragElId);
134 <span id='Ext-dd-DDProxy-method-showFrame'> /**
135 </span> * Resizes the drag frame to the dimensions of the clicked object, positions
136 * it over the object, and finally displays it
138 * @param {int} iPageX X click position
139 * @param {int} iPageY Y click position
142 showFrame: function(iPageX, iPageY) {
143 var el = this.getEl();
144 var dragEl = this.getDragEl();
145 var s = dragEl.style;
149 if (this.centerFrame) {
150 this.setDelta( Math.round(parseInt(s.width, 10)/2),
151 Math.round(parseInt(s.height, 10)/2) );
154 this.setDragElPos(iPageX, iPageY);
156 Ext.fly(dragEl).show();
159 <span id='Ext-dd-DDProxy-method-_resizeProxy'> /**
160 </span> * The proxy is automatically resized to the dimensions of the linked
161 * element when a drag is initiated, unless resizeFrame is set to false
162 * @method _resizeProxy
165 _resizeProxy: function() {
166 if (this.resizeFrame) {
167 var el = this.getEl();
168 Ext.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
172 // overrides Ext.dd.DragDrop
173 b4MouseDown: function(e) {
174 var x = e.getPageX();
175 var y = e.getPageY();
176 this.autoOffset(x, y);
177 this.setDragElPos(x, y);
180 // overrides Ext.dd.DragDrop
181 b4StartDrag: function(x, y) {
182 // show the drag frame
183 this.showFrame(x, y);
186 // overrides Ext.dd.DragDrop
187 b4EndDrag: function(e) {
188 Ext.fly(this.getDragEl()).hide();
191 // overrides Ext.dd.DragDrop
192 // By default we try to move the element to the last location of the frame.
193 // This is so that the default behavior mirrors that of Ext.dd.DD.
194 endDrag: function(e) {
196 var lel = this.getEl();
197 var del = this.getDragEl();
199 // Show the drag frame briefly so we can get its position
200 del.style.visibility = "";
203 // Hide the linked element before the move to get around a Safari
205 lel.style.visibility = "hidden";
206 Ext.dd.DDM.moveToEl(lel, del);
207 del.style.visibility = "hidden";
208 lel.style.visibility = "";
213 beforeMove : function(){
217 afterDrag : function(){
221 toString: function() {
222 return ("DDProxy " + this.id);