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 this.showOnParentShow = this.isVisible();
101 onFloatParentShow: function() {
102 if (this.showOnParentShow) {
103 delete this.showOnParentShow;
108 <span id='Ext-util-Floating-method-getZIndexParent'> /**
110 * <p>Finds the ancestor Container responsible for allocating zIndexes for the passed Component.</p>
111 * <p>That will be the outermost floating Container (a Container which has no ownerCt and has floating:true).</p>
112 * <p>If we have no ancestors, or we walk all the way up to the document body, there's no zIndexParent,
113 * and the global Ext.WindowManager will be used.</p>
115 getZIndexParent: function() {
116 var p = this.ownerCt,
131 // z-index is managed by the zIndexManager and may be overwritten at any time.
132 // Returns the next z-index to be used.
133 // If this is a Container, then it will have rebased any managed floating Components,
134 // and so the next available z-index will be approximately 10000 above that.
135 setZIndex: function(index) {
137 this.el.setZIndex(index);
139 // Next item goes 10 above;
142 // When a Container with floating items has its z-index set, it rebases any floating items it is managing.
143 // The returned value is a round number approximately 10000 above the last z-index used.
144 if (me.floatingItems) {
145 index = Math.floor(me.floatingItems.setBase(index) / 100) * 100 + 10000;
150 <span id='Ext-util-Floating-method-doConstrain'> /**
151 </span> * <p>Moves this floating Component into a constrain region.</p>
152 * <p>By default, this Component is constrained to be within the container it was added to, or the element
153 * it was rendered to.</p>
154 * <p>An alternative constraint may be passed.</p>
155 * @param {Mixed} constrainTo Optional. The Element or {@link Ext.util.Region Region} into which this Component is to be constrained.
157 doConstrain: function(constrainTo) {
159 vector = me.getConstrainVector(constrainTo),
163 xy = me.getPosition();
171 <span id='Ext-util-Floating-method-getConstrainVector'> /**
172 </span> * Gets the x/y offsets to constrain this float
174 * @param {Mixed} constrainTo Optional. The Element or {@link Ext.util.Region Region} into which this Component is to be constrained.
175 * @return {Array} The x/y constraints
177 getConstrainVector: function(constrainTo){
181 if (me.constrain || me.constrainHeader) {
182 el = me.constrainHeader ? me.header.el : me.el;
183 constrainTo = constrainTo || (me.floatParent && me.floatParent.getTargetEl()) || me.container;
184 return el.getConstrainVector(constrainTo);
188 <span id='Ext-util-Floating-method-alignTo'> /**
189 </span> * Aligns this floating Component to the specified element
190 * @param {Mixed} element The element or {@link Ext.Component} to align to. If passing a component, it must
191 * be a omponent instance. If a string id is passed, it will be used as an element id.
192 * @param {String} position (optional, defaults to "tl-bl?") The position to align to (see {@link Ext.core.Element#alignTo} for more details).
193 * @param {Array} offsets (optional) Offset the positioning by [x, y]
194 * @return {Component} this
196 alignTo: function(element, position, offsets) {
197 if (element.isComponent) {
198 element = element.getEl();
200 var xy = this.el.getAlignToXY(element, position, offsets);
201 this.setPagePosition(xy);
205 <span id='Ext-util-Floating-method-toFront'> /**
206 </span> * <p>Brings this floating Component to the front of any other visible, floating Components managed by the same {@link Ext.ZIndexManager ZIndexManager}</p>
207 * <p>If this Component is modal, inserts the modal mask just below this Component in the z-index stack.</p>
208 * @param {Boolean} preventFocus (optional) Specify <code>true</code> to prevent the Component from being focused.
209 * @return {Component} this
211 toFront: function(preventFocus) {
214 // Find the floating Component which provides the base for this Component's zIndexing.
215 // That must move to front to then be able to rebase its zIndex stack and move this to the front
216 if (me.zIndexParent) {
217 me.zIndexParent.toFront(true);
219 if (me.zIndexManager.bringToFront(me)) {
220 if (!Ext.isDefined(preventFocus)) {
221 preventFocus = !me.focusOnToFront;
224 // Kick off a delayed focus request.
225 // If another floating Component is toFronted before the delay expires
226 // this will not receive focus.
227 me.focus(false, true);
233 <span id='Ext-util-Floating-method-setActive'> /**
234 </span> * <p>This method is called internally by {@link Ext.ZIndexManager} to signal that a floating
235 * Component has either been moved to the top of its zIndex stack, or pushed from the top of its zIndex stack.</p>
236 * <p>If a <i>Window</i> is superceded by another Window, deactivating it hides its shadow.</p>
237 * <p>This method also fires the {@link #activate} or {@link #deactivate} event depending on which action occurred.</p>
238 * @param {Boolean} active True to activate the Component, false to deactivate it (defaults to false)
239 * @param {Component} newActive The newly active Component which is taking over topmost zIndex position.
241 setActive: function(active, newActive) {
243 if ((this instanceof Ext.window.Window) && !this.maximized) {
244 this.el.enableShadow(true);
246 this.fireEvent('activate', this);
248 // Only the *Windows* in a zIndex stack share a shadow. All other types of floaters
249 // can keep their shadows all the time
250 if ((this instanceof Ext.window.Window) && (newActive instanceof Ext.window.Window)) {
251 this.el.disableShadow();
253 this.fireEvent('deactivate', this);
257 <span id='Ext-util-Floating-method-toBack'> /**
258 </span> * Sends this Component to the back of (lower z-index than) any other visible windows
259 * @return {Component} this
262 this.zIndexManager.sendToBack(this);
266 <span id='Ext-util-Floating-method-center'> /**
267 </span> * Center this Component in its container.
268 * @return {Component} this
271 var xy = this.el.getAlignToXY(this.container, 'c-c');
272 this.setPagePosition(xy);
277 syncShadow : function(){
284 fitContainer: function() {
285 var parent = this.floatParent,
286 container = parent ? parent.getTargetEl() : this.container,
287 size = container.getViewSize(false);