PageSourceSearch

https://tennisrolan.ru/t/v915/images/js/jquery.equalheightresponsive.js

js tennisrolan.ru collected 2026-10-08 08:14:27 UTC 4,617 bytes, 143 lines download raw bytes

1/*! jQuery.equalHeightResponsive | v.1.6 | 24.04.2015 | http://git.io/OwM7Ow */
2/**
3 * Плагин     : jQuery.equalHeightResponsive
4 * Версия     : 1.6 (24.04.2015)
5 * Репозиторий: http://git.io/OwM7Ow
6 * Автор      : ПафНутиЙ
7 * Twitter    : @pafnuty_name
8 * Назначение : Автоматическое выравнивание высоты блоков (в каждом ряду своя высота) для адаптивных сайтов. Плагин срабатывает при событиях window:
9 * load
10 * resize
11 * equal-refresh
12 *
13 * Плагин основан на коде из поста: http://css-tricks.com/equal-height-blocks-in-rows/
14 *
15 *
16 * Использование:
17 * HTML:
18 * <div class="container">
19 *     <div class="element"></div>
20 *     <div class="element"></div>
21 *     <div class="element"></div>
22 *     <div class="element"></div>
23 * </div>
24 *
25 * jQuery(document).ready(function($) {
26 *     $('.element').equalHeightResponsive();
27 * });
28 *
29 * Для повторной инициализации делаем так:
30 * $('.element').equalHeightResponsive('refresh');
31 * или
32 * $('.element').trigger('equal-refresh.equalHeightResponsive');
33 * или
34 * $('.element').trigger('equal-refresh');
35 *
36 * Так же возможно устанавливать обрабатываемым блокам свойство line-height, равное высоте.
37 * Предусмотрена возможность влиять на line-height (иногда нужно на её уменьшить/увеличить.)
38 * Для этого нужно "активировать" опцию setLineHeight, вот так:
39 * $('.element').equalHeightResponsive({
40 *     setLineHeight : true,
41 *     lineHeightOffset: 0
42 * });
43 *
44 *
45 */
46
47
48;(function ($, window, document, undefined) {
49	'use strict';
50	var maxHeight = 0,
51		currentRowStart = 0,
52		rowEls = [],
53		topPostion = 0,
54		$el,
55		currentEl,
56		defaults = {
57			setLineHeight: false,
58			lineHeightOffset: -4
59		},
60		methods = {
61			init: function (options) {
62
63				var props = $.extend({}, defaults, options),
64					_this = this,
65					$window = $(window),
66					winWidth = $window.width(), // IE8 loop resize fix
67					winHeight = $window.height(), // IE8 loop resize fix
68					_run = function (e) {
69						var winNewWidth = $window.width(), // IE8 loop resize fix
70							winNewHeight = $window.height(); // IE8 loop resize fix
71						// IE8 loop resize fix
72						if ((winWidth != winNewWidth || winHeight != winNewHeight) || e.type == 'load' || e.type == 'equal-refresh') {
73							methods.run(_this, props);
74						}
75						// IE8 loop resize fix
76						winWidth = winNewWidth;
77						winHeight = winNewHeight;
78					};
79
80				$window.on('load.equalHeightResponsive resize.equalHeightResponsive equal-refresh.equalHeightResponsive', _this, _run);
81
82				// Bitrix composite fix
83				if (window.frameCacheVars !== undefined) {
84					methods.run(_this, props);
85				}
86
87				return this;
88
89			},
90			run: function (elements, options) {
91
92				$.each(elements, function () {
93					$el = $(this);
94					$($el).height('auto');
95					topPostion = $el.offset().top;
96					if ($el.is(':visible')) {
97						if (currentRowStart != topPostion) {
98							for (currentEl = 0; currentEl < rowEls.length; currentEl++) {
99								rowEls[currentEl].height(maxHeight);
100							}
101							rowEls.length = 0;
102							currentRowStart = topPostion;
103							maxHeight = $el.height();
104							rowEls.push($el);
105						}
106						else {
107							rowEls.push($el);
108							maxHeight = (maxHeight < $el.height()) ? ($el.height()) : (maxHeight);
109						}
110						for (currentEl = 0; currentEl < rowEls.length; currentEl++) {
111							rowEls[currentEl].height(maxHeight);
112							if (options.setLineHeight) {
113								rowEls[currentEl].css({
114									'line-height': maxHeight + options.lineHeightOffset + 'px'
115								});
116							}
117						}
118					}
119				});
120
121				return this;
122			},
123			refresh: function () {
124				$(window).trigger('equal-refresh.equalHeightResponsive');
125				return this;
126			}
127		};
128
129	$.fn.equalHeightResponsive = function (method) {
130
131		if (methods[method]) {
132			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
133		}
134		else if (typeof method === 'object' || !method) {
135			return methods.init.apply(this, arguments);
136		}
137		else {
138			$.error('Метод с именем ' + method + ' не существует для jQuery.equalHeightResponsive');
139		}
140
141	};
142
143})(jQuery, window, document);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.