jquery.ui.effect-blind.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*!
  2. * jQuery UI Effects Blind 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/blind-effect/
  10. *
  11. * Depends:
  12. * jquery.ui.effect.js
  13. */
  14. (function( $, undefined ) {
  15. var rvertical = /up|down|vertical/,
  16. rpositivemotion = /up|left|vertical|horizontal/;
  17. $.effects.effect.blind = function( o, done ) {
  18. // Create element
  19. var el = $( this ),
  20. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  21. mode = $.effects.setMode( el, o.mode || "hide" ),
  22. direction = o.direction || "up",
  23. vertical = rvertical.test( direction ),
  24. ref = vertical ? "height" : "width",
  25. ref2 = vertical ? "top" : "left",
  26. motion = rpositivemotion.test( direction ),
  27. animation = {},
  28. show = mode === "show",
  29. wrapper, distance, margin;
  30. // if already wrapped, the wrapper's properties are my property. #6245
  31. if ( el.parent().is( ".ui-effects-wrapper" ) ) {
  32. $.effects.save( el.parent(), props );
  33. } else {
  34. $.effects.save( el, props );
  35. }
  36. el.show();
  37. wrapper = $.effects.createWrapper( el ).css({
  38. overflow: "hidden"
  39. });
  40. distance = wrapper[ ref ]();
  41. margin = parseFloat( wrapper.css( ref2 ) ) || 0;
  42. animation[ ref ] = show ? distance : 0;
  43. if ( !motion ) {
  44. el
  45. .css( vertical ? "bottom" : "right", 0 )
  46. .css( vertical ? "top" : "left", "auto" )
  47. .css({ position: "absolute" });
  48. animation[ ref2 ] = show ? margin : distance + margin;
  49. }
  50. // start at 0 if we are showing
  51. if ( show ) {
  52. wrapper.css( ref, 0 );
  53. if ( ! motion ) {
  54. wrapper.css( ref2, margin + distance );
  55. }
  56. }
  57. // Animate
  58. wrapper.animate( animation, {
  59. duration: o.duration,
  60. easing: o.easing,
  61. queue: false,
  62. complete: function() {
  63. if ( mode === "hide" ) {
  64. el.hide();
  65. }
  66. $.effects.restore( el, props );
  67. $.effects.removeWrapper( el );
  68. done();
  69. }
  70. });
  71. };
  72. })(jQuery);