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