forked from artfinder/jquery-equal-height
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevfort.equal-height.js
59 lines (50 loc) · 1.78 KB
/
devfort.equal-height.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Naive jQuery Equal Height Children plugin
// Original by Art Discovery Ltd (https://github.com/artfinder/jquery-equal-height)
(function($) {
// This is pretty grubby
$.fn.set_minish_height = function(height) {
return this.each( function() {
var $this = $(this);
if ($this.css('display') == 'table') {
$this.css('height', height);
} else {
$this.css('min-height', height);
}
});
}
$.fn.make_children_equal_height = function () {
var make_equal_height = function (element) {
var $within = $(element),
selector = $within.attr('data-equal-height'),
$children = $(selector, $within),
tallest = 0;
$children.each( function() {
var $this = $(this);
$this.set_minish_height('');
var h = $this.height();
if ( h > tallest ) {
tallest = h;
}
});
$children.each( function() {
$(this).set_minish_height(tallest + 'px');
});
};
return this.each( function () {
make_equal_height(this);
});
};
$.fn.make_children_disequal_height = function () {
var make_disequal_height = function (element) {
var $within = $(element),
selector = $within.attr('data-equal-height'),
$children = $(selector, $within);
$children.each( function() {
$(this).set_minish_height('');
});
};
return this.each( function () {
make_disequal_height(this);
});
};
})( jQuery );