jquery-matchheight-rails 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jquery/matchheight/rails/version.rb +1 -1
- data/vendor/assets/javascripts/jquery.matchHeight.js +226 -177
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dda21a54769de7c41dc9b8bde943b26bf06a91c1
|
|
4
|
+
data.tar.gz: 195c80927b650a26fe39dbc4d0472b6bee97e85c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f7576692610b4206bd97ffe56ff38112bdd4e61921cf6ee845f7c8121127aef4d31b05b068185267516613e7fd2d4275aec542f11c49f43e9f0bec421625609
|
|
7
|
+
data.tar.gz: 2620efaa8a4466a32971fda0d5b940c896f95b0ba5236c9f56df5414d6f3cc77aa96b535e2b394e60e8d3f408cc55c5a7deb0973d2b70ad6fe22fa68fee9942b
|
|
@@ -1,178 +1,227 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* jquery.matchHeight.js v0.5.
|
|
3
|
-
* http://brm.io/jquery-match-height/
|
|
4
|
-
* License: MIT
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
(function($) {
|
|
8
|
-
|
|
9
|
-
$.fn.matchHeight = function(byRow) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
elements
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
var
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
1
|
+
/**
|
|
2
|
+
* jquery.matchHeight.js v0.5.1
|
|
3
|
+
* http://brm.io/jquery-match-height/
|
|
4
|
+
* License: MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
(function($) {
|
|
8
|
+
|
|
9
|
+
$.fn.matchHeight = function(byRow) {
|
|
10
|
+
|
|
11
|
+
// handle matchHeight('remove')
|
|
12
|
+
if (byRow === 'remove') {
|
|
13
|
+
var that = this;
|
|
14
|
+
|
|
15
|
+
// remove fixed height from all selected elements
|
|
16
|
+
this.css('height', '');
|
|
17
|
+
|
|
18
|
+
// remove selected elements from all groups
|
|
19
|
+
$.each($.fn.matchHeight._groups, function(key, group) {
|
|
20
|
+
group.elements = group.elements.not(that);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// TODO: cleanup empty groups
|
|
24
|
+
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (this.length <= 1)
|
|
29
|
+
return this;
|
|
30
|
+
|
|
31
|
+
// byRow default to true
|
|
32
|
+
byRow = (typeof byRow !== 'undefined') ? byRow : true;
|
|
33
|
+
|
|
34
|
+
// keep track of this group so we can re-apply later on load and resize events
|
|
35
|
+
$.fn.matchHeight._groups.push({
|
|
36
|
+
elements: this,
|
|
37
|
+
byRow: byRow
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// match each element's height to the tallest element in the selection
|
|
41
|
+
$.fn.matchHeight._apply(this, byRow);
|
|
42
|
+
|
|
43
|
+
return this;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
$.fn.matchHeight._apply = function(elements, byRow) {
|
|
47
|
+
var $elements = $(elements),
|
|
48
|
+
rows = [$elements];
|
|
49
|
+
|
|
50
|
+
// get rows if using byRow, otherwise assume one row
|
|
51
|
+
if (byRow) {
|
|
52
|
+
|
|
53
|
+
// must first force an arbitrary equal height so floating elements break evenly
|
|
54
|
+
$elements.css({
|
|
55
|
+
'display': 'block',
|
|
56
|
+
'padding-top': '0',
|
|
57
|
+
'padding-bottom': '0',
|
|
58
|
+
'border-top': '0',
|
|
59
|
+
'border-bottom': '0',
|
|
60
|
+
'height': '100px'
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// get the array of rows (based on element top position)
|
|
64
|
+
rows = _rows($elements);
|
|
65
|
+
|
|
66
|
+
// revert the temporary forced style
|
|
67
|
+
$elements.css({
|
|
68
|
+
'display': '',
|
|
69
|
+
'padding-top': '',
|
|
70
|
+
'padding-bottom': '',
|
|
71
|
+
'border-top': '',
|
|
72
|
+
'border-bottom': '',
|
|
73
|
+
'height': ''
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
$.each(rows, function(key, row) {
|
|
78
|
+
var $row = $(row),
|
|
79
|
+
maxHeight = 0;
|
|
80
|
+
|
|
81
|
+
// iterate the row and find the max height
|
|
82
|
+
$row.each(function(){
|
|
83
|
+
var $that = $(this);
|
|
84
|
+
|
|
85
|
+
// ensure we get the correct actual height (and not a previously set height value)
|
|
86
|
+
$that.css({ 'display': 'block', 'height': '' });
|
|
87
|
+
|
|
88
|
+
// find the max height (including padding, but not margin)
|
|
89
|
+
if ($that.outerHeight(false) > maxHeight)
|
|
90
|
+
maxHeight = $that.outerHeight(false);
|
|
91
|
+
|
|
92
|
+
// revert display block
|
|
93
|
+
$that.css({ 'display': '' });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// iterate the row and apply the height to all elements
|
|
97
|
+
$row.each(function(){
|
|
98
|
+
var $that = $(this),
|
|
99
|
+
verticalPadding = 0;
|
|
100
|
+
|
|
101
|
+
// handle padding and border correctly (required when not using border-box)
|
|
102
|
+
if ($that.css('box-sizing') !== 'border-box') {
|
|
103
|
+
verticalPadding += _parse($that.css('border-top-width')) + _parse($that.css('border-bottom-width'));
|
|
104
|
+
verticalPadding += _parse($that.css('padding-top')) + _parse($that.css('padding-bottom'));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// set the height (accounting for padding and border)
|
|
108
|
+
$that.css('height', maxHeight - verticalPadding);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return this;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/*
|
|
116
|
+
* _applyDataApi will apply matchHeight to all elements with a data-match-height attribute
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
$.fn.matchHeight._applyDataApi = function() {
|
|
120
|
+
var groups = {};
|
|
121
|
+
|
|
122
|
+
// generate groups by their groupId set by elements using data-match-height
|
|
123
|
+
$('[data-match-height], [data-mh]').each(function() {
|
|
124
|
+
var $this = $(this),
|
|
125
|
+
groupId = $this.attr('data-match-height');
|
|
126
|
+
if (groupId in groups) {
|
|
127
|
+
groups[groupId] = groups[groupId].add($this);
|
|
128
|
+
} else {
|
|
129
|
+
groups[groupId] = $this;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// apply matchHeight to each group
|
|
134
|
+
$.each(groups, function() {
|
|
135
|
+
this.matchHeight(true);
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/*
|
|
140
|
+
* _update function will re-apply matchHeight to all groups with the correct options
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
$.fn.matchHeight._groups = [];
|
|
144
|
+
$.fn.matchHeight._throttle = 80;
|
|
145
|
+
|
|
146
|
+
var previousResizeWidth = -1,
|
|
147
|
+
updateTimeout = -1;
|
|
148
|
+
|
|
149
|
+
$.fn.matchHeight._update = function(event) {
|
|
150
|
+
// prevent update if fired from a resize event
|
|
151
|
+
// where the viewport width hasn't actually changed
|
|
152
|
+
// fixes an event looping bug in IE8
|
|
153
|
+
if (event && event.type === 'resize') {
|
|
154
|
+
var windowWidth = $(window).width();
|
|
155
|
+
if (windowWidth === previousResizeWidth)
|
|
156
|
+
return;
|
|
157
|
+
previousResizeWidth = windowWidth;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// throttle updates
|
|
161
|
+
if (updateTimeout === -1) {
|
|
162
|
+
updateTimeout = setTimeout(function() {
|
|
163
|
+
|
|
164
|
+
$.each($.fn.matchHeight._groups, function() {
|
|
165
|
+
$.fn.matchHeight._apply(this.elements, this.byRow);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
updateTimeout = -1;
|
|
169
|
+
|
|
170
|
+
}, $.fn.matchHeight._throttle);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/*
|
|
175
|
+
* bind events
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
// apply on DOM ready event
|
|
179
|
+
$($.fn.matchHeight._applyDataApi);
|
|
180
|
+
|
|
181
|
+
// update heights on load and resize events
|
|
182
|
+
$(window).bind('load resize orientationchange', $.fn.matchHeight._update);
|
|
183
|
+
|
|
184
|
+
/*
|
|
185
|
+
* rows utility function
|
|
186
|
+
* returns array of jQuery selections representing each row
|
|
187
|
+
* (as displayed after float wrapping applied by browser)
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
var _rows = function(elements) {
|
|
191
|
+
var tolerance = 1,
|
|
192
|
+
$elements = $(elements),
|
|
193
|
+
lastTop = null,
|
|
194
|
+
rows = [];
|
|
195
|
+
|
|
196
|
+
// group elements by their top position
|
|
197
|
+
$elements.each(function(){
|
|
198
|
+
var $that = $(this),
|
|
199
|
+
top = $that.offset().top - _parse($that.css('margin-top')),
|
|
200
|
+
lastRow = rows.length > 0 ? rows[rows.length - 1] : null;
|
|
201
|
+
|
|
202
|
+
if (lastRow === null) {
|
|
203
|
+
// first item on the row, so just push it
|
|
204
|
+
rows.push($that);
|
|
205
|
+
} else {
|
|
206
|
+
// if the row top is the same, add to the row group
|
|
207
|
+
if (Math.floor(Math.abs(lastTop - top)) <= tolerance) {
|
|
208
|
+
rows[rows.length - 1] = lastRow.add($that);
|
|
209
|
+
} else {
|
|
210
|
+
// otherwise start a new row group
|
|
211
|
+
rows.push($that);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// keep track of the last row top
|
|
216
|
+
lastTop = top;
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
return rows;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
var _parse = function(value) {
|
|
223
|
+
// parse value and convert NaN to 0
|
|
224
|
+
return parseFloat(value) || 0;
|
|
225
|
+
};
|
|
226
|
+
|
|
178
227
|
})(jQuery);
|