~ubuntu-branches/ubuntu/quantal/maas/quantal-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/widget-stack/widget-stack.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('widget-stack', function(Y) {
8
 
 
9
 
/**
10
 
 * Provides stackable (z-index) support for Widgets through an extension.
11
 
 *
12
 
 * @module widget-stack
13
 
 */
14
 
    var L = Y.Lang,
15
 
        UA = Y.UA,
16
 
        Node = Y.Node,
17
 
        Widget = Y.Widget,
18
 
 
19
 
        ZINDEX = "zIndex",
20
 
        SHIM = "shim",
21
 
        VISIBLE = "visible",
22
 
 
23
 
        BOUNDING_BOX = "boundingBox",
24
 
 
25
 
        RENDER_UI = "renderUI",
26
 
        BIND_UI = "bindUI",
27
 
        SYNC_UI = "syncUI",
28
 
 
29
 
        OFFSET_WIDTH = "offsetWidth",
30
 
        OFFSET_HEIGHT = "offsetHeight",
31
 
        PARENT_NODE = "parentNode",
32
 
        FIRST_CHILD = "firstChild",
33
 
        OWNER_DOCUMENT = "ownerDocument",
34
 
 
35
 
        WIDTH = "width",
36
 
        HEIGHT = "height",
37
 
        PX = "px",
38
 
 
39
 
        // HANDLE KEYS
40
 
        SHIM_DEFERRED = "shimdeferred",
41
 
        SHIM_RESIZE = "shimresize",
42
 
 
43
 
        // Events
44
 
        VisibleChange = "visibleChange",
45
 
        WidthChange = "widthChange",
46
 
        HeightChange = "heightChange",
47
 
        ShimChange = "shimChange",
48
 
        ZIndexChange = "zIndexChange",
49
 
        ContentUpdate = "contentUpdate",
50
 
 
51
 
        // CSS
52
 
        STACKED = "stacked";
53
 
 
54
 
    /**
55
 
     * Widget extension, which can be used to add stackable (z-index) support to the
56
 
     * base Widget class along with a shimming solution, through the
57
 
     * <a href="Base.html#method_build">Base.build</a> method.
58
 
     *
59
 
     * @class WidgetStack
60
 
     * @param {Object} User configuration object
61
 
     */
62
 
    function Stack(config) {
63
 
        this._stackNode = this.get(BOUNDING_BOX);
64
 
        this._stackHandles = {};
65
 
 
66
 
        // WIDGET METHOD OVERLAP
67
 
        Y.after(this._renderUIStack, this, RENDER_UI);
68
 
        Y.after(this._syncUIStack, this, SYNC_UI);
69
 
        Y.after(this._bindUIStack, this, BIND_UI);
70
 
    }
71
 
 
72
 
    // Static Properties
73
 
    /**
74
 
     * Static property used to define the default attribute
75
 
     * configuration introduced by WidgetStack.
76
 
     *
77
 
     * @property ATTRS
78
 
     * @type Object
79
 
     * @static
80
 
     */
81
 
    Stack.ATTRS = {
82
 
        /**
83
 
         * @attribute shim
84
 
         * @type boolean
85
 
         * @default false, for all browsers other than IE6, for which a shim is enabled by default.
86
 
         *
87
 
         * @description Boolean flag to indicate whether or not a shim should be added to the Widgets
88
 
         * boundingBox, to protect it from select box bleedthrough.
89
 
         */
90
 
        shim: {
91
 
            value: (UA.ie == 6)
92
 
        },
93
 
 
94
 
        /**
95
 
         * @attribute zIndex
96
 
         * @type number
97
 
         * @default 0
98
 
         * @description The z-index to apply to the Widgets boundingBox. Non-numerical values for
99
 
         * zIndex will be converted to 0
100
 
         */
101
 
        zIndex: {
102
 
            value:1,
103
 
            setter: function(val) {
104
 
                return this._setZIndex(val);
105
 
            }
106
 
        }
107
 
    };
108
 
 
109
 
    /**
110
 
     * The HTML parsing rules for the WidgetStack class.
111
 
     *
112
 
     * @property HTML_PARSER
113
 
     * @static
114
 
     * @type Object
115
 
     */
116
 
    Stack.HTML_PARSER = {
117
 
        zIndex: function(contentBox) {
118
 
            return contentBox.getStyle(ZINDEX);
119
 
        }
120
 
    };
121
 
 
122
 
    /**
123
 
     * Default class used to mark the shim element
124
 
     *
125
 
     * @property SHIM_CLASS_NAME
126
 
     * @type String
127
 
     * @static
128
 
     * @default "yui3-widget-shim"
129
 
     */
130
 
    Stack.SHIM_CLASS_NAME = Widget.getClassName(SHIM);
131
 
 
132
 
    /**
133
 
     * Default class used to mark the boundingBox of a stacked widget.
134
 
     *
135
 
     * @property STACKED_CLASS_NAME
136
 
     * @type String
137
 
     * @static
138
 
     * @default "yui3-widget-stacked"
139
 
     */
140
 
    Stack.STACKED_CLASS_NAME = Widget.getClassName(STACKED);
141
 
 
142
 
    /**
143
 
     * Default markup template used to generate the shim element.
144
 
     *
145
 
     * @property SHIM_TEMPLATE
146
 
     * @type String
147
 
     * @static
148
 
     */
149
 
    Stack.SHIM_TEMPLATE = '<iframe class="' + Stack.SHIM_CLASS_NAME + '" frameborder="0" title="Widget Stacking Shim" src="javascript:false" tabindex="-1" role="presentation"></iframe>';
150
 
 
151
 
    Stack.prototype = {
152
 
 
153
 
        /**
154
 
         * Synchronizes the UI to match the Widgets stack state. This method in
155
 
         * invoked after syncUI is invoked for the Widget class using YUI's aop infrastructure.
156
 
         *
157
 
         * @method _syncUIStack
158
 
         * @protected
159
 
         */
160
 
        _syncUIStack: function() {
161
 
            this._uiSetShim(this.get(SHIM));
162
 
            this._uiSetZIndex(this.get(ZINDEX));
163
 
        },
164
 
 
165
 
        /**
166
 
         * Binds event listeners responsible for updating the UI state in response to
167
 
         * Widget stack related state changes.
168
 
         * <p>
169
 
         * This method is invoked after bindUI is invoked for the Widget class
170
 
         * using YUI's aop infrastructure.
171
 
         * </p>
172
 
         * @method _bindUIStack
173
 
         * @protected
174
 
         */
175
 
        _bindUIStack: function() {
176
 
            this.after(ShimChange, this._afterShimChange);
177
 
            this.after(ZIndexChange, this._afterZIndexChange);
178
 
        },
179
 
 
180
 
        /**
181
 
         * Creates/Initializes the DOM to support stackability.
182
 
         * <p>
183
 
         * This method in invoked after renderUI is invoked for the Widget class
184
 
         * using YUI's aop infrastructure.
185
 
         * </p>
186
 
         * @method _renderUIStack
187
 
         * @protected
188
 
         */
189
 
        _renderUIStack: function() {
190
 
            this._stackNode.addClass(Stack.STACKED_CLASS_NAME);
191
 
        },
192
 
 
193
 
        /**
194
 
         * Default setter for zIndex attribute changes. Normalizes zIndex values to
195
 
         * numbers, converting non-numerical values to 0.
196
 
         *
197
 
         * @method _setZIndex
198
 
         * @protected
199
 
         * @param {String | Number} zIndex
200
 
         * @return {Number} Normalized zIndex
201
 
         */
202
 
        _setZIndex: function(zIndex) {
203
 
            if (L.isString(zIndex)) {
204
 
                zIndex = parseInt(zIndex, 10);
205
 
            }
206
 
            if (!L.isNumber(zIndex)) {
207
 
                zIndex = 0;
208
 
            }
209
 
            return zIndex;
210
 
        },
211
 
 
212
 
        /**
213
 
         * Default attribute change listener for the shim attribute, responsible
214
 
         * for updating the UI, in response to attribute changes.
215
 
         *
216
 
         * @method _afterShimChange
217
 
         * @protected
218
 
         * @param {EventFacade} e The event facade for the attribute change
219
 
         */
220
 
        _afterShimChange : function(e) {
221
 
            this._uiSetShim(e.newVal);
222
 
        },
223
 
 
224
 
        /**
225
 
         * Default attribute change listener for the zIndex attribute, responsible
226
 
         * for updating the UI, in response to attribute changes.
227
 
         *
228
 
         * @method _afterZIndexChange
229
 
         * @protected
230
 
         * @param {EventFacade} e The event facade for the attribute change
231
 
         */
232
 
        _afterZIndexChange : function(e) {
233
 
            this._uiSetZIndex(e.newVal);
234
 
        },
235
 
 
236
 
        /**
237
 
         * Updates the UI to reflect the zIndex value passed in.
238
 
         *
239
 
         * @method _uiSetZIndex
240
 
         * @protected
241
 
         * @param {number} zIndex The zindex to be reflected in the UI
242
 
         */
243
 
        _uiSetZIndex: function (zIndex) {
244
 
            this._stackNode.setStyle(ZINDEX, zIndex);
245
 
        },
246
 
 
247
 
        /**
248
 
         * Updates the UI to enable/disable the shim. If the widget is not currently visible,
249
 
         * creation of the shim is deferred until it is made visible, for performance reasons.
250
 
         *
251
 
         * @method _uiSetShim
252
 
         * @protected
253
 
         * @param {boolean} enable If true, creates/renders the shim, if false, removes it.
254
 
         */
255
 
        _uiSetShim: function (enable) {
256
 
            if (enable) {
257
 
                // Lazy creation
258
 
                if (this.get(VISIBLE)) {
259
 
                    this._renderShim();
260
 
                } else {
261
 
                    this._renderShimDeferred();
262
 
                }
263
 
 
264
 
                // Eagerly attach resize handlers
265
 
                //
266
 
                // Required because of Event stack behavior, commit ref: cd8dddc
267
 
                // Should be revisted after Ticket #2531067 is resolved.
268
 
                if (UA.ie == 6) {
269
 
                    this._addShimResizeHandlers();
270
 
                }
271
 
            } else {
272
 
                this._destroyShim();
273
 
            }
274
 
        },
275
 
 
276
 
        /**
277
 
         * Sets up change handlers for the visible attribute, to defer shim creation/rendering
278
 
         * until the Widget is made visible.
279
 
         *
280
 
         * @method _renderShimDeferred
281
 
         * @private
282
 
         */
283
 
        _renderShimDeferred : function() {
284
 
 
285
 
            this._stackHandles[SHIM_DEFERRED] = this._stackHandles[SHIM_DEFERRED] || [];
286
 
 
287
 
            var handles = this._stackHandles[SHIM_DEFERRED],
288
 
                createBeforeVisible = function(e) {
289
 
                    if (e.newVal) {
290
 
                        this._renderShim();
291
 
                    }
292
 
                };
293
 
 
294
 
            handles.push(this.on(VisibleChange, createBeforeVisible));
295
 
            // Depending how how Ticket #2531067 is resolved, a reversal of
296
 
            // commit ref: cd8dddc could lead to a more elagent solution, with
297
 
            // the addition of this line here:
298
 
            //
299
 
            // handles.push(this.after(VisibleChange, this.sizeShim));
300
 
        },
301
 
 
302
 
        /**
303
 
         * Sets up event listeners to resize the shim when the size of the Widget changes.
304
 
         * <p>
305
 
         * NOTE: This method is only used for IE6 currently, since IE6 doesn't support a way to
306
 
         * resize the shim purely through CSS, when the Widget does not have an explicit width/height
307
 
         * set.
308
 
         * </p>
309
 
         * @method _addShimResizeHandlers
310
 
         * @private
311
 
         */
312
 
        _addShimResizeHandlers : function() {
313
 
 
314
 
            this._stackHandles[SHIM_RESIZE] = this._stackHandles[SHIM_RESIZE] || [];
315
 
 
316
 
            var sizeShim = this.sizeShim,
317
 
                handles = this._stackHandles[SHIM_RESIZE];
318
 
 
319
 
            handles.push(this.after(VisibleChange, sizeShim));
320
 
            handles.push(this.after(WidthChange, sizeShim));
321
 
            handles.push(this.after(HeightChange, sizeShim));
322
 
            handles.push(this.after(ContentUpdate, sizeShim));
323
 
        },
324
 
 
325
 
        /**
326
 
         * Detaches any handles stored for the provided key
327
 
         *
328
 
         * @method _detachStackHandles
329
 
         * @param String handleKey The key defining the group of handles which should be detached
330
 
         * @private
331
 
         */
332
 
        _detachStackHandles : function(handleKey) {
333
 
            var handles = this._stackHandles[handleKey],
334
 
                handle;
335
 
 
336
 
            if (handles && handles.length > 0) {
337
 
                while((handle = handles.pop())) {
338
 
                    handle.detach();
339
 
                }
340
 
            }
341
 
        },
342
 
 
343
 
        /**
344
 
         * Creates the shim element and adds it to the DOM
345
 
         *
346
 
         * @method _renderShim
347
 
         * @private
348
 
         */
349
 
        _renderShim : function() {
350
 
            var shimEl = this._shimNode,
351
 
                stackEl = this._stackNode;
352
 
 
353
 
            if (!shimEl) {
354
 
                shimEl = this._shimNode = this._getShimTemplate();
355
 
                stackEl.insertBefore(shimEl, stackEl.get(FIRST_CHILD));
356
 
 
357
 
                this._detachStackHandles(SHIM_DEFERRED);
358
 
                this.sizeShim();
359
 
            }
360
 
        },
361
 
 
362
 
        /**
363
 
         * Removes the shim from the DOM, and detaches any related event
364
 
         * listeners.
365
 
         *
366
 
         * @method _destroyShim
367
 
         * @private
368
 
         */
369
 
        _destroyShim : function() {
370
 
            if (this._shimNode) {
371
 
                this._shimNode.get(PARENT_NODE).removeChild(this._shimNode);
372
 
                this._shimNode = null;
373
 
 
374
 
                this._detachStackHandles(SHIM_DEFERRED);
375
 
                this._detachStackHandles(SHIM_RESIZE);
376
 
            }
377
 
        },
378
 
 
379
 
        /**
380
 
         * For IE6, synchronizes the size and position of iframe shim to that of
381
 
         * Widget bounding box which it is protecting. For all other browsers,
382
 
         * this method does not do anything.
383
 
         *
384
 
         * @method sizeShim
385
 
         */
386
 
        sizeShim: function () {
387
 
            var shim = this._shimNode,
388
 
                node = this._stackNode;
389
 
 
390
 
            if (shim && UA.ie === 6 && this.get(VISIBLE)) {
391
 
                shim.setStyle(WIDTH, node.get(OFFSET_WIDTH) + PX);
392
 
                shim.setStyle(HEIGHT, node.get(OFFSET_HEIGHT) + PX);
393
 
            }
394
 
        },
395
 
 
396
 
        /**
397
 
         * Creates a cloned shim node, using the SHIM_TEMPLATE html template, for use on a new instance.
398
 
         *
399
 
         * @method _getShimTemplate
400
 
         * @private
401
 
         * @return {Node} node A new shim Node instance.
402
 
         */
403
 
        _getShimTemplate : function() {
404
 
            return Node.create(Stack.SHIM_TEMPLATE, this._stackNode.get(OWNER_DOCUMENT));
405
 
        }
406
 
    };
407
 
 
408
 
    Y.WidgetStack = Stack;
409
 
 
410
 
 
411
 
}, '3.4.1' ,{requires:['base-build', 'widget']});