Skip to content

Commit 878ff96

Browse files
committed
fix issue maintaining inline styles, closes #95
1 parent 61a9ed4 commit 878ff96

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed

jquery.matchHeight-min.js

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jquery.matchHeight.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
// iterate the row and find the max height
233233
$row.each(function(){
234234
var $that = $(this),
235+
style = $that.attr('style'),
235236
display = $that.css('display');
236237

237238
// temporarily force a usable display value
@@ -249,8 +250,12 @@
249250
targetHeight = $that.outerHeight(false);
250251
}
251252

252-
// revert display block
253-
$that.css('display', '');
253+
// revert styles
254+
if (style) {
255+
$that.attr('style', style);
256+
} else {
257+
$that.css('display', '');
258+
}
254259
});
255260
} else {
256261
// if target set, use the height of the target element

test/page/test.html

+20
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,26 @@ <h3>min-height</h3>
394394
<p>Aenean semper.</p>
395395
</div>
396396
</div>
397+
398+
<div class="items-container inline-style-items">
399+
<div class="item item-0" style="display: inline-block">
400+
<h2>min-height</h2>
401+
<p>Phasellus ut nibh fermentum, vulputate urna vel, semper diam.</p>
402+
<p>Aenean semper felis ipsum, vulputate consequat dui elementum vel.</p>
403+
</div>
404+
<div class="item item-1" style="position: relative">
405+
<h3>min-height</h3>
406+
<p>Phasellus ut nibh fermentum, vulputate urna vel, semper diam. Nunc sollicitudin felis ut pellentesque fermentum. In erat mi, pulvinar sit amet tincidunt vitae, gravida id felis. Phasellus hendrerit erat sed porta imperdiet. Vivamus viverra ipsum tortor, et congue mauris porttitor ut.</p>
407+
</div>
408+
<div class="item item-2" style="min-height: 10px">
409+
<h4>min-height</h4>
410+
<p>Aenean semper felis ipsum, vulputate consequat dui elementum vel. Nullam odio eros, sagittis vitae lectus id, pretium viverra lectus. Etiam auctor dolor non dui ultricies pulvinar.</p>
411+
</div>
412+
<div class="item item-3" style="padding: 15px">
413+
<h3>min-height</h3>
414+
<p>Aenean semper.</p>
415+
</div>
416+
</div>
397417
</div>
398418
<div id='results'></div>
399419
</body>

test/specs/matchHeight.spec.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('matchHeight', function() {
107107
expect(1.0001).not.toBeWithinTolerance(0);
108108

109109
$('.simple-items, .image-items, .nested-items-parent, .nested-items,' +
110-
'.fixed-items, .inline-block-items, .inline-flex-items, .items-with-float')
110+
'.fixed-items, .inline-block-items, .inline-flex-items, .items-with-float, .inline-style-items')
111111
.each(function() {
112112
var $items = $(this).children('.item'),
113113
rows = $.fn.matchHeight._rows($items);
@@ -148,7 +148,7 @@ describe('matchHeight', function() {
148148
$.fn.matchHeight._update();
149149

150150
$('.simple-items, .image-items,' +
151-
'.fixed-items, .inline-block-items, .inline-flex-items, .items-with-float')
151+
'.fixed-items, .inline-block-items, .inline-flex-items, .items-with-float, .inline-style-items')
152152
.each(function() {
153153
var $items = $(this).children('.item'),
154154
targetHeight = $items.first().outerHeight(),
@@ -392,6 +392,21 @@ describe('matchHeight', function() {
392392

393393
done();
394394
});
395+
396+
it('maintains inline styles', function(done) {
397+
var $items = $('.inline-style-items'),
398+
item0Value = $items.find('.item-0')[0].style.display,
399+
item1Value = $items.find('.item-1')[0].style.position,
400+
item2Value = $items.find('.item-2')[0].style.minHeight,
401+
item3Value = $items.find('.item-3')[0].style.padding;
402+
403+
expect(item0Value).toBe('inline-block');
404+
expect(item1Value).toBe('relative');
405+
expect(item2Value).toBe('10px');
406+
expect(item3Value).toBe('15px');
407+
408+
done();
409+
});
395410
});
396411

397412

0 commit comments

Comments
 (0)