Projet

Général

Profil

Paste
Télécharger (16,8 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / libraries / flexslider-2.5.0 / bower_components / jquery / src / effects.js @ 0aee3c58

1
define([
2
        "./core",
3
        "./var/pnum",
4
        "./css/var/cssExpand",
5
        "./css/var/isHidden",
6
        "./css/defaultDisplay",
7
        "./effects/support",
8

    
9
        "./core/init",
10
        "./effects/Tween",
11
        "./queue",
12
        "./css",
13
        "./deferred",
14
        "./traversing"
15
], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, support ) {
16

    
17
var
18
        fxNow, timerId,
19
        rfxtypes = /^(?:toggle|show|hide)$/,
20
        rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
21
        rrun = /queueHooks$/,
22
        animationPrefilters = [ defaultPrefilter ],
23
        tweeners = {
24
                "*": [ function( prop, value ) {
25
                        var tween = this.createTween( prop, value ),
26
                                target = tween.cur(),
27
                                parts = rfxnum.exec( value ),
28
                                unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
29

    
30
                                // Starting value computation is required for potential unit mismatches
31
                                start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
32
                                        rfxnum.exec( jQuery.css( tween.elem, prop ) ),
33
                                scale = 1,
34
                                maxIterations = 20;
35

    
36
                        if ( start && start[ 3 ] !== unit ) {
37
                                // Trust units reported by jQuery.css
38
                                unit = unit || start[ 3 ];
39

    
40
                                // Make sure we update the tween properties later on
41
                                parts = parts || [];
42

    
43
                                // Iteratively approximate from a nonzero starting point
44
                                start = +target || 1;
45

    
46
                                do {
47
                                        // If previous iteration zeroed out, double until we get *something*
48
                                        // Use a string for doubling factor so we don't accidentally see scale as unchanged below
49
                                        scale = scale || ".5";
50

    
51
                                        // Adjust and apply
52
                                        start = start / scale;
53
                                        jQuery.style( tween.elem, prop, start + unit );
54

    
55
                                // Update scale, tolerating zero or NaN from tween.cur()
56
                                // And breaking the loop if scale is unchanged or perfect, or if we've just had enough
57
                                } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
58
                        }
59

    
60
                        // Update tween properties
61
                        if ( parts ) {
62
                                start = tween.start = +start || +target || 0;
63
                                tween.unit = unit;
64
                                // If a +=/-= token was provided, we're doing a relative animation
65
                                tween.end = parts[ 1 ] ?
66
                                        start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
67
                                        +parts[ 2 ];
68
                        }
69

    
70
                        return tween;
71
                } ]
72
        };
73

    
74
// Animations created synchronously will run synchronously
75
function createFxNow() {
76
        setTimeout(function() {
77
                fxNow = undefined;
78
        });
79
        return ( fxNow = jQuery.now() );
80
}
81

    
82
// Generate parameters to create a standard animation
83
function genFx( type, includeWidth ) {
84
        var which,
85
                attrs = { height: type },
86
                i = 0;
87

    
88
        // if we include width, step value is 1 to do all cssExpand values,
89
        // if we don't include width, step value is 2 to skip over Left and Right
90
        includeWidth = includeWidth ? 1 : 0;
91
        for ( ; i < 4 ; i += 2 - includeWidth ) {
92
                which = cssExpand[ i ];
93
                attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
94
        }
95

    
96
        if ( includeWidth ) {
97
                attrs.opacity = attrs.width = type;
98
        }
99

    
100
        return attrs;
101
}
102

    
103
function createTween( value, prop, animation ) {
104
        var tween,
105
                collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
106
                index = 0,
107
                length = collection.length;
108
        for ( ; index < length; index++ ) {
109
                if ( (tween = collection[ index ].call( animation, prop, value )) ) {
110

    
111
                        // we're done with this property
112
                        return tween;
113
                }
114
        }
115
}
116

    
117
function defaultPrefilter( elem, props, opts ) {
118
        /* jshint validthis: true */
119
        var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
120
                anim = this,
121
                orig = {},
122
                style = elem.style,
123
                hidden = elem.nodeType && isHidden( elem ),
124
                dataShow = jQuery._data( elem, "fxshow" );
125

    
126
        // handle queue: false promises
127
        if ( !opts.queue ) {
128
                hooks = jQuery._queueHooks( elem, "fx" );
129
                if ( hooks.unqueued == null ) {
130
                        hooks.unqueued = 0;
131
                        oldfire = hooks.empty.fire;
132
                        hooks.empty.fire = function() {
133
                                if ( !hooks.unqueued ) {
134
                                        oldfire();
135
                                }
136
                        };
137
                }
138
                hooks.unqueued++;
139

    
140
                anim.always(function() {
141
                        // doing this makes sure that the complete handler will be called
142
                        // before this completes
143
                        anim.always(function() {
144
                                hooks.unqueued--;
145
                                if ( !jQuery.queue( elem, "fx" ).length ) {
146
                                        hooks.empty.fire();
147
                                }
148
                        });
149
                });
150
        }
151

    
152
        // height/width overflow pass
153
        if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
154
                // Make sure that nothing sneaks out
155
                // Record all 3 overflow attributes because IE does not
156
                // change the overflow attribute when overflowX and
157
                // overflowY are set to the same value
158
                opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
159

    
160
                // Set display property to inline-block for height/width
161
                // animations on inline elements that are having width/height animated
162
                display = jQuery.css( elem, "display" );
163

    
164
                // Test default display if display is currently "none"
165
                checkDisplay = display === "none" ?
166
                        jQuery._data( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
167

    
168
                if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
169

    
170
                        // inline-level elements accept inline-block;
171
                        // block-level elements need to be inline with layout
172
                        if ( !support.inlineBlockNeedsLayout || defaultDisplay( elem.nodeName ) === "inline" ) {
173
                                style.display = "inline-block";
174
                        } else {
175
                                style.zoom = 1;
176
                        }
177
                }
178
        }
179

    
180
        if ( opts.overflow ) {
181
                style.overflow = "hidden";
182
                if ( !support.shrinkWrapBlocks() ) {
183
                        anim.always(function() {
184
                                style.overflow = opts.overflow[ 0 ];
185
                                style.overflowX = opts.overflow[ 1 ];
186
                                style.overflowY = opts.overflow[ 2 ];
187
                        });
188
                }
189
        }
190

    
191
        // show/hide pass
192
        for ( prop in props ) {
193
                value = props[ prop ];
194
                if ( rfxtypes.exec( value ) ) {
195
                        delete props[ prop ];
196
                        toggle = toggle || value === "toggle";
197
                        if ( value === ( hidden ? "hide" : "show" ) ) {
198

    
199
                                // If there is dataShow left over from a stopped hide or show and we are going to proceed with show, we should pretend to be hidden
200
                                if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
201
                                        hidden = true;
202
                                } else {
203
                                        continue;
204
                                }
205
                        }
206
                        orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
207

    
208
                // Any non-fx value stops us from restoring the original display value
209
                } else {
210
                        display = undefined;
211
                }
212
        }
213

    
214
        if ( !jQuery.isEmptyObject( orig ) ) {
215
                if ( dataShow ) {
216
                        if ( "hidden" in dataShow ) {
217
                                hidden = dataShow.hidden;
218
                        }
219
                } else {
220
                        dataShow = jQuery._data( elem, "fxshow", {} );
221
                }
222

    
223
                // store state if its toggle - enables .stop().toggle() to "reverse"
224
                if ( toggle ) {
225
                        dataShow.hidden = !hidden;
226
                }
227
                if ( hidden ) {
228
                        jQuery( elem ).show();
229
                } else {
230
                        anim.done(function() {
231
                                jQuery( elem ).hide();
232
                        });
233
                }
234
                anim.done(function() {
235
                        var prop;
236
                        jQuery._removeData( elem, "fxshow" );
237
                        for ( prop in orig ) {
238
                                jQuery.style( elem, prop, orig[ prop ] );
239
                        }
240
                });
241
                for ( prop in orig ) {
242
                        tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
243

    
244
                        if ( !( prop in dataShow ) ) {
245
                                dataShow[ prop ] = tween.start;
246
                                if ( hidden ) {
247
                                        tween.end = tween.start;
248
                                        tween.start = prop === "width" || prop === "height" ? 1 : 0;
249
                                }
250
                        }
251
                }
252

    
253
        // If this is a noop like .hide().hide(), restore an overwritten display value
254
        } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
255
                style.display = display;
256
        }
