Skip to content

Commit

Permalink
fix last-item class and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
brunjo committed Nov 20, 2017
1 parent d59e59d commit 7bbc6a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# rowGrid.js
**rowGrid.js is a small, lightweight (~900 bytes gzipped) jQuery plugin for placing images (or other items) in straight rows.**
**rowGrid.js is a small, lightweight (~1000 bytes gzipped) jQuery plugin for placing images (or other items) in straight rows.**

The grid is similar to grids on Google Image Search, flickr, shutterstock and Google+ images.

Expand All @@ -22,7 +22,7 @@ At first rowGrid.js adjusts the margin between the items. If this is not enough
## Demos & Examples
Examples with explanation: http://brunjo.github.io/rowGrid.js/

Real world example: http://www.pexels.com/
Real world example: https://www.pexels.com/

## Installation
RowGrid.js requires jQuery 1.7 or above.
Expand Down Expand Up @@ -105,6 +105,11 @@ The first item in the last row gets this class.
* **default value:** ```null```

The first item in every row gets this class.
#### lastItemClass
* **value:** ```string``` or ```null```
* **default value:** ```null```

The last item in every row gets this class.


[1]: https://twitter.com/3runjo "@3runjo"
Expand Down
4 changes: 3 additions & 1 deletion jquery.row-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
rowElems = [],
items = jQuery.makeArray(items || container.querySelectorAll(options.itemSelector)),
itemsSize = items.length;

// read

var containerBoundingRect = container.getBoundingClientRect();
Expand All @@ -49,6 +50,7 @@
--itemsSize;
continue;
}

// get width and height via attribute or js value
if (!(w = parseInt(theImage.getAttribute('width')))) {
theImage.setAttribute('width', w = theImage.offsetWidth);
Expand All @@ -72,7 +74,7 @@
items[index].classList.remove(options.lastRowClass);
} else {
// IE <10
items[index].className = items[index].className.replace(new RegExp('(^|\\b)' + options.firstItemClass + '|' + options.lastRowClass + '(\\b|$)', 'gi'), ' ');
items[index].className = items[index].className.replace(new RegExp('(^|\\b)' + options.firstItemClass + '|' + options.lastItemClass + '|' + options.lastRowClass + '(\\b|$)', 'gi'), ' ');
}

rowWidth += itemAttrs[index].width;
Expand Down
10 changes: 5 additions & 5 deletions jquery.row-grid.min.js

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

0 comments on commit 7bbc6a9

Please sign in to comment.