Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing Isotope filters (basic)

I'm trying to implement Isotope's filtering on a news section of a WordPress installation. I'm new to JavaScript / jQuery and am trying to learn on the go. I started by using the code provided in the Filters section of the Isotope website.

Having had no luck, I started Googling. On Stack Overflow I found Implementing isotop filtering portfolio with wordpress which looked promising but had no responses. Then I found Implementing jQuery isotope. I thought, wow, alright same exact question. Answered. Great.

...but my excitement soon turned to even more frustration. I am still sitting here after hours of tinkering without having anything to show for it.

My simple question is, what am I doing wrong / missing / not understanding?

Thanks in advance for your help, forgetfuljames

HTML OUTPUT

<div id="grid_page">
<ul id="isotope_filters">
    <li><a data-filter="*" href="#">show all</a></li>
    <li><a data-filter="event-planning" href="#">event planning</a></li>
    <li><a data-filter="marketing" href="#">marketing</a></li>
    <li><a data-filter="site-survey" href="#">site survey</a></li>
</ul>

<ul id="isotope_container">
    <li class="isotope_selector event-planning marketing">
        <a href="./link-1/"></a>
        <div class="caption">
            ...
        </div>
    </li>
    <li class="isotope_selector site-survey">
        <a href="./link-2/"></a>
        <div class="caption">
            ...
        </div>
    </li>
    <li class="isotope_selector event-planning marketing">
        <a href="./link-3/"></a>
        <div class="caption">
            ...
        </div>
    </li>
    <li class="isotope_selector marketing">
        <a href="./link-4/"></a>
        <div class="caption">
            ...
        </div>
    </li>
</ul>
</div>

JavaScript

<script type="text/javascript">

$(window).load(function()

    // cache container
    var $container = $('#isotope_container');

    // initialize isotope
    $container.isotope({
    // options...
    animationEngine: 'best-available',
    itemSelector: '.isotope_selector'
    });

    // filter items when filter link is clicked
    $('#isotope_filters li a').on('click', function() {
    var selector = $(this).data('filter');
    $container.isotope({
    filter: selector
    });

});
</script>
like image 466
forgetfuljames Avatar asked Sep 17 '13 17:09

forgetfuljames


2 Answers

You are simply missing an opening brace (and the .'s on your selectors as you found):

<script type="text/javascript">

$(window).load(function() { <<<<

    // cache container
    var $container = $('#isotope_container');

    // initialize isotope
    $container.isotope({
    // options...
    animationEngine: 'best-available',
    itemSelector: '.isotope_selector'
    });

    // filter items when filter link is clicked
    $('#isotope_filters li a').on('click', function() {
    var selector = $(this).data('filter');
    $container.isotope({
    filter: selector
    });

});
</script>
like image 168
Gone Coding Avatar answered Oct 06 '22 00:10

Gone Coding


For future visitors of this question I leave the code working (without Css)

Code Snippet

$(window).load(function()
{
    // cache container
    var $container = $('#isotope_container');

    // initialize isotope
    $container.isotope({
    // options...
    animationEngine: 'best-available',
    itemSelector: '.isotope_selector'
    });

    // filter items when filter link is clicked
    $('#isotope_filters li a').on('click', function() {
    var selector = $(this).data('filter');
    $container.isotope({
    filter: selector
    });

}); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://npmcdn.com/isotope-layout@3/dist/isotope.pkgd.js"></script>
<div id="grid_page">
<ul id="isotope_filters">
    <li><a data-filter="*" href="#">show all</a></li>
    <li><a data-filter=".event-planning" href="#">event planning</a></li>
    <li><a data-filter=".marketing" href="#">marketing</a></li>
    <li><a data-filter=".site-survey" href="#">site survey</a></li>
</ul>

<ul id="isotope_container">
    <li class="isotope_selector event-planning marketing">
        <a href="./link-1/"></a>
        <div class="caption">
          ----> event-planning marketing  <-----
        </div>
    </li>
    <li class="isotope_selector site-survey">
        <a href="./link-2/"></a>
        <div class="caption">
           ----> site-survey  <-----
        </div>
    </li>
    <li class="isotope_selector event-planning marketing">
        <a href="./link-3/"></a>
        <div class="caption">
           ----> event-planning marketing  <-----
        </div>
    </li>
    <li class="isotope_selector marketing">
        <a href="./link-4/"></a>
        <div class="caption">
           ----> marketing  <-----
        </div>
    </li>
</ul>
</div>
like image 41
metalbox Avatar answered Oct 05 '22 22:10

metalbox