effect-fold.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*!
  2. * jQuery UI Effects Fold 1.11.4
  3. * http://jqueryui.com
  4. *
  5. * Copyright jQuery Foundation and other contributors
  6. * Released under the MIT license.
  7. * http://jquery.org/license
  8. *
  9. * http://api.jqueryui.com/fold-effect/
  10. */
  11. (function( factory ) {
  12. if ( typeof define === "function" && define.amd ) {
  13. // AMD. Register as an anonymous module.
  14. define([
  15. "jquery",
  16. "./effect"
  17. ], factory );
  18. } else {
  19. // Browser globals
  20. factory( jQuery );
  21. }
  22. }(function( $ ) {
  23. return $.effects.effect.fold = function( o, done ) {
  24. // Create element
  25. var el = $( this ),
  26. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  27. mode = $.effects.setMode( el, o.mode || "hide" ),
  28. show = mode === "show",
  29. hide = mode === "hide",
  30. size = o.size || 15,
  31. percent = /([0-9]+)%/.exec( size ),
  32. horizFirst = !!o.horizFirst,
  33. widthFirst = show !== horizFirst,
  34. ref = widthFirst ? [ "width", "height" ] : [ "height", "width" ],
  35. duration = o.duration / 2,
  36. wrapper, distance,
  37. animation1 = {},
  38. animation2 = {};
  39. $.effects.save( el, props );
  40. el.show();
  41. // Create Wrapper
  42. wrapper = $.effects.createWrapper( el ).css({
  43. overflow: "hidden"
  44. });
  45. distance = widthFirst ?
  46. [ wrapper.width(), wrapper.height() ] :
  47. [ wrapper.height(), wrapper.width() ];
  48. if ( percent ) {
  49. size = parseInt( percent[ 1 ], 10 ) / 100 * distance[ hide ? 0 : 1 ];
  50. }
  51. if ( show ) {
  52. wrapper.css( horizFirst ? {
  53. height: 0,
  54. width: size
  55. } : {
  56. height: size,
  57. width: 0
  58. });
  59. }
  60. // Animation
  61. animation1[ ref[ 0 ] ] = show ? distance[ 0 ] : size;
  62. animation2[ ref[ 1 ] ] = show ? distance[ 1 ] : 0;
  63. // Animate
  64. wrapper
  65. .animate( animation1, duration, o.easing )
  66. .animate( animation2, duration, o.easing, function() {
  67. if ( hide ) {
  68. el.hide();
  69. }
  70. $.effects.restore( el, props );
  71. $.effects.removeWrapper( el );
  72. done();
  73. });
  74. };
  75. }));