PageSourceSearch

https://www.vesi.fi/wp-content/plugins/equal-height-columns/public/js/equal-height-columns-public.js?ver=1.2.1

js vesi.fi collected 2026-09-24 18:32:15 UTC 9,062 bytes, 298 lines download raw bytes

1/**
2 * Equal Height Columns Public JS
3 *
4 * @since  1.0.0
5 */
6( function( $ ) {
7	'use strict';
8
9	$( window ).on( 'load', function() {
10
11		// Don't do anything if no equal height column elements are specified.
12		if ( 'undefined' === typeof equalHeightColumnElements ) {
13			return;
14		}
15
16		// Initialize equal heights using variables passed from PHP.
17		$.each( equalHeightColumnElements, function() {
18
19			// Loop through each item in the collection
20			$.each( this, function() {
21
22				// Scope the vars
23				var $selector, breakpoint;
24
25				// Confirm that the selector is valid
26				try {
27
28					// Test the selector
29					$selector = $( this.selector );
30
31				} catch ( e ) {
32
33					// If we have an error, the selector must not be valid,
34					// so skip it and continue to the next selector
35					return true;
36				}
37
38				// Set the breakpoint
39				breakpoint = this.breakpoint;
40
41				// Set the selector (needed on latest jQuery versions)
42				$selector.selector = this.selector;
43
44				// Start the party
45				$selector.initEqualHeights( null, null, breakpoint );
46
47				// Restart the party if an image is lazy loaded
48				$( $selector.selector).find( 'img[loading="lazy"]' ).on( 'load', function(){
49					$selector.equalizeTheHeights( null, null, breakpoint );
50				});
51			});
52		});
53	});
54
55})( jQuery );
56
57/**
58 * Equal Heights jQuery Plugin
59 *
60 * Equalize the heights of elements. Great for columns or any elements that need to be the same height.
61 *
62 * Based on Rob Glazebrook's (cssnewbie.com) script.
63 *
64 * Features
65 *  - ability to include a break point (the minimum viewport width at which the script does anything)
66 *  - binds to window resize events (resize and orientationchange)
67 *  - will automatically detect new elements added to the DOM
68 *  - can be called multiple times without duplicating any events
69 *
70 * This plugin contains two methods - initEqualHeights() and equalizeTheHeights(). The initEqualHeights()
71 * method will set up all of the events to handle window resizing and manual retriggering via the global
72 * 'equalheights' event on the window. The equalizeTheHeights() method will directly equalize heights but
73 * not set up any events. Both methods work on a standard jQuery collection object and accept the same args.
74 *
75 * Usage for the full method: jQuery( selector ).initEqualHeights( [minHeight], [maxHeight], [breakPoint] );
76 * Usage for the direct method: jQuery( selector ).equalizeTheHeights( [minHeight], [maxHeight], [breakPoint] );
77 *
78 * Example 1: jQuery( ".cols" ).initEqualHeights(); Sets all .cols to the same height.
79 * Example 2: jQuery( ".cols" ).initEqualHeights( 400 ); Sets all .cols to at least 400px tall.
80 * Example 3: jQuery( ".cols" ).initEqualHeights( 100, 300 ); Cols are at least 100 but no more than 300 pixels
81 * tall. Elements with too much content will gain a scrollbar.
82 * Example 4: jQuery( ".cols" ).initEqualHeights( null, null, 768 ); Only resize .cols above 768px viewport
83 */
84( function( $ ) {
85	'use strict';
86
87	// Debouncing function from John Hann.
88	// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
89	var debounce = function( func, threshold ) {
90
91		// The timer
92		var timeout;
93
94		return function debounced() {
95
96			// Store the passed in function and args.
97			var obj = this;
98			var args = arguments;
99
100			// This is the callback that the timer triggers when debouncing is complete.
101			function delayed() {
102
103				// We have successfully debounced, trigger the function.
104				func.apply( obj, args );
105
106				// And clear the timer.
107				timeout = null;
108			}
109
110			// If the timer is active, clear it.
111			if ( timeout ) {
112				clearTimeout( timeout );
113			}
114
115			// Set the timer to 50ms and have it call delayed() when it completes.
116			timeout = setTimeout( delayed, threshold || 50 );
117		};
118	};
119
120	let manualElementsCount = 0;
121
122	// Main function for equalizing heights AND setting up events.
123	$.fn.initEqualHeights = function( minHeight, maxHeight, breakPoint ) {
124
125		// Scope our variables.
126		var selector, minHeight, maxHeight, breakPoint, args, eventData,
127			ourEvents, eventSet, thisEvent, eventName;
128
129		/*
130		The .selector property was removed on jQuery 1.9, we already addressed this for the default elements
131		but manual instances (directly calling .initEqualHeights()) were not working without this.
132		*/
133		if ( 'undefined' == typeof this.selector ) {
134			this.addClass( 'equal-height-columns-manual-' + manualElementsCount );
135			this.selector = '.equal-height-columns-manual-' + manualElementsCount;
136			manualElementsCount++;
137		}
138
139		// Get the selector used to call equalHeights.
140		selector = this.selector;
141
142		// Use the args that were passed in or use the defaults.
143		minHeight = minHeight || null;
144		maxHeight = maxHeight || null;
145		breakPoint = breakPoint || 0;
146
147		// Combine args into an object.
148		args = { minHeight: minHeight, maxHeight: maxHeight, breakPoint: breakPoint };
149
150		// Check if our global already exists.
151		if ( window.equalHeightsItems ) {
152
153			// It does, so add or overwrite the current object in it.
154			window.equalHeightsItems[selector] = args;
155		} else {
156
157			// It doesn't, so create the global and store the current object in it.
158			window.equalHeightsItems = {};
159			window.equalHeightsItems[selector] = args;
160		}
161
162		// Grab the current event data from the window object if it exists.
163		eventData = $._data( window, 'events' ) || {};
164
165		// Store the events that will retrigger doEqualHeights().
166		ourEvents = [ 'resize', 'orientationchange', 'equalheights' ];
167
168		// Loop through each event and attach our handler if it isn't attached already.
169		$( ourEvents ).each( function() {
170
171			// Reset our flag to false.
172			eventSet = false;
173
174			// Store this event.
175			thisEvent = this;
176
177			// Add the namespace.
178			eventName = this + '.equalheights';
179
180			// Check whether this event is already on the window.
181			if ( eventData[ thisEvent ] ) {
182
183				// Be careful not to disturb any unrelated listeners.
184				$( eventData[ thisEvent ] ).each( function() {
185
186					// Confirm that the event has our namespace.
187					if ( this.namespace == 'equalheights' ) {
188
189						// It does, so set our flag to true.
190						eventSet = true;
191					}
192				});
193			}
194
195			// If our flag is still false then we can safely attach the event.
196			if ( ! eventSet ) {
197
198				// Namespace it and debounce it to be safe.
199				$( window ).on( eventName, debounce( triggerEqualHeights ) );
200			}
201		});
202
203		// Trigger the first equalizing.
204		triggerEqualHeights();
205	};
206
207	// Function to trigger the equalizing.
208	function triggerEqualHeights() {
209
210		// Loop through each object in our global.
211		$.each( window.equalHeightsItems, function( selector, args ) {
212
213			// Call doEqualHeights and pass in the current object.
214			doEqualHeights( selector, args );
215		});
216	}
217
218	// Function to do the equalizing of the heights.
219	function doEqualHeights( selector, args ) {
220
221		// Scope our variables.
222		var $items, minHeight, maxHeight, breakPoint;
223
224		// Grab the collection of items fresh from the DOM.
225		$items = $( selector );
226
227		// Store the passed in args.
228		minHeight = args.minHeight;
229		maxHeight = args.maxHeight;
230		breakPoint = args.breakPoint;
231
232		$items.equalizeTheHeights( minHeight, maxHeight, breakPoint );
233	}
234
235	// Function for directly equalizing heights WITHOUT setting up any events.
236	$.fn.equalizeTheHeights = function( minHeight, maxHeight, breakPoint, breakPointMax ) {
237
238		// Scope our variables.
239		var minHeight, maxHeight, breakPoint, breakPointMax, tallest, e, a, width;
240
241		// Make all variables optional.
242		minHeight = minHeight || 0;
243		maxHeight = maxHeight || 0;
244		breakPoint = breakPoint || 0;
245		breakPointMax = breakPointMax || Number.MAX_SAFE_INTEGER;
246
247		// Calculate the tallest item.
248		tallest = minHeight;
249		$( this ).each( function() {
250			$( this ).outerHeight( 'auto' );
251			if ( $( this ).outerHeight() > tallest ) {
252				tallest = $( this ).outerHeight();
253			}
254		});
255
256		// Get viewport width (taking scrollbars into account).
257		e = window;
258		a = 'inner';
259		if ( ! ( 'innerWidth' in window ) ) {
260			a = 'client';
261			e = document.documentElement || document.body;
262		}
263		width = e[ a + 'Width' ];
264
265		// Equalize heights if viewport width is above the breakpoint and below the max-breakpoint.
266		if ( width >= breakPoint && width <= breakPointMax ) {
267			if ( ( maxHeight ) && tallest > maxHeight ) {
268				tallest = maxHeight;
269			}
270			return $( this ).each( function() {
271				$( this ).outerHeight( tallest );
272			});
273		}
274	}
275
276	$.fn.equalHeight = function( selector, columns, min, max ) {
277		selector = selector || '';
278		columns = columns || 0;
279		min = min || 0;
280		max = max || Number.MAX_SAFE_INTEGER;
281
282		$( window ).on( 'resize orientationchange equalheights', debounce( function() {
283			let width = $( window ).width();
284			if ( width >= min && width <= max ) {
285				let start;
286				let end;
287				let $elements = $( selector );
288
289				for ( start = 0, end = columns; end <= $elements.size(); start = end, end = end + columns ) {
290					$elements.slice( start, end ).equalizeTheHeights();
291				}
292				$elements.slice( start, end ).equalizeTheHeights();
293			}
294		} ) );
295
296		$( window ).trigger( 'equalheights' );
297	}
298})( jQuery );

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.