jquery.transition.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. /* Cases where transition is disabled:
  2. * - in incompatible browsers (Opera 11 included)
  3. * - when the animated object is not an element
  4. * - when there is a special easing
  5. * - when there is a step function
  6. * - when jQuery.fx.off is true (should work out of the box)
  7. *
  8. * jQuery.fx.stop() will stop animations instead of pausing them (undocumented method and behavior anyway).
  9. */
  10. (function( jQuery ) {
  11. var elemdisplay = {},
  12. iframe, iframeDoc,
  13. rfxtypes = /^(?:toggle|show|hide)$/,
  14. rfxnum = /^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,
  15. //rMarginProp = /^margin/,
  16. timerId,
  17. /*fxAttrs = [
  18. // height animations
  19. [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
  20. // width animations
  21. [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
  22. // opacity animations
  23. [ "opacity" ]
  24. ],*/
  25. fxNow;
  26. // ++TRANSITION++
  27. // Following feature test code should be moved to support.js
  28. var div = document.createElement( "div" ),
  29. divStyle = div.style,
  30. trans = "Transition",
  31. _cubicBezier = "cubic-bezier(",
  32. easingTable;
  33. // Only test for transition support in Firefox and Webkit
  34. // as we know for sure that Opera has too much bugs (see http://csstransition.net)
  35. // and there's no guarantee that first IE implementation will be bug-free
  36. jQuery.support.transition =
  37. "Moz" + trans in divStyle ? "Moz" + trans :
  38. "Webkit" + trans in divStyle ? "Webkit" + trans :
  39. false;
  40. // Following declarations should be moved to css.js
  41. jQuery.cssNumber.color = jQuery.cssNumber.backgroundColor = true;
  42. // Translation table from "jQuery easings" to "transition timing functions"
  43. easingTable = {
  44. linear: "linear",
  45. swing: "ease-out",
  46. bounce: _cubicBezier + "0,.35,.5,1.3)",
  47. // Penner equation approximations from Matthew Lein's Ceaser: http://matthewlein.com/ceaser/
  48. easeInQuad: _cubicBezier + ".55,.085,.68,.53)",
  49. easeInCubic: _cubicBezier + ".55,.055,.675,.19)",
  50. easeInQuart: _cubicBezier + ".895,.03,.685,.22)",
  51. easeInQuint: _cubicBezier + ".755,.05,.855,.06)",
  52. easeInSine: _cubicBezier + ".47,0,.745,.715)",
  53. easeInExpo: _cubicBezier + ".95,.05,.795,.035)",
  54. easeInCirc: _cubicBezier + ".6,.04,.98,.335)",
  55. easeOutQuad: _cubicBezier + ".25,.46,.45,.94)",
  56. easeOutCubic: _cubicBezier + ".215,.61,.355,1)",
  57. easeOutQuart: _cubicBezier + ".165,.84,.44,1)",
  58. easeOutQuint: _cubicBezier + ".23,1,.32,1)",
  59. easeOutSine: _cubicBezier + ".39,.575,.565,1)",
  60. easeOutExpo: _cubicBezier + ".19,1,.22,1)",
  61. easeOutCirc: _cubicBezier + ".075,.82,.165,1)",
  62. easeInOutQuad: _cubicBezier + ".455,.03,.515,.955)",
  63. easeInOutCubic: _cubicBezier + ".645,.045,.355,1)",
  64. easeInOutQuart: _cubicBezier + ".77,0,.175,1)",
  65. easeInOutQuint: _cubicBezier + ".86,0,.07,1)",
  66. easeInOutSine: _cubicBezier + ".445,.05,.55,.95)",
  67. easeInOutExpo: _cubicBezier + "1,0,0,1)",
  68. easeInOutCirc: _cubicBezier + ".785,.135,.15,.86)"
  69. };
  70. jQuery.fn.extend({
  71. /*show: function( speed, easing, callback ) {
  72. var elem, display;
  73. if ( speed || speed === 0 ) {
  74. return this.animate( genFx("show", 3), speed, easing, callback );
  75. } else {
  76. for ( var i = 0, j = this.length; i < j; i++ ) {
  77. elem = this[ i ];
  78. if ( elem.style ) {
  79. display = elem.style.display;
  80. // Reset the inline display of this element to learn if it is
  81. // being hidden by cascaded rules or not
  82. if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
  83. display = elem.style.display = "";
  84. }
  85. // Set elements which have been overridden with display: none
  86. // in a stylesheet to whatever the default browser style is
  87. // for such an element
  88. if ( (display === "" && jQuery.css(elem, "display") === "none") ||
  89. !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
  90. jQuery._data( elem, "olddisplay", defaultDisplay(elem.nodeName) );
  91. }
  92. }
  93. }
  94. // Set the display of most of the elements in a second loop
  95. // to avoid the constant reflow
  96. for ( i = 0; i < j; i++ ) {
  97. elem = this[ i ];
  98. if ( elem.style ) {
  99. display = elem.style.display;
  100. if ( display === "" || display === "none" ) {
  101. elem.style.display = jQuery._data( elem, "olddisplay" ) || "";
  102. }
  103. }
  104. }
  105. return this;
  106. }
  107. },
  108. hide: function( speed, easing, callback ) {
  109. if ( speed || speed === 0 ) {
  110. return this.animate( genFx("hide", 3), speed, easing, callback);
  111. } else {
  112. var elem, display,
  113. i = 0,
  114. j = this.length;
  115. for ( ; i < j; i++ ) {
  116. elem = this[i];
  117. if ( elem.style ) {
  118. display = jQuery.css( elem, "display" );
  119. if ( display !== "none" && !jQuery._data( elem, "olddisplay" ) ) {
  120. jQuery._data( elem, "olddisplay", display );
  121. }
  122. }
  123. }
  124. // Set the display of the elements in a second loop
  125. // to avoid the constant reflow
  126. for ( i = 0; i < j; i++ ) {
  127. if ( this[i].style ) {
  128. this[i].style.display = "none";
  129. }
  130. }
  131. return this;
  132. }
  133. },
  134. // Save the old toggle function
  135. _toggle: jQuery.fn.toggle,
  136. toggle: function( fn, fn2, callback ) {
  137. var bool = typeof fn === "boolean";
  138. if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
  139. this._toggle.apply( this, arguments );
  140. } else if ( fn == null || bool ) {
  141. this.each(function() {
  142. var state = bool ? fn : jQuery(this).is(":hidden");
  143. jQuery(this)[ state ? "show" : "hide" ]();
  144. });
  145. } else {
  146. this.animate(genFx("toggle", 3), fn, fn2, callback);
  147. }
  148. return this;
  149. },
  150. fadeTo: function( speed, to, easing, callback ) {
  151. return this.filter(":hidden").css("opacity", 0).show().end()
  152. .animate({opacity: to}, speed, easing, callback);
  153. },*/
  154. animate: function( prop, speed, easing, callback ) {
  155. var optall = jQuery.speed( speed, easing, callback );
  156. if ( jQuery.isEmptyObject( prop ) ) {
  157. return this.each( optall.complete, [ false ] );
  158. }
  159. // Do not change referenced properties as per-property easing will be lost
  160. prop = jQuery.extend( {}, prop );
  161. function doAnimation() {
  162. // XXX 'this' does not always have a nodeName when running the
  163. // test suite
  164. if ( optall.queue === false ) {
  165. jQuery._mark( this );
  166. }
  167. var opt = jQuery.extend( {}, optall ),
  168. isElement = this.nodeType === 1,
  169. hidden = isElement && jQuery(this).is(":hidden"),
  170. name, val, p, e, hooks, replace,
  171. parts, start, end, unit,
  172. method,
  173. // ++TRANSITION++
  174. cssProps = jQuery.cssProps,
  175. // disable transition if a step option is supplied
  176. supportTransition = !opt.step && jQuery.support.transition,
  177. transition,
  178. transitions = [],
  179. easing, real, lower,
  180. computedStyle;
  181. // will store per property easing and be used to determine when an animation is complete
  182. opt.animatedProperties = {};
  183. // ++TRANSITION++
  184. // transition is enabled per property, when:
  185. // - there is no step function for the animation
  186. // - there is no special easing for the property
  187. opt.transition = {};
  188. // first pass over propertys to expand / normalize
  189. for ( p in prop ) {
  190. name = jQuery.camelCase( p );
  191. if ( p !== name ) {
  192. prop[ name ] = prop[ p ];
  193. delete prop[ p ];
  194. }
  195. if ( ( hooks = jQuery.cssHooks[ name ] ) && "expand" in hooks ) {
  196. replace = hooks.expand( prop[ name ] );
  197. delete prop[ name ];
  198. // not quite $.extend, this wont overwrite keys already present.
  199. // also - reusing 'p' from above because we have the correct "name"
  200. for ( p in replace ) {
  201. if ( ! ( p in prop ) ) {
  202. prop[ p ] = replace[ p ];
  203. }
  204. }
  205. }
  206. }
  207. for ( name in prop ) {
  208. val = prop[ name ];
  209. // easing resolution: per property > opt.specialEasing > opt.easing > 'swing' (default)
  210. if ( jQuery.isArray( val ) ) {
  211. /* ++TRANSITION++ */ easing = opt.animatedProperties[ name ] = val[ 1 ];
  212. val = prop[ name ] = val[ 0 ];
  213. } else {
  214. /* ++TRANSITION++ */ easing = opt.animatedProperties[ name ] = opt.specialEasing && opt.specialEasing[ name ] || opt.easing || "swing";
  215. }
  216. // ++TRANSITION++
  217. // check that CSS Transitions can be used
  218. transition = supportTransition && isElement && opt.duration > 0 && name.indexOf( "scroll" ) && easingTable[ easing ];
  219. // collect the properties to be added to elem.style.transition...
  220. if ( transition ) {
  221. real = cssProps[ name ] || name;
  222. lower = real.replace(/([A-Z])/g, '-$1').toLowerCase();
  223. transition =
  224. lower +" "+
  225. opt.duration +"ms "+
  226. transition;
  227. opt.transition[ name ] = {
  228. lower: lower,
  229. real: real
  230. };
  231. transitions.push(transition);
  232. }
  233. if ( val === "hide" && hidden || val === "show" && !hidden ) {
  234. return opt.complete.call( this );
  235. }
  236. if ( isElement && ( name === "height" || name === "width" ) ) {
  237. // Make sure that nothing sneaks out
  238. // Record all 3 overflow attributes because IE does not
  239. // change the overflow attribute when overflowX and
  240. // overflowY are set to the same value
  241. opt.overflow = [ this.style.overflow, this.style.overflowX, this.style.overflowY ];
  242. // Set display property to inline-block for height/width
  243. // animations on inline elements that are having width/height animated
  244. if ( jQuery.css( this, "display" ) === "inline" &&
  245. jQuery.css( this, "float" ) === "none" ) {
  246. // inline-level elements accept inline-block;
  247. // block-level elements need to be inline with layout
  248. if ( !jQuery.support.inlineBlockNeedsLayout || defaultDisplay( this.nodeName ) === "inline" ) {
  249. this.style.display = "inline-block";
  250. } else {
  251. this.style.zoom = 1;
  252. }
  253. }
  254. }
  255. }
  256. if ( opt.overflow != null ) {
  257. this.style.overflow = "hidden";
  258. }
  259. for ( p in prop ) {
  260. e = new jQuery.fx( this, opt, p );
  261. val = prop[ p ];
  262. if ( rfxtypes.test( val ) ) {
  263. // Tracks whether to show or hide based on private
  264. // data attached to the element
  265. method = jQuery._data( this, "toggle" + p ) || ( val === "toggle" ? hidden ? "show" : "hide" : 0 );
  266. if ( method ) {
  267. jQuery._data( this, "toggle" + p, method === "show" ? "hide" : "show" );
  268. e[ method ]();
  269. } else {
  270. e[ val ]();
  271. }
  272. } else {
  273. parts = rfxnum.exec( val );
  274. start = e.cur();
  275. if ( parts ) {
  276. end = parseFloat( parts[2] );
  277. unit = parts[3] || ( jQuery.cssNumber[ p ] ? "" : "px" );
  278. // We need to compute starting value
  279. if ( unit !== "px" && p !== "opacity" ) {
  280. jQuery.style( this, p, (end || 1) + unit);
  281. start = ( (end || 1) / e.cur() ) * start;
  282. jQuery.style( this, p, start + unit);
  283. }
  284. // If a +=/-= token was provided, we're doing a relative animation
  285. if ( parts[1] ) {
  286. end = ( (parts[ 1 ] === "-=" ? -1 : 1) * end ) + start;
  287. }
  288. e.custom( start, end, unit );
  289. } else {
  290. e.custom( start, val, "" );
  291. }
  292. }
  293. }
  294. // ++TRANSITION++
  295. if ( supportTransition && transitions.length ) {
  296. transition = this.style[supportTransition];
  297. computedStyle = window.getComputedStyle( this );
  298. this.style[ supportTransition ] =
  299. transitions.join() + ( transition && transition.indexOf( "none" ) ? "," + transition : "" );
  300. // Once the transition property has been set, it's time to set all animated style properties
  301. for ( p in opt.transition ) {
  302. // access the computed style to make sure it has been taken into account by the browser
  303. computedStyle[ p ];
  304. // ...before setting the target style
  305. jQuery.style.apply( null, opt.transition[ p ].styleToSet );
  306. }
  307. }
  308. // For JS strict compliance
  309. return true;
  310. }
  311. return optall.queue === false ?
  312. this.each( doAnimation ) :
  313. this.queue( optall.queue, doAnimation );
  314. },
  315. stop: function( type, clearQueue, gotoEnd ) {
  316. if ( typeof type !== "string" ) {
  317. gotoEnd = clearQueue;
  318. clearQueue = type;
  319. type = undefined;
  320. }
  321. if ( clearQueue && type !== false ) {
  322. this.queue( type || "fx", [] );
  323. }
  324. return this.each(function() {
  325. var index,
  326. hadTimers = false,
  327. timers = jQuery.timers,
  328. data = jQuery._data( this ),
  329. // ++TRANSITION++
  330. supportTransition = jQuery.support.transition;
  331. // clear marker counters if we know they won't be
  332. if ( !gotoEnd ) {
  333. jQuery._unmark( true, this );
  334. }
  335. function stopQueue( elem, data, index ) {
  336. var hooks = data[ index ];
  337. jQuery.removeData( elem, index, true );
  338. hooks.stop( gotoEnd );
  339. }
  340. if ( type == null ) {
  341. for ( index in data ) {
  342. if ( data[ index ] && data[ index ].stop && index.indexOf(".run") === index.length - 4 ) {
  343. stopQueue( this, data, index );
  344. }
  345. }
  346. } else if ( data[ index = type + ".run" ] && data[ index ].stop ){
  347. stopQueue( this, data, index );
  348. }
  349. for ( index = timers.length; index--; ) {
  350. // ++TRANSITION++
  351. if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
  352. if ( gotoEnd || supportTransition ) {
  353. // force the next step to be the last
  354. timers[ index ]( /* ++TRANSITION++*/ gotoEnd );
  355. }
  356. if ( !gotoEnd ) {
  357. timers[ index ].saveState();
  358. }
  359. hadTimers = true;
  360. timers.splice( index, 1 );
  361. }
  362. }
  363. // start the next in the queue if the last step wasn't forced
  364. // timers currently will call their complete callbacks, which will dequeue
  365. // but only if they were gotoEnd
  366. if ( !( gotoEnd && hadTimers ) ) {
  367. jQuery.dequeue( this, type );
  368. }
  369. });
  370. }
  371. });
  372. // Animations created synchronously will run synchronously
  373. function createFxNow() {
  374. setTimeout( clearFxNow, 0 );
  375. return ( fxNow = jQuery.now() );
  376. }
  377. function clearFxNow() {
  378. fxNow = undefined;
  379. }
  380. /*// Generate parameters to create a standard animation
  381. function genFx( type, num ) {
  382. var obj = {};
  383. jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice( 0, num )), function() {
  384. obj[ this ] = type;
  385. });
  386. return obj;
  387. }
  388. // Generate shortcuts for custom animations
  389. jQuery.each({
  390. slideDown: genFx( "show", 1 ),
  391. slideUp: genFx( "hide", 1 ),
  392. slideToggle: genFx( "toggle", 1 ),
  393. fadeIn: { opacity: "show" },
  394. fadeOut: { opacity: "hide" },
  395. fadeToggle: { opacity: "toggle" }
  396. }, function( name, props ) {
  397. jQuery.fn[ name ] = function( speed, easing, callback ) {
  398. return this.animate( props, speed, easing, callback );
  399. };
  400. });
  401. jQuery.extend({
  402. speed: function( speed, easing, fn ) {
  403. var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
  404. complete: fn || !fn && easing ||
  405. jQuery.isFunction( speed ) && speed,
  406. duration: speed,
  407. easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
  408. };
  409. opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
  410. opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
  411. // normalize opt.queue - true/undefined/null -> "fx"
  412. if ( opt.queue == null || opt.queue === true ) {
  413. opt.queue = "fx";
  414. }
  415. // Queueing
  416. opt.old = opt.complete;
  417. opt.complete = function( noUnmark ) {
  418. if ( jQuery.isFunction( opt.old ) ) {
  419. opt.old.call( this );
  420. }
  421. if ( opt.queue ) {
  422. jQuery.dequeue( this, opt.queue );
  423. } else if ( noUnmark !== false ) {
  424. jQuery._unmark( this );
  425. }
  426. };
  427. return opt;
  428. },
  429. easing: {
  430. linear: function( p ) {
  431. return p;
  432. },
  433. swing: function( p ) {
  434. return ( -Math.cos( p*Math.PI ) / 2 ) + 0.5;
  435. }
  436. },
  437. timers: [],
  438. fx: function( elem, options, prop ) {
  439. this.options = options;
  440. this.elem = elem;
  441. this.prop = prop;
  442. options.orig = options.orig || {};
  443. }
  444. });*/
  445. jQuery.extend( jQuery.fx.prototype, {
  446. /*jQuery.fx.prototype = {
  447. // Simple function for setting a style value
  448. update: function() {
  449. if ( this.options.step ) {
  450. this.options.step.call( this.elem, this.now, this );
  451. }
  452. ( jQuery.fx.step[ this.prop ] || jQuery.fx.step._default )( this );
  453. },*/
  454. // Get the current size
  455. cur: function() {
  456. if ( this.elem[ this.prop ] != null && (!this.elem.style || this.elem.style[ this.prop ] == null) ) {
  457. return this.elem[ this.prop ];
  458. }
  459. var parsed,
  460. r = jQuery.css( this.elem, this.prop );
  461. // Empty strings, null, undefined and "auto" are converted to 0,
  462. // complex values such as "rotate(1rad)" are returned as is,
  463. // simple values such as "10px" are parsed to Float.
  464. return isNaN( parsed = parseFloat( r ) ) ? !r || r === "auto" ? 0 : r : parsed;
  465. },
  466. // Start an animation from one number to another
  467. custom: function( from, to, unit ) {
  468. var self = this,
  469. fx = jQuery.fx,
  470. // ++TRANSITION++
  471. transition = self.options.transition,
  472. // prop has to be saved, or it'll be undefined in the setTimeout closure
  473. prop = this.prop;
  474. this.startTime = fxNow || createFxNow();
  475. this.end = to;
  476. this.now = this.start = from;
  477. this.pos = this.state = 0;
  478. this.unit = unit || this.unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
  479. function t( gotoEnd ) {
  480. return self.step( gotoEnd );
  481. }
  482. t.queue = this.options.queue;
  483. t.elem = this.elem;
  484. t.saveState = function() {
  485. if ( jQuery._data( self.elem, "fxshow" + self.prop ) === undefined ) {
  486. if ( self.options.hide ) {
  487. jQuery._data( self.elem, "fxshow" + self.prop, self.start );
  488. } else if ( self.options.show ) {
  489. jQuery._data( self.elem, "fxshow" + self.prop, self.end );
  490. }
  491. }
  492. };
  493. // ++TRANSITION++
  494. if ( ( t.transition = transition[ prop ] ) ) {
  495. jQuery.timers.push( t );
  496. // explicitly set the property to it's initial value to workaround bugzil.la/571344
  497. // transform shouldn't cause any problem in this case, as it is covered by the spec.
  498. if ( prop != "transform" ) {
  499. self.elem.style[ transition[ prop ].real ] = from + self.unit;
  500. }
  501. // prevent negative values on certain properties
  502. jQuery.fx.step[ prop ] && ( to = Math.max(0, to) );
  503. transition[ prop ].styleToSet = [ self.elem, prop, to + self.unit ];
  504. // use a setTimeout to detect the end of a transition
  505. // the transitionend event is unreliable
  506. transition[ prop ].timeout = setTimeout(function() {
  507. jQuery.timers.splice( jQuery.timers.indexOf( t ), 1 );
  508. self.step( true );
  509. // add an unperceptible delay to help some tests pass in Firefox
  510. }, self.options.duration + 30);
  511. } else if ( t() && jQuery.timers.push(t) && !timerId ) {
  512. timerId = setInterval( fx.tick, fx.interval );
  513. }
  514. },
  515. /*// Simple 'show' function
  516. show: function() {
  517. var dataShow = jQuery._data( this.elem, "fxshow" + this.prop );
  518. // Remember where we started, so that we can go back to it later
  519. this.options.orig[ this.prop ] = dataShow || jQuery.style( this.elem, this.prop );
  520. this.options.show = true;
  521. // Begin the animation
  522. // Make sure that we start at a small width/height to avoid any flash of content
  523. if ( dataShow !== undefined ) {
  524. // This show is picking up where a previous hide or show left off
  525. this.custom( this.cur(), dataShow );
  526. } else {
  527. this.custom( this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur() );
  528. }
  529. // Start by showing the element
  530. jQuery( this.elem ).show();
  531. },
  532. // Simple 'hide' function
  533. hide: function() {
  534. // Remember where we started, so that we can go back to it later
  535. this.options.orig[ this.prop ] = jQuery._data( this.elem, "fxshow" + this.prop ) || jQuery.style( this.elem, this.prop );
  536. this.options.hide = true;
  537. // Begin the animation
  538. this.custom( this.cur(), 0 );
  539. },*/
  540. // Each step of an animation
  541. step: function( gotoEnd ) {
  542. var p, n, complete,
  543. t = fxNow || createFxNow(),
  544. done = true,
  545. elem = this.elem,
  546. options = this.options,
  547. // ++TRANSITION++
  548. transition = options.transition[ this.prop ],
  549. naturalEnd = t >= options.duration + this.startTime,
  550. supportTransition = jQuery.support.transition;
  551. if ( transition || gotoEnd || naturalEnd ) {
  552. if ( !transition ) {
  553. this.now = this.end;
  554. this.pos = this.state = 1;
  555. this.update();
  556. // ++TRANSITION++
  557. } else {
  558. clearTimeout( transition.timeout );
  559. // Stop a transition halfway through
  560. if ( !gotoEnd && !naturalEnd ) {
  561. // yes, stopping a transition halfway through should be as simple as setting a property to its current value.
  562. // Try to call window.getComputedStyle() only once per element (in tick()?)
  563. this.elem.style[ transition.real ] = jQuery.css( this.elem, transition.real );
  564. }
  565. }
  566. options.animatedProperties[ this.prop ] = true;
  567. for ( p in options.animatedProperties ) {
  568. if ( options.animatedProperties[ p ] !== true ) {
  569. done = false;
  570. }
  571. }
  572. if ( done ) {
  573. // Reset the overflow
  574. if ( options.overflow != null && !jQuery.support.shrinkWrapBlocks ) {
  575. jQuery.each( [ "", "X", "Y" ], function( index, value ) {
  576. elem.style[ "overflow" + value ] = options.overflow[ index ];
  577. });
  578. }
  579. // Hide the element if the "hide" operation was done
  580. if ( options.hide ) {
  581. jQuery( elem ).hide();
  582. }
  583. // ++TRANSITION++
  584. // cleanup the transition property
  585. if ( transition ) {
  586. transition = "," + elem.style[ supportTransition ];
  587. for ( p in options.transition ) {
  588. transition = transition.split( options.transition[ p ].lower ).join("_");
  589. }
  590. transition = transition.replace( /, ?_[^,]*/g, "" ).substr(1);
  591. // if the resulting string is empty, replace it with "none" to achieve gotoEnd
  592. elem.style[ supportTransition ] = transition || "none";
  593. // finish on an empty string if "none" has been used
  594. // this way transitions set with CSS aren't overridden.
  595. !transition && ( elem.style[ supportTransition ] = transition );
  596. }
  597. // Reset the properties, if the item has been hidden or shown
  598. if ( options.hide || options.show ) {
  599. for ( p in options.animatedProperties ) {
  600. ( gotoEnd || naturalEnd ) && jQuery.style( elem, p, options.orig[ p ] );
  601. jQuery.removeData( elem, "fxshow" + p, true );
  602. // Toggle data is no longer needed
  603. jQuery.removeData( elem, "toggle" + p, true );
  604. }
  605. }
  606. // Execute the complete function
  607. // in the event that the complete function throws an exception
  608. // we must ensure it won't be called twice. #5684
  609. complete = options.complete;
  610. if ( complete && ( gotoEnd || naturalEnd ) ) {
  611. options.complete = false;
  612. complete.call( elem );
  613. }
  614. }
  615. return false;
  616. } else {
  617. // classical easing cannot be used with an Infinity duration
  618. if ( options.duration == Infinity ) {
  619. this.now = t;
  620. } else {
  621. n = t - this.startTime;
  622. this.state = n / options.duration;
  623. // Perform the easing function, defaults to swing
  624. this.pos = jQuery.easing[ options.animatedProperties[this.prop] ]( this.state, n, 0, 1, options.duration );
  625. this.now = this.start + ( (this.end - this.start) * this.pos );
  626. }
  627. // Perform the next step of the animation
  628. this.update();
  629. }
  630. return true;
  631. }
  632. });//};
  633. jQuery.extend( jQuery.fx, {
  634. tick: function() {
  635. var timer,
  636. timers = jQuery.timers,
  637. i = 0;
  638. for ( ; i < timers.length; i++ ) {
  639. timer = timers[ i ];
  640. // Checks the timer has not already been removed
  641. // ++TRANSITION++
  642. if ( !timer.transition && !timer() && timers[ i ] === timer ) {
  643. timers.splice( i--, 1 );
  644. }
  645. }
  646. if ( !timers.length ) {
  647. jQuery.fx.stop();
  648. }
  649. }/*,
  650. interval: 13,
  651. stop: function() {
  652. clearInterval( timerId );
  653. timerId = null;
  654. },
  655. speeds: {
  656. slow: 600,
  657. fast: 200,
  658. // Default speed
  659. _default: 400
  660. },
  661. step: {
  662. opacity: function( fx ) {
  663. jQuery.style( fx.elem, "opacity", fx.now );
  664. },
  665. _default: function( fx ) {
  666. if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
  667. fx.elem.style[ fx.prop ] = fx.now + fx.unit;
  668. } else {
  669. fx.elem[ fx.prop ] = fx.now;
  670. }
  671. }
  672. }*/
  673. });
  674. /*// Ensure props that can't be negative don't go there on undershoot easing
  675. jQuery.each( fxAttrs.concat.apply( [], fxAttrs ), function( i, prop ) {
  676. // Exclude marginTop, marginLeft, marginBottom and marginRight from this list
  677. if ( !rMarginProp.test( prop ) ) {
  678. jQuery.fx.step[ prop ] = function( fx ) {
  679. jQuery.style( fx.elem, prop, Math.max(0, fx.now) + fx.unit );
  680. };
  681. }
  682. });
  683. if ( jQuery.expr && jQuery.expr.filters ) {
  684. jQuery.expr.filters.animated = function( elem ) {
  685. return jQuery.grep(jQuery.timers, function( fn ) {
  686. return elem === fn.elem;
  687. }).length;
  688. };
  689. }*/
  690. // Try to restore the default display value of an element
  691. function defaultDisplay( nodeName ) {
  692. if ( !elemdisplay[ nodeName ] ) {
  693. var body = document.body,
  694. elem = jQuery( "<" + nodeName + ">" ).appendTo( body ),
  695. display = elem.css( "display" );
  696. elem.remove();
  697. // If the simple way fails,
  698. // get element's real default display by attaching it to a temp iframe
  699. if ( display === "none" || display === "" ) {
  700. // No iframe to use yet, so create it
  701. if ( !iframe ) {
  702. iframe = document.createElement( "iframe" );
  703. iframe.frameBorder = iframe.width = iframe.height = 0;
  704. }
  705. body.appendChild( iframe );
  706. // Create a cacheable copy of the iframe document on first call.
  707. // IE and Opera will allow us to reuse the iframeDoc without re-writing the fake HTML
  708. // document to it; WebKit & Firefox won't allow reusing the iframe document.
  709. if ( !iframeDoc || !iframe.createElement ) {
  710. iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document;
  711. iframeDoc.write( ( jQuery.support.boxModel ? "<!doctype html>" : "" ) + "<html><body>" );
  712. iframeDoc.close();
  713. }
  714. elem = iframeDoc.createElement( nodeName );
  715. iframeDoc.body.appendChild( elem );
  716. display = jQuery.css( elem, "display" );
  717. body.removeChild( iframe );
  718. }
  719. // Store the correct default display
  720. elemdisplay[ nodeName ] = display;
  721. }
  722. return elemdisplay[ nodeName ];
  723. }
  724. })( jQuery );