Skip to content

Commit

Permalink
refactored plugin definition
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Oct 16, 2014
1 parent 0b31e21 commit 467d928
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
11 changes: 5 additions & 6 deletions jquery.matchHeight-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 27 additions & 27 deletions jquery.matchHeight.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@
};

/*
* $.fn.matchHeight
* matchHeight
* plugin definition
*/

$.fn.matchHeight = function(byRow) {
var matchHeight = $.fn.matchHeight = function(byRow) {

// handle matchHeight('remove')
if (byRow === 'remove') {
Expand All @@ -75,7 +75,7 @@
this.css('height', '');

// remove selected elements from all groups
$.each($.fn.matchHeight._groups, function(key, group) {
$.each(matchHeight._groups, function(key, group) {
group.elements = group.elements.not(that);
});

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

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

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

return this;
};
Expand All @@ -106,18 +106,18 @@
* plugin global options
*/

$.fn.matchHeight._groups = [];
$.fn.matchHeight._throttle = 80;
$.fn.matchHeight._maintainScroll = false;
$.fn.matchHeight._beforeUpdate = null;
$.fn.matchHeight._afterUpdate = null;
matchHeight._groups = [];
matchHeight._throttle = 80;
matchHeight._maintainScroll = false;
matchHeight._beforeUpdate = null;
matchHeight._afterUpdate = null;

/*
* $.fn.matchHeight._apply
* matchHeight._apply
* apply matchHeight to given elements
*/

$.fn.matchHeight._apply = function(elements, byRow) {
matchHeight._apply = function(elements, byRow) {
var $elements = $(elements),
rows = [$elements];

Expand Down Expand Up @@ -208,18 +208,18 @@
$hiddenParents.css('display', '');

// restore scroll position if enabled
if ($.fn.matchHeight._maintainScroll)
if (matchHeight._maintainScroll)
$(window).scrollTop((scrollTop / htmlHeight) * $('html').outerHeight(true));

return this;
};

/*
* $.fn.matchHeight._applyDataApi
* matchHeight._applyDataApi
* applies matchHeight to all elements with a data-match-height attribute
*/

$.fn.matchHeight._applyDataApi = function() {
matchHeight._applyDataApi = function() {
var groups = {};

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

/*
* $.fn.matchHeight._update
* matchHeight._update
* updates matchHeight on all current groups with their correct options
*/

var _update = function(event) {
if ($.fn.matchHeight._beforeUpdate)
$.fn.matchHeight._beforeUpdate(event, $.fn.matchHeight._groups);
if (matchHeight._beforeUpdate)
matchHeight._beforeUpdate(event, matchHeight._groups);

$.each($.fn.matchHeight._groups, function() {
$.fn.matchHeight._apply(this.elements, this.byRow);
$.each(matchHeight._groups, function() {
matchHeight._apply(this.elements, this.byRow);
});

if ($.fn.matchHeight._afterUpdate)
$.fn.matchHeight._afterUpdate(event, $.fn.matchHeight._groups);
if (matchHeight._afterUpdate)
matchHeight._afterUpdate(event, matchHeight._groups);
};

$.fn.matchHeight._update = function(throttle, event) {
matchHeight._update = function(throttle, event) {
// prevent update if fired from a resize event
// where the viewport width hasn't actually changed
// fixes an event looping bug in IE8
Expand All @@ -274,7 +274,7 @@
_updateTimeout = setTimeout(function() {
_update(event);
_updateTimeout = -1;
}, $.fn.matchHeight._throttle);
}, matchHeight._throttle);
}
};

Expand All @@ -283,16 +283,16 @@
*/

// apply on DOM ready event
$($.fn.matchHeight._applyDataApi);
$(matchHeight._applyDataApi);

// update heights on load and resize events
$(window).bind('load', function(event) {
$.fn.matchHeight._update(false, event);
matchHeight._update(false, event);
});

// throttled update heights on resize events
$(window).bind('resize orientationchange', function(event) {
$.fn.matchHeight._update(true, event);
matchHeight._update(true, event);
});

})(jQuery);

0 comments on commit 467d928

Please sign in to comment.