I’m asking this first question because I’m quite stuck with this following code.
Basically : I’d like to toggle divs visibility by filtering them, based on a specific content.
Each div contains several “tags”. When a “tag” is clicked, only divs that contains same “tag” get displayed. Looks simple said like that.
But I’m running inside an isotope div container. More important, there is no external tag menu, so the trigger is right inside the div that will be toggled.
I’m facing 2 paths :
1. Go with an additional isotope plugin from Gatsby : IsoSelective and it goes like this:
$container.isoSelective({
linkSelector: '.filter', // this is the filter link
attrSelector: 'rel', // the attribute containing the filter
activeClass: 'selected' // class to add to selected
});
But doesn’t seem to be happy if my triggers are inside the targets.
-
A fork I did on an existing JSFiddle code which work awesome but cannot run inside isotope until now :
—————
And finally here is my an extract from my code in html page :
<div class="articlesBlock">
<div class="blockBox">
<a href="#"><p>Lorem ipsum paragraph.</p></a>
<em><a class='filter base-first-tag' rel='.first-tag' href='#'>The Base First Tag</a></em>
<em><a class='filter second-tag' rel='.second-tag' href='#'>The Second Tag</a></em>
<em><a class='filter third-tag' rel='.third-tag' href='#'> The Third Tag</a></em>
</div>
</div>
<div class="articlesBlock">
<div class="blockBox">
<a href="#"><p>Lorem ipsum paragraph.</p></a>
<em><a class='filter base-first-tag' rel='.base-first-tag' href='#'>The First also Base Tag</a</em>
<em><a class='filter second-tag' rel='.second-tag' href='#'>The Second Tag</a></em>
<em><a class='filter third-tag' rel='.third-tag' href='#'> The Third Tag</a></em>
</div>
</div>
<div class="articlesBlock">
<div class="blockBox">
<a href="#"><p>Lorem ipsum paragraph.</p></a>
<em><a class='filter first-tag' rel='.first-tag' href='#'>The First Tag</a></em>
<em><a class='filter second-new-tag' rel='.second-new-tag' href='#'>The New Second Tag</a></em>
<em><a class='filter third-tag' rel='.third-tag' href='#'> The Third Tag</a></em>
</div>
</div>
Below is the JSFiddle with the IsoSelective approach, but still doesn’t work.
What do you think ?
Thanks
So here’s what’s going on: isoSelective acts as a toggle. Individual filters can be on/off in combinations — not just one filter on vs one filter off. Not sure if that’s what you want, but here’s an example. I made the active (
selected) class bold for demonstration.http://jsfiddle.net/48nh6/4/ NOte that in this version, I moved the tag classes to the container — not on the anchors themselves. Since you want to show/hide (filter) the blocks and not the links, the tag classes need to be moved up to the top level.
Now. You can repeat the same exercise with the tags internal to the isotopes.
1. Make sure “All” is toggled at the top nav
2. Click Third Tag in the first box. Note only two items active
3. Click The Base First Class in the first box. Note all three now appear.
Also notice that the tags are only “active” in the first box. If you click “The First and also Base Class” in Box 2, it toggles “active” but it was already active because of the first one! So nothing changes (except the text becomes bold).
I offer two alternatives:
Option 1: http://jsfiddle.net/gy8Xf/1/
Select only on #filters .filter, then…
Anytime a link is clicked inside container, find the
#filters .filterwith the samerelattribute as the link that was just clicked, and trigger aclick.Option 2: http://jsfiddle.net/9ThvU/1/
Simply, anytime an anchor is clicked (I kept the #filters, not sure if you want them) set the new isotope filter according to the
relattribute.