257
}
258

    
259
function propFilter( props, specialEasing ) {
260
        var index, name, easing, value, hooks;
261

    
262
        // camelCase, specialEasing and expand cssHook pass
263
        for ( index in props ) {
264
                name = jQuery.camelCase( index );
265
                easing = specialEasing[ name ];
266
                value = props[ index ];
267
                if ( jQuery.isArray( value ) ) {
268
                        easing = value[ 1 ];
269
                        value = props[ index ] = value[ 0 ];
270
                }
271

    
272
                if ( index !== name ) {
273
                        props[ name ] = value;
274
                        delete props[ index ];
275
                }
276

    
277
                hooks = jQuery.cssHooks[ name ];
278
                if ( hooks && "expand" in hooks ) {
279
                        value = hooks.expand( value );
280
                        delete props[ name ];
281

    
282
                        // not quite $.extend, this wont overwrite keys already present.
283
                        // also - reusing 'index' from above because we have the correct "name"
284
                        for ( index in value ) {
285
                                if ( !( index in props ) ) {
286
                                        props[ index ] = value[ index ];
287
                                        specialEasing[ index ] = easing;
288
                                }
289
                        }
290
                } else {
291
                        specialEasing[ name ] = easing;
292
                }
293
        }
294
}
295

    
296
function Animation( elem, properties, options ) {
297
        var result,
298
                stopped,
299
                index = 0,
300
                length = animationPrefilters.length,
301
                deferred = jQuery.Deferred().always( function() {
302
                        // don't match elem in the :animated selector
303
                        delete tick.elem;
304
                }),
305
                tick = function() {
306
                        if ( stopped ) {
307
                                return false;
308
                        }
309
                        var currentTime = fxNow || createFxNow(),
310
                                remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
311
                                // archaic crash bug won't allow us to use 1 - ( 0.5 || 0 ) (#12497)
312
                                temp = remaining / animation.duration || 0,
313
                                percent = 1 - temp,
314
                                index = 0,
315
                                length = animation.tweens.length;
316

    
317
                        for ( ; index < length ; index++ ) {
318
                                animation.tweens[ index ].run( percent );
319
                        }
320

    
321
                        deferred.notifyWith( elem, [ animation, percent, remaining ]);
322

    
323
                        if ( percent < 1 && length ) {
324
                                return remaining;
325
                        } else {
326
                                deferred.resolveWith( elem, [ animation ] );
327
                                return false;
328
                        }
329
                },
330
                animation = deferred.promise({
331
                        elem: elem,
332
                        props: jQuery.extend( {}, properties ),
333
                        opts: jQuery.extend( true, { specialEasing: {} }, options ),
334
                        originalProperties: properties,
335
                        originalOptions: options,
336
                        startTime: fxNow || createFxNow(),
337
                        duration: options.duration,
338
                        tweens: [],
339
                        createTween: function( prop, end ) {
340
                                var tween = jQuery.Tween( elem, animation.opts, prop, end,
341
                                                animation.opts.specialEasing[ prop ] || animation.opts.easing );
342
                                animation.tweens.push( tween );
343
                                return tween;
344
                        },
345
                        stop: function( gotoEnd ) {
346
                                var index = 0,
347
                                        // if we are going to the end, we want to run all the tweens
348
                                        // otherwise we skip this part
349
                                        length = gotoEnd ? animation.tweens.length : 0;
350
                                if ( stopped ) {
351
                                        return this;
352
                                }
353
                                stopped = true;
354
                                for ( ; index < length ; index++ ) {
355
                                        animation.tweens[ index ].run( 1 );
356
                                }
357

    
358
                                // resolve when we played the last frame
359
                                // otherwise, reject
360
                                if ( gotoEnd ) {
361
                                        deferred.resolveWith( elem, [ animation, gotoEnd ] );
362
                                } else {
363
                                        deferred.rejectWith( elem, [ animation, gotoEnd ] );
364
                                }
365
                                return this;
366
                        }
367
                }),
368
                props = animation.props;
369

    
370
        propFilter( props, animation.opts.specialEasing );
371

    
372
        for ( ; index < length ; index++ ) {
373
                result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
374
                if ( result ) {
375
                        return result;
376
                }
377
        }
378

    
379
        jQuery.map( props, createTween, animation );
380

    
381
        if ( jQuery.isFunction( animation.opts.start ) ) {
382
                animation.opts.start.call( elem, animation );
383
        }
384

    
385
        jQuery.fx.timer(
386
                jQuery.extend( tick, {
387
                        elem: elem,
388
                        anim: animation,
389
                        queue: animation.opts.queue
390
                })
391
        );
392

    
393
        // attach callbacks from options
394
        return animation.progress( animation.opts.progress )
395
                .done( animation.opts.done, animation.opts.complete )
396
                .fail( animation.opts.fail )
397
                .always( animation.opts.always );
398
}
399

    
400
jQuery.Animation = jQuery.extend( Animation, {
401
        tweener: function( props, callback ) {
402
                if ( jQuery.isFunction( props ) ) {
403
                        callback = props;
404
                        props = [ "*" ];
405
                } else {
406
                        props = props.split(" ");
407
                }
408

    
409
                var prop,
410
                        index = 0,
411
                        length = props.length;
412

    
413
                for ( ; index < length ; index++ ) {
414
                        prop = props[ index ];
415
                        tweeners[ prop ] = tweeners[ prop ] || [];
416
                        tweeners[ prop ].unshift( callback );
417
                }
418
        },
419

    
420
        prefilter: function( callback, prepend ) {
421
                if ( prepend ) {
422
                        animationPrefilters.unshift( callback );
423
                } else {
424
                        animationPrefilters.push( callback );
425
                }
426
        }
427
});
428

    
429
jQuery.speed = function( speed, easing, fn ) {
430
        var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
431
                complete: fn || !fn && easing ||
432
                        jQuery.isFunction( speed ) && speed,
433
                duration: speed,
434
                easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
435
        };
