1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-util.Floating'>/**
2 </span> * @class Ext.util.Floating
3 * A mixin to add floating capability to a Component
5 Ext.define('Ext.util.Floating', {
7 uses: ['Ext.Layer', 'Ext.window.Window'],
9 <span id='Ext-util.Floating-cfg-focusOnToFront'> /**
10 </span> * @cfg {Boolean} focusOnToFront
11 * Specifies whether the floated component should be automatically {@link #focus focused} when it is
12 * {@link #toFront brought to the front}. Defaults to true.
16 <span id='Ext-util.Floating-cfg-shadow'> /**
17 </span> * @cfg {String/Boolean} shadow Specifies whether the floating component should be given a shadow. Set to
18 * <tt>true</tt> to automatically create an {@link Ext.Shadow}, or a string indicating the
19 * shadow's display {@link Ext.Shadow#mode}. Set to <tt>false</tt> to disable the shadow.
20 * (Defaults to <tt>'sides'</tt>.)
24 constructor: function(config) {
26 this.el = Ext.create('Ext.Layer', Ext.apply({}, config, {
27 hideMode: this.hideMode,
29 shadow: Ext.isDefined(this.shadow) ? this.shadow : 'sides',
30 shadowOffset: this.shadowOffset,
32 shim: this.shim === false ? false : undefined
36 onFloatRender: function() {
38 me.zIndexParent = me.getZIndexParent();
39 me.setFloatParent(me.ownerCt);
42 if (me.zIndexParent) {
43 me.zIndexParent.registerFloatingItem(me);
45 Ext.WindowManager.register(me);
49 setFloatParent: function(floatParent) {
52 // Remove listeners from previous floatParent
54 me.mun(me.floatParent, {
55 hide: me.onFloatParentHide,
56 show: me.onFloatParentShow,
61 me.floatParent = floatParent;
63 // Floating Components as children of Containers must hide when their parent hides.
65 me.mon(me.floatParent, {
66 hide: me.onFloatParentHide,
67 show: me.onFloatParentShow,
72 // If a floating Component is configured to be constrained, but has no configured
73 // constrainTo setting, set its constrainTo to be it's ownerCt before rendering.
74 if ((me.constrain || me.constrainHeader) && !me.constrainTo) {
75 me.constrainTo = floatParent ? floatParent.getTargetEl() : me.container;
79 onFloatParentHide: function() {
80 this.showOnParentShow = this.isVisible();
84 onFloatParentShow: function() {
85 if (this.showOnParentShow) {
86 delete this.showOnParentShow;
91 <span id='Ext-util.Floating-method-getZIndexParent'> /**
93 * <p>Finds the ancestor Container responsible for allocating zIndexes for the passed Component.</p>
94 * <p>That will be the outermost floating Container (a Container which has no ownerCt and has floating:true).</p>
95 * <p>If we have no ancestors, or we walk all the way up to the document body, there's no zIndexParent,
96 * and the global Ext.WindowManager will be used.</p>
98 getZIndexParent: function() {
114 // z-index is managed by the zIndexManager and may be overwritten at any time.
115 // Returns the next z-index to be used.
116 // If this is a Container, then it will have rebased any managed floating Components,
117 // and so the next available z-index will be approximately 10000 above that.
118 setZIndex: function(index) {
120 this.el.setZIndex(index);
122 // Next item goes 10 above;
125 // When a Container with floating items has its z-index set, it rebases any floating items it is managing.
126 // The returned value is a round number approximately 10000 above the last z-index used.
127 if (me.floatingItems) {
128 index = Math.floor(me.floatingItems.setBase(index) / 100) * 100 + 10000;
133 <span id='Ext-util.Floating-method-doConstrain'> /**
134 </span> * <p>Moves this floating Component into a constrain region.</p>
135 * <p>By default, this Component is constrained to be within the container it was added to, or the element
136 * it was rendered to.</p>
137 * <p>An alternative constraint may be passed.</p>
138 * @param {Mixed} constrainTo Optional. The Element or {@link Ext.util.Region Region} into which this Component is to be constrained.
140 doConstrain: function(constrainTo) {
146 if (me.constrain || me.constrainHeader) {
147 if (me.constrainHeader) {
148 constrainEl = me.header.el;
152 vector = constrainEl.getConstrainVector(constrainTo || (me.floatParent && me.floatParent.getTargetEl()) || me.container);
154 xy = me.getPosition();
162 <span id='Ext-util.Floating-method-alignTo'> /**
163 </span> * Aligns this floating Component to the specified element
164 * @param {Mixed} element The element or {@link Ext.Component} to align to. If passing a component, it must
165 * be a omponent instance. If a string id is passed, it will be used as an element id.
166 * @param {String} position (optional, defaults to "tl-bl?") The position to align to (see {@link Ext.core.Element#alignTo} for more details).
167 * @param {Array} offsets (optional) Offset the positioning by [x, y]
168 * @return {Component} this
170 alignTo: function(element, position, offsets) {
171 if (element.isComponent) {
172 element = element.getEl();
174 var xy = this.el.getAlignToXY(element, position, offsets);
175 this.setPagePosition(xy);
179 <span id='Ext-util.Floating-method-toFront'> /**
180 </span> * <p>Brings this floating Component to the front of any other visible, floating Components managed by the same {@link Ext.ZIndexManager ZIndexManager}</p>
181 * <p>If this Component is modal, inserts the modal mask just below this Component in the z-index stack.</p>
182 * @param {Boolean} preventFocus (optional) Specify <code>true</code> to prevent the Component from being focused.
183 * @return {Component} this
185 toFront: function(preventFocus) {
188 // Find the floating Component which provides the base for this Component's zIndexing.
189 // That must move to front to then be able to rebase its zIndex stack and move this to the front
190 if (me.zIndexParent) {
191 me.zIndexParent.toFront(true);
193 if (me.zIndexManager.bringToFront(me)) {
194 if (!Ext.isDefined(preventFocus)) {
195 preventFocus = !me.focusOnToFront;
198 // Kick off a delayed focus request.
199 // If another floating Component is toFronted before the delay expires
200 // this will not receive focus.
201 me.focus(false, true);
207 <span id='Ext-util.Floating-method-setActive'> /**
208 </span> * <p>This method is called internally by {@link Ext.ZIndexManager} to signal that a floating
209 * Component has either been moved to the top of its zIndex stack, or pushed from the top of its zIndex stack.</p>
210 * <p>If a <i>Window</i> is superceded by another Window, deactivating it hides its shadow.</p>
211 * <p>This method also fires the {@link #activate} or {@link #deactivate} event depending on which action occurred.</p>
212 * @param {Boolean} active True to activate the Component, false to deactivate it (defaults to false)
213 * @param {Component} newActive The newly active Component which is taking over topmost zIndex position.
215 setActive: function(active, newActive) {
217 if ((this instanceof Ext.window.Window) && !this.maximized) {
218 this.el.enableShadow(true);
220 this.fireEvent('activate', this);
222 // Only the *Windows* in a zIndex stack share a shadow. All other types of floaters
223 // can keep their shadows all the time
224 if ((this instanceof Ext.window.Window) && (newActive instanceof Ext.window.Window)) {
225 this.el.disableShadow();
227 this.fireEvent('deactivate', this);
231 <span id='Ext-util.Floating-method-toBack'> /**
232 </span> * Sends this Component to the back of (lower z-index than) any other visible windows
233 * @return {Component} this
236 this.zIndexManager.sendToBack(this);
240 <span id='Ext-util.Floating-method-center'> /**
241 </span> * Center this Component in its container.
242 * @return {Component} this
245 var xy = this.el.getAlignToXY(this.container, 'c-c');
246 this.setPagePosition(xy);
251 syncShadow : function(){
258 fitContainer: function() {
259 var parent = this.floatParent,
260 container = parent ? parent.getTargetEl() : this.container,
261 size = container.getViewSize(false);
265 });</pre></pre></body></html>