forked from jsliang/eqHeight.coffee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.eqheight.js
86 lines (80 loc) · 2.49 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
78
79
80
81
82
83
84
85
86
// Generated by CoffeeScript 1.7.1
/*
eqHeight.coffee v1.2.9
http://jsliang.github.com/eqHeight.coffee
Copyright (c) 2013, Jui-Shan Liang <jenny@jsliang.com>
All rights reserved.
Licensed under GPL v2.
*/
(function() {
var $;
$ = jQuery;
$.fn.extend({
eqHeight: function(column_selector, option) {
if (option == null) {
option = {
equalize_interval: null,
breakPoint: 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(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).height(), max_col_height);
});
marked_columns.height(max_col_height);
return $(".eqHeight_row").removeClass("eqHeight_row");
};
equalizer = function() {
var row_top_value;
columns.height("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);
if (typeof option.breakPoint === "number"){
if($(window).width()> option.breakPoint){
return timer = setTimeout(equalizer, 100);
}else{
columns.height("auto");
}
}else{
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);
}
});
}
});
}).call(this);