436

    
437
        opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
438
                opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
439

    
440
        // normalize opt.queue - true/undefined/null -> "fx"
441
        if ( opt.queue == null || opt.queue === true ) {
442
                opt.queue = "fx";
443
        }
444

    
445
        // Queueing
446
        opt.old = opt.complete;
447

    
448
        opt.complete = function() {
449
                if ( jQuery.isFunction( opt.old ) ) {
450
                        opt.old.call( this );
451
                }
452

    
453
                if ( opt.queue ) {
454
                        jQuery.dequeue( this, opt.queue );
455
                }
456
        };
457

    
458
        return opt;
459
};
460

    
461
jQuery.fn.extend({
462
        fadeTo: function( speed, to, easing, callback ) {
463

    
464
                // show any hidden elements after setting opacity to 0
465
                return this.filter( isHidden ).css( "opacity", 0 ).show()
466

    
467
                        // animate to the value specified
468
                        .end().animate({ opacity: to }, speed, easing, callback );
469
        },
470
        animate: function( prop, speed, easing, callback ) {
471
                var empty = jQuery.isEmptyObject( prop ),
472
                        optall = jQuery.speed( speed, easing, callback ),
473
                        doAnimation = function() {
474
                                // Operate on a copy of prop so per-property easing won't be lost
475
                                var anim = Animation( this, jQuery.extend( {}, prop ), optall );
476

    
477
                                // Empty animations, or finishing resolves immediately
478
                                if ( empty || jQuery._data( this, "finish" ) ) {
479
                                        anim.stop( true );
480
                                }
481
                        };
482
                        doAnimation.finish = doAnimation;
483

    
484
                return empty || optall.queue === false ?
485
                        this.each( doAnimation ) :
486
                        this.queue( optall.queue, doAnimation );
487
        },
488
        stop: function( type, clearQueue, gotoEnd ) {
489
                var stopQueue = function( hooks ) {
490
                        var stop = hooks.stop;
491
                        delete hooks.stop;
492
                        stop( gotoEnd );
493
                };
494

    
495
                if ( typeof type !== "string" ) {
496
                        gotoEnd = clearQueue;
497
                        clearQueue = type;
498
                        type = undefined;
499
                }
500
                if ( clearQueue && type !== false ) {
501
                        this.queue( type || "fx", [] );
502
                }
503

    
504
                return this.each(function() {
505
                        var dequeue = true,
506
                                index = type != null && type + "queueHooks",
507
                                timers = jQuery.timers,
508
                                data = jQuery._data( this );
509

    
510
                        if ( index ) {
511
                                if ( data[ index ] && data[ index ].stop ) {
512
                                        stopQueue( data[ index ] );
513
                                }
514
                        } else {
515
                                for ( index in data ) {
516
                                        if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
517
                                                stopQueue( data[ index ] );
518
                                        }
519
                                }
520
                        }
521

    
522
                        for ( index = timers.length; index--; ) {
523
                                if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
524
                                        timers[ index ].anim.stop( gotoEnd );
525
                                        dequeue = false;
526
                                        timers.splice( index, 1 );
527
                                }
528
                        }
529

    
530
                        // start the next in the queue if the last step wasn't forced
531
                        // timers currently will call their complete callbacks, which will dequeue
532
                        // but only if they were gotoEnd
533
                        if ( dequeue || !gotoEnd ) {
534
                                jQuery.dequeue( this, type );
535
                        }
536
                });
537
        },
