Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple gallery view includes per page – handle conflicting html ids #169

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 34 additions & 23 deletions _includes/collection_gallery.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,53 @@
{% assign collection = site[include.collection] %}
{% assign undefined = include.undefined | default: 'undefined' %}
{% assign id = include.id | default: include | jsonify | slugify %}

{% if include.only and include.facet_by %}
{% if include.only.size > 0 %}
{% assign subset = collection | where: include.facet_by, include.only | sort: 'order' %}
{% else %}
{% assign subset = nil %}
{% endif %}

<div id='wax-gallery-{{ include.collection }}-container' class='wax-gallery-container full-width'>
<div id='{{ id }}-container' class='wax-gallery-container full-width'>
<div class='wax-inline-container'>
<div id="{{ include.collection }}-facet-buttons" class="facet-buttons"></div>
<div id="wax-gallery-{{ include.collection }}" class="wax-gallery"></div>
{% if include.facet_by %}
<div id="{{ id }}-facet-buttons" class="facet-buttons"></div>
{% endif %}
<div id="wax-gallery-{{ id }}" class="wax-gallery"></div>
</div>
</div>

{% if subset.size > 0 %}
<script type="text/javascript">
$( document ).ready(function() {
let container = $('#{{ id }}-container');
let gallery = $('#wax-gallery-{{ id }}');
let buttonDiv = $('#{{ id }}-facet-buttons');

<script type="text/javascript">
$( document ).ready(function() {
var container = $('#wax-gallery-{{ include.collection }}-container');
var gallery = $('#wax-gallery-{{ include.collection }}');
var buttonDiv = $('#{{ include.collection }}-facet-buttons');

{% if subset %}
{% for item in subset %}
{%- capture item_html -%}
"<div class='gallery-item {{ item[include.facet_by] | slugify }} all'><a href='{{ item.url | absolute_url }}'><div class='hovereffect'><img class='img-responsive gallery-thumb' src='{{ item.thumbnail | default: site.default_thumb | absolute_url }}' alt='{{ item.label | escape }}'/><div class='overlay'><p class='info'>{{ item.label | escape }}</p></div></div></a></div>"
{%- endcapture -%}
gallery.append({{ item_html | strip_newlines }});
{% endfor %}
{% else %}
});
</script>
{% else %}
<script type="text/javascript">
$( document ).ready(function() {
let container = $('#{{ id }}-container');
let gallery = $('#wax-gallery-{{ id }}');
let buttonDiv = $('#{{ id }}-facet-buttons');


{% for item in collection %}
{%- capture item_html -%}
"<div class='gallery-item {{ item[include.facet_by] | default: undefined | slugify }} all'><a href='{{ item.url | absolute_url }}'><div class='hovereffect'><img class='img-responsive gallery-thumb' src='{{ item.thumbnail | default: site.default_thumb | absolute_url }}' alt='{{ item.label | escape }}'/><div class='overlay'><p class='info'>{{ item.label | escape }}</p></div></div></a></div>"
{%- endcapture -%}
gallery.append({{ item_html | strip_newlines }});
{% endfor %}
{% endif %}

{% if include.facet_by %}
{% unless subset %}
{% if include.facet_by %}
var facets = Array.from(new Set([{%- for item in collection -%}'{{ item[include.facet_by] | default: undefined | slugify }}'{% unless forloop.last %}, {% endunless %}{%- endfor -%}]));
buttonDiv.append("<button class='btn facet active' data-filter='all'>show all</button>");

Expand All @@ -45,15 +56,15 @@
}

$(document).ready(function(){
$(".facet").click(function(){
$("#{{ id }}-container .facet").click(function(){
var filterValue = $(this).attr('data-filter');
$('.facet').removeClass('active');
$('#{{ id }}-container .facet').removeClass('active');
$(this).addClass('active');
if(filterValue == 'all') { $('.all').show('slow'); }
else { $('.all').hide('slow'); $(`.${filterValue}`).show('slow'); }
if(filterValue == 'all') { $('#{{ id }}-container .all').show('slow'); }
else { $('#{{ id }}-container .all').hide('slow'); $(`.${filterValue}`).show('slow'); }
});
});
{% endunless %}
{% endif %}
});
</script>
{% endif %}
});
</script>
{% endif %}
1 change: 0 additions & 1 deletion _sass/_wax.scss
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ search box
}
.wax-gallery {
margin: $margin auto;
min-height: 30vh;
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
Expand Down
1 change: 1 addition & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ The collection items in this demo are from The Museum of Islamic Art, Qatar, (co

### Browse the Collection

#### By Item Type
{% include collection_gallery.html facet_by='object_type' collection='qatar' %}
13 changes: 12 additions & 1 deletion pages/collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,16 @@ permalink: /collection/

This site's sample collection comprises a set of objects, each of which is represented by one or more images. The collection items in this demo are from The Museum of Islamic Art, Qatar, (courtesy of [WikiMedia](https://commons.wikimedia.org/wiki/Category:Google_Art_Project_works_in_The_Museum_of_Islamic_Art,_Qatar) and [Google Art Project](https://www.google.com/culturalinstitute/about/artproject/)) and The Qatar National Library (via [World Digital Library](https://www.wdl.org/en/)).

## By Location
{% include collection_gallery.html facet_by='location' collection='qatar' %}

{% include collection_gallery.html collection='qatar' facet_by='object_type' %}
## By Object Type

### Manuscripts
{% include collection_gallery.html facet_by='object_type' only='manuscript' collection='qatar' %}
### Portraits
{% include collection_gallery.html facet_by='object_type' only='portrait' collection='qatar' %}
### Maps
{% include collection_gallery.html facet_by='object_type' only='map' collection='qatar' %}
### Panels
{% include collection_gallery.html facet_by='object_type' only='panel' collection='qatar' %}