brookedot icon

Sorting Dynamic Data with Isotope.js

brookedot | PRO | 04/16/13 03:45:02 AM UTC | 0 ⭐ | 621 👁️ | Never ⏰ | []
JavaScript |

1.97 KB

|

None

|

0 👍

/

0 👎

var $container = $('.sort-container');
    createSortFunction = function(slug) {
        return function($elem) {
            var is_slug = $elem.hasClass(slug) ? ' ' : '';
                 return (!is_slug?' ':'');
          };
    }, 
    getSortData = function(data) {
        var sortMethods = {};
 
        for (var index in data) {
            var slug = data[index].slug;
            sortMethods[slug] = createSortFunction(slug);
        }
 
        return sortMethods;
    }
 
$.getJSON('member-cat-json.php', function (data) {
 
$container.isotope({
        itemSelector: '.member-item',
        layoutMode: 'straightDown',
        sortAscending: true,
        getSortData: getSortData(data)
    });
});
        var $optionSets = $('.option-set'),
                $optionLinks = $optionSets.find('a');
                
                      $optionLinks.click(function(){
                        var $this = $(this);
                        // don't proceed if already selected
                        if ( $this.hasClass('selected') ) {
                          return false;
                        }
                        var $optionSet = $this.parents('.option-set');
                        $optionSet.find('.selected').removeClass('selected');
                        $this.addClass('selected');
                  
                        // make option object dynamically, i.e. { filter: '.my-filter-class' }
                        var options = {},
                            key = $optionSet.attr('data-option-key'),
                            value = $this.attr('data-option-value');
                        // parse 'false' as false boolean
                        value = value === 'false' ? false : value;
                        options[ key ] = value;
                          // otherwise, apply new options
                          $container.isotope( options );
                       
                        return false;
                });

Comments