Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

effects.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. define( [
  2. "./core",
  3. "./core/camelCase",
  4. "./var/document",
  5. "./var/isFunction",
  6. "./var/rcssNum",
  7. "./var/rnothtmlwhite",
  8. "./css/var/cssExpand",
  9. "./css/var/isHiddenWithinTree",
  10. "./css/var/swap",
  11. "./css/adjustCSS",
  12. "./data/var/dataPriv",
  13. "./css/showHide",
  14. "./core/init",
  15. "./queue",
  16. "./deferred",
  17. "./traversing",
  18. "./manipulation",
  19. "./css",
  20. "./effects/Tween"
  21. ], function( jQuery, camelCase, document, isFunction, rcssNum, rnothtmlwhite, cssExpand,
  22. isHiddenWithinTree, swap, adjustCSS, dataPriv, showHide ) {
  23. "use strict";
  24. var
  25. fxNow, inProgress,
  26. rfxtypes = /^(?:toggle|show|hide)$/,
  27. rrun = /queueHooks$/;
  28. function schedule() {
  29. if ( inProgress ) {
  30. if ( document.hidden === false && window.requestAnimationFrame ) {
  31. window.requestAnimationFrame( schedule );
  32. } else {
  33. window.setTimeout( schedule, jQuery.fx.interval );
  34. }
  35. jQuery.fx.tick();
  36. }
  37. }
  38. // Animations created synchronously will run synchronously
  39. function createFxNow() {
  40. window.setTimeout( function() {
  41. fxNow = undefined;
  42. } );
  43. return ( fxNow = Date.now() );
  44. }
  45. // Generate parameters to create a standard animation
  46. function genFx( type, includeWidth ) {
  47. var which,
  48. i = 0,
  49. attrs = { height: type };
  50. // If we include width, step value is 1 to do all cssExpand values,
  51. // otherwise step value is 2 to skip over Left and Right
  52. includeWidth = includeWidth ? 1 : 0;
  53. for ( ; i < 4; i += 2 - includeWidth ) {
  54. which = cssExpand[ i ];
  55. attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
  56. }
  57. if ( includeWidth ) {
  58. attrs.opacity = attrs.width = type;
  59. }
  60. return attrs;
  61. }
  62. function createTween( value, prop, animation ) {
  63. var tween,
  64. collection = ( Animation.tweeners[ prop ] || [] ).concat( Animation.tweeners[ "*" ] ),
  65. index = 0,
  66. length = collection.length;
  67. for ( ; index < length; index++ ) {
  68. if ( ( tween = collection[ index ].call( animation, prop, value ) ) ) {
  69. // We're done with this property
  70. return tween;
  71. }
  72. }
  73. }
  74. function defaultPrefilter( elem, props, opts ) {
  75. var prop, value, toggle, hooks, oldfire, propTween, restoreDisplay, display,
  76. isBox = "width" in props || "height" in props,
  77. anim = this,
  78. orig = {},
  79. style = elem.style,
  80. hidden = elem.nodeType && isHiddenWithinTree( elem ),
  81. dataShow = dataPriv.get( elem, "fxshow" );
  82. // Queue-skipping animations hijack the fx hooks
  83. if ( !opts.queue ) {
  84. hooks = jQuery._queueHooks( elem, "fx" );
  85. if ( hooks.unqueued == null ) {
  86. hooks.unqueued = 0;
  87. oldfire = hooks.empty.fire;
  88. hooks.empty.fire = function() {
  89. if ( !hooks.unqueued ) {
  90. oldfire();
  91. }
  92. };
  93. }
  94. hooks.unqueued++;
  95. anim.always( function() {
  96. // Ensure the complete handler is called before this completes
  97. anim.always( function() {
  98. hooks.unqueued--;
  99. if ( !jQuery.queue( elem, "fx" ).length ) {
  100. hooks.empty.fire();
  101. }
  102. } );
  103. } );
  104. }
  105. // Detect show/hide animations
  106. for ( prop in props ) {
  107. value = props[ prop ];
  108. if ( rfxtypes.test( value ) ) {
  109. delete props[ prop ];
  110. toggle = toggle || value === "toggle";
  111. if ( value === ( hidden ? "hide" : "show" ) ) {
  112. // Pretend to be hidden if this is a "show" and
  113. // there is still data from a stopped show/hide
  114. if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
  115. hidden = true;
  116. // Ignore all other no-op show/hide data
  117. } else {
  118. continue;
  119. }
  120. }
  121. orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
  122. }
  123. }
  124. // Bail out if this is a no-op like .hide().hide()
  125. propTween = !jQuery.isEmptyObject( props );
  126. if ( !propTween && jQuery.isEmptyObject( orig ) ) {
  127. return;
  128. }
  129. // Restrict "overflow" and "display" styles during box animations
  130. if ( isBox && elem.nodeType === 1 ) {
  131. // Support: IE <=9 - 11, Edge 12 - 15
  132. // Record all 3 overflow attributes because IE does not infer the shorthand
  133. // from identically-valued overflowX and overflowY and Edge just mirrors
  134. // the overflowX value there.
  135. opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
  136. // Identify a display type, preferring old show/hide data over the CSS cascade
  137. restoreDisplay = dataShow && dataShow.display;
  138. if ( restoreDisplay == null ) {
  139. restoreDisplay = dataPriv.get( elem, "display" );
  140. }
  141. display = jQuery.css( elem, "display" );
  142. if ( display === "none" ) {
  143. if ( restoreDisplay ) {
  144. display = restoreDisplay;
  145. } else {
  146. // Get nonempty value(s) by temporarily forcing visibility
  147. showHide( [ elem ], true );
  148. restoreDisplay = elem.style.display || restoreDisplay;
  149. display = jQuery.css( elem, "display" );
  150. showHide( [ elem ] );
  151. }
  152. }
  153. // Animate inline elements as inline-block
  154. if ( display === "inline" || display === "inline-block" && restoreDisplay != null ) {
  155. if ( jQuery.css( elem, "float" ) === "none" ) {
  156. // Restore the original display value at the end of pure show/hide animations
  157. if ( !propTween ) {
  158. anim.done( function() {
  159. style.display = restoreDisplay;
  160. } );
  161. if ( restoreDisplay == null ) {
  162. display = style.display;
  163. restoreDisplay = display === "none" ? "" : display;
  164. }
  165. }
  166. style.display = "inline-block";
  167. }
  168. }
  169. }
  170. if ( opts.overflow ) {
  171. style.overflow = "hidden";
  172. anim.always( function() {
  173. style.overflow = opts.overflow[ 0 ];
  174. style.overflowX = opts.overflow[ 1 ];
  175. style.overflowY = opts.overflow[ 2 ];
  176. } );
  177. }
  178. // Implement show/hide animations
  179. propTween = false;
  180. for ( prop in orig ) {
  181. // General show/hide setup for this element animation
  182. if ( !propTween ) {
  183. if ( dataShow ) {
  184. if ( "hidden" in dataShow ) {
  185. hidden = dataShow.hidden;
  186. }
  187. } else {
  188. dataShow = dataPriv.access( elem, "fxshow", { display: restoreDisplay } );
  189. }
  190. // Store hidden/visible for toggle so `.stop().toggle()` "reverses"
  191. if ( toggle ) {
  192. dataShow.hidden = !hidden;
  193. }
  194. // Show elements before animating them
  195. if ( hidden ) {
  196. showHide( [ elem ], true );
  197. }
  198. /* eslint-disable no-loop-func */
  199. anim.done( function() {
  200. /* eslint-enable no-loop-func */
  201. // The final step of a "hide" animation is actually hiding the element
  202. if ( !hidden ) {
  203. showHide( [ elem ] );
  204. }
  205. dataPriv.remove( elem, "fxshow" );
  206. for ( prop in orig ) {
  207. jQuery.style( elem, prop, orig[ prop ] );
  208. }
  209. } );
  210. }
  211. // Per-property setup
  212. propTween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
  213. if ( !( prop in dataShow ) ) {
  214. dataShow[ prop ] = propTween.start;
  215. if ( hidden ) {
  216. propTween.end = propTween.start;
  217. propTween.start = 0;
  218. }
  219. }
  220. }
  221. }
  222. function propFilter( props, specialEasing ) {
  223. var index, name, easing, value, hooks;
  224. // camelCase, specialEasing and expand cssHook pass
  225. for ( index in props ) {
  226. name = camelCase( index );
  227. easing = specialEasing[ name ];
  228. value = props[ index ];
  229. if ( Array.isArray( value ) ) {
  230. easing = value[ 1 ];
  231. value = props[ index ] = value[ 0 ];
  232. }
  233. if ( index !== name ) {
  234. props[ name ] = value;
  235. delete props[ index ];
  236. }
  237. hooks = jQuery.cssHooks[ name ];
  238. if ( hooks && "expand" in hooks ) {
  239. value = hooks.expand( value );
  240. delete props[ name ];
  241. // Not quite $.extend, this won't overwrite existing keys.
  242. // Reusing 'index' because we have the correct "name"
  243. for ( index in value ) {
  244. if ( !( index in props ) ) {
  245. props[ index ] = value[ index ];
  246. specialEasing[ index ] = easing;
  247. }
  248. }
  249. } else {
  250. specialEasing[ name ] = easing;
  251. }
  252. }
  253. }
  254. function Animation( elem, properties, options ) {
  255. var result,
  256. stopped,
  257. index = 0,
  258. length = Animation.prefilters.length,
  259. deferred = jQuery.Deferred().always( function() {
  260. // Don't match elem in the :animated selector
  261. delete tick.elem;
  262. } ),
  263. tick = function() {
  264. if ( stopped ) {
  265. return false;
  266. }
  267. var currentTime = fxNow || createFxNow(),
  268. remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
  269. // Support: Android 2.3 only
  270. // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
  271. temp = remaining / animation.duration || 0,
  272. percent = 1 - temp,
  273. index = 0,
  274. length = animation.tweens.length;
  275. for ( ; index < length; index++ ) {
  276. animation.tweens[ index ].run( percent );
  277. }
  278. deferred.notifyWith( elem, [ animation, percent, remaining ] );
  279. // If there's more to do, yield
  280. if ( percent < 1 && length ) {
  281. return remaining;
  282. }
  283. // If this was an empty animation, synthesize a final progress notification
  284. if ( !length ) {
  285. deferred.notifyWith( elem, [ animation, 1, 0 ] );
  286. }
  287. // Resolve the animation and report its conclusion
  288. deferred.resolveWith( elem, [ animation ] );
  289. return false;
  290. },
  291. animation = deferred.promise( {
  292. elem: elem,
  293. props: jQuery.extend( {}, properties ),
  294. opts: jQuery.extend( true, {
  295. specialEasing: {},
  296. easing: jQuery.easing._default
  297. }, options ),
  298. originalProperties: properties,
  299. originalOptions: options,
  300. startTime: fxNow || createFxNow(),
  301. duration: options.duration,
  302. tweens: [],
  303. createTween: function( prop, end ) {
  304. var tween = jQuery.Tween( elem, animation.opts, prop, end,
  305. animation.opts.specialEasing[ prop ] || animation.opts.easing );
  306. animation.tweens.push( tween );
  307. return tween;
  308. },
  309. stop: function( gotoEnd ) {
  310. var index = 0,
  311. // If we are going to the end, we want to run all the tweens
  312. // otherwise we skip this part
  313. length = gotoEnd ? animation.tweens.length : 0;
  314. if ( stopped ) {
  315. return this;
  316. }
  317. stopped = true;
  318. for ( ; index < length; index++ ) {
  319. animation.tweens[ index ].run( 1 );
  320. }
  321. // Resolve when we played the last frame; otherwise, reject
  322. if ( gotoEnd ) {
  323. deferred.notifyWith( elem, [ animation, 1, 0 ] );
  324. deferred.resolveWith( elem, [ animation, gotoEnd ] );
  325. } else {
  326. deferred.rejectWith( elem, [ animation, gotoEnd ] );
  327. }
  328. return this;
  329. }
  330. } ),
  331. props = animation.props;
  332. propFilter( props, animation.opts.specialEasing );
  333. for ( ; index < length; index++ ) {
  334. result = Animation.prefilters[ index ].call( animation, elem, props, animation.opts );
  335. if ( result ) {
  336. if ( isFunction( result.stop ) ) {
  337. jQuery._queueHooks( animation.elem, animation.opts.queue ).stop =
  338. result.stop.bind( result );
  339. }
  340. return result;
  341. }
  342. }
  343. jQuery.map( props, createTween, animation );
  344. if ( isFunction( animation.opts.start ) ) {
  345. animation.opts.start.call( elem, animation );
  346. }
  347. // Attach callbacks from options
  348. animation
  349. .progress( animation.opts.progress )
  350. .done( animation.opts.done, animation.opts.complete )
  351. .fail( animation.opts.fail )
  352. .always( animation.opts.always );
  353. jQuery.fx.timer(
  354. jQuery.extend( tick, {
  355. elem: elem,
  356. anim: animation,
  357. queue: animation.opts.queue
  358. } )
  359. );
  360. return animation;
  361. }
  362. jQuery.Animation = jQuery.extend( Animation, {
  363. tweeners: {
  364. "*": [ function( prop, value ) {
  365. var tween = this.createTween( prop, value );
  366. adjustCSS( tween.elem, prop, rcssNum.exec( value ), tween );
  367. return tween;
  368. } ]
  369. },
  370. tweener: function( props, callback ) {
  371. if ( isFunction( props ) ) {
  372. callback = props;
  373. props = [ "*" ];
  374. } else {
  375. props = props.match( rnothtmlwhite );
  376. }
  377. var prop,
  378. index = 0,
  379. length = props.length;
  380. for ( ; index < length; index++ ) {
  381. prop = props[ index ];
  382. Animation.tweeners[ prop ] = Animation.tweeners[ prop ] || [];
  383. Animation.tweeners[ prop ].unshift( callback );
  384. }
  385. },
  386. prefilters: [ defaultPrefilter ],
  387. prefilter: function( callback, prepend ) {
  388. if ( prepend ) {
  389. Animation.prefilters.unshift( callback );
  390. } else {
  391. Animation.prefilters.push( callback );
  392. }
  393. }
  394. } );
  395. jQuery.speed = function( speed, easing, fn ) {
  396. var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
  397. complete: fn || !fn && easing ||
  398. isFunction( speed ) && speed,
  399. duration: speed,
  400. easing: fn && easing || easing && !isFunction( easing ) && easing
  401. };
  402. // Go to the end state if fx are off
  403. if ( jQuery.fx.off ) {
  404. opt.duration = 0;
  405. } else {
  406. if ( typeof opt.duration !== "number" ) {
  407. if ( opt.duration in jQuery.fx.speeds ) {
  408. opt.duration = jQuery.fx.speeds[ opt.duration ];
  409. } else {
  410. opt.duration = jQuery.fx.speeds._default;
  411. }
  412. }
  413. }
  414. // Normalize opt.queue - true/undefined/null -> "fx"
  415. if ( opt.queue == null || opt.queue === true ) {
  416. opt.queue = "fx";
  417. }
  418. // Queueing
  419. opt.old = opt.complete;
  420. opt.complete = function() {
  421. if ( isFunction( opt.old ) ) {
  422. opt.old.call( this );
  423. }
  424. if ( opt.queue ) {
  425. jQuery.dequeue( this, opt.queue );
  426. }
  427. };
  428. return opt;
  429. };
  430. jQuery.fn.extend( {
  431. fadeTo: function( speed, to, easing, callback ) {
  432. // Show any hidden elements after setting opacity to 0
  433. return this.filter( isHiddenWithinTree ).css( "opacity", 0 ).show()
  434. // Animate to the value specified
  435. .end().animate( { opacity: to }, speed, easing, callback );
  436. },
  437. animate: function( prop, speed, easing, callback ) {
  438. var empty = jQuery.isEmptyObject( prop ),
  439. optall = jQuery.speed( speed, easing, callback ),
  440. doAnimation = function() {
  441. // Operate on a copy of prop so per-property easing won't be lost
  442. var anim = Animation( this, jQuery.extend( {}, prop ), optall );
  443. // Empty animations, or finishing resolves immediately
  444. if ( empty || dataPriv.get( this, "finish" ) ) {
  445. anim.stop( true );
  446. }
  447. };
  448. doAnimation.finish = doAnimation;
  449. return empty || optall.queue === false ?
  450. this.each( doAnimation ) :
  451. this.queue( optall.queue, doAnimation );
  452. },
  453. stop: function( type, clearQueue, gotoEnd ) {
  454. var stopQueue = function( hooks ) {
  455. var stop = hooks.stop;
  456. delete hooks.stop;
  457. stop( gotoEnd );
  458. };
  459. if ( typeof type !== "string" ) {
  460. gotoEnd = clearQueue;
  461. clearQueue = type;
  462. type = undefined;
  463. }
  464. if ( clearQueue && type !== false ) {
  465. this.queue( type || "fx", [] );
  466. }
  467. return this.each( function() {
  468. var dequeue = true,
  469. index = type != null && type + "queueHooks",
  470. timers = jQuery.timers,
  471. data = dataPriv.get( this );
  472. if ( index ) {
  473. if ( data[ index ] && data[ index ].stop ) {
  474. stopQueue( data[ index ] );
  475. }
  476. } else {
  477. for ( index in data ) {
  478. if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
  479. stopQueue( data[ index ] );
  480. }
  481. }
  482. }
  483. for ( index = timers.length; index--; ) {
  484. if ( timers[ index ].elem === this &&
  485. ( type == null || timers[ index ].queue === type ) ) {
  486. timers[ index ].anim.stop( gotoEnd );
  487. dequeue = false;
  488. timers.splice( index, 1 );
  489. }
  490. }
  491. // Start the next in the queue if the last step wasn't forced.
  492. // Timers currently will call their complete callbacks, which
  493. // will dequeue but only if they were gotoEnd.
  494. if ( dequeue || !gotoEnd ) {
  495. jQuery.dequeue( this, type );
  496. }
  497. } );
  498. },
  499. finish: function( type ) {
  500. if ( type !== false ) {
  501. type = type || "fx";
  502. }
  503. return this.each( function() {
  504. var index,
  505. data = dataPriv.get( this ),
  506. queue = data[ type + "queue" ],
  507. hooks = data[ type + "queueHooks" ],
  508. timers = jQuery.timers,
  509. length = queue ? queue.length : 0;
  510. // Enable finishing flag on private data
  511. data.finish = true;
  512. // Empty the queue first
  513. jQuery.queue( this, type, [] );
  514. if ( hooks && hooks.stop ) {
  515. hooks.stop.call( this, true );
  516. }
  517. // Look for any active animations, and finish them
  518. for ( index = timers.length; index--; ) {
  519. if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
  520. timers[ index ].anim.stop( true );
  521. timers.splice( index, 1 );
  522. }
  523. }
  524. // Look for any animations in the old queue and finish them
  525. for ( index = 0; index < length; index++ ) {
  526. if ( queue[ index ] && queue[ index ].finish ) {
  527. queue[ index ].finish.call( this );
  528. }
  529. }
  530. // Turn off finishing flag
  531. delete data.finish;
  532. } );
  533. }
  534. } );
  535. jQuery.each( [ "toggle", "show", "hide" ], function( i, name ) {
  536. var cssFn = jQuery.fn[ name ];
  537. jQuery.fn[ name ] = function( speed, easing, callback ) {
  538. return speed == null || typeof speed === "boolean" ?
  539. cssFn.apply( this, arguments ) :
  540. this.animate( genFx( name, true ), speed, easing, callback );
  541. };
  542. } );
  543. // Generate shortcuts for custom animations
  544. jQuery.each( {
  545. slideDown: genFx( "show" ),
  546. slideUp: genFx( "hide" ),
  547. slideToggle: genFx( "toggle" ),
  548. fadeIn: { opacity: "show" },
  549. fadeOut: { opacity: "hide" },
  550. fadeToggle: { opacity: "toggle" }
  551. }, function( name, props ) {
  552. jQuery.fn[ name ] = function( speed, easing, callback ) {
  553. return this.animate( props, speed, easing, callback );
  554. };
  555. } );
  556. jQuery.timers = [];
  557. jQuery.fx.tick = function() {
  558. var timer,
  559. i = 0,
  560. timers = jQuery.timers;
  561. fxNow = Date.now();
  562. for ( ; i < timers.length; i++ ) {
  563. timer = timers[ i ];
  564. // Run the timer and safely remove it when done (allowing for external removal)
  565. if ( !timer() && timers[ i ] === timer ) {
  566. timers.splice( i--, 1 );
  567. }
  568. }
  569. if ( !timers.length ) {
  570. jQuery.fx.stop();
  571. }
  572. fxNow = undefined;
  573. };
  574. jQuery.fx.timer = function( timer ) {
  575. jQuery.timers.push( timer );
  576. jQuery.fx.start();
  577. };
  578. jQuery.fx.interval = 13;
  579. jQuery.fx.start = function() {
  580. if ( inProgress ) {
  581. return;
  582. }
  583. inProgress = true;
  584. schedule();
  585. };
  586. jQuery.fx.stop = function() {
  587. inProgress = null;
  588. };
  589. jQuery.fx.speeds = {
  590. slow: 600,
  591. fast: 200,
  592. // Default speed
  593. _default: 400
  594. };
  595. return jQuery;
  596. } );