ademilter / bricklayer

Lightweight and independent Pinterest-like cascading grid layout library
http://bricklayer.js.org
Other
2.46k stars 119 forks source link

Multiple bricklayers on one page #7

Closed Ernedar closed 8 years ago

Ernedar commented 8 years ago

I just tried your work. It works like magic, but only for one gallery on a page. I tried to use more generated galleries, where in every gallery i use bricklayer class. But it takes only first appearance and not the others. Can I ask you for help. Javascript amateur here, sorry.

Do not really know if this is an issue of it or not.

f commented 8 years ago

Can you please send us the code fragment you create multiple bricklayers?

You have to apply new Bricklayer(container) to every container. Otherwise it won't work.

Ernedar commented 8 years ago
<div>
  <div id="gallery">
    <div class="bricklayer">
      <dl class="gallery-item">
        <dt>
          <a href="#">
            <img src="#">
          </a>              
        </dt>
      </dl>
      <dl class="gallery-item">
        <dt>
          <a href="#">
            <img src="#">
          </a>              
        </dt>
      </dl>
    </div>
  </div>
</div>
<div>
  <div id="gallery">
    <div class="bricklayer">
      <dl class="gallery-item">
        <dt>
          <a href="#">
            <img src="#">
          </a>              
        </dt>
      </dl>
      <dl class="gallery-item">
        <dt>
          <a href="#">
            <img src="#">
          </a>              
        </dt>
      </dl>
    </div>
  </div>
</div>
<script>
  var bricklayer = new Bricklayer(document.querySelector('.bricklayer'));     
</script>

I am using it for WP generated Galleries and i need more than one on page. For the first one, it works correctly, second one not working.

f commented 8 years ago

It must be like that if you want to bricklayer all the .bricklayer classes dynamically:

Array.prototype.slice.call(null, document.querySelectorAll('.bricklayer')).forEach(function (container) {
  var bricklayer = new Bricklayer(container);
});

or, if you want to use one by one:

var firstBricklayer = new Bricklayer(document.querySelector('.bricklayer.first'));
var secondBricklayer = new Bricklayer(document.querySelector('.bricklayer.second'));
Ernedar commented 8 years ago

Hm. The first thing you wrote with Array seems not working:

Uncaught TypeError: Array.prototype.slice called on null or undefined

EDIT: I deleted null, in call function and the first gallery works, but not more.

f commented 8 years ago

Which browser do you work in?

Ernedar commented 8 years ago

Tested on Chrome 49 + 50, IE Edge 25.10586.0.0, IE 11.212.10586.0, Firefox 45.0.2.

f commented 8 years ago

Any update on this? Still active?

shohagbhuiyan commented 7 years ago

I am having the same problem.

Uncaught TypeError: Array.prototype.slice called on null or undefined

I deleted null in call function and only the first gallery works.

Any solution?

ahmeddabak commented 6 years ago

i know this is an old question, but since it is not answered i wanted to help. please try this:

document.querySelectorAll('.bricklayer').forEach(function (section) { var bricklayer = new Bricklayer(section); });