286
Sf
simple-flask-coffee-sass-boilerplate / files
simple-flask-coffee-sass-boilerplate / bower_components / jquery / src / effects.js
16.6 KB
1define([ 2 "./core", 3 "./var/pnum", 4 "./css/var/cssExpand", 5 "./css/var/isHidden", 6 "./css/defaultDisplay", 7 "./data/var/data_priv", 8 9 "./core/init", 10 "./effects/Tween", 11 "./queue", 12 "./css", 13 "./deferred", 14 "./traversing" 15], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, data_priv ) { 16 17var 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 75function createFxNow() { 76 setTimeout(function() { 77 fxNow = undefined; 78 }); 79 return ( fxNow = jQuery.now() ); 80} 81 82// Generate parameters to create a standard animation 83function genFx( type, includeWidth ) { 84 var which, 85 i = 0, 86 attrs = { height: type }; 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 103function 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 117function 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 = data_priv.get( 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 IE9-10 do 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 data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display; 167 168 if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) { 169 style.display = "inline-block"; 170 } 171 } 172 173 if ( opts.overflow ) { 174 style.overflow = "hidden"; 175 anim.always(function() { 176 style.overflow = opts.overflow[ 0 ]; 177 style.overflowX = opts.overflow[ 1 ]; 178 style.overflowY = opts.overflow[ 2 ]; 179 }); 180 } 181 182 // show/hide pass 183 for ( prop in props ) { 184 value = props[ prop ]; 185 if ( rfxtypes.exec( value ) ) { 186 delete props[ prop ]; 187 toggle = toggle || value === "toggle"; 188 if ( value === ( hidden ? "hide" : "show" ) ) { 189 190 // 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 191 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) { 192 hidden = true; 193 } else { 194 continue; 195 } 196 } 197 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop ); 198 199 // Any non-fx value stops us from restoring the original display value 200 } else { 201 display = undefined; 202 } 203 } 204 205 if ( !jQuery.isEmptyObject( orig ) ) { 206 if ( dataShow ) { 207 if ( "hidden" in dataShow ) { 208 hidden = dataShow.hidden; 209 } 210 } else { 211 dataShow = data_priv.access( elem, "fxshow", {} ); 212 } 213 214 // store state if its toggle - enables .stop().toggle() to "reverse" 215 if ( toggle ) { 216 dataShow.hidden = !hidden; 217 } 218 if ( hidden ) { 219 jQuery( elem ).show(); 220 } else { 221 anim.done(function() { 222 jQuery( elem ).hide(); 223 }); 224 } 225 anim.done(function() { 226 var prop; 227 228 data_priv.remove( elem, "fxshow" ); 229 for ( prop in orig ) { 230 jQuery.style( elem, prop, orig[ prop ] ); 231 } 232 }); 233 for ( prop in orig ) { 234 tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim ); 235 236 if ( !( prop in dataShow ) ) { 237 dataShow[ prop ] = tween.start; 238 if ( hidden ) { 239 tween.end = tween.start; 240 tween.start = prop === "width" || prop === "height" ? 1 : 0; 241 } 242 } 243 } 244 245 // If this is a noop like .hide().hide(), restore an overwritten display value 246 } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) { 247 style.display = display; 248 } 249} 250 251function propFilter( props, specialEasing ) { 252 var index, name, easing, value, hooks; 253 254 // camelCase, specialEasing and expand cssHook pass 255 for ( index in props ) { 256 name = jQuery.camelCase( index ); 257 easing = specialEasing[ name ]; 258 value = props[ index ]; 259 if ( jQuery.isArray( value ) ) { 260 easing = value[ 1 ]; 261 value = props[ index ] = value[ 0 ]; 262 } 263 264 if ( index !== name ) { 265 props[ name ] = value; 266 delete props[ index ]; 267 } 268 269 hooks = jQuery.cssHooks[ name ]; 270 if ( hooks && "expand" in hooks ) { 271 value = hooks.expand( value ); 272 delete props[ name ]; 273 274 // not quite $.extend, this wont overwrite keys already present. 275 // also - reusing 'index' from above because we have the correct "name" 276 for ( index in value ) { 277 if ( !( index in props ) ) { 278 props[ index ] = value[ index ]; 279 specialEasing[ index ] = easing; 280 } 281 } 282 } else { 283 specialEasing[ name ] = easing; 284 } 285 } 286} 287 288function Animation( elem, properties, options ) { 289 var result, 290 stopped, 291 index = 0, 292 length = animationPrefilters.length, 293 deferred = jQuery.Deferred().always( function() { 294 // don't match elem in the :animated selector 295 delete tick.elem; 296 }), 297 tick = function() { 298 if ( stopped ) { 299 return false; 300 } 301 var currentTime = fxNow || createFxNow(), 302 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ), 303 // archaic crash bug won't allow us to use 1 - ( 0.5 || 0 ) (#12497) 304 temp = remaining / animation.duration || 0, 305 percent = 1 - temp, 306 index = 0, 307 length = animation.tweens.length; 308 309 for ( ; index < length ; index++ ) { 310 animation.tweens[ index ].run( percent ); 311 } 312 313 deferred.notifyWith( elem, [ animation, percent, remaining ]); 314 315 if ( percent < 1 && length ) { 316 return remaining; 317 } else { 318 deferred.resolveWith( elem, [ animation ] ); 319 return false; 320 } 321 }, 322 animation = deferred.promise({ 323 elem: elem, 324 props: jQuery.extend( {}, properties ), 325 opts: jQuery.extend( true, { specialEasing: {} }, options ), 326 originalProperties: properties, 327 originalOptions: options, 328 startTime: fxNow || createFxNow(), 329 duration: options.duration, 330 tweens: [], 331 createTween: function( prop, end ) { 332 var tween = jQuery.Tween( elem, animation.opts, prop, end, 333 animation.opts.specialEasing[ prop ] || animation.opts.easing ); 334 animation.tweens.push( tween ); 335 return tween; 336 }, 337 stop: function( gotoEnd ) { 338 var index = 0, 339 // if we are going to the end, we want to run all the tweens 340 // otherwise we skip this part 341 length = gotoEnd ? animation.tweens.length : 0; 342 if ( stopped ) { 343 return this; 344 } 345 stopped = true; 346 for ( ; index < length ; index++ ) { 347 animation.tweens[ index ].run( 1 ); 348 } 349 350 // resolve when we played the last frame 351 // otherwise, reject 352 if ( gotoEnd ) { 353 deferred.resolveWith( elem, [ animation, gotoEnd ] ); 354 } else { 355 deferred.rejectWith( elem, [ animation, gotoEnd ] ); 356 } 357 return this; 358 } 359 }), 360 props = animation.props; 361 362 propFilter( props, animation.opts.specialEasing ); 363 364 for ( ; index < length ; index++ ) { 365 result = animationPrefilters[ index ].call( animation, elem, props, animation.opts ); 366 if ( result ) { 367 return result; 368 } 369 } 370 371 jQuery.map( props, createTween, animation ); 372 373 if ( jQuery.isFunction( animation.opts.start ) ) { 374 animation.opts.start.call( elem, animation ); 375 } 376 377 jQuery.fx.timer( 378 jQuery.extend( tick, { 379 elem: elem, 380 anim: animation, 381 queue: animation.opts.queue 382 }) 383 ); 384 385 // attach callbacks from options 386 return animation.progress( animation.opts.progress ) 387 .done( animation.opts.done, animation.opts.complete ) 388 .fail( animation.opts.fail ) 389 .always( animation.opts.always ); 390} 391 392jQuery.Animation = jQuery.extend( Animation, { 393 394 tweener: function( props, callback ) { 395 if ( jQuery.isFunction( props ) ) { 396 callback = props; 397 props = [ "*" ]; 398 } else { 399 props = props.split(" "); 400 } 401 402 var prop, 403 index = 0, 404 length = props.length; 405 406 for ( ; index < length ; index++ ) { 407 prop = props[ index ]; 408 tweeners[ prop ] = tweeners[ prop ] || []; 409 tweeners[ prop ].unshift( callback ); 410 } 411 }, 412 413 prefilter: function( callback, prepend ) { 414 if ( prepend ) { 415 animationPrefilters.unshift( callback ); 416 } else { 417 animationPrefilters.push( callback ); 418 } 419 } 420}); 421 422jQuery.speed = function( speed, easing, fn ) { 423 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : { 424 complete: fn || !fn && easing || 425 jQuery.isFunction( speed ) && speed, 426 duration: speed, 427 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing 428 }; 429 430 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration : 431 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default; 432 433 // normalize opt.queue - true/undefined/null -> "fx" 434 if ( opt.queue == null || opt.queue === true ) { 435 opt.queue = "fx"; 436 } 437 438 // Queueing 439 opt.old = opt.complete; 440 441 opt.complete = function() { 442 if ( jQuery.isFunction( opt.old ) ) { 443 opt.old.call( this ); 444 } 445 446 if ( opt.queue ) { 447 jQuery.dequeue( this, opt.queue ); 448 } 449 }; 450 451 return opt; 452}; 453 454jQuery.fn.extend({ 455 fadeTo: function( speed, to, easing, callback ) { 456 457 // show any hidden elements after setting opacity to 0 458 return this.filter( isHidden ).css( "opacity", 0 ).show() 459 460 // animate to the value specified 461 .end().animate({ opacity: to }, speed, easing, callback ); 462 }, 463 animate: function( prop, speed, easing, callback ) { 464 var empty = jQuery.isEmptyObject( prop ), 465 optall = jQuery.speed( speed, easing, callback ), 466 doAnimation = function() { 467 // Operate on a copy of prop so per-property easing won't be lost 468 var anim = Animation( this, jQuery.extend( {}, prop ), optall ); 469 470 // Empty animations, or finishing resolves immediately 471 if ( empty || data_priv.get( this, "finish" ) ) { 472 anim.stop( true ); 473 } 474 }; 475 doAnimation.finish = doAnimation; 476 477 return empty || optall.queue === false ? 478 this.each( doAnimation ) : 479 this.queue( optall.queue, doAnimation ); 480 }, 481 stop: function( type, clearQueue, gotoEnd ) { 482 var stopQueue = function( hooks ) { 483 var stop = hooks.stop; 484 delete hooks.stop; 485 stop( gotoEnd ); 486 }; 487 488 if ( typeof type !== "string" ) { 489 gotoEnd = clearQueue; 490 clearQueue = type; 491 type = undefined; 492 } 493 if ( clearQueue && type !== false ) { 494 this.queue( type || "fx", [] ); 495 } 496 497 return this.each(function() { 498 var dequeue = true, 499 index = type != null && type + "queueHooks", 500 timers = jQuery.timers, 501 data = data_priv.get( this ); 502 503 if ( index ) { 504 if ( data[ index ] && data[ index ].stop ) { 505 stopQueue( data[ index ] ); 506 } 507 } else { 508 for ( index in data ) { 509 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) { 510 stopQueue( data[ index ] ); 511 } 512 } 513 } 514 515 for ( index = timers.length; index--; ) { 516 if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) { 517 timers[ index ].anim.stop( gotoEnd ); 518 dequeue = false; 519 timers.splice( index, 1 ); 520 } 521 } 522 523 // start the next in the queue if the last step wasn't forced 524 // timers currently will call their complete callbacks, which will dequeue 525 // but only if they were gotoEnd 526 if ( dequeue || !gotoEnd ) { 527 jQuery.dequeue( this, type ); 528 } 529 }); 530 }, 531 finish: function( type ) { 532 if ( type !== false ) { 533 type = type || "fx"; 534 } 535 return this.each(function() { 536 var index, 537 data = data_priv.get( this ), 538 queue = data[ type + "queue" ], 539 hooks = data[ type + "queueHooks" ], 540 timers = jQuery.timers, 541 length = queue ? queue.length : 0; 542 543 // enable finishing flag on private data 544 data.finish = true; 545 546 // empty the queue first 547 jQuery.queue( this, type, [] ); 548 549 if ( hooks && hooks.stop ) { 550 hooks.stop.call( this, true ); 551 } 552 553 // look for any active animations, and finish them 554 for ( index = timers.length; index--; ) { 555 if ( timers[ index ].elem === this && timers[ index ].queue === type ) { 556 timers[ index ].anim.stop( true ); 557 timers.splice( index, 1 ); 558 } 559 } 560 561 // look for any animations in the old queue and finish them 562 for ( index = 0; index < length; index++ ) { 563 if ( queue[ index ] && queue[ index ].finish ) { 564 queue[ index ].finish.call( this ); 565 } 566 } 567 568 // turn off finishing flag 569 delete data.finish; 570 }); 571 } 572}); 573 574jQuery.each([ "toggle", "show", "hide" ], function( i, name ) { 575 var cssFn = jQuery.fn[ name ]; 576 jQuery.fn[ name ] = function( speed, easing, callback ) { 577 return speed == null || typeof speed === "boolean" ? 578 cssFn.apply( this, arguments ) : 579 this.animate( genFx( name, true ), speed, easing, callback ); 580 }; 581}); 582 583// Generate shortcuts for custom animations 584jQuery.each({ 585 slideDown: genFx("show"), 586 slideUp: genFx("hide"), 587 slideToggle: genFx("toggle"), 588 fadeIn: { opacity: "show" }, 589 fadeOut: { opacity: "hide" }, 590 fadeToggle: { opacity: "toggle" } 591}, function( name, props ) { 592 jQuery.fn[ name ] = function( speed, easing, callback ) { 593 return this.animate( props, speed, easing, callback ); 594 }; 595}); 596 597jQuery.timers = []; 598jQuery.fx.tick = function() { 599 var timer, 600 i = 0, 601 timers = jQuery.timers; 602 603 fxNow = jQuery.now(); 604 605 for ( ; i < timers.length; i++ ) { 606 timer = timers[ i ]; 607 // Checks the timer has not already been removed 608 if ( !timer() && timers[ i ] === timer ) { 609 timers.splice( i--, 1 ); 610 } 611 } 612 613 if ( !timers.length ) { 614 jQuery.fx.stop(); 615 } 616 fxNow = undefined; 617}; 618 619jQuery.fx.timer = function( timer ) { 620 jQuery.timers.push( timer ); 621 if ( timer() ) { 622 jQuery.fx.start(); 623 } else { 624 jQuery.timers.pop(); 625 } 626}; 627 628jQuery.fx.interval = 13; 629 630jQuery.fx.start = function() { 631 if ( !timerId ) { 632 timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval ); 633 } 634}; 635 636jQuery.fx.stop = function() { 637 clearInterval( timerId ); 638 timerId = null; 639}; 640 641jQuery.fx.speeds = { 642 slow: 600, 643 fast: 200, 644 // Default speed 645 _default: 400 646}; 647 648return jQuery; 649});