Advertisement
Guest User

filterable.js

a guest
May 11th, 2010
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Copyright (C) 2009 Joel Sutherland.
  3. * Liscenced under the MIT liscense
  4. */
  5.  
  6. (function($) {
  7.     $.fn.filterable = function(settings) {
  8.         settings = $.extend({
  9.             useHash: true,
  10.             animationSpeed: 1000,
  11.             show: { width: 'show', opacity: 'show' },
  12.             hide: { width: 'hide', opacity: 'hide' },
  13.             useTags: true,
  14.             tagSelector: '#portfolio-filter a',
  15.             selectedTagClass: 'current',
  16.             allTag: 'web'
  17.         }, settings);
  18.        
  19.         return $(this).each(function(){
  20.        
  21.             /* FILTER: select a tag and filter */
  22.             $(this).bind("filter", function( e, tagToShow ){
  23.                 if(settings.useTags){
  24.                     $(settings.tagSelector).removeClass(settings.selectedTagClass);
  25.                     $(settings.tagSelector + '[href=' + tagToShow + ']').addClass(settings.selectedTagClass);
  26.                 }
  27.                 $(this).trigger("filterportfolio", [ tagToShow.substr(1) ]);
  28.             });
  29.        
  30.             /* FILTERPORTFOLIO: pass in a class to show, all others will be hidden */
  31.             $(this).bind("filterportfolio", function( e, classToShow ){
  32.                 if(classToShow == settings.allTag){
  33.                     $(this).trigger("show");
  34.                 }else{
  35.                     $(this).trigger("show", [ '.' + classToShow ] );
  36.                     $(this).trigger("hide", [ ':not(.' + classToShow + ')' ] );
  37.                 }
  38.                 if(settings.useHash){
  39.                     location.hash = '#' + classToShow;
  40.                 }
  41.             });
  42.            
  43.             /* SHOW: show a single class*/
  44.             $(this).bind("show", function( e, selectorToShow ){
  45.                 $(this).children(selectorToShow).animate(settings.show, settings.animationSpeed);
  46.             });
  47.            
  48.             /* SHOW: hide a single class*/
  49.             $(this).bind("hide", function( e, selectorToHide ){
  50.                 $(this).children(selectorToHide).animate(settings.hide, settings.animationSpeed);  
  51.             });
  52.            
  53.             /* ============ Check URL Hash ====================*/
  54.             if(settings.useHash){
  55.                 if(location.hash != '')
  56.                     $(this).trigger("filter", [ location.hash ]);
  57.                 else
  58.                     $(this).trigger("filter", [ '#' + settings.allTag ]);
  59.             }
  60.            
  61.             /* ============ Setup Tags ====================*/
  62.             if(settings.useTags){
  63.                 $(settings.tagSelector).click(function(){
  64.                     $('#portfolio-list').trigger("filter", [ $(this).attr('href') ]);
  65.                    
  66.                     $(settings.tagSelector).removeClass('current');
  67.                     $(this).addClass('current');
  68.                 });
  69.             }
  70.         });
  71.     }
  72. })(jQuery);
  73.  
  74.  
  75. $(document).ready(function(){
  76.    
  77.     $('#portfolio-list').filterable();
  78.  
  79. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement