Skip to content
This repository was archived by the owner on Feb 23, 2025. It is now read-only.

Added excludeLastSingleItem option and functionality #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# jquery.wRECkeR

wRECkeR: Responsive Equal-Height Columns and Rows

---

[![Analytics](https://ga-beacon.appspot.com/UA-3614308-8/stevenvachon/jquery.wrecker)](https://github.com/igrigorik/ga-beacon "Google Analytics") [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/stevenvachon/jquery.wrecker/trend.png)](https://bitdeli.com/free)
42 changes: 30 additions & 12 deletions jquery.wrecker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* jQuery Wrecker v0.2
* jQuery Wrecker v0.4
* Responsive Equal-Height Columns and Rows
* http://www.svachon.com/blog/wrecker-responsive-equal-height-columns-and-rows
*
Expand All @@ -20,7 +20,8 @@ $.Wrecker = function()
var settings = {
itemSelector : "",
maxColumns : 1,
responsiveColumns : [ /*{800:1}*/ ] // Had to nest this way because not all browsers loop through objects in correct order
responsiveColumns : [ /*{800:1}*/ ], // Had to nest this way because not all browsers loop through objects in correct order
excludeLastSingleItem : false
};


Expand Down Expand Up @@ -112,6 +113,13 @@ $.Wrecker = function()

var startIndex = 0;
var count = 0;

var numCellsIsEven = numCells % 2 === 0;
var excludeLastItem = false;
if (settings.excludeLastSingleItem && !numCellsIsEven) {
excludeLastItem = true;
var lastCell = cells.last().addClass("wrecker-single-last");
}

// Add row containers
cells.each(function(i)
Expand All @@ -120,22 +128,32 @@ $.Wrecker = function()
{
startIndex = i;
}
if (count>=columnCount || i>=numCells-1)

if (!excludeLastItem || i < numCells-1)
{
cells.slice(startIndex,i+1).wrapAll('<div class="wrecker-row" style="display:table-row"/>');

count = 0;
}

// Since Wrecker styles are removed for single columns, they must be re-added
if (previousColumnCount <= 1)
{
$(this).addClass("wrecker-cell").css({display:"table-cell", float:"none"});
if (count>=columnCount || i>=numCells-1)
{
cells.slice(startIndex,i+1).wrapAll('<div class="wrecker-row" style="display:table-row"/>');

count = 0;
}

// Since Wrecker styles are removed for single columns, they must be re-added
if (previousColumnCount <= 1)
{
$(this).addClass("wrecker-cell").css({display:"table-cell", float:"none"});
}

}else{
$(this).remove();
}
});

element.addClass("wrecker").css("display", "table");
if (excludeLastItem) {
lastCell.insertAfter(element);
}
}
else
{
Expand Down
6 changes: 2 additions & 4 deletions jquery.wrecker.min.js

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