Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Can't say if this is much faster, but it's more concise

jQuery(document).ready(function($) {
 "use strict";
 var firstItems = $('.item.first');
 firstItems.each(function() {
 var $first, row, headings, heights, maxHeight;
 
 $first = $(this);
 
 // Get collection of "columns"
 row = $first.add($first.nextUntil(firstItems));
 
 // Find each column's heading
 headings = row.find("h2"); 
 // Get the heights of the headings
 heights = headings.map(function () {
 return $(this).outerHeight();
 }).toArray();
 
 // Get the maximum
 maxHeight = Math.max.apply(null, heights);
 
 // Set the heading heights to the maximum
 headings.css("height", maxHeight);
 });
});​​​

--Edit--

In my particular instance, the above script had conflict issues with prototype, since it lives inside a Magento install. I sought help and found this improvement sought help and found this improvement.

/Jezen

Can't say if this is much faster, but it's more concise

jQuery(document).ready(function($) {
 "use strict";
 var firstItems = $('.item.first');
 firstItems.each(function() {
 var $first, row, headings, heights, maxHeight;
 
 $first = $(this);
 
 // Get collection of "columns"
 row = $first.add($first.nextUntil(firstItems));
 
 // Find each column's heading
 headings = row.find("h2"); 
 // Get the heights of the headings
 heights = headings.map(function () {
 return $(this).outerHeight();
 }).toArray();
 
 // Get the maximum
 maxHeight = Math.max.apply(null, heights);
 
 // Set the heading heights to the maximum
 headings.css("height", maxHeight);
 });
});​​​

--Edit--

In my particular instance, the above script had conflict issues with prototype, since it lives inside a Magento install. I sought help and found this improvement.

/Jezen

Can't say if this is much faster, but it's more concise

jQuery(document).ready(function($) {
 "use strict";
 var firstItems = $('.item.first');
 firstItems.each(function() {
 var $first, row, headings, heights, maxHeight;
 
 $first = $(this);
 
 // Get collection of "columns"
 row = $first.add($first.nextUntil(firstItems));
 
 // Find each column's heading
 headings = row.find("h2"); 
 // Get the heights of the headings
 heights = headings.map(function () {
 return $(this).outerHeight();
 }).toArray();
 
 // Get the maximum
 maxHeight = Math.max.apply(null, heights);
 
 // Set the heading heights to the maximum
 headings.css("height", maxHeight);
 });
});​​​

--Edit--

In my particular instance, the above script had conflict issues with prototype, since it lives inside a Magento install. I sought help and found this improvement.

/Jezen

Can't say if this is much faster, but it's more concise

jQuery(document).ready(function($) {
 "use strict";
 var firstItems = $('.item.first');
 firstItems.each(function() {
 var $first, row, headings, heights, maxHeight;
 
 $first = $(this);
 
 // Get collection of "columns"
 row = $first.add($first.nextUntil(firstItems));
 
 // Find each column's heading
 headings = row.find("h2"); 
 // Get the heights of the headings
 heights = headings.map(function () {
 return $(this).outerHeight();
 }).toArray();
 
 // Get the maximum
 maxHeight = Math.max.apply(null, heights);
 
 // Set the heading heights to the maximum
 headings.css("height", maxHeight);
 });
});​​​

--Edit--

In my particular instance, the above script had conflict issues with prototype, since it lives inside a Magento install. I sought help and found this improvement .

/Jezen

Can't say if this is much faster, but it's more concise

jQuery(document).ready(function($) {
 "use strict";
 var firstItems = $('.item.first');
 firstItems.each(function() {
 var $first, row, headings, heights, maxHeight;
 
 $first = $(this);
 
 // Get collection of "columns"
 row = $first.add($first.nextUntil(firstItems));
 
 // Find each column's heading
 headings = row.find("h2"); 
 // Get the heights of the headings
 heights = headings.map(function () {
 return $(this).outerHeight();
 });
 
 // Get the maximum
 maxHeight = Math.max.apply(null, heights);
 
 // Set the heading heights to the maximum
 headings.css("height", maxHeight);
 });
});​​​

Can't say if this is much faster, but it's more concise

jQuery(document).ready(function($) {
 "use strict";
 var firstItems = $('.item.first');
 firstItems.each(function() {
 var $first, row, headings, heights, maxHeight;
 
 $first = $(this);
 
 // Get collection of "columns"
 row = $first.add($first.nextUntil(firstItems));
 
 // Find each column's heading
 headings = row.find("h2"); 
 // Get the heights of the headings
 heights = headings.map(function () {
 return $(this).outerHeight();
 }).toArray();
 
 // Get the maximum
 maxHeight = Math.max.apply(null, heights);
 
 // Set the heading heights to the maximum
 headings.css("height", maxHeight);
 });
});​​​

--Edit--

In my particular instance, the above script had conflict issues with prototype, since it lives inside a Magento install. I sought help and found this improvement .

/Jezen

Source Link
Flambino
  • 33.3k
  • 2
  • 46
  • 90

Can't say if this is much faster, but it's more concise

jQuery(document).ready(function($) {
 "use strict";
 var firstItems = $('.item.first');
 firstItems.each(function() {
 var $first, row, headings, heights, maxHeight;
 
 $first = $(this);
 
 // Get collection of "columns"
 row = $first.add($first.nextUntil(firstItems));
 
 // Find each column's heading
 headings = row.find("h2"); 
 // Get the heights of the headings
 heights = headings.map(function () {
 return $(this).outerHeight();
 });
 
 // Get the maximum
 maxHeight = Math.max.apply(null, heights);
 
 // Set the heading heights to the maximum
 headings.css("height", maxHeight);
 });
});​​​
default

AltStyle によって変換されたページ (->オリジナル) /