From ee11dc03d1a9602e5370f0bfe33c40c3bd534ad4 Mon Sep 17 00:00:00 2001 From: Splines Date: Mon, 13 Nov 2023 19:21:41 +0100 Subject: [PATCH] Use JQuery syntax and lint file Note we also use .trigger("change") to trigger event listeners for the checkbox, otherwise they won't be fired. --- app/views/annotations/edit.js.erb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/views/annotations/edit.js.erb b/app/views/annotations/edit.js.erb index f14a7f774..3bdf7afef 100644 --- a/app/views/annotations/edit.js.erb +++ b/app/views/annotations/edit.js.erb @@ -67,9 +67,9 @@ function constructWarningMessage() { var categoryRadios = document.getElementById('category-radios'); -categoryRadios.addEventListener('click', function(evt) { +categoryRadios.addEventListener('click', function (evt) { if (evt.target && event.target.matches("input[type='radio']")) { - switch(evt.target.value) { + switch (evt.target.value) { case Category.NOTE.name: note(); break; @@ -100,7 +100,7 @@ function content() { visibleForTeacher(true); postComment(false); var contentCategoryRadios = document.getElementById('content-category-radios'); - contentCategoryRadios.addEventListener('click', function(evt) { + contentCategoryRadios.addEventListener('click', function (evt) { if (evt.target && event.target.matches("input[type='radio']")) { submitButton.disabled = false; switch (evt.target.value) { @@ -180,13 +180,13 @@ function updatePreview() { /* * Auxiliary methods */ -function visibleForTeacher(boolean) { - $('#annotation_visible_for_teacher').prop("checked", boolean); +function visibleForTeacher(isVisible) { + $('#annotation_visible_for_teacher').prop("checked", isVisible).trigger("change"); } -function postComment(boolean) { - boolean = posted ? true : boolean; - $('#annotation_post_as_comment').prop("checked", boolean); +function postComment(isVisible) { + isVisible = posted ? true : isVisible; + $('#annotation_post_as_comment').prop("checked", isVisible).trigger("change"); } function previewCSS(show, modalWidth, contentWidth, previewWidth) { @@ -209,8 +209,8 @@ function previewCSS(show, modalWidth, contentWidth, previewWidth) { /* If this script is rendered by the edit method of the annotation controller: Select correct subcategory (this is not automatically done by the rails form as the content is dynamically rendered). */ -var contentRadio = document.getElementById('annotation_category_content'); -if (contentRadio.checked) { +var contentRadio = $('#annotation_category_content'); +if (contentRadio.is(':checked')) { content(); submitButton.disabled = false; var subcategory = document.getElementById('annotation_subcategory').textContent.replace(/[^a-z]/g, ''); @@ -229,7 +229,7 @@ if (contentRadio.checked) { // render preview var annotationComment = document.getElementById('annotation_comment'); -annotationComment.addEventListener('input', function() { +annotationComment.addEventListener('input', function () { updatePreview(); }); @@ -237,7 +237,7 @@ previewCSS(false, 100, 100, 0); // preview toggle listener var previewToggle = document.getElementById('preview-toggle'); -previewToggle.addEventListener('change', function() { +previewToggle.addEventListener('change', function () { if ($('#preview-toggle-check').is(":checked")) { previewCSS(true, 150, 65, 35); } else {