load later

This commit is contained in:
j 2025-03-24 15:43:47 +00:00
parent a3f32323b1
commit 99a37b946a

View file

@ -1,18 +1,20 @@
django.jQuery(function() { window.addEventListener("load", function() {
django.jQuery('textarea[maxlength]').each(function(i, textarea) { django.jQuery(function() {
var t = django.jQuery(textarea), django.jQuery('textarea[maxlength]').each(function(i, textarea) {
count = t.parent().find('.maxlength-count') var t = django.jQuery(textarea),
if (count.length == 0) { count = t.parent().find('.maxlength-count')
count = django.jQuery('<div>', {'class': 'maxlength-count'} ).insertAfter(t) if (count.length == 0) {
t.on({ count = django.jQuery('<div>', {'class': 'maxlength-count'} ).insertAfter(t)
keydown: update, t.on({
change: update, keydown: update,
drop: update, change: update,
}) drop: update,
} })
function update() { }
var max = Math.round(t.attr('maxlength')), left = max - t.val().length function update() {
count.html(left + ' characters left. (max: ' + max + ')') var max = Math.round(t.attr('maxlength')), left = max - t.val().length
} count.html(left + ' characters left. (max: ' + max + ')')
}
});
}); });
}); })