effect-scale.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*!
  2. * jQuery UI Effects Scale 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/scale-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. "./effect-size"
  18. ], factory );
  19. } else {
  20. // Browser globals
  21. factory( jQuery );
  22. }
  23. }(function( $ ) {
  24. return $.effects.effect.scale = function( o, done ) {
  25. // Create element
  26. var el = $( this ),
  27. options = $.extend( true, {}, o ),
  28. mode = $.effects.setMode( el, o.mode || "effect" ),
  29. percent = parseInt( o.percent, 10 ) ||
  30. ( parseInt( o.percent, 10 ) === 0 ? 0 : ( mode === "hide" ? 0 : 100 ) ),
  31. direction = o.direction || "both",
  32. origin = o.origin,
  33. original = {
  34. height: el.height(),
  35. width: el.width(),
  36. outerHeight: el.outerHeight(),
  37. outerWidth: el.outerWidth()
  38. },
  39. factor = {
  40. y: direction !== "horizontal" ? (percent / 100) : 1,
  41. x: direction !== "vertical" ? (percent / 100) : 1
  42. };
  43. // We are going to pass this effect to the size effect:
  44. options.effect = "size";
  45. options.queue = false;
  46. options.complete = done;
  47. // Set default origin and restore for show/hide
  48. if ( mode !== "effect" ) {
  49. options.origin = origin || [ "middle", "center" ];
  50. options.restore = true;
  51. }
  52. options.from = o.from || ( mode === "show" ? {
  53. height: 0,
  54. width: 0,
  55. outerHeight: 0,
  56. outerWidth: 0
  57. } : original );
  58. options.to = {
  59. height: original.height * factor.y,
  60. width: original.width * factor.x,
  61. outerHeight: original.outerHeight * factor.y,
  62. outerWidth: original.outerWidth * factor.x
  63. };
  64. // Fade option to support puff
  65. if ( options.fade ) {
  66. if ( mode === "show" ) {
  67. options.from.opacity = 0;
  68. options.to.opacity = 1;
  69. }
  70. if ( mode === "hide" ) {
  71. options.from.opacity = 1;
  72. options.to.opacity = 0;
  73. }
  74. }
  75. // Animate
  76. el.effect( options );
  77. };
  78. }));