Skip to content

Commit 467d928

Browse files
committed
refactored plugin definition
1 parent 0b31e21 commit 467d928

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

jquery.matchHeight-min.js

+5-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jquery.matchHeight.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@
6161
};
6262

6363
/*
64-
* $.fn.matchHeight
64+
* matchHeight
6565
* plugin definition
6666
*/
6767

68-
$.fn.matchHeight = function(byRow) {
68+
var matchHeight = $.fn.matchHeight = function(byRow) {
6969

7070
// handle matchHeight('remove')
7171
if (byRow === 'remove') {
@@ -75,7 +75,7 @@
7575
this.css('height', '');
7676

7777
// remove selected elements from all groups
78-
$.each($.fn.matchHeight._groups, function(key, group) {
78+
$.each(matchHeight._groups, function(key, group) {
7979
group.elements = group.elements.not(that);
8080
});
8181

@@ -91,13 +91,13 @@
9191
byRow = (typeof byRow !== 'undefined') ? byRow : true;
9292

9393
// keep track of this group so we can re-apply later on load and resize events
94-
$.fn.matchHeight._groups.push({
94+
matchHeight._groups.push({
9595
elements: this,
9696
byRow: byRow
9797
});
9898

9999
// match each element's height to the tallest element in the selection
100-
$.fn.matchHeight._apply(this, byRow);
100+
matchHeight._apply(this, byRow);
101101

102102
return this;
103103
};
@@ -106,18 +106,18 @@
106106
* plugin global options
107107
*/
108108

109-
$.fn.matchHeight._groups = [];
110-
$.fn.matchHeight._throttle = 80;
111-
$.fn.matchHeight._maintainScroll = false;
112-
$.fn.matchHeight._beforeUpdate = null;
113-
$.fn.matchHeight._afterUpdate = null;
109+
matchHeight._groups = [];
110+
matchHeight._throttle = 80;
111+
matchHeight._maintainScroll = false;
112+
matchHeight._beforeUpdate = null;
113+
matchHeight._afterUpdate = null;
114114

115115
/*
116-
* $.fn.matchHeight._apply
116+
* matchHeight._apply
117117
* apply matchHeight to given elements
118118
*/
119119

120-
$.fn.matchHeight._apply = function(elements, byRow) {
120+
matchHeight._apply = function(elements, byRow) {
121121
var $elements = $(elements),
122122
rows = [$elements];
123123

@@ -208,18 +208,18 @@
208208
$hiddenParents.css('display', '');
209209

210210
// restore scroll position if enabled
211-
if ($.fn.matchHeight._maintainScroll)
211+
if (matchHeight._maintainScroll)
212212
$(window).scrollTop((scrollTop / htmlHeight) * $('html').outerHeight(true));
213213

214214
return this;
215215
};
216216

217217
/*
218-
* $.fn.matchHeight._applyDataApi
218+
* matchHeight._applyDataApi
219219
* applies matchHeight to all elements with a data-match-height attribute
220220
*/
221221

222-
$.fn.matchHeight._applyDataApi = function() {
222+
matchHeight._applyDataApi = function() {
223223
var groups = {};
224224

225225
// generate groups by their groupId set by elements using data-match-height
@@ -240,23 +240,23 @@
240240
};
241241

242242
/*
243-
* $.fn.matchHeight._update
243+
* matchHeight._update
244244
* updates matchHeight on all current groups with their correct options
245245
*/
246246

247247
var _update = function(event) {
248-
if ($.fn.matchHeight._beforeUpdate)
249-
$.fn.matchHeight._beforeUpdate(event, $.fn.matchHeight._groups);
248+
if (matchHeight._beforeUpdate)
249+
matchHeight._beforeUpdate(event, matchHeight._groups);
250250

251-
$.each($.fn.matchHeight._groups, function() {
252-
$.fn.matchHeight._apply(this.elements, this.byRow);
251+
$.each(matchHeight._groups, function() {
252+
matchHeight._apply(this.elements, this.byRow);
253253
});
254254

255-
if ($.fn.matchHeight._afterUpdate)
256-
$.fn.matchHeight._afterUpdate(event, $.fn.matchHeight._groups);
255+
if (matchHeight._afterUpdate)
256+
matchHeight._afterUpdate(event, matchHeight._groups);
257257
};
258258

259-
$.fn.matchHeight._update = function(throttle, event) {
259+
matchHeight._update = function(throttle, event) {
260260
// prevent update if fired from a resize event
261261
// where the viewport width hasn't actually changed
262262
// fixes an event looping bug in IE8
@@ -274,7 +274,7 @@
274274
_updateTimeout = setTimeout(function() {
275275
_update(event);
276276
_updateTimeout = -1;
277-
}, $.fn.matchHeight._throttle);
277+
}, matchHeight._throttle);
278278
}
279279
};
280280

@@ -283,16 +283,16 @@
283283
*/
284284

285285
// apply on DOM ready event
286-
$($.fn.matchHeight._applyDataApi);
286+
$(matchHeight._applyDataApi);
287287

288288
// update heights on load and resize events
289289
$(window).bind('load', function(event) {
290-
$.fn.matchHeight._update(false, event);
290+
matchHeight._update(false, event);
291291
});
292292

293293
// throttled update heights on resize events
294294
$(window).bind('resize orientationchange', function(event) {
295-
$.fn.matchHeight._update(true, event);
295+
matchHeight._update(true, event);
296296
});
297297

298298
})(jQuery);

0 commit comments

Comments
 (0)