Merge pull request #3276 from hennevogel/bugfix/word-count-js

Move word counting javascript to the page
This commit is contained in:
Henne Vogelsang 2024-03-05 16:00:52 +01:00 committed by GitHub
commit 9fd0807a9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 24 deletions

View file

@ -45,6 +45,7 @@ linters:
- "app/views/layouts/_admin_sidebar.html.haml" - "app/views/layouts/_admin_sidebar.html.haml"
- "app/views/proposals/index.html.haml" - "app/views/proposals/index.html.haml"
- "app/views/proposals/show.html.haml" - "app/views/proposals/show.html.haml"
- "app/views/proposals/_form.html.haml"
# Offense count: 28 # Offense count: 28
IdNames: IdNames:
@ -145,4 +146,4 @@ linters:
# Offense count: 1 # Offense count: 1
FinalNewline: FinalNewline:
exclude: exclude:
- "app/views/layouts/_admin.html.haml" - "app/views/layouts/_admin.html.haml"

View file

@ -142,29 +142,6 @@ function word_count(text, divId, maxcount) {
}); });
}; };
/* 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);
} );
});
/* Commodity function for modal windows */ /* Commodity function for modal windows */
window.build_dialog = function(selector, content) { window.build_dialog = function(selector, content) {

View file

@ -90,3 +90,27 @@
- submit_copy = action_is_edit ? 'Update Proposal' : 'Create Proposal' - submit_copy = action_is_edit ? 'Update Proposal' : 'Create Proposal'
= f.submit submit_copy, class: 'btn btn-success' = 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);
} );
});