1(function($) { 2 // Function normalizes height 3 // looks for [data-equalizer], and equals 4 // height for all [data-equalize-height] children 5 // 6 // var mq (optional) 7 // mq = a media query, test for true 8 // mq = null, then run resize for all windows 9 $.fn.equalizeHeight = (function(mq, childrenSel) { 10 11 var self = this, 12 $children = [], 13 childrenSel = childrenSel || '[data-equalize-height]', 14 mq = mq || false; 15 16 self.init = function() { 17 $children = $(this).find(childrenSel); 18 if($children.length) { 19 self.equalize(true); 20 self.setWatch(); 21 } 22 } 23 24 self.reset = function() { 25 $.each($children, function (index, element) { 26 $(element).css("height", ""); 27 }); 28 } 29 30 self.runCalc = function() { 31 var largestHeight = 0; 32 if( !mq || window.matchMedia(mq).matches ) { 33 $.each($children, function (index, element) { 34 var thisHeight = $(element).outerHeight(); 35 if (thisHeight > largestHeight) { 36 largestHeight = thisHeight; 37 } 38 }); 39 } 40 $.each($children, function(index, element) { 41 $(element).css({ 'height': largestHeight + "px" }); 42 }); 43 } 44 45 self.equalize = function(firstCall) { 46 if(firstCall) { 47 $(self).waitForImages({ 48 finished: function() { 49 self.runCalc(); 50 }, 51 each: $.noop, 52 waitForAll: true 53 }); 54 } 55 else { 56 self.reset(); 57 self.runCalc(); 58 } 59 60 } 61 62 // Description: 63 // Executes a function a max of once every n milliseconds 64 self.throttle = function (func, delay) { 65 var timer = null; 66 67 return function () { 68 var context = this, args = arguments; 69 70 if (timer == null) { 71 timer = setTimeout(function () { 72 func.apply(context, args); 73 timer = null; 74 }, delay); 75 } 76 }; 77 } 78 79 self.setWatch = function() { 80 // Set watch 81 $(window).on('resize.equalizer', self.throttle(function () { 82 self.equalize(); 83 }, 50)); 84 } 85 86 return self.init(); 87 }); 88})(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.