5
5
*/
6
6
7
7
; ( function ( $ ) {
8
+ /*
9
+ * internal
10
+ */
11
+
12
+ var _previousResizeWidth = - 1 ,
13
+ _updateTimeout = - 1 ;
14
+
15
+ /*
16
+ * _rows
17
+ * utility function returns array of jQuery selections representing each row
18
+ * (as displayed after float wrapping applied by browser)
19
+ */
20
+
21
+ var _rows = function ( elements ) {
22
+ var tolerance = 1 ,
23
+ $elements = $ ( elements ) ,
24
+ lastTop = null ,
25
+ rows = [ ] ;
26
+
27
+ // group elements by their top position
28
+ $elements . each ( function ( ) {
29
+ var $that = $ ( this ) ,
30
+ top = $that . offset ( ) . top - _parse ( $that . css ( 'margin-top' ) ) ,
31
+ lastRow = rows . length > 0 ? rows [ rows . length - 1 ] : null ;
32
+
33
+ if ( lastRow === null ) {
34
+ // first item on the row, so just push it
35
+ rows . push ( $that ) ;
36
+ } else {
37
+ // if the row top is the same, add to the row group
38
+ if ( Math . floor ( Math . abs ( lastTop - top ) ) <= tolerance ) {
39
+ rows [ rows . length - 1 ] = lastRow . add ( $that ) ;
40
+ } else {
41
+ // otherwise start a new row group
42
+ rows . push ( $that ) ;
43
+ }
44
+ }
45
+
46
+ // keep track of the last row top
47
+ lastTop = top ;
48
+ } ) ;
49
+
50
+ return rows ;
51
+ } ;
52
+
53
+ /*
54
+ * _parse
55
+ * value parse utility function
56
+ */
57
+
58
+ var _parse = function ( value ) {
59
+ // parse value and convert NaN to 0
60
+ return parseFloat ( value ) || 0 ;
61
+ } ;
62
+
63
+ /*
64
+ * $.fn.matchHeight
65
+ * plugin definition
66
+ */
8
67
9
68
$ . fn . matchHeight = function ( byRow ) {
10
69
43
102
return this ;
44
103
} ;
45
104
105
+ /*
106
+ * plugin global options
107
+ */
108
+
109
+ $ . fn . matchHeight . _groups = [ ] ;
110
+ $ . fn . matchHeight . _throttle = 80 ;
111
+ $ . fn . matchHeight . _maintainScroll = false ;
112
+
113
+ /*
114
+ * $.fn.matchHeight._apply
115
+ * apply matchHeight to given elements
116
+ */
117
+
46
118
$ . fn . matchHeight . _apply = function ( elements , byRow ) {
47
119
var $elements = $ ( elements ) ,
48
120
rows = [ $elements ] ;
134
206
} ;
135
207
136
208
/*
137
- * _applyDataApi will apply matchHeight to all elements with a data-match-height attribute
209
+ * $.fn.matchHeight._applyDataApi
210
+ * applies matchHeight to all elements with a data-match-height attribute
138
211
*/
139
212
140
213
$ . fn . matchHeight . _applyDataApi = function ( ) {
158
231
} ;
159
232
160
233
/*
161
- * _update function will re-apply matchHeight to all groups with the correct options
234
+ * $.fn.matchHeight._update
235
+ * updates matchHeight on all current groups with their correct options
162
236
*/
163
-
164
- $ . fn . matchHeight . _groups = [ ] ;
165
- $ . fn . matchHeight . _throttle = 80 ;
166
- $ . fn . matchHeight . _maintainScroll = false ;
167
-
168
- var previousResizeWidth = - 1 ,
169
- updateTimeout = - 1 ;
170
237
171
238
$ . fn . matchHeight . _update = function ( event ) {
172
239
// prevent update if fired from a resize event
173
240
// where the viewport width hasn't actually changed
174
241
// fixes an event looping bug in IE8
175
242
if ( event && event . type === 'resize' ) {
176
243
var windowWidth = $ ( window ) . width ( ) ;
177
- if ( windowWidth === previousResizeWidth )
244
+ if ( windowWidth === _previousResizeWidth )
178
245
return ;
179
- previousResizeWidth = windowWidth ;
246
+ _previousResizeWidth = windowWidth ;
180
247
}
181
248
182
249
// throttle updates
183
- if ( updateTimeout === - 1 ) {
184
- updateTimeout = setTimeout ( function ( ) {
250
+ if ( _updateTimeout === - 1 ) {
251
+ _updateTimeout = setTimeout ( function ( ) {
185
252
186
253
$ . each ( $ . fn . matchHeight . _groups , function ( ) {
187
254
$ . fn . matchHeight . _apply ( this . elements , this . byRow ) ;
188
255
} ) ;
189
256
190
- updateTimeout = - 1 ;
257
+ _updateTimeout = - 1 ;
191
258
192
259
} , $ . fn . matchHeight . _throttle ) ;
193
260
}
203
270
// update heights on load and resize events
204
271
$ ( window ) . bind ( 'load resize orientationchange' , $ . fn . matchHeight . _update ) ;
205
272
206
- /*
207
- * rows utility function
208
- * returns array of jQuery selections representing each row
209
- * (as displayed after float wrapping applied by browser)
210
- */
211
-
212
- var _rows = function ( elements ) {
213
- var tolerance = 1 ,
214
- $elements = $ ( elements ) ,
215
- lastTop = null ,
216
- rows = [ ] ;
217
-
218
- // group elements by their top position
219
- $elements . each ( function ( ) {
220
- var $that = $ ( this ) ,
221
- top = $that . offset ( ) . top - _parse ( $that . css ( 'margin-top' ) ) ,
222
- lastRow = rows . length > 0 ? rows [ rows . length - 1 ] : null ;
223
-
224
- if ( lastRow === null ) {
225
- // first item on the row, so just push it
226
- rows . push ( $that ) ;
227
- } else {
228
- // if the row top is the same, add to the row group
229
- if ( Math . floor ( Math . abs ( lastTop - top ) ) <= tolerance ) {
230
- rows [ rows . length - 1 ] = lastRow . add ( $that ) ;
231
- } else {
232
- // otherwise start a new row group
233
- rows . push ( $that ) ;
234
- }
235
- }
236
-
237
- // keep track of the last row top
238
- lastTop = top ;
239
- } ) ;
240
-
241
- return rows ;
242
- } ;
243
-
244
- var _parse = function ( value ) {
245
- // parse value and convert NaN to 0
246
- return parseFloat ( value ) || 0 ;
247
- } ;
248
-
249
- } ) ( jQuery ) ;
273
+ } ) ( jQuery ) ;
0 commit comments