From 7bbc6a929e3f0c5c5ef8d6304034305b9bc4609a Mon Sep 17 00:00:00 2001 From: Bruno Joseph Date: Mon, 20 Nov 2017 23:45:03 +0100 Subject: [PATCH] fix last-item class and add documentation --- README.md | 9 +++++++-- jquery.row-grid.js | 4 +++- jquery.row-grid.min.js | 10 +++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7de0ea6..e6b2634 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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. @@ -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" diff --git a/jquery.row-grid.js b/jquery.row-grid.js index 40e3629..45bffda 100644 --- a/jquery.row-grid.js +++ b/jquery.row-grid.js @@ -35,6 +35,7 @@ rowElems = [], items = jQuery.makeArray(items || container.querySelectorAll(options.itemSelector)), itemsSize = items.length; + // read var containerBoundingRect = container.getBoundingClientRect(); @@ -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); @@ -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; diff --git a/jquery.row-grid.min.js b/jquery.row-grid.min.js index 6fc0418..385b829 100644 --- a/jquery.row-grid.min.js +++ b/jquery.row-grid.min.js @@ -1,5 +1,5 @@ -(function(m){function n(c,b,f){var g,p=0,e=[];f=jQuery.makeArray(f||c.querySelectorAll(b.itemSelector));var q=f.length,h=c.getBoundingClientRect();c=Math.floor(h.right-h.left)-parseFloat(m(c).css("padding-left"))-parseFloat(m(c).css("padding-right"));h=[];for(var d,k,a=0;ac){k=p+b.maxMargin*(e.length-1)-c;a=e.length;(b.maxMargin-b.minMargin)*(a-1)d){h=p+a.maxMargin*(e.length-1)-d;b=e.length;(a.maxMargin-a.minMargin)*(b-1)