Move word counting javascript to the page

It really does not need to run on every page load...
This commit is contained in:
Henne Vogelsang 2024-03-05 15:32:14 +01:00
parent c63ed43825
commit 30bc21c96a
No known key found for this signature in database
GPG key ID: 97DDB66BDAF8D4D6
3 changed files with 26 additions and 24 deletions

View file

@ -90,3 +90,27 @@
- submit_copy = action_is_edit ? 'Update Proposal' : 'Create Proposal'
= f.submit submit_copy, class: 'btn btn-success'
- content_for :script_head do
:javascript
/* Wait for the DOM to be ready before attaching events to the elements */
$( document ).ready(function() {
/* Set the minimum and maximum proposal abstract word length */
function updateEventTypeRequirements() {
var $selected = $("#event_event_type_id option:selected")
var max = $selected.data("max-words");
var min = $selected.data("min-words");
$("#abstract-maximum-word-count").text(max);
$("#abstract-minimum-word-count").text(min);
word_count($('#event_abstract').get(0), 'abstract-count', max);
}
$("#event_event_type_id").change(updateEventTypeRequirements);
updateEventTypeRequirements();
/* Count the proposal abstract length */
$("#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);
} );
});