Sha256: 3ca697cee9cc4b16d5f4300e946fec9ff1b80e1f7c036c11914c52626a941b42
Contents?: true
Size: 1.16 KB
Versions: 16
Compression:
Stored size: 1.16 KB
Contents
$(function() { const COUNT_KEY = "%count%"; $.fn.remainingCharacters = function() { return $(this).each( /** * @this HTMLElement * @returns {void} */ function() { const $input = $(this); const $target = $($input.data("remaining-characters")); const maxCharacters = parseInt($(this).attr("maxlength"), 10); if ($target.length > 0 && maxCharacters > 0) { const messagesJson = $target.data("remaining-characters-messages"); const messages = $.extend({ one: `${COUNT_KEY} character left`, many: `${COUNT_KEY} characters left` }, messagesJson); const updateStatus = function() { const numCharacters = $input.val().length; const remaining = maxCharacters - numCharacters; let message = messages.many; if (remaining === 1) { message = messages.one; } $target.text(message.replace(COUNT_KEY, remaining)); }; $input.on("keyup focus", function() { updateStatus(); }); updateStatus(); } } ); }; });
Version data entries
16 entries across 16 versions & 1 rubygems