robinwebdev
12/29/2019 - 2:51 PM

Truncate

// Ajouter la class `js-truncate` et un attribut `data-truncate` égal au nombre maximal de caractères autorisés.
function truncate() {
    $('.js-truncate').each(function(index, elem) {
        var contentLength = $(this).text().length;
        var limit = $(this).data('truncate');
        if(contentLength > limit) {
            var limitedContent = $(this).text().substring(0, limit-3) + '...';
            $(this).text(limitedContent);
        }
    });
}