views:

40

answers:

1

Hi all,

I have a hardcoded li menu that is using filterable.js to filter a list of items, based on hash tags.

I can get focus to work if the item is selected, however, I want the all tag to be selected on page load. I added the class "current" to the "all" menu item, however this did not work.

see: http://thinquetanque.com/portfolio

code for filterable.js:

/*
* Copyright (C) 2009 Joel Sutherland.
* Liscenced under the MIT liscense
*/

(function($) {
    $.fn.filterable = function(settings) {
        settings = $.extend({
            useHash: true,
            animationSpeed: 5000,
            show: { width: 'show', opacity: 'show' },
            hide: { width: 'hide', opacity: 'hide' },
            useTags: true,
            tagSelector: '#portfolio-filter a',
            selectedTagClass: 'current',
            allTag: 'all'
        }, settings);

        return $(this).each(function(){

            /* FILTER: select a tag and filter */
            $(this).bind("filter", function( e, tagToShow ){
                if(settings.useTags){
                    $(settings.tagSelector).removeClass(settings.selectedTagClass);
                    $(settings.tagSelector + '[href=' + tagToShow + ']').addClass(settings.selectedTagClass);
                }
                $(this).trigger("filterportfolio", [ tagToShow.substr(1) ]);
            });

            /* FILTERPORTFOLIO: pass in a class to show, all others will be hidden */
            $(this).bind("filterportfolio", function( e, classToShow ){
                if(classToShow == settings.allTag){
                    $(this).trigger("show");
                }else{
                    $(this).trigger("show", [ '.' + classToShow ] );
                    $(this).trigger("hide", [ ':not(.' + classToShow + ')' ] );
                }
                if(settings.useHash){
                    location.hash = '#' + classToShow;
                }
            });

            /* SHOW: show a single class*/
            $(this).bind("show", function( e, selectorToShow ){
                $(this).children(selectorToShow).fadeIn('slow');
            });

            /* SHOW: hide a single class*/
            $(this).bind("hide", function( e, selectorToHide ){
                $(this).children(selectorToHide).fadeOut('slow');
            });

            /* ============ Check URL Hash ====================*/
            if(settings.useHash){
                if(location.hash != '')
                    $(this).trigger("filter", [ location.hash ]);
                else
                    $(this).trigger("filter", [ '#' + settings.allTag ]);
            }

            /* ============ Setup Tags ====================*/
            if(settings.useTags){
                $(settings.tagSelector).click(function(){
                    $('#portfolio-list').trigger("filter", [ $(this).attr('href') ]);

                    $(settings.tagSelector).removeClass('current');
                    $(this).addClass('current');
                });
            }
        });
    }
})(jQuery);


$(document).ready(function(){

    $('#portfolio-list').filterable();

});

which is adding and removing the "current" class to my list of portfolio items. I'm sure there must be a jquery function to load a class, but I haven't found it.

Any help would be appreciated.

Thanks!

A: 

Where you have this:

$(document).ready(function(){

    $('#portfolio-list').filterable();

});

Try this:

$(document).ready(function(){

    $('#portfolio-list').filterable();
    $('#portfolio-list').trigger('filter', [ '#all' ]);

});

Or maybe (untested)...

$(document).ready(function(){

    $('#portfolio-list').filterable();
    $("#portfolio-filter li:first a").addClass("current");

});

This will add the current class to the first list element "All" on page load.. Not quite sure if this helps or not.

betamax
I ended up figuring it out with css. I had my lists all wonky, and it was interfering with the correct css. But thanks for the input.
Jason