Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. var filterArray = [];
  2.  
  3. $(function() {
  4.  
  5. // split current url and check if there is a filter
  6. var myURL = window.location.href;
  7. var splitted = myURL.split('#');
  8. //global variable:
  9. var alreadyAdded = false;
  10.  
  11. if(splitted[1]){
  12. filterOn(splitted[1]);
  13. }
  14.  
  15. $('#mobilenav').on( 'click', 'a', function() {
  16. filterOn( $(this).parent('li').attr('data-filter') );
  17. });
  18. });
  19.  
  20. function filterOn(filter){
  21.  
  22. //hide filtered results
  23. $('li.list:not([data-filter*="'+ filter +'"])').slideUp();
  24.  
  25.  
  26.  
  27. //hide filtered results
  28. for(var i=0; i < filterArray.length ; i++){
  29. if( filterArray[i] == newFilter ){
  30. alreadyAdded = true;
  31. filterArray.splice(i, 1); //toggle filter off incase it's already in there
  32. }
  33.  
  34. if(!alreadyAdded){
  35. filterArray.push(filter);
  36. }
  37.  
  38. for(var i=0; i < filterArray.length ; i++){
  39. $('li.list:not([data-filter*="'+ filterArray[i] +'"])').hide();
  40. }
  41.  
  42. //change url
  43. var myURL = window.location.href;
  44. var splitted = myURL.split('#');
  45.  
  46. //show all results
  47. //$('li.list').show();
  48.  
  49. window.history.pushState({}, 'Assignment', splitted[0] + '#' + filter);
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement