jquery.ui.effect-fold.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*!
  2. * jQuery UI Effects Fold v1.9 stable
  3. * http://jqueryui.com
  4. *
  5. * Copyright 2012 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. * Depends:
  12. * jquery.ui.effect.js
  13. */
  14. (function( $, undefined ) {
  15. $.effects.effect.fold = function( o, done ) {
  16. // Create element
  17. var el = $( this ),
  18. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  19. mode = $.effects.setMode( el, o.mode || "hide" ),
  20. show = mode === "show",
  21. hide = mode === "hide",
  22. size = o.size || 15,
  23. percent = /([0-9]+)%/.exec( size ),
  24. horizFirst = !!o.horizFirst,
  25. widthFirst = show !== horizFirst,
  26. ref = widthFirst ? [ "width", "height" ] : [ "height", "width" ],
  27. duration = o.duration / 2,
  28. wrapper, distance,
  29. animation1 = {},
  30. animation2 = {};
  31. $.effects.save( el, props );
  32. el.show();
  33. // Create Wrapper
  34. wrapper = $.effects.createWrapper( el ).css({
  35. overflow: "hidden"
  36. });
  37. distance = widthFirst ?
  38. [ wrapper.width(), wrapper.height() ] :
  39. [ wrapper.height(), wrapper.width() ];
  40. if ( percent ) {
  41. size = parseInt( percent[ 1 ], 10 ) / 100 * distance[ hide ? 0 : 1 ];
  42. }
  43. if ( show ) {
  44. wrapper.css( horizFirst ? {
  45. height: 0,
  46. width: size
  47. } : {
  48. height: size,
  49. width: 0
  50. });
  51. }
  52. // Animation
  53. animation1[ ref[ 0 ] ] = show ? distance[ 0 ] : size;
  54. animation2[ ref[ 1 ] ] = show ? distance[ 1 ] : 0;
  55. // Animate
  56. wrapper
  57. .animate( animation1, duration, o.easing )
  58. .animate( animation2, duration, o.easing, function() {
  59. if ( hide ) {
  60. el.hide();
  61. }
  62. $.effects.restore( el, props );
  63. $.effects.removeWrapper( el );
  64. done();
  65. });
  66. };
  67. })(jQuery);