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