Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

630 rindas
16KB

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