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).innerHeight() > maxHeight ) maxHeight = $(this).innerHeight(); 59 }); 60 if ($('body').hasClass('sp')) 61 return this.css("height","auto"); 62 else 63 return this.height(maxHeight); 64 } 65 66 function getChildren( i_parent ) { 67 var $parent = $( i_parent ); 68 69 if ( $parent.data("fixHeightChildrenGroups") ) return $parent.data("fixHeightChildrenGroups"); 70 var childrenGroups = []; 71 72 var $children = $parent.find(".fixHeightChild"); 73 if ( $children.length ) childrenGroups.push( $children ); 74 75 var $groupedChildren = $parent.find("*[class*='fixHeightChild']:not(.fixHeightChild)"); 76 if ( $groupedChildren.length ) { 77 var classNames = {}; 78 $groupedChildren.each(function(){ 79 var a = $(this).attr("class").split(" "); 80 var i; 81 var l = a.length; 82 var c; 83 for ( i=0; i<l; i++ ) { 84 c = a[i].match(/fixHeightChild[a-z0-9_-]+/i); 85 if ( !c ) continue; 86 c = c.toString(); 87 if ( c ) classNames[c] = c; 88 } 89 }); 90 for ( var c in classNames ) childrenGroups.push( $parent.find("."+c) ); 91 } 92 93 if ( !childrenGroups.length ) { 94 $children = $parent.children(); 95 if ( $children.length ) childrenGroups.push( $children ); 96 } 97 98 $parent.data("fixHeightChildrenGroups", childrenGroups ); 99 parents.push( $parent ); 100 101 return childrenGroups; 102 } 103 104 105 function init() { 106 if ( isInitialized ) return; 107 isInitialized = true; 108 $fontSizeDiv = $(document).append('<div style="position:absolute;left:-9999px;top:-9999px;">s</div>'); 109 setInterval($.checkFixHeight,1000); 110 $(window).resize($.checkFixHeight); 111 $.checkFixHeight(); 112 $(window).load( function(){ $.checkFixHeight(true); } ); 113 } 114 115})(jQuery); 116 117 118 119jQuery(document).ready(function(){ 120 $(".fixHeight").fixHeight(); 121});
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.