Skip to content

Commit

Permalink
Use JQuery syntax and lint file
Browse files Browse the repository at this point in the history
Note we also use .trigger("change") to trigger event listeners
for the checkbox, otherwise they won't be fired.
  • Loading branch information
Splines committed Nov 13, 2023
1 parent 0a426d1 commit ee11dc0
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/views/annotations/edit.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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, '');
Expand All @@ -229,15 +229,15 @@ if (contentRadio.checked) {

// render preview
var annotationComment = document.getElementById('annotation_comment');
annotationComment.addEventListener('input', function() {
annotationComment.addEventListener('input', function () {
updatePreview();
});

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 {
Expand Down

0 comments on commit ee11dc0

Please sign in to comment.