From 99a37b946adbcaa9ff1d2a670a2e3e22594a34df Mon Sep 17 00:00:00 2001 From: j Date: Mon, 24 Mar 2025 15:43:47 +0000 Subject: [PATCH] load later --- content/static/js/maxlength_count.js | 36 +++++++++++++++------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/content/static/js/maxlength_count.js b/content/static/js/maxlength_count.js index ce6f05b..5d6a768 100644 --- a/content/static/js/maxlength_count.js +++ b/content/static/js/maxlength_count.js @@ -1,18 +1,20 @@ -django.jQuery(function() { - django.jQuery('textarea[maxlength]').each(function(i, textarea) { - var t = django.jQuery(textarea), - count = t.parent().find('.maxlength-count') - if (count.length == 0) { - count = django.jQuery('
', {'class': 'maxlength-count'} ).insertAfter(t) - t.on({ - keydown: update, - change: update, - drop: update, - }) - } - function update() { - var max = Math.round(t.attr('maxlength')), left = max - t.val().length - count.html(left + ' characters left. (max: ' + max + ')') - } +window.addEventListener("load", function() { + django.jQuery(function() { + django.jQuery('textarea[maxlength]').each(function(i, textarea) { + var t = django.jQuery(textarea), + count = t.parent().find('.maxlength-count') + if (count.length == 0) { + count = django.jQuery('
', {'class': 'maxlength-count'} ).insertAfter(t) + t.on({ + keydown: update, + change: update, + drop: update, + }) + } + function update() { + var max = Math.round(t.attr('maxlength')), left = max - t.val().length + count.html(left + ' characters left. (max: ' + max + ')') + } + }); }); -}); +})