~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/slider-value-range/slider-value-range-debug.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('slider-value-range', function(Y) {
8
 
 
9
 
/**
10
 
 * Adds value support for Slider as a range of integers between a configured
11
 
 * minimum and maximum value.  For use with <code>Y.Base.build(..)</code> to
12
 
 * add the plumbing to <code>Y.SliderBase</code>.
13
 
 *
14
 
 * @module slider
15
 
 * @submodule slider-value-range
16
 
 */
17
 
 
18
 
// Constants for compression or performance
19
 
var MIN       = 'min',
20
 
    MAX       = 'max',
21
 
    VALUE     = 'value',
22
 
 
23
 
    round = Math.round;
24
 
 
25
 
/**
26
 
 * One class of value algorithm that can be built onto SliderBase.  By default,
27
 
 * values range between 0 and 100, but you can configure these on the
28
 
 * built Slider class by setting the <code>min</code> and <code>max</code>
29
 
 * configurations.  Set the initial value (will cause the thumb to move to the
30
 
 * appropriate location on the rail) in configuration as well if appropriate.
31
 
 *
32
 
 * @class SliderValueRange
33
 
 */
34
 
function SliderValueRange() {
35
 
    this._initSliderValueRange();
36
 
}
37
 
 
38
 
Y.SliderValueRange = Y.mix( SliderValueRange, {
39
 
 
40
 
    // Prototype properties and methods that will be added onto host class
41
 
    prototype: {
42
 
 
43
 
        /**
44
 
         * Factor used to translate value -&gt; position -&gt; value.
45
 
         *
46
 
         * @property _factor
47
 
         * @type {Number}
48
 
         * @protected
49
 
         */
50
 
        _factor: 1,
51
 
 
52
 
        /**
53
 
         * Stub for construction logic.  Override if extending this class and
54
 
         * you need to set something up during the initializer phase.
55
 
         *
56
 
         * @method _initSliderValueRange
57
 
         * @protected
58
 
         */
59
 
        _initSliderValueRange: function () {},
60
 
 
61
 
        /**
62
 
         * Override of stub method in SliderBase that is called at the end of
63
 
         * its bindUI stage of render().  Subscribes to internal events to
64
 
         * trigger UI and related state updates.
65
 
         *
66
 
         * @method _bindValueLogic
67
 
         * @protected
68
 
         */
69
 
        _bindValueLogic: function () {
70
 
            this.after( {
71
 
                minChange  : this._afterMinChange,
72
 
                maxChange  : this._afterMaxChange,
73
 
                valueChange: this._afterValueChange
74
 
            } );
75
 
        },
76
 
 
77
 
        /**
78
 
         * Move the thumb to appropriate position if necessary.  Also resets
79
 
         * the cached offsets and recalculates the conversion factor to
80
 
         * translate position to value.
81
 
         *
82
 
         * @method _syncThumbPosition
83
 
         * @protected
84
 
         */
85
 
        _syncThumbPosition: function () {
86
 
            this._calculateFactor();
87
 
 
88
 
            this._setPosition( this.get( VALUE ) );
89
 
        },
90
 
 
91
 
        /**
92
 
         * Calculates and caches
93
 
         * (range between max and min) / (rail length)
94
 
         * for fast runtime calculation of position -&gt; value.
95
 
         *
96
 
         * @method _calculateFactor
97
 
         * @protected
98
 
         */
99
 
        _calculateFactor: function () {
100
 
            var length    = this.get( 'length' ),
101
 
                thumbSize = this.thumb.getStyle( this._key.dim ),
102
 
                min       = this.get( MIN ),
103
 
                max       = this.get( MAX );
104
 
 
105
 
            // The default thumb width is based on Sam skin's thumb dimension.
106
 
            // This attempts to allow for rendering off-DOM, then attaching
107
 
            // without the need to call syncUI().  It is still recommended
108
 
            // to call syncUI() in these cases though, just to be sure.
109
 
            length = parseFloat( length ) || 150;
110
 
            thumbSize = parseFloat( thumbSize ) || 15;
111
 
 
112
 
            this._factor = ( max - min ) / ( length - thumbSize );
113
 
 
114
 
            Y.log("Calculating factor(~" + this._factor.toFixed(3) + " = (max(" + max + ") - min(" + min + ")) / (length(" + length + ") - thumb size(" + thumbSize + "))","info","slider");
115
 
        },
116
 
 
117
 
        /**
118
 
         * Dispatch the new position of the thumb into the value setting
119
 
         * operations.
120
 
         *
121
 
         * @method _defThumbMoveFn
122
 
         * @param e { EventFacade } The host's thumbMove event
123
 
         * @protected
124
 
         */
125
 
        _defThumbMoveFn: function ( e ) {
126
 
            var previous = this.get( VALUE ),
127
 
                value    = this._offsetToValue( e.offset );
128
 
 
129
 
            // This test avoids duplication of this.set(..) if the origin
130
 
            // of this thumbMove is from slider.set('value',x);
131
 
            // slider.set() -> afterValueChange -> uiMoveThumb ->
132
 
            // fire(thumbMove) -> _defThumbMoveFn -> this.set()
133
 
            if ( previous !== value ) {
134
 
                this.set( VALUE, value, { positioned: true } );
135
 
            }
136
 
        },
137
 
 
138
 
        /**
139
 
         * <p>Converts a pixel position into a value.  Calculates current
140
 
         * thumb offset from the leading edge of the rail multiplied by the
141
 
         * ratio of <code>(max - min) / (constraining dim)</code>.</p>
142
 
         *
143
 
         * <p>Override this if you want to use a different value mapping
144
 
         * algorithm.</p>
145
 
         *
146
 
         * @method _offsetToValue
147
 
         * @param offset { Number } X or Y pixel offset
148
 
         * @return { mixed } Value corresponding to the provided pixel offset
149
 
         * @protected
150
 
         */
151
 
        _offsetToValue: function ( offset ) {
152
 
 
153
 
            var value = round( offset * this._factor ) + this.get( MIN );
154
 
 
155
 
            Y.log("Offset: " + offset + " => Value: " + value, "info", "slider");
156
 
            return round( this._nearestValue( value ) );
157
 
        },
158
 
 
159
 
        /**
160
 
         * Converts a value into a pixel offset for use in positioning
161
 
         * the thumb according to the reverse of the
162
 
         * <code>_offsetToValue( xy )</code> operation.
163
 
         *
164
 
         * @method _valueToOffset
165
 
         * @param val { Number } The value to map to pixel X or Y position
166
 
         * @return { Number } The pixel offset 
167
 
         * @protected
168
 
         */
169
 
        _valueToOffset: function ( value ) {
170
 
            var offset = round( ( value - this.get( MIN ) ) / this._factor );
171
 
 
172
 
            Y.log("Value: " + value + " => Offset: " + offset, "info", "slider");
173
 
            return offset;
174
 
        },
175
 
 
176
 
        /**
177
 
         * Returns the current value.  Override this if you want to introduce
178
 
         * output formatting. Otherwise equivalent to slider.get( "value" );
179
 
         *
180
 
         * @method getValue
181
 
         * @return {Number}
182
 
         */
183
 
        getValue: function () {
184
 
            return this.get( VALUE );
185
 
        },
186
 
 
187
 
        /**
188
 
         * Updates the current value.  Override this if you want to introduce
189
 
         * input value parsing or preprocessing.  Otherwise equivalent to
190
 
         * slider.set( "value", v );
191
 
         *
192
 
         * @method setValue
193
 
         * @param val {Number} The new value
194
 
         * @return {Slider}
195
 
         * @chainable
196
 
         */
197
 
        setValue: function ( val ) {
198
 
            return this.set( VALUE, val );
199
 
        },
200
 
 
201
 
        /**
202
 
         * Update position according to new min value.  If the new min results
203
 
         * in the current value being out of range, the value is set to the
204
 
         * closer of min or max.
205
 
         *
206
 
         * @method _afterMinChange
207
 
         * @param e { EventFacade } The <code>min</code> attribute change event.
208
 
         * @protected
209
 
         */
210
 
        _afterMinChange: function ( e ) {
211
 
            this._verifyValue();
212
 
 
213
 
            this._syncThumbPosition();
214
 
        },
215
 
 
216
 
        /**
217
 
         * Update position according to new max value.  If the new max results
218
 
         * in the current value being out of range, the value is set to the
219
 
         * closer of min or max.
220
 
         *
221
 
         * @method _afterMaxChange
222
 
         * @param e { EventFacade } The <code>max</code> attribute change event.
223
 
         * @protected
224
 
         */
225
 
        _afterMaxChange: function ( e ) {
226
 
            this._verifyValue();
227
 
 
228
 
            this._syncThumbPosition();
229
 
        },
230
 
 
231
 
        /**
232
 
         * Verifies that the current value is within the min - max range.  If
233
 
         * not, value is set to either min or max, depending on which is
234
 
         * closer.
235
 
         *
236
 
         * @method _verifyValue
237
 
         * @protected
238
 
         */
239
 
        _verifyValue: function () {
240
 
            var value   = this.get( VALUE ),
241
 
                nearest = this._nearestValue( value );
242
 
 
243
 
            if ( value !== nearest ) {
244
 
                // @TODO Can/should valueChange, minChange, etc be queued
245
 
                // events? To make dd.set( 'min', n ); execute after minChange
246
 
                // subscribers before on/after valueChange subscribers.
247
 
                this.set( VALUE, nearest );
248
 
            }
249
 
        },
250
 
 
251
 
        /**
252
 
         * Propagate change to the thumb position unless the change originated
253
 
         * from the thumbMove event.
254
 
         *
255
 
         * @method _afterValueChange
256
 
         * @param e { EventFacade } The <code>valueChange</code> event.
257
 
         * @protected
258
 
         */
259
 
        _afterValueChange: function ( e ) {
260
 
            if ( !e.positioned ) {
261
 
                Y.log("Positioning thumb after set('value',x)","info","slider");
262
 
                this._setPosition( e.newVal );
263
 
            }
264
 
        },
265
 
 
266
 
        /**
267
 
         * Positions the thumb in accordance with the translated value.
268
 
         *
269
 
         * @method _setPosition
270
 
         * @protected
271
 
         */
272
 
        _setPosition: function ( value ) {
273
 
            this._uiMoveThumb( this._valueToOffset( value ) );
274
 
        },
275
 
 
276
 
        /**
277
 
         * Validates new values assigned to <code>min</code> attribute.  Numbers
278
 
         * are acceptable.  Override this to enforce different rules.
279
 
         *
280
 
         * @method _validateNewMin
281
 
         * @param value { mixed } Value assigned to <code>min</code> attribute.
282
 
         * @return { Boolean } True for numbers.  False otherwise.
283
 
         * @protected
284
 
         */
285
 
        _validateNewMin: function ( value ) {
286
 
            return Y.Lang.isNumber( value );
287
 
        },
288
 
 
289
 
        /**
290
 
         * Validates new values assigned to <code>max</code> attribute.  Numbers
291
 
         * are acceptable.  Override this to enforce different rules.
292
 
         *
293
 
         * @method _validateNewMax
294
 
         * @param value { mixed } Value assigned to <code>max</code> attribute.
295
 
         * @return { Boolean } True for numbers.  False otherwise.
296
 
         * @protected
297
 
         */
298
 
        _validateNewMax: function ( value ) {
299
 
            return Y.Lang.isNumber( value );
300
 
        },
301
 
 
302
 
        /**
303
 
         * Restricts new values assigned to <code>value</code> attribute to be
304
 
         * between the configured <code>min</code> and <code>max</code>.
305
 
         * Rounds to nearest integer value.
306
 
         *
307
 
         * @method _setNewValue
308
 
         * @param value { Number } Value assigned to <code>value</code> attribute
309
 
         * @return { Number } Normalized and constrained value
310
 
         * @protected
311
 
         */
312
 
        _setNewValue: function ( value ) {
313
 
            return round( this._nearestValue( value ) );
314
 
        },
315
 
 
316
 
        /**
317
 
         * Returns the nearest valid value to the value input.  If the provided
318
 
         * value is outside the min - max range, accounting for min > max
319
 
         * scenarios, the nearest of either min or max is returned.  Otherwise,
320
 
         * the provided value is returned.
321
 
         *
322
 
         * @method _nearestValue
323
 
         * @param value { mixed } Value to test against current min - max range
324
 
         * @return { Number } Current min, max, or value if within range
325
 
         * @protected
326
 
         */
327
 
        _nearestValue: function ( value ) {
328
 
            var min = this.get( MIN ),
329
 
                max = this.get( MAX ),
330
 
                tmp;
331
 
 
332
 
            // Account for reverse value range (min > max)
333
 
            tmp = ( max > min ) ? max : min;
334
 
            min = ( max > min ) ? min : max;
335
 
            max = tmp;
336
 
 
337
 
            return ( value < min ) ?
338
 
                    min :
339
 
                    ( value > max ) ?
340
 
                        max :
341
 
                        value;
342
 
        }
343
 
 
344
 
    },
345
 
 
346
 
    /**
347
 
     * Attributes that will be added onto host class.
348
 
     *
349
 
     * @property ATTRS
350
 
     * @type {Object}
351
 
     * @static
352
 
     * @protected
353
 
     */
354
 
    ATTRS: {
355
 
        /**
356
 
         * The value associated with the farthest top, left position of the
357
 
         * rail.  Can be greater than the configured <code>max</code> if you
358
 
         * want values to increase from right-to-left or bottom-to-top.
359
 
         *
360
 
         * @attribute min
361
 
         * @type { Number }
362
 
         * @default 0
363
 
         */
364
 
        min: {
365
 
            value    : 0,
366
 
            validator: '_validateNewMin'
367
 
        },
368
 
 
369
 
        /**
370
 
         * The value associated with the farthest bottom, right position of
371
 
         * the rail.  Can be less than the configured <code>min</code> if
372
 
         * you want values to increase from right-to-left or bottom-to-top.
373
 
         *
374
 
         * @attribute max
375
 
         * @type { Number }
376
 
         * @default 100
377
 
         */
378
 
        max: {
379
 
            value    : 100,
380
 
            validator: '_validateNewMax'
381
 
        },
382
 
 
383
 
        /**
384
 
         * The value associated with the thumb's current position on the
385
 
         * rail. Defaults to the value inferred from the thumb's current
386
 
         * position. Specifying value in the constructor will move the
387
 
         * thumb to the position that corresponds to the supplied value.
388
 
         *
389
 
         * @attribute value
390
 
         * @type { Number }
391
 
         * @default (inferred from current thumb position)
392
 
         */
393
 
        value: {
394
 
            value : 0,
395
 
            setter: '_setNewValue'
396
 
        }
397
 
    }
398
 
}, true );
399
 
 
400
 
 
401
 
}, '3.4.1' ,{requires:['slider-base']});