Files
poll/templates/js/common.js
2026-03-29 18:38:12 +05:00

31 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(function initLimit() {
// Ждем, пока jQuery (или $) появится в глобальном окне
if (window.jQuery || window.$) {
var $ = window.jQuery || window.$;
$.fn.extend({
limit: function (limit, element) {
var self = $(this);
var $element = $(element);
var doSubstring = function () {
var val = self.val();
var length = val.length;
if (length > limit) {
self.val(val.substring(0, limit));
length = limit;
}
if ($element.length) {
var remaining = limit - length;
$element.html(remaining <= 0 ? '0' : remaining);
}
};
this.on('input focus blur keyup', doSubstring);
doSubstring();
}
});
} else {
// Если jQuery еще нет, проверяем снова через 50мс
setTimeout(initLimit, 50);
}
})();