Created
December 6, 2017 16:11
-
-
Save luancmaia/a604b9c67a5969ab19c442ee2fb047dd to your computer and use it in GitHub Desktop.
JS Filtro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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