Greasy Fork is available in English.

jQueryResize

jQueryResize Library

ეს სკრიპტი არ უნდა იყოს პირდაპირ დაინსტალირებული. ეს ბიბლიოთეკაა, სხვა სკრიპტებისთვის უნდა ჩართეთ მეტა-დირექტივაში // @require https://update.greatest.deepsurf.us/scripts/377563/669077/jQueryResize.js.

  1. /*
  2. * Custom resize jQuery event for element version 1.0.1
  3. *
  4. * Copyright (c) 2018 Jakub Jankiewicz <http://jcubic.pl/me>
  5. * Released under the MIT license
  6. *
  7. * based on marcj/css-element-queries same license
  8. */
  9.  
  10. /* global jQuery, ResizeObserver */
  11. (function($) {
  12. "use strict";
  13. // ----------------------------------------------------------------------------------
  14. // :: Cross-browser resize element plugin
  15. // :: Taken from ResizeSensor.js file from marcj/css-element-queries (MIT license)
  16. // :: updated by jQuery Terminal (same license)
  17. // :: usage:
  18. // :: to add callback use:
  19. // :: $('node').resize(handler_function);
  20. // :: to remove use:
  21. // :: $('node').resize('unbind', handler_function);
  22. // :: handler function in unbind is optional if omitted all handlers will be removed
  23. // ----------------------------------------------------------------------------------
  24. $.fn.resizer = function(callback) {
  25. var unbind = arguments[0] === "unbind";
  26. if (!unbind && !$.isFunction(callback)) {
  27. throw new Error(
  28. 'Invalid argument, it need to a function or string "unbind".'
  29. );
  30. }
  31. if (unbind) {
  32. callback = $.isFunction(arguments[1]) ? arguments[1] : null;
  33. }
  34. return this.each(function() {
  35. var $this = $(this);
  36. var callbacks;
  37. if (unbind) {
  38. callbacks = $this.data('callbacks');
  39. if (callback && callbacks) {
  40. callbacks.remove(callback);
  41. if (!callbacks.has()) {
  42. callbacks = null;
  43. }
  44. } else {
  45. callbacks = null;
  46. }
  47. if (!callbacks) {
  48. $this.removeData('callbacks');
  49. if (window.ResizeObserver) {
  50. var observer = $this.data('observer');
  51. if (observer) {
  52. observer.unobserve(this);
  53. $this.removeData('observer');
  54. }
  55. } else {
  56. $this.find('.resizer').remove();
  57. }
  58. }
  59. } else if ($this.data('callbacks')) {
  60. $this.data('callbacks').add(callback);
  61. } else {
  62. callbacks = $.Callbacks();
  63. callbacks.add(callback);
  64. $this.data('callbacks', callbacks);
  65. var resizer;
  66. var first = true;
  67. if (window.ResizeObserver) {
  68. resizer = new ResizeObserver(function() {
  69. if (!first) {
  70. var callbacks = $this.data('callbacks');
  71. callbacks.fireWith($this[0], $.Event('resize'));
  72. }
  73. first = false;
  74. });
  75. resizer.observe(this);
  76. $this.data('observer', resizer);
  77. return;
  78. }
  79. var self = this;
  80. resizer = $('<div/>').addClass('resizer').appendTo(this)[0];
  81. var style =
  82. 'position: absolute; left: 0; top: 0; right: 0; bottom: 0; ' +
  83. 'overflow: hidden; z-index: -1; visibility: hidden;';
  84. var styleChild = 'position: absolute; left: 0; top: 0; transition: 0s;';
  85. resizer.style.cssText = style;
  86. resizer.innerHTML =
  87. '<div class="resize-sensor-expand" style="' + style + '">' +
  88. '<div style="' + styleChild + '"></div>' + "</div>" +
  89. '<div class="resize-sensor-shrink" style="' + style + '">' +
  90. '<div style="' + styleChild + ' width: 200%; height: 200%"></div>' +
  91. "</div>";
  92.  
  93. var expand = resizer.childNodes[0];
  94. var expandChild = expand.childNodes[0];
  95. var shrink = resizer.childNodes[1];
  96. var dirty, rafId, newWidth, newHeight;
  97. var lastWidth = self.offsetWidth;
  98. var lastHeight = self.offsetHeight;
  99.  
  100. var reset = function() {
  101. expandChild.style.width = '100000px';
  102. expandChild.style.height = '100000px';
  103.  
  104. expand.scrollLeft = 100000;
  105. expand.scrollTop = 100000;
  106.  
  107. shrink.scrollLeft = 100000;
  108. shrink.scrollTop = 100000;
  109. };
  110.  
  111. reset();
  112.  
  113. var onResized = function() {
  114. rafId = 0;
  115.  
  116. if (!dirty) {
  117. return;
  118. }
  119.  
  120. lastWidth = newWidth;
  121. lastHeight = newHeight;
  122. callbacks.fireWith($this[0], $.Event('resize'));
  123. };
  124.  
  125. var onScroll = function() {
  126. newWidth = self.offsetWidth;
  127. newHeight = self.offsetHeight;
  128. dirty = newWidth !== lastWidth || newHeight !== lastHeight;
  129.  
  130. if (dirty && !rafId) {
  131. rafId = requestAnimationFrame(onResized);
  132. }
  133.  
  134. reset();
  135. };
  136. $(expand).on("scroll", onScroll);
  137. $(shrink).on("scroll", onScroll);
  138. }
  139. });
  140. };
  141. var window_events = $.Callbacks();
  142. // custom resize jQuery event with handling of default window resize
  143. $.event.special.resize = {
  144. setup: function(data, namespaces, eventHandle) {
  145. if (this === window) {
  146. window.addEventListener('resize', eventHandle);
  147. }
  148. },
  149. teardown: function() {
  150. window.removeEventListener('resize');
  151. },
  152. add: function(handleObj) {
  153. if (this === window) {
  154. window_events.add(handleObj.handler);
  155. } else {
  156. $(this).resizer(handleObj.handler);
  157. }
  158. },
  159. remove: function(handleObj) {
  160. if (this === window) {
  161. if (!handleObj.handler) {
  162. window_events.empty();
  163. } else {
  164. window_events.remove(handleObj.handler);
  165. }
  166. } else {
  167. $(this).resizer('unbind', handleObj.handler);
  168. }
  169. },
  170. handle: function(event, data) {
  171. window_events.fireWith(window, event, data);
  172. }
  173. };
  174. })(jQuery);