Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var filterArray = [];
- $(function() {
- // split current url and check if there is a filter
- var myURL = window.location.href;
- var splitted = myURL.split('#');
- //global variable:
- var alreadyAdded = false;
- if(splitted[1]){
- filterOn(splitted[1]);
- }
- $('#mobilenav').on( 'click', 'a', function() {
- filterOn( $(this).parent('li').attr('data-filter') );
- });
- });
- function filterOn(filter){
- //hide filtered results
- $('li.list:not([data-filter*="'+ filter +'"])').slideUp();
- //hide filtered results
- for(var i=0; i < filterArray.length ; i++){
- if( filterArray[i] == newFilter ){
- alreadyAdded = true;
- filterArray.splice(i, 1); //toggle filter off incase it's already in there
- }
- if(!alreadyAdded){
- filterArray.push(filter);
- }
- for(var i=0; i < filterArray.length ; i++){
- $('li.list:not([data-filter*="'+ filterArray[i] +'"])').hide();
- }
- //change url
- var myURL = window.location.href;
- var splitted = myURL.split('#');
- //show all results
- //$('li.list').show();
- window.history.pushState({}, 'Assignment', splitted[0] + '#' + filter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement