@sabanna awesome mixitup tutorial for dynamic lists, but it doesn’t seem to work for a category that has more than multiple words (such as New York) , or even a comma in the title (such as Queens, New York). Just seems to work if it only has one word.
How can this be accomplished? I think it might be by adjusting the code below, but not sure how.
$('.w-dyn-item .categ').each(
function(index, element) {
var _this = $(element);
var text = _this.text();
var select = text.indexOf(' ') == -1 ? text.length : text.indexOf(' ');
var className = text.substr(0, select);
_this.parent().addClass(className.toLowerCase());
}
);
<script src="https://cdn.jsdelivr.net/jquery.mixitup/latest/jquery.mixitup.min.js"></script>
<script>
// Utility function to convert any string to class-friendly format
function classify(str) {
return str.toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/(^-|-$)/g, '');
}
// Document ready function
$(function() {
// For each dynamic item, add a class based on the category text
$('.w-dyn-item').addClass(function() {
return classify($(this).find('.categ').text());
});
// Adding data-filter attributes to category filters
$('#dyn-filter-menu > div').attr('data-filter', function() {
return '.' + classify($(this).children('a').text());
});
// Init MixItUp
$('#container').mixItUp();
}); // End doc ready
</script>
You’re welcome. Have a nice day
Also, feel free to contact me for further code help and/or customization of third-party plugins