effect.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. /*!
  2. * jQuery UI Effects 1.14.1
  3. * https://jqueryui.com
  4. *
  5. * Copyright OpenJS Foundation and other contributors
  6. * Released under the MIT license.
  7. * https://jquery.org/license
  8. */
  9. //>>label: Effects Core
  10. //>>group: Effects
  11. /* eslint-disable max-len */
  12. //>>description: Extends the internal jQuery effects. Includes morphing and easing. Required by all other effects.
  13. /* eslint-enable max-len */
  14. //>>docs: https://api.jqueryui.com/category/effects-core/
  15. //>>demos: https://jqueryui.com/effect/
  16. ( function( factory ) {
  17. "use strict";
  18. if ( typeof define === "function" && define.amd ) {
  19. // AMD. Register as an anonymous module.
  20. define( [
  21. "jquery",
  22. "./jquery-var-for-color",
  23. "./vendor/jquery-color/jquery.color",
  24. "./version"
  25. ], factory );
  26. } else {
  27. // Browser globals
  28. factory( jQuery );
  29. }
  30. } )( function( $ ) {
  31. "use strict";
  32. var dataSpace = "ui-effects-",
  33. dataSpaceStyle = "ui-effects-style",
  34. dataSpaceAnimated = "ui-effects-animated";
  35. $.effects = {
  36. effect: {}
  37. };
  38. /******************************************************************************/
  39. /****************************** CLASS ANIMATIONS ******************************/
  40. /******************************************************************************/
  41. ( function() {
  42. var classAnimationActions = [ "add", "remove", "toggle" ],
  43. shorthandStyles = {
  44. border: 1,
  45. borderBottom: 1,
  46. borderColor: 1,
  47. borderLeft: 1,
  48. borderRight: 1,
  49. borderTop: 1,
  50. borderWidth: 1,
  51. margin: 1,
  52. padding: 1
  53. };
  54. $.each(
  55. [ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopStyle" ],
  56. function( _, prop ) {
  57. $.fx.step[ prop ] = function( fx ) {
  58. if ( fx.end !== "none" && !fx.setAttr || fx.pos === 1 && !fx.setAttr ) {
  59. jQuery.style( fx.elem, prop, fx.end );
  60. fx.setAttr = true;
  61. }
  62. };
  63. }
  64. );
  65. function camelCase( string ) {
  66. return string.replace( /-([\da-z])/gi, function( all, letter ) {
  67. return letter.toUpperCase();
  68. } );
  69. }
  70. function getElementStyles( elem ) {
  71. var key, len,
  72. style = elem.ownerDocument.defaultView.getComputedStyle( elem ),
  73. styles = {};
  74. len = style.length;
  75. while ( len-- ) {
  76. key = style[ len ];
  77. if ( typeof style[ key ] === "string" ) {
  78. styles[ camelCase( key ) ] = style[ key ];
  79. }
  80. }
  81. return styles;
  82. }
  83. function styleDifference( oldStyle, newStyle ) {
  84. var diff = {},
  85. name, value;
  86. for ( name in newStyle ) {
  87. value = newStyle[ name ];
  88. if ( oldStyle[ name ] !== value ) {
  89. if ( !shorthandStyles[ name ] ) {
  90. if ( $.fx.step[ name ] || !isNaN( parseFloat( value ) ) ) {
  91. diff[ name ] = value;
  92. }
  93. }
  94. }
  95. }
  96. return diff;
  97. }
  98. $.effects.animateClass = function( value, duration, easing, callback ) {
  99. var o = $.speed( duration, easing, callback );
  100. return this.queue( function() {
  101. var animated = $( this ),
  102. baseClass = animated.attr( "class" ) || "",
  103. applyClassChange,
  104. allAnimations = o.children ? animated.find( "*" ).addBack() : animated;
  105. // Map the animated objects to store the original styles.
  106. allAnimations = allAnimations.map( function() {
  107. var el = $( this );
  108. return {
  109. el: el,
  110. start: getElementStyles( this )
  111. };
  112. } );
  113. // Apply class change
  114. applyClassChange = function() {
  115. $.each( classAnimationActions, function( i, action ) {
  116. if ( value[ action ] ) {
  117. animated[ action + "Class" ]( value[ action ] );
  118. }
  119. } );
  120. };
  121. applyClassChange();
  122. // Map all animated objects again - calculate new styles and diff
  123. allAnimations = allAnimations.map( function() {
  124. this.end = getElementStyles( this.el[ 0 ] );
  125. this.diff = styleDifference( this.start, this.end );
  126. return this;
  127. } );
  128. // Apply original class
  129. animated.attr( "class", baseClass );
  130. // Map all animated objects again - this time collecting a promise
  131. allAnimations = allAnimations.map( function() {
  132. var styleInfo = this,
  133. dfd = $.Deferred(),
  134. opts = $.extend( {}, o, {
  135. queue: false,
  136. complete: function() {
  137. dfd.resolve( styleInfo );
  138. }
  139. } );
  140. this.el.animate( this.diff, opts );
  141. return dfd.promise();
  142. } );
  143. // Once all animations have completed:
  144. $.when.apply( $, allAnimations.get() ).done( function() {
  145. // Set the final class
  146. applyClassChange();
  147. // For each animated element,
  148. // clear all css properties that were animated
  149. $.each( arguments, function() {
  150. var el = this.el;
  151. $.each( this.diff, function( key ) {
  152. el.css( key, "" );
  153. } );
  154. } );
  155. // This is guarnteed to be there if you use jQuery.speed()
  156. // it also handles dequeuing the next anim...
  157. o.complete.call( animated[ 0 ] );
  158. } );
  159. } );
  160. };
  161. $.fn.extend( {
  162. addClass: ( function( orig ) {
  163. return function( classNames, speed, easing, callback ) {
  164. return speed ?
  165. $.effects.animateClass.call( this,
  166. { add: classNames }, speed, easing, callback ) :
  167. orig.apply( this, arguments );
  168. };
  169. } )( $.fn.addClass ),
  170. removeClass: ( function( orig ) {
  171. return function( classNames, speed, easing, callback ) {
  172. return arguments.length > 1 ?
  173. $.effects.animateClass.call( this,
  174. { remove: classNames }, speed, easing, callback ) :
  175. orig.apply( this, arguments );
  176. };
  177. } )( $.fn.removeClass ),
  178. toggleClass: ( function( orig ) {
  179. return function( classNames, force, speed, easing, callback ) {
  180. if ( typeof force === "boolean" || force === undefined ) {
  181. if ( !speed ) {
  182. // Without speed parameter
  183. return orig.apply( this, arguments );
  184. } else {
  185. return $.effects.animateClass.call( this,
  186. ( force ? { add: classNames } : { remove: classNames } ),
  187. speed, easing, callback );
  188. }
  189. } else {
  190. // Without force parameter
  191. return $.effects.animateClass.call( this,
  192. { toggle: classNames }, force, speed, easing );
  193. }
  194. };
  195. } )( $.fn.toggleClass ),
  196. switchClass: function( remove, add, speed, easing, callback ) {
  197. return $.effects.animateClass.call( this, {
  198. add: add,
  199. remove: remove
  200. }, speed, easing, callback );
  201. }
  202. } );
  203. } )();
  204. /******************************************************************************/
  205. /*********************************** EFFECTS **********************************/
  206. /******************************************************************************/
  207. ( function() {
  208. if ( $.expr && $.expr.pseudos && $.expr.pseudos.animated ) {
  209. $.expr.pseudos.animated = ( function( orig ) {
  210. return function( elem ) {
  211. return !!$( elem ).data( dataSpaceAnimated ) || orig( elem );
  212. };
  213. } )( $.expr.pseudos.animated );
  214. }
  215. if ( $.uiBackCompat === true ) {
  216. $.extend( $.effects, {
  217. // Saves a set of properties in a data storage
  218. save: function( element, set ) {
  219. var i = 0, length = set.length;
  220. for ( ; i < length; i++ ) {
  221. if ( set[ i ] !== null ) {
  222. element.data( dataSpace + set[ i ], element[ 0 ].style[ set[ i ] ] );
  223. }
  224. }
  225. },
  226. // Restores a set of previously saved properties from a data storage
  227. restore: function( element, set ) {
  228. var val, i = 0, length = set.length;
  229. for ( ; i < length; i++ ) {
  230. if ( set[ i ] !== null ) {
  231. val = element.data( dataSpace + set[ i ] );
  232. element.css( set[ i ], val );
  233. }
  234. }
  235. },
  236. setMode: function( el, mode ) {
  237. if ( mode === "toggle" ) {
  238. mode = el.is( ":hidden" ) ? "show" : "hide";
  239. }
  240. return mode;
  241. },
  242. // Wraps the element around a wrapper that copies position properties
  243. createWrapper: function( element ) {
  244. // If the element is already wrapped, return it
  245. if ( element.parent().is( ".ui-effects-wrapper" ) ) {
  246. return element.parent();
  247. }
  248. // Wrap the element
  249. var props = {
  250. width: element.outerWidth( true ),
  251. height: element.outerHeight( true ),
  252. "float": element.css( "float" )
  253. },
  254. wrapper = $( "<div></div>" )
  255. .addClass( "ui-effects-wrapper" )
  256. .css( {
  257. fontSize: "100%",
  258. background: "transparent",
  259. border: "none",
  260. margin: 0,
  261. padding: 0
  262. } ),
  263. // Store the size in case width/height are defined in % - Fixes #5245
  264. size = {
  265. width: element.width(),
  266. height: element.height()
  267. },
  268. active = document.activeElement;
  269. // Support: Firefox
  270. // Firefox incorrectly exposes anonymous content
  271. // https://bugzilla.mozilla.org/show_bug.cgi?id=561664
  272. try {
  273. // eslint-disable-next-line no-unused-expressions
  274. active.id;
  275. } catch ( e ) {
  276. active = document.body;
  277. }
  278. element.wrap( wrapper );
  279. // Fixes #7595 - Elements lose focus when wrapped.
  280. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  281. $( active ).trigger( "focus" );
  282. }
  283. // Hotfix for jQuery 1.4 since some change in wrap() seems to actually
  284. // lose the reference to the wrapped element
  285. wrapper = element.parent();
  286. // Transfer positioning properties to the wrapper
  287. if ( element.css( "position" ) === "static" ) {
  288. wrapper.css( { position: "relative" } );
  289. element.css( { position: "relative" } );
  290. } else {
  291. $.extend( props, {
  292. position: element.css( "position" ),
  293. zIndex: element.css( "z-index" )
  294. } );
  295. $.each( [ "top", "left", "bottom", "right" ], function( i, pos ) {
  296. props[ pos ] = element.css( pos );
  297. if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
  298. props[ pos ] = "auto";
  299. }
  300. } );
  301. element.css( {
  302. position: "relative",
  303. top: 0,
  304. left: 0,
  305. right: "auto",
  306. bottom: "auto"
  307. } );
  308. }
  309. element.css( size );
  310. return wrapper.css( props ).show();
  311. },
  312. removeWrapper: function( element ) {
  313. var active = document.activeElement;
  314. if ( element.parent().is( ".ui-effects-wrapper" ) ) {
  315. element.parent().replaceWith( element );
  316. // Fixes #7595 - Elements lose focus when wrapped.
  317. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  318. $( active ).trigger( "focus" );
  319. }
  320. }
  321. return element;
  322. }
  323. } );
  324. }
  325. $.extend( $.effects, {
  326. version: "1.14.1",
  327. define: function( name, mode, effect ) {
  328. if ( !effect ) {
  329. effect = mode;
  330. mode = "effect";
  331. }
  332. $.effects.effect[ name ] = effect;
  333. $.effects.effect[ name ].mode = mode;
  334. return effect;
  335. },
  336. scaledDimensions: function( element, percent, direction ) {
  337. if ( percent === 0 ) {
  338. return {
  339. height: 0,
  340. width: 0,
  341. outerHeight: 0,
  342. outerWidth: 0
  343. };
  344. }
  345. var x = direction !== "horizontal" ? ( ( percent || 100 ) / 100 ) : 1,
  346. y = direction !== "vertical" ? ( ( percent || 100 ) / 100 ) : 1;
  347. return {
  348. height: element.height() * y,
  349. width: element.width() * x,
  350. outerHeight: element.outerHeight() * y,
  351. outerWidth: element.outerWidth() * x
  352. };
  353. },
  354. clipToBox: function( animation ) {
  355. return {
  356. width: animation.clip.right - animation.clip.left,
  357. height: animation.clip.bottom - animation.clip.top,
  358. left: animation.clip.left,
  359. top: animation.clip.top
  360. };
  361. },
  362. // Injects recently queued functions to be first in line (after "inprogress")
  363. unshift: function( element, queueLength, count ) {
  364. var queue = element.queue();
  365. if ( queueLength > 1 ) {
  366. queue.splice.apply( queue,
  367. [ 1, 0 ].concat( queue.splice( queueLength, count ) ) );
  368. }
  369. element.dequeue();
  370. },
  371. saveStyle: function( element ) {
  372. element.data( dataSpaceStyle, element[ 0 ].style.cssText );
  373. },
  374. restoreStyle: function( element ) {
  375. element[ 0 ].style.cssText = element.data( dataSpaceStyle ) || "";
  376. element.removeData( dataSpaceStyle );
  377. },
  378. mode: function( element, mode ) {
  379. var hidden = element.is( ":hidden" );
  380. if ( mode === "toggle" ) {
  381. mode = hidden ? "show" : "hide";
  382. }
  383. if ( hidden ? mode === "hide" : mode === "show" ) {
  384. mode = "none";
  385. }
  386. return mode;
  387. },
  388. // Translates a [top,left] array into a baseline value
  389. getBaseline: function( origin, original ) {
  390. var y, x;
  391. switch ( origin[ 0 ] ) {
  392. case "top":
  393. y = 0;
  394. break;
  395. case "middle":
  396. y = 0.5;
  397. break;
  398. case "bottom":
  399. y = 1;
  400. break;
  401. default:
  402. y = origin[ 0 ] / original.height;
  403. }
  404. switch ( origin[ 1 ] ) {
  405. case "left":
  406. x = 0;
  407. break;
  408. case "center":
  409. x = 0.5;
  410. break;
  411. case "right":
  412. x = 1;
  413. break;
  414. default:
  415. x = origin[ 1 ] / original.width;
  416. }
  417. return {
  418. x: x,
  419. y: y
  420. };
  421. },
  422. // Creates a placeholder element so that the original element can be made absolute
  423. createPlaceholder: function( element ) {
  424. var placeholder,
  425. cssPosition = element.css( "position" ),
  426. position = element.position();
  427. // Lock in margins first to account for form elements, which
  428. // will change margin if you explicitly set height
  429. // see: https://jsfiddle.net/JZSMt/3/ https://bugs.webkit.org/show_bug.cgi?id=107380
  430. // Support: Safari
  431. element.css( {
  432. marginTop: element.css( "marginTop" ),
  433. marginBottom: element.css( "marginBottom" ),
  434. marginLeft: element.css( "marginLeft" ),
  435. marginRight: element.css( "marginRight" )
  436. } )
  437. .outerWidth( element.outerWidth() )
  438. .outerHeight( element.outerHeight() );
  439. if ( /^(static|relative)/.test( cssPosition ) ) {
  440. cssPosition = "absolute";
  441. placeholder = $( "<" + element[ 0 ].nodeName + ">" ).insertAfter( element ).css( {
  442. // Convert inline to inline block to account for inline elements
  443. // that turn to inline block based on content (like img)
  444. display: /^(inline|ruby)/.test( element.css( "display" ) ) ?
  445. "inline-block" :
  446. "block",
  447. visibility: "hidden",
  448. // Margins need to be set to account for margin collapse
  449. marginTop: element.css( "marginTop" ),
  450. marginBottom: element.css( "marginBottom" ),
  451. marginLeft: element.css( "marginLeft" ),
  452. marginRight: element.css( "marginRight" ),
  453. "float": element.css( "float" )
  454. } )
  455. .outerWidth( element.outerWidth() )
  456. .outerHeight( element.outerHeight() )
  457. .addClass( "ui-effects-placeholder" );
  458. element.data( dataSpace + "placeholder", placeholder );
  459. }
  460. element.css( {
  461. position: cssPosition,
  462. left: position.left,
  463. top: position.top
  464. } );
  465. return placeholder;
  466. },
  467. removePlaceholder: function( element ) {
  468. var dataKey = dataSpace + "placeholder",
  469. placeholder = element.data( dataKey );
  470. if ( placeholder ) {
  471. placeholder.remove();
  472. element.removeData( dataKey );
  473. }
  474. },
  475. // Removes a placeholder if it exists and restores
  476. // properties that were modified during placeholder creation
  477. cleanUp: function( element ) {
  478. $.effects.restoreStyle( element );
  479. $.effects.removePlaceholder( element );
  480. },
  481. setTransition: function( element, list, factor, value ) {
  482. value = value || {};
  483. $.each( list, function( i, x ) {
  484. var unit = element.cssUnit( x );
  485. if ( unit[ 0 ] > 0 ) {
  486. value[ x ] = unit[ 0 ] * factor + unit[ 1 ];
  487. }
  488. } );
  489. return value;
  490. }
  491. } );
  492. // Return an effect options object for the given parameters:
  493. function _normalizeArguments( effect, options, speed, callback ) {
  494. // Allow passing all options as the first parameter
  495. if ( $.isPlainObject( effect ) ) {
  496. options = effect;
  497. effect = effect.effect;
  498. }
  499. // Convert to an object
  500. effect = { effect: effect };
  501. // Catch (effect, null, ...)
  502. if ( options == null ) {
  503. options = {};
  504. }
  505. // Catch (effect, callback)
  506. if ( typeof options === "function" ) {
  507. callback = options;
  508. speed = null;
  509. options = {};
  510. }
  511. // Catch (effect, speed, ?)
  512. if ( typeof options === "number" || $.fx.speeds[ options ] ) {
  513. callback = speed;
  514. speed = options;
  515. options = {};
  516. }
  517. // Catch (effect, options, callback)
  518. if ( typeof speed === "function" ) {
  519. callback = speed;
  520. speed = null;
  521. }
  522. // Add options to effect
  523. if ( options ) {
  524. $.extend( effect, options );
  525. }
  526. speed = speed || options.duration;
  527. effect.duration = $.fx.off ? 0 :
  528. typeof speed === "number" ? speed :
  529. speed in $.fx.speeds ? $.fx.speeds[ speed ] :
  530. $.fx.speeds._default;
  531. effect.complete = callback || options.complete;
  532. return effect;
  533. }
  534. function standardAnimationOption( option ) {
  535. // Valid standard speeds (nothing, number, named speed)
  536. if ( !option || typeof option === "number" || $.fx.speeds[ option ] ) {
  537. return true;
  538. }
  539. // Invalid strings - treat as "normal" speed
  540. if ( typeof option === "string" && !$.effects.effect[ option ] ) {
  541. return true;
  542. }
  543. // Complete callback
  544. if ( typeof option === "function" ) {
  545. return true;
  546. }
  547. // Options hash (but not naming an effect)
  548. if ( typeof option === "object" && !option.effect ) {
  549. return true;
  550. }
  551. // Didn't match any standard API
  552. return false;
  553. }
  554. $.fn.extend( {
  555. effect: function( /* effect, options, speed, callback */ ) {
  556. var args = _normalizeArguments.apply( this, arguments ),
  557. effectMethod = $.effects.effect[ args.effect ],
  558. defaultMode = effectMethod.mode,
  559. queue = args.queue,
  560. queueName = queue || "fx",
  561. complete = args.complete,
  562. mode = args.mode,
  563. modes = [],
  564. prefilter = function( next ) {
  565. var el = $( this ),
  566. normalizedMode = $.effects.mode( el, mode ) || defaultMode;
  567. // Sentinel for duck-punching the :animated pseudo-selector
  568. el.data( dataSpaceAnimated, true );
  569. // Save effect mode for later use,
  570. // we can't just call $.effects.mode again later,
  571. // as the .show() below destroys the initial state
  572. modes.push( normalizedMode );
  573. // See $.uiBackCompat inside of run() for removal of defaultMode in 1.14
  574. if ( defaultMode && ( normalizedMode === "show" ||
  575. ( normalizedMode === defaultMode && normalizedMode === "hide" ) ) ) {
  576. el.show();
  577. }
  578. if ( !defaultMode || normalizedMode !== "none" ) {
  579. $.effects.saveStyle( el );
  580. }
  581. if ( typeof next === "function" ) {
  582. next();
  583. }
  584. };
  585. if ( $.fx.off || !effectMethod ) {
  586. // Delegate to the original method (e.g., .show()) if possible
  587. if ( mode ) {
  588. return this[ mode ]( args.duration, complete );
  589. } else {
  590. return this.each( function() {
  591. if ( complete ) {
  592. complete.call( this );
  593. }
  594. } );
  595. }
  596. }
  597. function run( next ) {
  598. var elem = $( this );
  599. function cleanup() {
  600. elem.removeData( dataSpaceAnimated );
  601. $.effects.cleanUp( elem );
  602. if ( args.mode === "hide" ) {
  603. elem.hide();
  604. }
  605. done();
  606. }
  607. function done() {
  608. if ( typeof complete === "function" ) {
  609. complete.call( elem[ 0 ] );
  610. }
  611. if ( typeof next === "function" ) {
  612. next();
  613. }
  614. }
  615. // Override mode option on a per element basis,
  616. // as toggle can be either show or hide depending on element state
  617. args.mode = modes.shift();
  618. if ( $.uiBackCompat === true && !defaultMode ) {
  619. if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) {
  620. // Call the core method to track "olddisplay" properly
  621. elem[ mode ]();
  622. done();
  623. } else {
  624. effectMethod.call( elem[ 0 ], args, done );
  625. }
  626. } else {
  627. if ( args.mode === "none" ) {
  628. // Call the core method to track "olddisplay" properly
  629. elem[ mode ]();
  630. done();
  631. } else {
  632. effectMethod.call( elem[ 0 ], args, cleanup );
  633. }
  634. }
  635. }
  636. // Run prefilter on all elements first to ensure that
  637. // any showing or hiding happens before placeholder creation,
  638. // which ensures that any layout changes are correctly captured.
  639. return queue === false ?
  640. this.each( prefilter ).each( run ) :
  641. this.queue( queueName, prefilter ).queue( queueName, run );
  642. },
  643. show: ( function( orig ) {
  644. return function( option ) {
  645. if ( standardAnimationOption( option ) ) {
  646. return orig.apply( this, arguments );
  647. } else {
  648. var args = _normalizeArguments.apply( this, arguments );
  649. args.mode = "show";
  650. return this.effect.call( this, args );
  651. }
  652. };
  653. } )( $.fn.show ),
  654. hide: ( function( orig ) {
  655. return function( option ) {
  656. if ( standardAnimationOption( option ) ) {
  657. return orig.apply( this, arguments );
  658. } else {
  659. var args = _normalizeArguments.apply( this, arguments );
  660. args.mode = "hide";
  661. return this.effect.call( this, args );
  662. }
  663. };
  664. } )( $.fn.hide ),
  665. toggle: ( function( orig ) {
  666. return function( option ) {
  667. if ( standardAnimationOption( option ) || typeof option === "boolean" ) {
  668. return orig.apply( this, arguments );
  669. } else {
  670. var args = _normalizeArguments.apply( this, arguments );
  671. args.mode = "toggle";
  672. return this.effect.call( this, args );
  673. }
  674. };
  675. } )( $.fn.toggle ),
  676. cssUnit: function( key ) {
  677. var style = this.css( key ),
  678. val = [];
  679. $.each( [ "em", "px", "%", "pt" ], function( i, unit ) {
  680. if ( style.indexOf( unit ) > 0 ) {
  681. val = [ parseFloat( style ), unit ];
  682. }
  683. } );
  684. return val;
  685. },
  686. cssClip: function( clipObj ) {
  687. if ( clipObj ) {
  688. return this.css( "clip", "rect(" + clipObj.top + "px " + clipObj.right + "px " +
  689. clipObj.bottom + "px " + clipObj.left + "px)" );
  690. }
  691. return parseClip( this.css( "clip" ), this );
  692. },
  693. transfer: function( options, done ) {
  694. var element = $( this ),
  695. target = $( options.to ),
  696. targetFixed = target.css( "position" ) === "fixed",
  697. body = $( "body" ),
  698. fixTop = targetFixed ? body.scrollTop() : 0,
  699. fixLeft = targetFixed ? body.scrollLeft() : 0,
  700. endPosition = target.offset(),
  701. animation = {
  702. top: endPosition.top - fixTop,
  703. left: endPosition.left - fixLeft,
  704. height: target.innerHeight(),
  705. width: target.innerWidth()
  706. },
  707. startPosition = element.offset(),
  708. transfer = $( "<div class='ui-effects-transfer'></div>" );
  709. transfer
  710. .appendTo( "body" )
  711. .addClass( options.className )
  712. .css( {
  713. top: startPosition.top - fixTop,
  714. left: startPosition.left - fixLeft,
  715. height: element.innerHeight(),
  716. width: element.innerWidth(),
  717. position: targetFixed ? "fixed" : "absolute"
  718. } )
  719. .animate( animation, options.duration, options.easing, function() {
  720. transfer.remove();
  721. if ( typeof done === "function" ) {
  722. done();
  723. }
  724. } );
  725. }
  726. } );
  727. function parseClip( str, element ) {
  728. var outerWidth = element.outerWidth(),
  729. outerHeight = element.outerHeight(),
  730. clipRegex = /^rect\((-?\d*\.?\d*px|-?\d+%|auto),?\s*(-?\d*\.?\d*px|-?\d+%|auto),?\s*(-?\d*\.?\d*px|-?\d+%|auto),?\s*(-?\d*\.?\d*px|-?\d+%|auto)\)$/,
  731. values = clipRegex.exec( str ) || [ "", 0, outerWidth, outerHeight, 0 ];
  732. return {
  733. top: parseFloat( values[ 1 ] ) || 0,
  734. right: values[ 2 ] === "auto" ? outerWidth : parseFloat( values[ 2 ] ),
  735. bottom: values[ 3 ] === "auto" ? outerHeight : parseFloat( values[ 3 ] ),
  736. left: parseFloat( values[ 4 ] ) || 0
  737. };
  738. }
  739. $.fx.step.clip = function( fx ) {
  740. if ( !fx.clipInit ) {
  741. fx.start = $( fx.elem ).cssClip();
  742. if ( typeof fx.end === "string" ) {
  743. fx.end = parseClip( fx.end, fx.elem );
  744. }
  745. fx.clipInit = true;
  746. }
  747. $( fx.elem ).cssClip( {
  748. top: fx.pos * ( fx.end.top - fx.start.top ) + fx.start.top,
  749. right: fx.pos * ( fx.end.right - fx.start.right ) + fx.start.right,
  750. bottom: fx.pos * ( fx.end.bottom - fx.start.bottom ) + fx.start.bottom,
  751. left: fx.pos * ( fx.end.left - fx.start.left ) + fx.start.left
  752. } );
  753. };
  754. } )();
  755. /******************************************************************************/
  756. /*********************************** EASING ***********************************/
  757. /******************************************************************************/
  758. ( function() {
  759. // Based on easing equations from Robert Penner (http://robertpenner.com/easing)
  760. var baseEasings = {};
  761. $.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i, name ) {
  762. baseEasings[ name ] = function( p ) {
  763. return Math.pow( p, i + 2 );
  764. };
  765. } );
  766. $.extend( baseEasings, {
  767. Sine: function( p ) {
  768. return 1 - Math.cos( p * Math.PI / 2 );
  769. },
  770. Circ: function( p ) {
  771. return 1 - Math.sqrt( 1 - p * p );
  772. },
  773. Elastic: function( p ) {
  774. return p === 0 || p === 1 ? p :
  775. -Math.pow( 2, 8 * ( p - 1 ) ) * Math.sin( ( ( p - 1 ) * 80 - 7.5 ) * Math.PI / 15 );
  776. },
  777. Back: function( p ) {
  778. return p * p * ( 3 * p - 2 );
  779. },
  780. Bounce: function( p ) {
  781. var pow2,
  782. bounce = 4;
  783. while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
  784. return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );
  785. }
  786. } );
  787. $.each( baseEasings, function( name, easeIn ) {
  788. $.easing[ "easeIn" + name ] = easeIn;
  789. $.easing[ "easeOut" + name ] = function( p ) {
  790. return 1 - easeIn( 1 - p );
  791. };
  792. $.easing[ "easeInOut" + name ] = function( p ) {
  793. return p < 0.5 ?
  794. easeIn( p * 2 ) / 2 :
  795. 1 - easeIn( p * -2 + 2 ) / 2;
  796. };
  797. } );
  798. } )();
  799. return $.effects;
  800. } );