aerohub / hugrid

Hugrid (Hugo+grid) is a simple grid theme for Hugo. It's a kind of boilerplate to perform anyone or anything quickly. Portfolio, collection, bookmarks, contacts and so on.
MIT License
165 stars 79 forks source link

Allow for multiple `og-grid` elements on the same page #19

Closed gcalmettes closed 6 years ago

gcalmettes commented 6 years ago

With the current javascript code, if multiple grids (og-grid elements) are initialized on the page, only the items of the first one will have a working interaction when they are clicked on.

This PR allows the on('click)' interaction to work for all the elements of all the grids if multiple grids sections are initialized on the same page.

e.g.: if the data in items are a list of categories and the index.html in layouts is modified like so:

<div class="main">
  {{ range $.Site.Data.items.categories}}
    <div>
      <div class="title">{{.title}}</div>
      <p class="description">{{.description | markdownify}}</p>
      <ul id="og-grid" class="og-grid">
        {{ range .items }}
          <li>
            <a href="{{.url}}" data-largesrc="{{.image}}" data-title="{{.title}}" data-description="{{.description}}" data-buttontext="{{.buttontext}}">
              <img src="{{.thumb}}" alt="{{.alt}}"/>
            </a>
          </li>
        {{ end }}
      </ul>
    </div>
  {{ end }}
  {{ partial "footer.html" . }}
</div>

Imgur

aerohub commented 6 years ago

Hi @gcalmettes! Nice idea, thanks) May be it would be nice to center section names on a page for better looking?