From 9de2cba0616535c943b4bee658d4be353d4fd6b1 Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 18 Mar 2022 19:52:48 -0700 Subject: [PATCH] Remove excessive word counts Resolves: - Duplicate event listeners are registered during every word count, increasing the number of word counts until the browser becomes unresponsive. - The word count is triggered multiple times on input due to listening to redundant events. --- app/assets/javascripts/osem.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/osem.js b/app/assets/javascripts/osem.js index 5f1bc6257a..65795fe3c2 100644 --- a/app/assets/javascripts/osem.js +++ b/app/assets/javascripts/osem.js @@ -133,7 +133,7 @@ function get_color() { function word_count(text, divId, maxcount) { var area = document.getElementById(text.id) - Countable.live(area, function(counter) { + Countable.once(area, function(counter) { $('#' + divId).text(counter.words); if (counter.words > maxcount) $('#' + divId).css('color', 'red'); @@ -157,7 +157,7 @@ $( document ).ready(function() { .trigger('change'); /* Count the proposal abstract length */ - $("#event_abstract").bind('change keyup paste input', function() { + $("#event_abstract").on('input', function() { var $selected = $("#event_event_type_id option:selected") var max = $selected.data("max-words"); word_count(this, 'abstract-count', max);