1// page init 2jQuery(function(){ 3 initSameHeight(); 4}); 5 6// align blocks height 7function initSameHeight() { 8 jQuery('#same-height').sameHeight({ 9 elements: '>*', 10 flexible: true 11 }); 12 jQuery('.test-holder').sameHeight({ 13 elements: 'div.stretch-me', 14 flexible: true, 15 multiLine: true 16 }); 17 jQuery('ul.list').sameHeight({ 18 elements: 'strong.caption', 19 flexible: true, 20 multiLine: true 21 }); 22 jQuery('ul.list').sameHeight({ 23 elements: 'div.info-box', 24 flexible: true, 25 multiLine: true 26 }); 27} 28 29/* 30 * jQuery SameHeight plugin 31 */ 32;(function($){ 33 $.fn.sameHeight = function(opt) { 34 var options = $.extend({ 35 skipClass: 'same-height-ignore', 36 leftEdgeClass: 'same-height-left', 37 rightEdgeClass: 'same-height-right', 38 elements: '>*', 39 flexible: false, 40 multiLine: false, 41 useMinHeight: false, 42 biggestHeight: false 43 },opt); 44 return this.each(function(){ 45 var holder = $(this), postResizeTimer, ignoreResize; 46 var elements = holder.find(options.elements).not('.' + options.skipClass); 47 if(!elements.length) return; 48 49 // resize handler 50 function doResize() { 51 elements.css(options.useMinHeight && supportMinHeight ? 'minHeight' : 'height', ''); 52 if(options.multiLine) { 53 // resize elements row by row 54 resizeElementsByRows(elements, options); 55 } else { 56 // resize elements by holder 57 resizeElements(elements, holder, options); 58 } 59 } 60 doResize(); 61 62 // handle flexible layout / font resize 63 var delayedResizeHandler = function() { 64 if(!ignoreResize) { 65 ignoreResize = true; 66 doResize(); 67 clearTimeout(postResizeTimer); 68 postResizeTimer = setTimeout(function() { 69 doResize(); 70 setTimeout(function(){ 71 ignoreResize = false; 72 }, 10); 73 }, 100); 74 } 75 }; 76 77 // handle flexible/responsive layout 78 if(options.flexible) { 79 $(window).bind('resize orientationchange fontresize', delayedResizeHandler); 80 } 81 82 // handle complete page load including images and fonts 83 $(window).bind('load', delayedResizeHandler); 84 }); 85 }; 86 87 // detect css min-height support 88 var supportMinHeight = typeof document.documentElement.style.maxHeight !== 'undefined'; 89 90 // get elements by rows 91 function resizeElementsByRows(boxes, options) { 92 var currentRow = $(), maxHeight, maxCalcHeight = 0, firstOffset = boxes.eq(0).offset().top; 93 boxes.each(function(ind){ 94 var curItem = $(this); 95 if(curItem.offset().top === firstOffset) { 96 currentRow = currentRow.add(this); 97 } else { 98 maxHeight = getMaxHeight(currentRow); 99 maxCalcHeight = Math.max(maxCalcHeight, resizeElements(currentRow, maxHeight, options)); 100 currentRow = curItem; 101 firstOffset = curItem.offset().top; 102 } 103 }); 104 if(currentRow.length) { 105 maxHeight = getMaxHeight(currentRow); 106 maxCalcHeight = Math.max(maxCalcHeight, resizeElements(currentRow, maxHeight, options)); 107 } 108 if(options.biggestHeight) { 109 boxes.css(options.useMinHeight && supportMinHeight ? 'minHeight' : 'height', maxCalcHeight); 110 } 111 } 112 113 // calculate max element height 114 function getMaxHeight(boxes) { 115 var maxHeight = 0; 116 boxes.each(function(){ 117 maxHeight = Math.max(maxHeight, $(this).outerHeight()); 118 }); 119 return maxHeight; 120 } 121 122 // resize helper function 123 function resizeElements(boxes, parent, options) { 124 var calcHeight; 125 var parentHeight = typeof parent === 'number' ? parent : parent.height(); 126 boxes.removeClass(options.leftEdgeClass).removeClass(options.rightEdgeClass).each(function(i){ 127 var element = $(this); 128 var depthDiffHeight = 0; 129 var isBorderBox = element.css('boxSizing') === 'border-box' || element.css('-moz-box-sizing') === 'border-box' || '-webkit-box-sizing' === 'border-box'; 130 131 if(typeof parent !== 'number') { 132 element.parents().each(function(){ 133 var tmpParent = $(this); 134 if(parent.is(this)) { 135 return false; 136 } else { 137 depthDiffHeight += tmpParent.outerHeight() - tmpParent.height(); 138 } 139 }); 140 } 141 calcHeight = parentHeight - depthDiffHeight; 142 calcHeight -= isBorderBox ? 0 : element.outerHeight() - element.height(); 143 144 if(calcHeight > 0) { 145 element.css(options.useMinHeight && supportMinHeight ? 'minHeight' : 'height', calcHeight); 146 } 147 }); 148 boxes.filter(':first').addClass(options.leftEdgeClass); 149 boxes.filter(':last').addClass(options.rightEdgeClass); 150 return calcHeight; 151 } 152}(jQuery)); 153 154/* 155 * jQuery FontResize Event 156 */ 157jQuery.onFontResize = (function($) { 158 $(function() { 159 var randomID = 'font-resize-frame-' + Math.floor(Math.random() * 1000); 160 var resizeFrame = $('<iframe>').attr('id', randomID).addClass('font-resize-helper'); 161 162 // required styles 163 resizeFrame.css({ 164 width: '100em', 165 height: '10px', 166 position: 'absolute', 167 borderWidth: 0, 168 top: '-9999px', 169 left: '-9999px' 170 }).appendTo('body'); 171 172 // use native IE resize event if possible 173 if (window.attachEvent && !window.addEventListener) { 174 resizeFrame.bind('resize', function () { 175 $.onFontResize.trigger(resizeFrame[0].offsetWidth / 100); 176 }); 177 } 178 // use script inside the iframe to detect resize for other browsers 179 else { 180 var doc = resizeFrame[0].contentWindow.document; 181 doc.open(); 182 doc.write('<scri' + 'pt>window.onload = function(){var em = parent.jQuery("#' + randomID + '")[0];window.onresize = function(){if(parent.jQuery.onFontResize){parent.jQuery.onFontResize.trigger(em.offsetWidth / 100);}}};</scri' + 'pt>'); 183 doc.close(); 184 }
185 jQuery.onFontResize.initialSize = resizeFrame[0].offsetWidth / 100; 186 }); 187 return { 188 // public method, so it can be called from within the iframe 189 trigger: function (em) { 190 $(window).trigger("fontresize", [em]); 191 } 192 }; 193}(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.