forked from jsliang/eqHeight.coffee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.eqheight.js
66 lines (58 loc) · 1.88 KB
/
jquery.eqheight.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
60
61
62
63
64
65
66
/*
eqHeight.coffee v1.2.4
http://jsliang.github.com/eqHeight.coffee
Copyright (c) 2013, Jui-Shan Liang <[email protected]>
All rights reserved.
Licensed under GPL v2.
*/
(function() {
var $;
$ = jQuery;
$.fn.extend({
eqHeight: function(column_selector) {
return this.each(function() {
var columns, equalizer, start_equalizing, timer, _equalize_marked_columns;
columns = $(this).find(column_selector);
timer = null;
if (columns.length === 0) {
columns = $(this).children(column_selector);
}
if (columns.length === 0) {
return;
}
_equalize_marked_columns = function() {
var marked_columns, max_col_height;
marked_columns = $(".eqHeight_row");
max_col_height = 0;
marked_columns.each(function() {
return max_col_height = Math.max($(this).outerHeight(), max_col_height);
});
marked_columns.outerHeight(max_col_height);
return $(".eqHeight_row").removeClass("eqHeight_row");
};
equalizer = function() {
var row_top_value;
columns.outerHeight("auto");
row_top_value = columns.first().position().top;
columns.each(function() {
var current_top;
current_top = $(this).position().top;
if (current_top !== row_top_value) {
_equalize_marked_columns();
row_top_value = $(this).position().top;
}
return $(this).addClass("eqHeight_row");
});
return _equalize_marked_columns();
};
start_equalizing = function() {
clearTimeout(timer);
return timer = setTimeout(equalizer, 100);
};
$(window).load(equalizer);
return $(window).resize(start_equalizing);
});
}
});
}).call(this);
// Generated by CoffeeScript 1.5.0-pre