PageSourceSearch

https://www.titandentalcare.com/wp-content/themes/doctorgenius-framework/js/jquery.matchHeight.js

js titandentalcare.com collected 2026-10-08 09:57:56 UTC 11,739 bytes, 386 lines download raw bytes

vendor: 11,739 bytes, lines 1-386
1/**
2 * jquery-match-height master by @liabru
3 * http://brm.io/jquery-match-height/
4 * License: MIT
5 */
6
7;(function(factory) { // eslint-disable-line no-extra-semi
8    'use strict';
9    if (typeof define === 'function' && define.amd) {
10        // AMD
11        define(['jquery'], factory);
12    } else if (typeof module !== 'undefined' && module.exports) {
13        // CommonJS
14        module.exports = factory(require('jquery'));
15    } else {
16        // Global
17        factory(jQuery);
18    }
19})(function($) {
20    /*
21    *  internal
22    */
23
24    var _previousResizeWidth = -1,
25        _updateTimeout = -1;
26
27    /*
28    *  _parse
29    *  value parse utility function
30    */
31
32    var _parse = function(value) {
33        // parse value and convert NaN to 0
34        return parseFloat(value) || 0;
35    };
36
37    /*
38    *  _rows
39    *  utility function returns array of jQuery selections representing each row
40    *  (as displayed after float wrapping applied by browser)
41    */
42
43    var _rows = function(elements) {
44        var tolerance = 1,
45            $elements = $(elements),
46            lastTop = null,
47            rows = [];
48
49        // group elements by their top position
50        $elements.each(function(){
51            var $that = $(this),
52                top = $that.offset().top - _parse($that.css('margin-top')),
53                lastRow = rows.length > 0 ? rows[rows.length - 1] : null;
54
55            if (lastRow === null) {
56                // first item on the row, so just push it
57                rows.push($that);
58            } else {
59                // if the row top is the same, add to the row group
60                if (Math.floor(Math.abs(lastTop - top)) <= tolerance) {
61                    rows[rows.length - 1] = lastRow.add($that);
62                } else {
63                    // otherwise start a new row group
64                    rows.push($that);
65                }
66            }
67
68            // keep track of the last row top
69            lastTop = top;
70        });
71
72        return rows;
73    };
74
75    /*
76    *  _parseOptions
77    *  handle plugin options
78    */
79
80    var _parseOptions = function(options) {
81        var opts = {
82            byRow: true,
83            property: 'height',
84            target: null,
85            remove: false
86        };
87
88        if (typeof options === 'object') {
89            return $.extend(opts, options);
90        }
91
92        if (typeof options === 'boolean') {
93            opts.byRow = options;
94        } else if (options === 'remove') {
95            opts.remove = true;
96        }
97
98        return opts;
99    };
100
101    /*
102    *  matchHeight
103    *  plugin definition
104    */
105
106    var matchHeight = $.fn.matchHeight = function(options) {
107        var opts = _parseOptions(options);
108
109        // handle remove
110        if (opts.remove) {
111            var that = this;
112
113            // remove fixed height from all selected elements
114            this.css(opts.property, '');
115
116            // remove selected elements from all groups
117            $.each(matchHeight._groups, function(key, group) {
118                group.elements = group.elements.not(that);
119            });
120
121            return this;
122        }
123
124        if (this.length <= 1 && !opts.target) {
125            return this;
126        }
127
128        // keep track of this group so we can re-apply later on load and resize events
129        matchHeight._groups.push({
130            elements: this,
131            options: opts
132        });
133
134        // match each element's height to the tallest element in the selection
135        matchHeight._apply(this, opts);
136
137        return this;
138    };
139
140    /*
141    *  plugin global options
142    */
143
144    matchHeight.version = 'master';
145    matchHeight._groups = [];
146    matchHeight._throttle = 80;
147    matchHeight._maintainScroll = false;
148    matchHeight._beforeUpdate = null;
149    matchHeight._afterUpdate = null;
150    matchHeight._rows = _rows;
151    matchHeight._parse = _parse;
152    matchHeight._parseOptions = _parseOptions;
153
154    /*
155    *  matchHeight._apply
156    *  apply matchHeight to given elements
157    */
158
159    matchHeight._apply = function(elements, options) {
160        var opts = _parseOptions(options),
161            $elements = $(elements),
162            rows = [$elements];
163
164        // take note of scroll position
165        var scrollTop = $(window).scrollTop(),
166            htmlHeight = $('html').outerHeight(true);
167
168        // get hidden parents
169        var $hiddenParents = $elements.parents().filter(':hidden');
170
171        // cache the original inline style
172        $hiddenParents.each(function() {
173            var $that = $(this);
174            $that.data('style-cache', $that.attr('style'));
175        });
176
177        // temporarily must force hidden parents visible
178        $hiddenParents.css('display', 'block');
179
180        // get rows if using byRow, otherwise assume one row
181        if (opts.byRow && !opts.target) {
182
183            // must first force an arbitrary equal height so floating elements break evenly
184            $elements.each(function() {
185                var $that = $(this),
186                    display = $that.css('display');
187
188                // temporarily force a usable display value
189                if (display !== 'inline-block' && display !== 'flex' && display !== 'inline-flex') {
190                    display = 'block';
191                }
192
193                // cache the original inline style
194                $that.data('style-cache', $that.attr('style'));
195
196                $that.css({
197                    'display': display,
198                    'padding-top': '0',
199                    'padding-bottom': '0',
200                    'margin-top': '0',
201                    'margin-bottom': '0',
202                    'border-top-width': '0',
203                    'border-bottom-width': '0',
204                    'height': '100px',
205                    'overflow': 'hidden'
206                });
207            });
208
209            // get the array of rows (based on element top position)
210            rows = _rows($elements);
211
212            // revert original inline styles
213            $elements.each(function() {
214                var $that = $(this);
215                $that.attr('style', $that.data('style-cache') || '');
216            });
217        }
218
219        $.each(rows, function(key, row) {
220            var $row = $(row),
221                targetHeight = 0;
222
223            if (!opts.target) {
224                // skip apply to rows with only one item
225                if (opts.byRow && $row.length <= 1) {
226                    $row.css(opts.property, '');
227                    return;
228                }
229
230                // iterate the row and find the max height
231                $row.each(function(){
232                    var $that = $(this),
233                        style = $that.attr('style'),
234                        display = $that.css('display');
235
236                    // temporarily force a usable display value
237                    if (display !== 'inline-block' && display !== 'flex' && display !== 'inline-flex') {
238                        display = 'block';
239                    }
240
241                    // ensure we get the correct actual height (and not a previously set height value)
242                    var css = { 'display': display };
243                    css[opts.property] = '';
244                    $that.css(css);
245
246                    // find the max height (including padding, but not margin)
247                    if ($that.outerHeight(false) > targetHeight) {
248                        targetHeight = $that.outerHeight(false);
249                    }
250
251                    // revert styles
252                    if (style) {
253                        $that.attr('style', style);
254                    } else {
255                        $that.css('display', '');
256                    }
257                });
258            } else {
259                // if target set, use the height of the target element
260                targetHeight = opts.target.outerHeight(false);
261            }
262
263            // iterate the row and apply the height to all elements
264            $row.each(function(){
265                var $that = $(this),
266                    verticalPadding = 0;
267
268                // don't apply to a target
269                if (opts.target && $that.is(opts.target)) {
270                    return;
271                }
272
273                // handle padding and border correctly (required when not using border-box)
274                if ($that.css('box-sizing') !== 'border-box') {
275                    verticalPadding += _parse($that.css('border-top-width')) + _parse($that.css('border-bottom-width'));
276                    verticalPadding += _parse($that.css('padding-top')) + _parse($that.css('padding-bottom'));
277                }
278
279                // set the height (accounting for padding and border)
280                $that.css(opts.property, (targetHeight - verticalPadding) + 'px');
281            });
282        });
283
284        // revert hidden parents
285        $hiddenParents.each(function() {
286            var $that = $(this);
287            $that.attr('style', $that.data('style-cache') || null);
288        });
289
290        // restore scroll position if enabled
291        if (matchHeight._maintainScroll) {
292            $(window).scrollTop((scrollTop / htmlHeight) * $('html').outerHeight(true));
293        }
294
295        return this;
296    };
297
298    /*
299    *  matchHeight._applyDataApi
300    *  applies matchHeight to all elements with a data-match-height attribute
301    */
302
303    matchHeight._applyDataApi = function() {
304        var groups = {};
305
306        // generate groups by their groupId set by elements using data-match-height
307        $('[data-match-height], [data-mh]').each(function() {
308            var $this = $(this),
309                groupId = $this.attr('data-mh') || $this.attr('data-match-height');
310
311            if (groupId in groups) {
312                groups[groupId] = groups[groupId].add($this);
313            } else {
314                groups[groupId] = $this;
315            }
316        });
317
318        // apply matchHeight to each group
319        $.each(groups, function() {
320            this.matchHeight(true);
321        });
322    };
323
324    /*
325    *  matchHeight._update
326    *  updates matchHeight on all current groups with their correct options
327    */
328
329    var _update = function(event) {
330        if (matchHeight._beforeUpdate) {
331            matchHeight._beforeUpdate(event, matchHeight._groups);
332        }
333
334        $.each(matchHeight._groups, function() {
335            matchHeight._apply(this.elements, this.options);
336        });
337
338        if (matchHeight._afterUpdate) {
339            matchHeight._afterUpdate(event, matchHeight._groups);
340        }
341    };
342
343    matchHeight._update = function(throttle, event) {
344        // prevent update if fired from a resize event
345        // where the viewport width hasn't actually changed
346        // fixes an event looping bug in IE8
347        if (event && event.type === 'resize') {
348            var windowWidth = $(window).width();
349            if (windowWidth === _previousResizeWidth) {
350                return;
351            }
352            _previousResizeWidth = windowWidth;
353        }
354
355        // throttle updates
356        if (!throttle) {
357            _update(event);
358        } else if (_updateTimeout === -1) {
359            _updateTimeout = setTimeout(function() {
360                _update(event);
361                _updateTimeout = -1;
362            }, matchHeight._throttle);
363        }
364    };
365
366    /*
367    *  bind events
368    */
369
370    // apply on DOM ready event
371    $(matchHeight._applyDataApi);
372
373    // use on or bind where supported
374    var on = $.fn.on ? 'on' : 'bind';
375
376    // update heights on load and resize events
377    $(window)[on]('load', function(event) {
378        matchHeight._update(false, event);
379    });
380
381    // throttled update heights on resize events
382    $(window)[on]('resize orientationchange', function(event) {
383        matchHeight._update(true, event);
384    });
385
386});

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.