538
        finish: function( type ) {
539
                if ( type !== false ) {
540
                        type = type || "fx";
541
                }
542
                return this.each(function() {
543
                        var index,
544
                                data = jQuery._data( this ),
545
                                queue = data[ type + "queue" ],
546
                                hooks = data[ type + "queueHooks" ],
547
                                timers = jQuery.timers,
548
                                length = queue ? queue.length : 0;
549

    
550
                        // enable finishing flag on private data
551
                        data.finish = true;
552

    
553
                        // empty the queue first
554
                        jQuery.queue( this, type, [] );
555

    
556
                        if ( hooks && hooks.stop ) {
557
                                hooks.stop.call( this, true );
558
                        }
559

    
560
                        // look for any active animations, and finish them
561
                        for ( index = timers.length; index--; ) {
562
                                if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
563
                                        timers[ index ].anim.stop( true );
564
                                        timers.splice( index, 1 );
565
                                }
566
                        }
567

    
568
                        // look for any animations in the old queue and finish them
569
                        for ( index = 0; index < length; index++ ) {
570
                                if ( queue[ index ] && queue[ index ].finish ) {
571
                                        queue[ index ].finish.call( this );
572
                                }
573
                        }
574

    
575
                        // turn off finishing flag
576
                        delete data.finish;
577
                });
