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"><span id='Ext-util-Floating'>/**
19 </span> * @class Ext.util.Floating
20 * A mixin to add floating capability to a Component
22 Ext.define('Ext.util.Floating', {
24 uses: ['Ext.Layer', 'Ext.window.Window'],
26 <span id='Ext-util-Floating-cfg-focusOnToFront'> /**
27 </span> * @cfg {Boolean} focusOnToFront
28 * Specifies whether the floated component should be automatically {@link #focus focused} when it is
29 * {@link #toFront brought to the front}. Defaults to true.
33 <span id='Ext-util-Floating-cfg-shadow'> /**
34 </span> * @cfg {String/Boolean} shadow Specifies whether the floating component should be given a shadow. Set to
35 * <tt>true</tt> to automatically create an {@link Ext.Shadow}, or a string indicating the
36 * shadow's display {@link Ext.Shadow#mode}. Set to <tt>false</tt> to disable the shadow.
37 * (Defaults to <tt>'sides'</tt>.)
41 constructor: function(config) {
43 this.el = Ext.create('Ext.Layer', Ext.apply({}, config, {
44 hideMode: this.hideMode,
46 shadow: Ext.isDefined(this.shadow) ? this.shadow : 'sides',
47 shadowOffset: this.shadowOffset,
49 shim: this.shim === false ? false : undefined
53 onFloatRender: function() {
55 me.zIndexParent = me.getZIndexParent();
56 me.setFloatParent(me.ownerCt);
59 if (me.zIndexParent) {
60 me.zIndexParent.registerFloatingItem(me);
62 Ext.WindowManager.register(me);
66 setFloatParent: function(floatParent) {
69 // Remove listeners from previous floatParent
71 me.mun(me.floatParent, {
72 hide: me.onFloatParentHide,
73 show: me.onFloatParentShow,
78 me.floatParent = floatParent;
80 // Floating Components as children of Containers must hide when their parent hides.
82 me.mon(me.floatParent, {
83 hide: me.onFloatParentHide,
84 show: me.onFloatParentShow,
89 // If a floating Component is configured to be constrained, but has no configured
90 // constrainTo setting, set its constrainTo to be it's ownerCt before rendering.
91 if ((me.constrain || me.constrainHeader) && !me.constrainTo) {
92 me.constrainTo = floatParent ? floatParent.getTargetEl() : me.container;
96 onFloatParentHide: function() {
97 if (this.hideOnParentHide !== false) {
98 this.showOnParentShow = this.isVisible();
103 onFloatParentShow: function() {
104 if (this.showOnParentShow) {
105 delete this.showOnParentShow;
110 <span id='Ext-util-Floating-method-getZIndexParent'> /**
112 * <p>Finds the ancestor Container responsible for allocating zIndexes for the passed Component.</p>
113 * <p>That will be the outermost floating Container (a Container which has no ownerCt and has floating:true).</p>
114 * <p>If we have no ancestors, or we walk all the way up to the document body, there's no zIndexParent,
115 * and the global Ext.WindowManager will be used.</p>
117 getZIndexParent: function() {
118 var p = this.ownerCt,
133 // z-index is managed by the zIndexManager and may be overwritten at any time.
134 // Returns the next z-index to be used.
135 // If this is a Container, then it will have rebased any managed floating Components,
136 // and so the next available z-index will be approximately 10000 above that.
137 setZIndex: function(index) {
139 this.el.setZIndex(index);
141 // Next item goes 10 above;
144 // When a Container with floating items has its z-index set, it rebases any floating items it is managing.
145 // The returned value is a round number approximately 10000 above the last z-index used.
146 if (me.floatingItems) {
147 index = Math.floor(me.floatingItems.setBase(index) / 100) * 100 + 10000;
152 <span id='Ext-util-Floating-method-doConstrain'> /**
153 </span> * <p>Moves this floating Component into a constrain region.</p>
154 * <p>By default, this Component is constrained to be within the container it was added to, or the element
155 * it was rendered to.</p>
156 * <p>An alternative constraint may be passed.</p>
157 * @param {Mixed} constrainTo Optional. The Element or {@link Ext.util.Region Region} into which this Component is to be constrained.
159 doConstrain: function(constrainTo) {
161 vector = me.getConstrainVector(constrainTo),
165 xy = me.getPosition();
173 <span id='Ext-util-Floating-method-getConstrainVector'> /**
174 </span> * Gets the x/y offsets to constrain this float
176 * @param {Mixed} constrainTo Optional. The Element or {@link Ext.util.Region Region} into which this Component is to be constrained.
177 * @return {Array} The x/y constraints
179 getConstrainVector: function(constrainTo){
183 if (me.constrain || me.constrainHeader) {
184 el = me.constrainHeader ? me.header.el : me.el;
185 constrainTo = constrainTo || (me.floatParent && me.floatParent.getTargetEl()) || me.container;
186 return el.getConstrainVector(constrainTo);
190 <span id='Ext-util-Floating-method-alignTo'> /**
191 </span> * Aligns this floating Component to the specified element
192 * @param {Mixed} element The element or {@link Ext.Component} to align to. If passing a component, it must
193 * be a omponent instance. If a string id is passed, it will be used as an element id.
194 * @param {String} position (optional, defaults to "tl-bl?") The position to align to (see {@link Ext.core.Element#alignTo} for more details).
195 * @param {Array} offsets (optional) Offset the positioning by [x, y]
196 * @return {Component} this
198 alignTo: function(element, position, offsets) {
199 if (element.isComponent) {
200 element = element.getEl();
202 var xy = this.el.getAlignToXY(element, position, offsets);
203 this.setPagePosition(xy);
207 <span id='Ext-util-Floating-method-toFront'> /**
208 </span> * <p>Brings this floating Component to the front of any other visible, floating Components managed by the same {@link Ext.ZIndexManager ZIndexManager}</p>
209 * <p>If this Component is modal, inserts the modal mask just below this Component in the z-index stack.</p>
210 * @param {Boolean} preventFocus (optional) Specify <code>true</code> to prevent the Component from being focused.
211 * @return {Component} this
213 toFront: function(preventFocus) {
216 // Find the floating Component which provides the base for this Component's zIndexing.
217 // That must move to front to then be able to rebase its zIndex stack and move this to the front
218 if (me.zIndexParent) {
219 me.zIndexParent.toFront(true);
221 if (me.zIndexManager.bringToFront(me)) {
222 if (!Ext.isDefined(preventFocus)) {
223 preventFocus = !me.focusOnToFront;
226 // Kick off a delayed focus request.
227 // If another floating Component is toFronted before the delay expires
228 // this will not receive focus.
229 me.focus(false, true);
235 <span id='Ext-util-Floating-method-setActive'> /**
236 </span> * <p>This method is called internally by {@link Ext.ZIndexManager} to signal that a floating
237 * Component has either been moved to the top of its zIndex stack, or pushed from the top of its zIndex stack.</p>
238 * <p>If a <i>Window</i> is superceded by another Window, deactivating it hides its shadow.</p>
239 * <p>This method also fires the {@link #activate} or {@link #deactivate} event depending on which action occurred.</p>
240 * @param {Boolean} active True to activate the Component, false to deactivate it (defaults to false)
241 * @param {Component} newActive The newly active Component which is taking over topmost zIndex position.
243 setActive: function(active, newActive) {
245 if ((this instanceof Ext.window.Window) && !this.maximized) {
246 this.el.enableShadow(true);
248 this.fireEvent('activate', this);
250 // Only the *Windows* in a zIndex stack share a shadow. All other types of floaters
251 // can keep their shadows all the time
252 if ((this instanceof Ext.window.Window) && (newActive instanceof Ext.window.Window)) {
253 this.el.disableShadow();
255 this.fireEvent('deactivate', this);
259 <span id='Ext-util-Floating-method-toBack'> /**
260 </span> * Sends this Component to the back of (lower z-index than) any other visible windows
261 * @return {Component} this
264 this.zIndexManager.sendToBack(this);
268 <span id='Ext-util-Floating-method-center'> /**
269 </span> * Center this Component in its container.
270 * @return {Component} this
273 var xy = this.el.getAlignToXY(this.container, 'c-c');
274 this.setPagePosition(xy);
279 syncShadow : function(){
286 fitContainer: function() {
287 var parent = this.floatParent,
288 container = parent ? parent.getTargetEl() : this.container,
289 size = container.getViewSize(false);