Skip to content

Instantly share code, notes, and snippets.

@luancmaia
Created December 6, 2017 16:11
Show Gist options
  • Save luancmaia/a604b9c67a5969ab19c442ee2fb047dd to your computer and use it in GitHub Desktop.
Save luancmaia/a604b9c67a5969ab19c442ee2fb047dd to your computer and use it in GitHub Desktop.
JS Filtro
$(document).on('ready', function(){
var check_img = 'http://petitpapier.com.br/wp-content/uploads/2017/12/square-check-x.png';
var uncheck_img = 'http://petitpapier.com.br/wp-content/uploads/2017/12/square-x.png';
$('a.remove-category-url').on('click', function(e){
e.preventDefault();
var url = $('.actual-url').val();
url = url.replace('&tid[]=' + $(this).attr('data-id'), '');
url = url.replace('?tid[]=' + $(this).attr('data-id'), '');
url = url.replace('?tid%5B%5D=' + $(this).attr('data-id'), '');
url = url.replace('/&tid%5B%5D', '/?tid');
url = url.replace('/&tid', '/?tid');
$(this).parent().fadeOut();
window.location = url;
});
$('a.link-category').on('click', function(e){
e.preventDefault();
var url = $('.actual-url').val();
if ( $(this).hasClass('active') ) {
$(this).removeClass('active');
$(this).find('img').attr('src', uncheck_img);
url = url.replace('&tid[]=' + $(this).attr('data-id'), '');
url = url.replace('?tid[]=' + $(this).attr('data-id'), '');
url = url.replace('/&tid', '/?tid');
window.location = url;
} else {
$(this).addClass('active');
$(this).find('img').attr('src', check_img);
url += ( url.match( /[\?]/g ) ? '&' : '?' ) + 'tid[]=' + $(this).attr('data-id');
window.location = url;
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment