vendor: 10,251 bytes, lines 1-398
1/** 2 * jquery-match-height master by @liabru 3 * http://brm.io/jquery-match-height/ 4 * License: MIT 5 */ 6 7(function(factory) { 8 // 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 // TODO: cleanup empty groups 123 124 return this; 125 } 126 127 if (this.length <= 1 && !opts.target) { 128 return this; 129 } 130 131 // keep track of this group so we can re-apply later on load and resize events 132 matchHeight._groups.push({ 133 elements: this, 134 options: opts 135 }); 136 137 // match each element's height to the tallest element in the selection 138 matchHeight._apply(this, opts); 139 140 return this; 141 }); 142 143 /* 144 * plugin global options 145 */ 146 147 matchHeight.version = 'master'; 148 matchHeight._groups = []; 149 matchHeight._throttle = 80; 150 matchHeight._maintainScroll = false; 151 matchHeight._beforeUpdate = null; 152 matchHeight._afterUpdate = null; 153 matchHeight._rows = _rows; 154 matchHeight._parse = _parse; 155 matchHeight._parseOptions = _parseOptions; 156 157 /* 158 * matchHeight._apply 159 * apply matchHeight to given elements 160 */ 161 162 matchHeight._apply = function(elements, options) { 163 var opts = _parseOptions(options), 164 $elements = $(elements), 165 rows = [$elements]; 166 167 // take note of scroll position 168 var scrollTop = $(window).scrollTop(), 169 htmlHeight = $('html').outerHeight(true); 170 171 // get hidden parents 172 var $hiddenParents = $elements.parents().filter(':hidden'); 173 174 // cache the original inline style 175 $hiddenParents.each(function() { 176 var $that = $(this); 177 $that.data('style-cache', $that.attr('style')); 178 }); 179 180 // temporarily must force hidden parents visible 181 $hiddenParents.css('display', 'block'); 182 183 // get rows if using byRow, otherwise assume one row 184 if (opts.byRow && !opts.target) { 185 // must first force an arbitrary equal height so floating elements break evenly 186 $elements.each(function() { 187 var $that = $(this), 188 display = $that.css('display'); 189 190 // temporarily force a usable display value 191 if ( 192 display !== 'inline-block' && 193 display !== 'flex' && 194 display !== 'inline-flex' 195 ) { 196 display = 'block'; 197 } 198 199 // cache the original inline style 200 $that.data('style-cache', $that.attr('style')); 201 202 $that.css({ 203 display: display, 204 'padding-top': '0', 205 'padding-bottom': '0', 206 'margin-top': '0', 207 'margin-bottom': '0', 208 'border-top-width': '0', 209 'border-bottom-width': '0', 210 height: '100px', 211 overflow: 'hidden' 212 }); 213 }); 214 215 // get the array of rows (based on element top position) 216 rows = _rows($elements); 217 218 // revert original inline styles 219 $elements.each(function() { 220 var $that = $(this); 221 $that.attr('style', $that.data('style-cache') || ''); 222 }); 223 } 224 225 $.each(rows, function(key, row) { 226 var $row = $(row), 227 targetHeight = 0; 228 229 if (!opts.target) { 230 // skip apply to rows with only one item 231 if (opts.byRow && $row.length <= 1) { 232 $row.css(opts.property, ''); 233 return; 234 } 235 236 // iterate the row and find the max height 237 $row.each(function() { 238 var $that = $(this), 239 style = $that.attr('style'), 240 display = $that.css('display'); 241 242 // temporarily force a usable display value 243 if ( 244 display !== 'inline-block' && 245 display !== 'flex' && 246 display !== 'inline-flex' 247 ) { 248 display = 'block'; 249 } 250 251 // ensure we get the correct actual height (and not a previously set height value) 252 var css = { display: display }; 253 css[opts.property] = ''; 254 $that.css(css); 255 256 // find the max height (including padding, but not margin) 257 if ($that.outerHeight(false) > targetHeight) { 258 targetHeight = $that.outerHeight(false); 259 } 260 261 // revert styles 262 if (style) { 263 $that.attr('style', style); 264 } else { 265 $that.css('display', ''); 266 } 267 }); 268 } else { 269 // if target set, use the height of the target element 270 targetHeight = opts.target.outerHeight(false); 271 } 272 273 // iterate the row and apply the height to all elements 274 $row.each(function() { 275 var $that = $(this), 276 verticalPadding = 0; 277 278 // don't apply to a target 279 if (opts.target && $that.is(opts.target)) { 280 return; 281 } 282 283 // handle padding and border correctly (required when not using border-box) 284 if ($that.css('box-sizing') !== 'border-box') { 285 verticalPadding += 286 _parse($that.css('border-top-width')) + 287 _parse($that.css('border-bottom-width')); 288 verticalPadding += 289 _parse($that.css('padding-top')) + 290 _parse($that.css('padding-bottom')); 291 } 292 293 // set the height (accounting for padding and border) 294 $that.css(opts.property, targetHeight - verticalPadding + 'px'); 295 }); 296 }); 297 298 // revert hidden parents 299 $hiddenParents.each(function() { 300 var $that = $(this); 301 $that.attr('style', $that.data('style-cache') || null); 302 }); 303 304 // restore scroll position if enabled 305 if (matchHeight._maintainScroll) { 306 $(window).scrollTop( 307 (scrollTop / htmlHeight) * $('html').outerHeight(true) 308 ); 309 } 310 311 return this; 312 }; 313 314 /* 315 * matchHeight._applyDataApi 316 * applies matchHeight to all elements with a data-match-height attribute 317 */ 318 319 matchHeight._applyDataApi = function() { 320 var groups = {}; 321 322 // generate groups by their groupId set by elements using data-match-height 323 $('[data-match-height], [data-mh]').each(function() { 324 var $this = $(this), 325 groupId = $this.attr('data-mh') || $this.attr('data-match-height'); 326 327 if (groupId in groups) { 328 groups[groupId] = groups[groupId].add($this); 329 } else { 330 groups[groupId] = $this; 331 } 332 }); 333 334 // apply matchHeight to each group 335 $.each(groups, function() { 336 this.matchHeight(true); 337 }); 338 }; 339 340 /* 341 * matchHeight._update 342 * updates matchHeight on all current groups with their correct options 343 */ 344 345 var _update = function(event) { 346 if (matchHeight._beforeUpdate) { 347 matchHeight._beforeUpdate(event, matchHeight._groups); 348 } 349 350 $.each(matchHeight._groups, function() { 351 matchHeight._apply(this.elements, this.options); 352 }); 353 354 if (matchHeight._afterUpdate) { 355 matchHeight._afterUpdate(event, matchHeight._groups); 356 } 357 }; 358 359 matchHeight._update = function(throttle, event) { 360 // prevent update if fired from a resize event 361 // where the viewport width hasn't actually changed 362 // fixes an event looping bug in IE8 363 if (event && event.type === 'resize') { 364 var windowWidth = $(window).width(); 365 if (windowWidth === _previousResizeWidth) { 366 return; 367 } 368 _previousResizeWidth = windowWidth; 369 } 370 371 // throttle updates 372 if (!throttle) { 373 _update(event); 374 } else if (_updateTimeout === -1) { 375 _updateTimeout = setTimeout(function() { 376 _update(event); 377 _updateTimeout = -1; 378 }, matchHeight._throttle); 379 } 380 }; 381 382 /* 383 * bind events 384 */ 385 386 // apply on DOM ready event 387 $(matchHeight._applyDataApi); 388 389 // update heights on load and resize events 390 $(window).bind('load', function(event) { 391 matchHeight._update(false, event); 392 }); 393 394 // throttled update heights on resize events 395 $(window).bind('resize orientationchange', function(event) { 396 matchHeight._update(true, event); 397 }); 398});
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.