Skip to content

Commit

Permalink
Resolve jQuery and DOM deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Jun 7, 2024
1 parent 73b1e6c commit 374cc91
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 39 deletions.
2 changes: 1 addition & 1 deletion funnel/assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Ticketing from './utils/ticket_widget';
$(() => {
window.Hasgeek.homeInit = function homeInit(markdownContainer, tickets = '') {
// Expand CFP section
$('.jquery-show-all').click(function showAll(event) {
$('.jquery-show-all').on('click', function showAll(event) {
event.preventDefault();
const projectElemClass = `.${$(this).data('projects')}`;
$(projectElemClass).removeClass('mui--hide');
Expand Down
2 changes: 1 addition & 1 deletion funnel/assets/js/labels_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $(() => {
},
});
}
$('#add-sublabel-form').click((e) => {
$('#add-sublabel-form').on('click', (e) => {
e.preventDefault();
$('#child-form').append(formHtml);
activateFormWidgets();
Expand Down
2 changes: 1 addition & 1 deletion funnel/assets/js/project_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $(() => {
});
}

$('a.js-register-btn').click(function showRegistrationModal() {
$('a.js-register-btn').on('click', function showRegistrationModal() {
window.history.pushState(
{
openModal: true,
Expand Down
2 changes: 1 addition & 1 deletion funnel/assets/js/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const LabelsWidget = {
self.updateLabels('', attr, false);
} else {
$(this).addClass('checked');
$(this).siblings().find('input[type="radio"]').first().click();
$(this).siblings().find('input[type="radio"]').first().trigger('click');
}
});

Expand Down
6 changes: 3 additions & 3 deletions funnel/assets/js/utils/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ const Analytics = {
},
init() {
// Send click events to Google analytics
$('.mui-btn, a').click(function gaHandler() {
$('.mui-btn, a').on('click', function gaHandler() {
const action = $(this).attr('data-ga') || $(this).attr('title') || $(this).html();
const target = $(this).attr('data-target') || $(this).attr('href') || '';
Analytics.sendToGA('click', action, target);
});
$('.ga-login-btn').click(function gaHandler() {
$('.ga-login-btn').on('click', function gaHandler() {
const action = $(this).attr('data-ga');
Analytics.sendToGA('login', action);
});
$('.search-form__submit').click(function gaHandler() {
$('.search-form__submit').on('click', function gaHandler() {
const target = $('.js-search-field').val();
Analytics.sendToGA('search', target, target);
});
Expand Down
5 changes: 2 additions & 3 deletions funnel/assets/js/utils/formhelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ const Form = {
},
preventSubmitOnEnter(id) {
$(`#${id}`).on('keyup keypress', (e) => {
const code = e.keyCode || e.which;
if (code === 13) {
if (e.key === 'Enter') {
e.preventDefault();
return false;
}
Expand Down Expand Up @@ -187,7 +186,7 @@ const Form = {
handleFormSubmit(formId, url, onSuccess, onError, config) {
$(`#${formId}`)
.find('button[type="submit"]')
.click((event) => {
.on('click', (event) => {
event.preventDefault();
Form.ajaxFormSubmit(formId, url, onSuccess, onError, config);
});
Expand Down
2 changes: 1 addition & 1 deletion funnel/assets/js/utils/jsonform.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const jsonForm = Vue.component('jsonform', {
};
$(`#${this.formid}`)
.find('button[type="submit"]')
.click((event) => {
.on('click', (event) => {
event.preventDefault();
Form.ajaxFormSubmit(this.formid, url, onSuccess, onError, {
contentType: 'application/json',
Expand Down
6 changes: 3 additions & 3 deletions funnel/assets/js/utils/modalhelper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Modal = {
handleModalForm() {
$('.js-modal-form').click(function addModalToWindowHash() {
$('.js-modal-form').on('click', function addModalToWindowHash() {
window.location.hash = $(this).data('hash');
});

Expand All @@ -27,7 +27,7 @@ const Modal = {
const hashId = window.location.hash.split('#')[1];
if (hashId) {
if ($(`a.js-modal-form[data-hash="${hashId}"]`).length) {
$(`a[data-hash="${hashId}"]`).click();
$(`a[data-hash="${hashId}"]`).trigger('click');
}
}

Expand All @@ -47,7 +47,7 @@ const Modal = {
$this.find('.modal__close').focus();

$this.on('keydown', (event) => {
if (event.keyCode !== 9) return;
if (event.key !== 'Tab') return;
focusedItem = $(document.activeElement);
focusedItemIndex = focusableItems.index(focusedItem);
if (!event.shiftKey && focusedItemIndex === numberOfFocusableItems - 1) {
Expand Down
36 changes: 17 additions & 19 deletions funnel/assets/js/utils/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ const Tabs = {
.wrap('<div class="md-tablist-wrapper"></div>')
.before($leftIcons)
.after($rightIcons);
$(icons.left.touch).click(function previousTab() {
$(icons.left.touch).on('click', function previousTab() {
tablist.dispatchEvent(new Event('previous-tab'));
});
$(icons.right.touch).click(function nextTab() {
$(icons.right.touch).on('click', function nextTab() {
tablist.dispatchEvent(new Event('next-tab'));
});
$(icons.left.scroll).click(function scrollLeft() {
$(icons.left.scroll).on('click', function scrollLeft() {
tablist.dispatchEvent(new Event('scroll-left'));
});
$(icons.right.scroll).click(function scrollRight() {
$(icons.right.scroll).on('click', function scrollRight() {
tablist.dispatchEvent(new Event('scroll-right'));
});
},
Expand Down Expand Up @@ -119,21 +119,19 @@ const Tabs = {
},
enhanceARIA(tablist, $tabs) {
$tabs.on('keydown', function addArrowNav(event) {
const [LEFT, UP, RIGHT, DOWN] = [37, 38, 39, 40];
const k = event.which || event.keyCode;
if (k >= LEFT && k <= DOWN) {
switch (k) {
case LEFT:
case UP:
tablist.dispatchEvent(new Event('previous-tab'));
break;
case RIGHT:
case DOWN:
tablist.dispatchEvent(new Event('next-tab'));
break;
default:
}
event.preventDefault();
const k = event.key;
switch (k) {
case 'ArrowLeft':
case 'ArrowUp':
event.preventDefault();
tablist.dispatchEvent(new Event('previous-tab'));
break;
case 'ArrowRight':
case 'ArrowDown':
event.preventDefault();
tablist.dispatchEvent(new Event('next-tab'));
break;
default:
}
});
$tabs.each(function addTabListeners(tabIndex, tab) {
Expand Down
2 changes: 1 addition & 1 deletion funnel/assets/js/utils/ticket_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const Ticketing = {
this.openTicketModal();
}

$('.js-open-ticket-widget').click((event) => {
$('.js-open-ticket-widget').on('click', (event) => {
event.preventDefault();
this.openTicketModal();
});
Expand Down
8 changes: 4 additions & 4 deletions funnel/static/js/libs/spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,15 @@
}

// Prevent clicks from bubbling up to document. This would cause it to be hidden.
container.click(stopPropagation);
container.on('click', stopPropagation);

// Handle user typed input
textInput.change(setFromTextInput);
textInput.on('change', setFromTextInput);
textInput.bind('paste', function () {
setTimeout(setFromTextInput, 1);
});
textInput.keydown(function (e) {
if (e.keyCode == 13) {
textInput.on('keydown', function (e) {
if (e.key === 'Enter') {
setFromTextInput();
}
});
Expand Down
2 changes: 1 addition & 1 deletion funnel/templates/siteadmin_comments.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

{% block footerscripts %}
<script type="text/javascript">
$("#check-comments-selectall:checkbox").change(function (e) {
$("#check-comments-selectall:checkbox").on("change", function (e) {
e.preventDefault();
$(".field-comment-id").attr("checked", this.checked);
});
Expand Down

0 comments on commit 374cc91

Please sign in to comment.