jquery.ba-resize.min.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * jQuery resize event - v1.1 - 3/14/2010
  3. * http://benalman.com/projects/jquery-resize-plugin/
  4. *
  5. * Copyright (c) 2010 "Cowboy" Ben Alman
  6. * Dual licensed under the MIT and GPL licenses.
  7. * http://benalman.com/about/license/
  8. */
  9. (function($, h, c) {
  10. var a = $([]),
  11. e = $.resize = $.extend($.resize, {}),
  12. i, k = "setTimeout",
  13. j = "resize",
  14. d = j + "-special-event",
  15. b = "delay",
  16. f = "throttleWindow";
  17. e[b] = 250;
  18. e[f] = true;
  19. $.event.special[j] = {
  20. setup: function() {
  21. if (!e[f] && this[k]) {
  22. return false
  23. }
  24. var l = $(this);
  25. a = a.add(l);
  26. $.data(this, d, {
  27. w: l.width(),
  28. h: l.height()
  29. });
  30. if (a.length === 1) {
  31. g()
  32. }
  33. },
  34. teardown: function() {
  35. if (!e[f] && this[k]) {
  36. return false
  37. }
  38. var l = $(this);
  39. a = a.not(l);
  40. l.removeData(d);
  41. if (!a.length) {
  42. clearTimeout(i)
  43. }
  44. },
  45. add: function(l) {
  46. if (!e[f] && this[k]) {
  47. return false
  48. }
  49. var n;
  50. function m(s, o, p) {
  51. var q = $(this),
  52. r = $.data(this, d);
  53. r.w = o !== c ? o : q.width();
  54. r.h = p !== c ? p : q.height();
  55. n.apply(this, arguments)
  56. }
  57. if ($.isFunction(l)) {
  58. n = l;
  59. return m
  60. } else {
  61. n = l.handler;
  62. l.handler = m
  63. }
  64. }
  65. };
  66. function g() {
  67. i = h[k](function() {
  68. a.each(function() {
  69. var n = $(this),
  70. m = n.width(),
  71. l = n.height(),
  72. o = $.data(this, d);
  73. if (m !== o.w || l !== o.h) {
  74. n.trigger(j, [o.w = m, o.h = l])
  75. }
  76. });
  77. g()
  78. }, e[b])
  79. }
  80. })(jQuery, this);