vendor: 9,066 bytes, lines 1-298
1/** 2* jquery.matchHeight.js v0.5.2 3* http://brm.io/jquery-match-height/ 4* License: MIT 5*/ 6 7;(function($) { 8 /* 9 * internal 10 */ 11 12 var _previousResizeWidth = -1, 13 _updateTimeout = -1; 14 15 /* 16 * _rows 17 * utility function returns array of jQuery selections representing each row 18 * (as displayed after float wrapping applied by browser) 19 */ 20 21 var _rows = function(elements) { 22 var tolerance = 1, 23 $elements = $(elements), 24 lastTop = null, 25 rows = []; 26 27 // group elements by their top position 28 $elements.each(function(){ 29 var $that = $(this), 30 top = $that.offset().top - _parse($that.css('margin-top')), 31 lastRow = rows.length > 0 ? rows[rows.length - 1] : null; 32 33 if (lastRow === null) { 34 // first item on the row, so just push it 35 rows.push($that); 36 } else { 37 // if the row top is the same, add to the row group 38 if (Math.floor(Math.abs(lastTop - top)) <= tolerance) { 39 rows[rows.length - 1] = lastRow.add($that); 40 } else { 41 // otherwise start a new row group 42 rows.push($that); 43 } 44 } 45 46 // keep track of the last row top 47 lastTop = top; 48 }); 49 50 return rows; 51 }; 52 53 /* 54 * _parse 55 * value parse utility function 56 */ 57 58 var _parse = function(value) { 59 // parse value and convert NaN to 0 60 return parseFloat(value) || 0; 61 }; 62 63 /* 64 * matchHeight 65 * plugin definition 66 */ 67 68 var matchHeight = $.fn.matchHeight = function(byRow) { 69 70 // handle matchHeight('remove') 71 if (byRow === 'remove') { 72 var that = this; 73 74 // remove fixed height from all selected elements 75 this.css('height', ''); 76 77 // remove selected elements from all groups 78 $.each(matchHeight._groups, function(key, group) { 79 group.elements = group.elements.not(that); 80 }); 81 82 // TODO: cleanup empty groups 83 84 return this; 85 } 86 87 if (this.length <= 1) 88 return this; 89 90 // byRow default to true 91 byRow = (typeof byRow !== 'undefined') ? byRow : true; 92 93 // keep track of this group so we can re-apply later on load and resize events 94 matchHeight._groups.push({ 95 elements: this, 96 byRow: byRow 97 }); 98 99 // match each element's height to the tallest element in the selection 100 matchHeight._apply(this, byRow); 101 102 return this; 103 }; 104 105 /* 106 * plugin global options 107 */ 108 109 matchHeight._groups = []; 110 matchHeight._throttle = 80; 111 matchHeight._maintainScroll = false; 112 matchHeight._beforeUpdate = null; 113 matchHeight._afterUpdate = null; 114 115 /* 116 * matchHeight._apply 117 * apply matchHeight to given elements 118 */ 119 120 matchHeight._apply = function(elements, byRow) { 121 var $elements = $(elements), 122 rows = [$elements]; 123 124 // take note of scroll position 125 var scrollTop = $(window).scrollTop(), 126 htmlHeight = $('html').outerHeight(true); 127 128 // temporarily must force hidden parents visible 129 var $hiddenParents = $elements.parents().filter(':hidden'); 130 $hiddenParents.css('display', 'block'); 131 132 // get rows if using byRow, otherwise assume one row 133 if (byRow) { 134 135 // must first force an arbitrary equal height so floating elements break evenly 136 $elements.each(function() { 137 var $that = $(this), 138 display = $that.css('display') === 'inline-block' ? 'inline-block' : 'block'; 139 140 // cache the original inline style 141 $that.data('style-cache', $that.attr('style')); 142 143 $that.css({ 144 'display': display, 145 'padding-top': '0', 146 'padding-bottom': '0', 147 'margin-top': '0', 148 'margin-bottom': '0', 149 'border-top-width': '0', 150 'border-bottom-width': '0', 151 'height': '100px' 152 }); 153 }); 154 155 // get the array of rows (based on element top position) 156 rows = _rows($elements); 157 158 // revert original inline styles 159 $elements.each(function() { 160 var $that = $(this); 161 162 $that.attr('style', $that.data('style-cache') || '') 163 .css('height', ''); 164 }); 165 } 166 167 $.each(rows, function(key, row) { 168 var $row = $(row), 169 maxHeight = 0; 170 171 // skip apply to rows with only one item 172 if (byRow && $row.length <= 1) 173 return; 174 175 // iterate the row and find the max height 176 $row.each(function(){ 177 var $that = $(this), 178 display = $that.css('display') === 'inline-block' ? 'inline-block' : 'block'; 179 180 // ensure we get the correct actual height (and not a previously set height value) 181 $that.css({ 'display': display, 'height': '' }); 182 183 // find the max height (including padding, but not margin) 184 if ($that.outerHeight(false) > maxHeight) 185 maxHeight = $that.outerHeight(false); 186 187 // revert display block 188 $that.css('display', ''); 189 }); 190 191 // iterate the row and apply the height to all elements 192 $row.each(function(){ 193 var $that = $(this), 194 verticalPadding = 0; 195 196 // handle padding and border correctly (required when not using border-box) 197 if ($that.css('box-sizing') !== 'border-box') { 198 verticalPadding += _parse($that.css('border-top-width')) + _parse($that.css('border-bottom-width')); 199 verticalPadding += _parse($that.css('padding-top')) + _parse($that.css('padding-bottom')); 200 } 201 202 // set the height (accounting for padding and border) 203 $that.css('height', maxHeight - verticalPadding); 204 }); 205 }); 206 207 // revert hidden parents 208 $hiddenParents.css('display', ''); 209 210 // restore scroll position if enabled 211 if (matchHeight._maintainScroll) 212 $(window).scrollTop((scrollTop / htmlHeight) * $('html').outerHeight(true)); 213 214 return this; 215 }; 216 217 /* 218 * matchHeight._applyDataApi 219 * applies matchHeight to all elements with a data-match-height attribute 220 */ 221 222 matchHeight._applyDataApi = function() { 223 var groups = {}; 224 225 // generate groups by their groupId set by elements using data-match-height 226 $('[data-match-height], [data-mh]').each(function() { 227 var $this = $(this), 228 groupId = $this.attr('data-match-height') || $this.attr('data-mh'); 229 if (groupId in groups) { 230 groups[groupId] = groups[groupId].add($this); 231 } else { 232 groups[groupId] = $this; 233 } 234 }); 235 236 // apply matchHeight to each group 237 $.each(groups, function() { 238 this.matchHeight(true); 239 }); 240 }; 241 242 /* 243 * matchHeight._update 244 * updates matchHeight on all current groups with their correct options 245 */ 246 247 var _update = function(event) { 248 if (matchHeight._beforeUpdate) 249 matchHeight._beforeUpdate(event, matchHeight._groups); 250 251 $.each(matchHeight._groups, function() { 252 matchHeight._apply(this.elements, this.byRow); 253 }); 254 255 if (matchHeight._afterUpdate) 256 matchHeight._afterUpdate(event, matchHeight._groups); 257 }; 258 259 matchHeight._update = function(throttle, event) { 260 // prevent update if fired from a resize event 261 // where the viewport width hasn't actually changed 262 // fixes an event looping bug in IE8 263 if (event && event.type === 'resize') { 264 var windowWidth = $(window).width(); 265 if (windowWidth === _previousResizeWidth) 266 return; 267 _previousResizeWidth = windowWidth; 268 } 269 270 // throttle updates 271 if (!throttle) { 272 _update(event); 273 } else if (_updateTimeout === -1) { 274 _updateTimeout = setTimeout(function() { 275 _update(event); 276 _updateTimeout = -1; 277 }, matchHeight._throttle); 278 } 279 }; 280 281 /* 282 * bind events 283 */ 284 285 // apply on DOM ready event 286 $(matchHeight._applyDataApi); 287 288 // update heights on load and resize events 289 $(window).bind('load', function(event) { 290 matchHeight._update(false, event); 291 }); 292 293 // throttled update heights on resize events 294 $(window).bind('resize orientationchange', function(event) { 295 matchHeight._update(true, event); 296 }); 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.