578
        }
579
});
580

    
581
jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
582
        var cssFn = jQuery.fn[ name ];
583
        jQuery.fn[ name ] = function( speed, easing, callback ) {
584
                return speed == null || typeof speed === "boolean" ?
585
                        cssFn.apply( this, arguments ) :
586
                        this.animate( genFx( name, true ), speed, easing, callback );
587
        };
588
});
589

    
590
// Generate shortcuts for custom animations
591
jQuery.each({
592
        slideDown: genFx("show"),
593
        slideUp: genFx("hide"),
594
        slideToggle: genFx("toggle"),
595
        fadeIn: { opacity: "show" },
596
        fadeOut: { opacity: "hide" },
597
        fadeToggle: { opacity: "toggle" }
598
}, function( name, props ) {
599
        jQuery.fn[ name ] = function( speed, easing, callback ) {
600
                return this.animate( props, speed, easing, callback );
601
        };
602
});
603

    
604
jQuery.timers = [];
605
jQuery.fx.tick = function() {
606
        var timer,
607
                timers = jQuery.timers,
608
                i = 0;
609

    
610
        fxNow = jQuery.now();
611

    
612
        for ( ; i < timers.length; i++ ) {
613
                timer = timers[ i ];
614
                // Checks the timer has not already been removed
615
                if ( !timer() && timers[ i ] === timer ) {
616
                        timers.splice( i--, 1 );
617
                }
618
        }
619

    
620
        if ( !timers.length ) {
621
                jQuery.fx.stop();
622
        }
623
        fxNow = undefined;
624
};
625

    
626
jQuery.fx.timer = function( timer ) {
627
        jQuery.timers.push( timer );
628
        if ( timer() ) {
629
                jQuery.fx.start();
630
        } else {
631
                jQuery.timers.pop();
632
        }
633
};
634

    
635
jQuery.fx.interval = 13;
636

    
637
jQuery.fx.start = function() {
638
        if ( !timerId ) {
639
                timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
640
        }
641
};
642

    
643
jQuery.fx.stop = function() {
644
        clearInterval( timerId );
645
        timerId = null;
646
};
647

    
648
jQuery.fx.speeds = {
649
        slow: 600,
650
        fast: 200,
651
        // Default speed
652
        _default: 400
653
};
654

    
655
return jQuery;
656
});