effects.fold.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * jQuery UI Effects Fold 1.7.2
  3. *
  4. * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
  5. * Dual licensed under the MIT (MIT-LICENSE.txt)
  6. * and GPL (GPL-LICENSE.txt) licenses.
  7. *
  8. * http://docs.jquery.com/UI/Effects/Fold
  9. *
  10. * Depends:
  11. * effects.core.js
  12. */
  13. (function($) {
  14. $.effects.fold = function(o) {
  15. return this.queue(function() {
  16. // Create element
  17. var el = $(this), props = ['position','top','left'];
  18. // Set options
  19. var mode = $.effects.setMode(el, o.options.mode || 'hide'); // Set Mode
  20. var size = o.options.size || 15; // Default fold size
  21. var horizFirst = !(!o.options.horizFirst); // Ensure a boolean value
  22. var duration = o.duration ? o.duration / 2 : $.fx.speeds._default / 2;
  23. // Adjust
  24. $.effects.save(el, props); el.show(); // Save & Show
  25. var wrapper = $.effects.createWrapper(el).css({overflow:'hidden'}); // Create Wrapper
  26. var widthFirst = ((mode == 'show') != horizFirst);
  27. var ref = widthFirst ? ['width', 'height'] : ['height', 'width'];
  28. var distance = widthFirst ? [wrapper.width(), wrapper.height()] : [wrapper.height(), wrapper.width()];
  29. var percent = /([0-9]+)%/.exec(size);
  30. if(percent) size = parseInt(percent[1],10) / 100 * distance[mode == 'hide' ? 0 : 1];
  31. if(mode == 'show') wrapper.css(horizFirst ? {height: 0, width: size} : {height: size, width: 0}); // Shift
  32. // Animation
  33. var animation1 = {}, animation2 = {};
  34. animation1[ref[0]] = mode == 'show' ? distance[0] : size;
  35. animation2[ref[1]] = mode == 'show' ? distance[1] : 0;
  36. // Animate
  37. wrapper.animate(animation1, duration, o.options.easing)
  38. .animate(animation2, duration, o.options.easing, function() {
  39. if(mode == 'hide') el.hide(); // Hide
  40. $.effects.restore(el, props); $.effects.removeWrapper(el); // Restore
  41. if(o.callback) o.callback.apply(el[0], arguments); // Callback
  42. el.dequeue();
  43. });
  44. });
  45. };
  46. })(jQuery);