Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jQuery): migrate deprecated jQuery functions #959

Merged
merged 5 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import eslint from "@eslint/js";
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import pluginPromise from 'eslint-plugin-promise'
import globals from 'globals';

const config = tseslint.config(
{
Expand All @@ -10,6 +11,10 @@ const config = tseslint.config(
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
globals: {
...globals.browser,
...globals.jquery,
},
},
extends: [
eslint.configs.recommended,
Expand All @@ -19,6 +24,7 @@ const config = tseslint.config(
rules: {
'no-console': 'off',
'no-debugger': 'off',
'@typescript-eslint/no-deprecated': 'warn',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-this-alias': 'off',
Expand Down
4 changes: 2 additions & 2 deletions web/typescript/backend/AdminIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class AdminIndex {

private initDelSite() {
let $delForm = $(".delSiteCaller");
$delForm.find("button").click(function (ev) {
$delForm.find("button").on("click", function (ev) {
ev.preventDefault();
let $button = $(this);
bootbox.confirm(__t('admin', 'consDeleteConfirm'), function (result) {
if (result) {
let $input = $('<input type="hidden">').attr("name", $button.attr("name")).attr("value", $button.attr("value"));
$delForm.append($input);
$delForm.submit();
$delForm.trigger("submit");
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion web/typescript/backend/MemberPetitionRespond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class MemberPetitionRespond {
ckeditor = new AntragsgruenEditor($textarea.attr("id")),
editor = ckeditor.getEditor();

$textarea.parents("form").submit(() => {
$textarea.parents("form").on("submit", () => {
$textarea.parent().find("textarea").val(editor.getData());
});
});
Expand Down
2 changes: 1 addition & 1 deletion web/typescript/backend/ProposedProcedureExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export class ProposedProcedureExport {
this.$widget.find("li.checkbox").on("click", function (ev) {
ev.stopPropagation();
});
this.$widget.find("input[type=checkbox]").change(this.recalcLinks.bind(this)).trigger("change");
this.$widget.find("input[type=checkbox]").on("change", this.recalcLinks.bind(this)).trigger("change");
}
}
2 changes: 1 addition & 1 deletion web/typescript/backend/ProposedProcedureOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class ProposedProcedureOverview {
$td = $btn.parents('td').first();

$td.addClass('writing');
$td.find('textarea').focus();
$td.find('textarea').trigger("focus");;
}

private submitComment($commentTd: JQuery) {
Expand Down
2 changes: 1 addition & 1 deletion web/typescript/backend/UserList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class UserList {
if (result) {
let id = $button.data("id");
$form.append('<input type="hidden" name="deleteUser" value="' + id + '">');
$form.submit();
$form.trigger("submit");
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion web/typescript/frontend/AccountEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AccountEdit {
ev.preventDefault();
$changeRow.removeClass("hidden");
$emailExisting.addClass("hidden");
$changeRow.find("input").focus();
$changeRow.find("input").trigger("focus");;
});
}

Expand Down
2 changes: 1 addition & 1 deletion web/typescript/frontend/CopyUrlToClipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class CopyUrlToClipboard {
clipboard.on('success', () => {
$widget.find(".form-group").addClass("has-success has-feedback");
$widget.find(".clipboard-done").removeClass("hidden");
$button.focus();
$button.trigger("focus");
});

clipboard.on('error', () => {
Expand Down
10 changes: 5 additions & 5 deletions web/typescript/frontend/DeadlineDebugBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ export class DeadlineDebugBar {
constructor(private $widget: JQuery) {
const csrf = $widget.find('> input[name=_csrf]').val();

$widget.submit(ev => ev.preventDefault());
$widget.on("submit", ev => ev.preventDefault());

$widget.find('.closeCol button').click(() => {
$widget.find('.closeCol button').on("click", () => {
$.post($widget.attr('action'), {
'_csrf': csrf,
'action': 'close'
Expand All @@ -21,8 +21,8 @@ export class DeadlineDebugBar {
$picker.datetimepicker({
locale: $picker.find('input').data('locale')
});
$widget.find('.setTime').click(() => {

$widget.find('.setTime').on("click", () => {
const time = $picker.find('input').val();
$.post($widget.attr('action'), {
'_csrf': csrf,
Expand All @@ -37,4 +37,4 @@ export class DeadlineDebugBar {
});
});
}
}
}
6 changes: 3 additions & 3 deletions web/typescript/frontend/InitiatorForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class InitiatorForm {
}

private initMinSupporters() {
this.$editforms.submit((ev) => {
this.$editforms.on("submit", (ev) => {
if ($('#personTypeOrga').prop('checked')) {
return;
}
Expand Down Expand Up @@ -278,9 +278,9 @@ export class InitiatorForm {
if ($row.next().hasClass('adderRow')) {
let $newEl = $($('#newSupporterTemplate').data('html'));
this.$supporterAdderRow.before($newEl);
$newEl.find('input[type=text]').first().focus();
$newEl.find('input[type=text]').first().trigger("focus");
} else {
$row.next().find('input[type=text]').first().focus();
$row.next().find('input[type=text]').first().trigger("focus");
}
} else if (ev.keyCode == 8) { // Backspace
$row = $(ev.target).parents('.supporterRow');
Expand Down
2 changes: 1 addition & 1 deletion web/typescript/frontend/LineNumberHighlighting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$lineInput = $panel.find("input[name=lineNumber]"),
panelIsOpen = false;
window.addEventListener('keypress', (ev) => {
if (!panelIsOpen && ev.charCode >= 48 && ev.charCode <= 57) {

Check warning on line 7 in web/typescript/frontend/LineNumberHighlighting.ts

View workflow job for this annotation

GitHub Actions / test-build

`charCode` is deprecated. [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/charCode)

Check warning on line 7 in web/typescript/frontend/LineNumberHighlighting.ts

View workflow job for this annotation

GitHub Actions / test-build

`charCode` is deprecated. [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/charCode)
let $target = $(ev.target);
if ($target.is('input, textarea, div.texteditor, .cke_editable') || $target.parents('input, textarea, div.texteditor, .cke_editable').length > 0) {
// Typing in an input field, like comments
Expand All @@ -13,7 +13,7 @@

$panel.addClass("active");
panelIsOpen = true;
$lineInput.focus();
$lineInput.trigger("focus");;
window.setTimeout(() => {
$lineInput.val(ev.key);
}, 1);
Expand Down
4 changes: 2 additions & 2 deletions web/typescript/frontend/MergeInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export class MergeInit {

private initAllCheckbox() {
this.recalcAllCheckbox();
this.$allCheckbox.change(() => {
this.$allCheckbox.on("change", () => {
this.$checkboxes.prop("checked", this.$allCheckbox.prop("checked"));
});
this.$checkboxes.change(() => {
this.$checkboxes.on("change", () => {
this.recalcAllCheckbox();
});
}
Expand Down
10 changes: 5 additions & 5 deletions web/typescript/frontend/MergeSingleAmendment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ class MergeSingleAmendment {
"3": this.$form.find("> .step_3")
};

this.$checkCollisions.click((ev) => {
this.$checkCollisions.on("click", (ev) => {
ev.preventDefault();
this.loadCollisions();
});
this.$steps["1"].find(".goto_2").click((ev) => {
this.$steps["1"].find(".goto_2").on("click", (ev) => {
ev.preventDefault();
this.gotoStep("2");
});
this.$affectedParagraphs.each((i, el) => {
this.initAffectedParagraph(el);
});
this.$form.submit(this.onSubmit.bind(this));
this.$form.on("submit", this.onSubmit.bind(this));

this.gotoStep("1");
}
Expand All @@ -58,14 +58,14 @@ class MergeSingleAmendment {
private initAffectedParagraph(el) {
let $paragraph = $(el);

$paragraph.find(".versionSelector input").change(() => {
$paragraph.find(".versionSelector input").on("change", () => {
if ($paragraph.find(".versionSelector input:checked").val() == "modified") {
$paragraph.removeClass("originalVersion").addClass("modifiedVersion");
} else {
$paragraph.addClass("originalVersion").removeClass("modifiedVersion");
}
}).trigger("change");
$paragraph.find(".modifySelector input").change(() => {
$paragraph.find(".modifySelector input").on("change", () => {
if ($paragraph.find(".modifySelector input").prop("checked")) {
$paragraph.addClass("changed").removeClass("unchanged");
} else {
Expand Down
4 changes: 2 additions & 2 deletions web/typescript/frontend/MotionMergeAmendmentsPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class MotionMergeAmendmentsPublic {
$toggle.prop('checked', (state == '1'));
}
}
$toggle.change(() => {
$toggle.on("change", () => {
let active: boolean = $toggle.prop('checked');
if (localStorage) {
localStorage.setItem('merging-draft-auto-update', (active ? '1' : '0'));
Expand All @@ -97,6 +97,6 @@ export class MotionMergeAmendmentsPublic {
}
}).trigger('change');

this.$updateWidget.find('#updateBtn').click(this.reload.bind(this, true));
this.$updateWidget.find('#updateBtn').on("click", this.reload.bind(this, true));
}
}
4 changes: 2 additions & 2 deletions web/typescript/frontend/UserNotificationsForm.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export class UserNotificationsForm {
constructor(private $widget: JQuery) {
$(".notiComment input").change((ev) => {
$(".notiComment input").on("change", (ev) => {
if ($(ev.currentTarget).prop("checked")) {
$(".commentSettings").removeClass("hidden");
} else {
$(".commentSettings").addClass("hidden");
}
}).trigger("change");

$(".notiAmendment input").change((ev) => {
$(".notiAmendment input").on("change", (ev) => {
if ($(ev.currentTarget).prop("checked")) {
$(".amendmentSettings").removeClass("hidden");
} else {
Expand Down
2 changes: 1 addition & 1 deletion web/typescript/shared/AmendmentEditSinglePara.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class AmendmentEditSinglePara {
$textarea.parent().find("textarea.consolidated").val(editor.getData());
}
});
$textarea.focus();
$textarea.trigger("focus");;
}

private setModifyable() {
Expand Down
Loading