Skip to content

Commit

Permalink
fixed throttling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Sep 10, 2014
1 parent f72ab91 commit fdc8f7a
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions jquery.matchHeight.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,13 @@
* updates matchHeight on all current groups with their correct options
*/

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

$.fn.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 @@ -251,15 +257,12 @@
}

// throttle updates
if (_updateTimeout === -1) {
if (!throttle) {
_update();
} else if (_updateTimeout === -1) {
_updateTimeout = setTimeout(function() {

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

_update();
_updateTimeout = -1;

}, $.fn.matchHeight._throttle);
}
};
Expand All @@ -272,6 +275,13 @@
$($.fn.matchHeight._applyDataApi);

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

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

})(jQuery);

0 comments on commit fdc8f7a

Please sign in to comment.