cmoreira

js filter team

Mar 13th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. jQuery.noConflict();
  3.  
  4. jQuery( document ).ready(function() {
  5.  
  6.     jQuery('#ts-all').addClass('ts-current-li');
  7.     jQuery("#ts-filter-nav > li").click(function(){
  8.         ts_show(this.id);
  9.     }).children().click(function(e) {
  10.       return false;
  11.     });
  12.  
  13.     jQuery("#ts-filter-nav > li > ul > li").click(function(){
  14.         ts_show(this.id);
  15.     });
  16.  
  17.     //Load specific category via url hash
  18.  
  19.     var start_filter = ts_get_hash()["show"];
  20.     if(start_filter!='') {
  21.         jQuery('#'+start_filter).click();
  22.        
  23.     }
  24.  
  25. });
  26.  
  27. //In case you want all entries to hide when the page loads
  28. //jQuery('.ts-05_project-5').hide();   
  29. //To load a particular category
  30. //jQuery('#ts-01-sales-team').click();
  31.  
  32.  
  33.  
  34.  
  35. //FILTER CODE
  36. function ts_show(category) {     
  37.  
  38.     //console.log(category);
  39.    
  40.     if (category == "ts-all") {
  41.         jQuery('#ts-filter-nav li').removeClass('ts-current-li');
  42.         jQuery('#ts-all').addClass('ts-current-li');
  43.         jQuery('.tshowcase-filter-active').show(1600,'easeInOutExpo');
  44.         }
  45.    
  46.     else {
  47.         jQuery('#ts-filter-nav li').removeClass('ts-current-li');
  48.         jQuery('#' + category).addClass('ts-current-li');
  49.         if(jQuery('#' + category).parent().parent().is('li')) {
  50.             jQuery('#' + category).parent().parent().addClass('ts-current-li');
  51.         }
  52.         jQuery('.' + category).show(1600,'easeInOutExpo');
  53.         jQuery('.tshowcase-filter-active:not(.'+ category+')').hide(1000,'easeInOutExpo');
  54.  
  55.         //to display first entry on pager layouts
  56.         jQuery('.tshowcase-pager-wrap .' + category + ' a').click();
  57.            
  58.     }
  59.  
  60.     //hack to solve menu left open on touch devices
  61.     /*
  62.  
  63.         jQuery('ul li ul li.ts-current-li')
  64.         .parent()
  65.         .hide()
  66.         .parent()
  67.         .on('click', function(){
  68.             jQuery(this).addClass('ts-current-li')
  69.             .children().show();
  70.         });
  71.  
  72.     */
  73. }
  74.  
  75.  
  76. jQuery(document).ajaxSuccess(function() {
  77.  
  78.     jQuery('#ts-all').addClass('ts-current-li');
  79.     jQuery("#ts-filter-nav > li").click(function(){
  80.         ts_show(this.id);
  81.     }).children().click(function(e) {
  82.       return false;
  83.     });
  84.  
  85.     jQuery("#ts-filter-nav > li > ul > li").click(function(){
  86.         ts_show(this.id);
  87.     });
  88. });
  89.  
  90.  
  91.  
  92.  
  93.  
  94. function ts_get_hash(){
  95.     var vars = [], hash;
  96.     var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('&');
  97.     for(var i = 0; i < hashes.length; i++)
  98.     {
  99.         hash = hashes[i].split('=');
  100.         vars.push(hash[0]);
  101.         vars[hash[0]] = hash[1];
  102.     }
  103.     return vars;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment