1/* 2 * fixHeight - jQuery Plugin 3 * http://www.starryworks.co.jp/blog/tips/javascript/fixheightjs.html 4 * 5 * Author Koji Kimura @ STARRYWORKS inc. 6 * http://www.starryworks.co.jp/ 7 * 8 * Licensed under the MIT License 9 * 10 */ 11 12 13(function($){ 14 15 var isInitialized = false; 16 var parents = []; 17 var textHeight = 0; 18 var $fontSizeDiv; 19 20 $.fn.fixHeight = function() { 21 this.each(function(){ 22 var childrenGroups = getChildren( this ); 23 24 $.each( childrenGroups, function(){ 25 26 var $children = $(this); 27 if ( !$children.filter(":visible").length ) return; 28 29 var row = []; 30 var top = 0; 31 $children.each(function(){ 32 if ( top != $(this).position().top ) { 33 $(row).sameHeight(); 34 row = []; 35 top = $(this).position().top; 36 } 37 row.push(this); 38 }); 39 if ( row.length ) $(row).sameHeight(); 40 }); 41 42 43 }); 44 init(); 45 return this; 46 }; 47 48 $.checkFixHeight = function( i_force ) { 49 if ( $fontSizeDiv.height() == textHeight && i_force !== true ) return; 50 textHeight = $fontSizeDiv.height(); 51 $(parents).fixHeight(); 52 }; 53 54 $.fn.sameHeight = function() { 55 var maxHeight = 0; 56 this.css("height","auto"); 57 this.each(function(){ 58 if ( $(this).height() > maxHeight ) maxHeight = $(this).height(); 59 }); 60 return this.height(maxHeight); 61 }; 62 63 function getChildren( i_parent ) { 64 var $parent = $( i_parent ); 65 66 if ( $parent.data("fixHeightChildrenGroups") ) return $parent.data("fixHeightChildrenGroups"); 67 var childrenGroups = []; 68 69 var $children = $parent.find(".fixHeightChild"); 70 if ( $children.length ) childrenGroups.push( $children ); 71 72 var $groupedChildren = $parent.find("*[class*='fixHeightChild']:not(.fixHeightChild)"); 73 if ( $groupedChildren.length ) { 74 var classNames = {}; 75 $groupedChildren.each(function(){ 76 var a = $(this).attr("class").split(" "); 77 var i; 78 var l = a.length; 79 var c; 80 for ( i=0; i<l; i++ ) { 81 c = a[i].match(/fixHeightChild[a-z0-9_-]+/i); 82 if ( !c ) continue; 83 c = c.toString(); 84 if ( c ) classNames[c] = c; 85 } 86 }); 87 for ( var c in classNames ) childrenGroups.push( $parent.find("."+c) ); 88 } 89 90 if ( !childrenGroups.length ) { 91 $children = $parent.children(); 92 if ( $children.length ) childrenGroups.push( $children ); 93 } 94 95 $parent.data("fixHeightChildrenGroups", childrenGroups ); 96 parents.push( $parent ); 97 98 return childrenGroups; 99 } 100 101 102 function init() { 103 if ( isInitialized ) return; 104 isInitialized = true; 105 $fontSizeDiv = $(document.body).append('<div style="position:absolute;left:-9999px;top:-9999px;">s</div>'); 106 setInterval($.checkFixHeight,1000); 107 //$(window).resize($.checkFixHeight); 108 $.checkFixHeight(); 109 $(window).load( function(){ $.checkFixHeight(true); } ); 110 } 111 112 113 $(window).on('load resize', function(){ 114 $(".fixHeight").fixHeight(); 115 116 //fixHeight after window resize 117 var timer = false; 118 $(window).resize(function() { 119 if (timer !== false) { 120 clearTimeout(timer); 121 } 122 timer = setTimeout(function() { 123 $('.fixHeight').fixHeight(); 124 }, 200); 125 }); 126 127 }); 128})(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.