-
-
Save Nikolasgrizli/92a6f69fb1819bda8627e5fcd7eb02c6 to your computer and use it in GitHub Desktop.
Окончание слова связанного с количеством
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
// html - <a href="'.$cart_url.'"><span class="cart-count">'.count($woo_cart_list).'</span><span class="end-count" id="end-count" >Товаров</span>в корзине</a> | |
(function($) { | |
$(document).ready(function(){ | |
setTimeout(function() { | |
var numberCounter = $('.cart-count').text(); | |
number = Math.abs(numberCounter); | |
function declOfNum(number, titles) { | |
cases = [2, 0, 1, 1, 1, 2]; | |
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ]; | |
} | |
var text = declOfNum(number, ['Товар', 'Товара', 'Товаров']); | |
// console.log(text) | |
$('.end-count').text(text); | |
}, 100); | |
}) | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment