Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare functions before they're used. #27

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 42 additions & 44 deletions jquery.matchHeight.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,48 @@
*/

(function($) {
/*
* rows utility function
* returns array of jQuery selections representing each row
* (as displayed after float wrapping applied by browser)
*/

var _rows = function(elements) {
var tolerance = 1,
$elements = $(elements),
lastTop = null,
rows = [];

// group elements by their top position
$elements.each(function(){
var $that = $(this),
top = $that.offset().top - _parse($that.css('margin-top')),
lastRow = rows.length > 0 ? rows[rows.length - 1] : null;

if (lastRow === null) {
// first item on the row, so just push it
rows.push($that);
} else {
// if the row top is the same, add to the row group
if (Math.floor(Math.abs(lastTop - top)) <= tolerance) {
rows[rows.length - 1] = lastRow.add($that);
} else {
// otherwise start a new row group
rows.push($that);
}
}

// keep track of the last row top
lastTop = top;
});

return rows;
};

var _parse = function(value) {
// parse value and convert NaN to 0
return parseFloat(value) || 0;
};

$.fn.matchHeight = function(byRow) {

Expand Down Expand Up @@ -202,48 +244,4 @@

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

/*
* rows utility function
* returns array of jQuery selections representing each row
* (as displayed after float wrapping applied by browser)
*/

var _rows = function(elements) {
var tolerance = 1,
$elements = $(elements),
lastTop = null,
rows = [];

// group elements by their top position
$elements.each(function(){
var $that = $(this),
top = $that.offset().top - _parse($that.css('margin-top')),
lastRow = rows.length > 0 ? rows[rows.length - 1] : null;

if (lastRow === null) {
// first item on the row, so just push it
rows.push($that);
} else {
// if the row top is the same, add to the row group
if (Math.floor(Math.abs(lastTop - top)) <= tolerance) {
rows[rows.length - 1] = lastRow.add($that);
} else {
// otherwise start a new row group
rows.push($that);
}
}

// keep track of the last row top
lastTop = top;
});

return rows;
};

var _parse = function(value) {
// parse value and convert NaN to 0
return parseFloat(value) || 0;
};

})(jQuery);