Skip to content

Commit

Permalink
Add resize listener only once when rowGrid is called multiple times
Browse files Browse the repository at this point in the history
This also removes the `resize` option. The resize event listener is now
always added.
  • Loading branch information
brunjo committed Jun 25, 2018
1 parent a035008 commit ff29ae9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ HTML:
JS:
```JS
var container = document.getElementsByClassName('container')[0];
rowGrid(container, {itemSelector: ".item", minMargin: 10, maxMargin: 25, firstItemClass: "first-item", lastRowClass: 'last-row', resize: true});
rowGrid(container, {itemSelector: ".item", minMargin: 10, maxMargin: 25, firstItemClass: "first-item", lastRowClass: 'last-row'});
```

### Relayout
Expand All @@ -74,11 +74,6 @@ This is the minimal horizontal margin between the items. The margin is only betw
* **value:** ```number``` or ```null```

This is the maximal horizontal margin between the items.
#### resize
* **value:** ```boolean```
* **default value:** ```true```

If ```resize``` is set to true the layout updates on resize events. This is useful for responsive websites.

#### minWidth
* **value:** ```number```
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rowGrid",
"description": "A small, lightweight JavaScript plugin for placing items in straight rows",
"version": "1.1.1",
"version": "2.0.0",
"license": "MIT",
"authors": [
{ "name": "Bruno Joseph", "email": "[email protected]"," homepage": "http://brunojoseph.com" }
Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
document.addEventListener('DOMContentLoaded', function(){
/* Start rowGrid.js */
var container = document.getElementsByClassName('container')[0];
rowGrid(container, {itemSelector: '.item', minMargin: 10, maxMargin: 25, firstItemClass: 'first-item', lastRowClass: 'last-row', resize: true, minWidth: 500});
rowGrid(container, {itemSelector: '.item', minMargin: 10, maxMargin: 25, firstItemClass: 'first-item', lastRowClass: 'last-row', minWidth: 500});
});
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rowgrid",
"version": "1.1.1",
"version": "2.0.0",
"description": "A small, lightweight JavaScript plugin for placing items in straight rows",
"main": "row-grid.js",
"directories": {
Expand Down
10 changes: 3 additions & 7 deletions row-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@ var rowGrid = function(container, options) {
if (!options) {
options = JSON.parse(container.getAttribute('data-row-grid'));
} else {
if (options.resize === undefined) options.resize = true;
if (options.minWidth === undefined) options.minWidth = 0;
if (options.lastRowClass === undefined) options.lastRowClass = 'last-row';
}

layout(container, options);

container.setAttribute('data-row-grid', JSON.stringify(options));

if (options.resize) {
container.setAttribute('data-row-grid', JSON.stringify(options));
window.addEventListener('resize', function(event) {
layout(container, options);
});
}

layout(container, options);
}

/* Get elem and all following siblings of elem */
Expand Down
10 changes: 5 additions & 5 deletions 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 ff29ae9

Please sign in to comment.