-
Notifications
You must be signed in to change notification settings - Fork 10
/
jquery.eqheight.js
77 lines (73 loc) · 2.26 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
67
68
69
70
71
72
73
74
75
76
77
// Generated by CoffeeScript 1.7.1
/*
eqHeight.coffee v1.3.5
http://jsliang.github.com/eqHeight.coffee
Copyright (c) 2013-2014, Jui-Shan Liang <[email protected]>
All rights reserved.
Licensed under GPL v2.
*/
var $;
$ = jQuery;
$.fn.extend({
eqHeight: function(column_selector, option) {
if (option == null) {
option = {
equalize_interval: null,
break_point: null
};
}
return this.each(function() {
var columns, equalizer, infinite_equalizing, start_equalizing, timer, _equalize_marked_columns;
timer = null;
columns = $(this).find(column_selector);
if (columns.length === 0) {
columns = $(this).children();
}
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.height(max_col_height);
return $(".eqHeight_row").removeClass("eqHeight_row");
};
equalizer = function() {
var row_top_value;
columns.height("auto");
if (typeof option.break_point === "number" && $(window).width() <= option.break_point) {
return;
}
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);
};
infinite_equalizing = function() {
equalizer();
return timer = setTimeout(infinite_equalizing, option.equalize_interval);
};
$(window).load(equalizer);
if (typeof option.equalize_interval === "number") {
return infinite_equalizing();
} else {
return $(window).resize(start_equalizing);
}
});
}
});