From aacc9edd6418648fc67076eb51b5806daec788ee Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 11 Apr 2025 08:26:19 -0400 Subject: [PATCH 01/11] Migrate jQuery:first, jQuery:last --- fec/fec/static/js/modules/dropdowns.js | 2 +- fec/fec/static/js/modules/maps.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fec/fec/static/js/modules/dropdowns.js b/fec/fec/static/js/modules/dropdowns.js index 0d1c0762f1..f91035ba8c 100644 --- a/fec/fec/static/js/modules/dropdowns.js +++ b/fec/fec/static/js/modules/dropdowns.js @@ -85,7 +85,7 @@ Dropdown.prototype.toggle = function(e) { Dropdown.prototype.show = function() { restoreTabindex(this.$panel); this.$panel.attr('aria-hidden', 'false'); - this.$panel.find('input[type="checkbox"]:first').focus(); // TODO: jQuery deprecation (:first and .focus) + this.$panel.find('input[type="checkbox"]').first().trigger('focus'); this.$button.addClass('is-active'); this.isOpen = true; }; diff --git a/fec/fec/static/js/modules/maps.js b/fec/fec/static/js/modules/maps.js index 09b1f9b5ab..20f6bc5224 100644 --- a/fec/fec/static/js/modules/maps.js +++ b/fec/fec/static/js/modules/maps.js @@ -315,7 +315,7 @@ function appendStateMap($parent, results, cached) { return displayed.indexOf(each) === -1; }) || _last(ids); $parent.append(candidateStateMapTemplate(results)); - const $select = $parent.find('.state-map:last select'); // TODO: jQuery deprecation (:last) + const $select = $parent.find('.state-map').last().find('select'); $select.val(value); $select.trigger('change'); updateButtonsDisplay($parent); From db3450df937ad019fcba1ca738064d43d36b0838 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 11 Apr 2025 08:26:40 -0400 Subject: [PATCH 02/11] Migrate jQuery:unique --- fec/fec/static/js/modules/election-map.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fec/fec/static/js/modules/election-map.js b/fec/fec/static/js/modules/election-map.js index d893b1ca35..384ed2a88f 100644 --- a/fec/fec/static/js/modules/election-map.js +++ b/fec/fec/static/js/modules/election-map.js @@ -166,7 +166,7 @@ ElectionMap.prototype.drawBackgroundDistricts = function(districts) { .map(function(district) { return Math.floor(district / 100); }) - .unique() // TODO: jQuery deprecation + .sortUnique() .value(); var stateDistricts = _filter(districtFeatures.features, function( feature From eec622f1ada50c9fa52da34006edf5d37714a252 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 11 Apr 2025 08:27:04 -0400 Subject: [PATCH 03/11] Migrate jQuery.hover --- .../static/js/modules/filters/date-filter.js | 100 ++++++++++-------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/fec/fec/static/js/modules/filters/date-filter.js b/fec/fec/static/js/modules/filters/date-filter.js index 6b3d3163ed..d7c453995c 100644 --- a/fec/fec/static/js/modules/filters/date-filter.js +++ b/fec/fec/static/js/modules/filters/date-filter.js @@ -239,29 +239,32 @@ DateFilter.prototype.handleMinDateSelect = function() { this.$grid.find('.is-active').removeClass('is-active'); $dateBegin.addClass('is-active'); - this.$grid.find('li').hover( // TODO: jQuery deprecation - function() { - var dateBeginNum = parseInt( - $(this) - .parent() - .attr('data-year') + $(this).attr('data-month') - ); - var dateEndNum = parseInt( - $dateEnd.parent().attr('data-year') + $dateEnd.attr('data-month') - ); - - if (dateBeginNum <= dateEndNum) { - self.$grid.removeClass('is-invalid'); - self.handleDateGridRange($(this), $dateEnd); - } else { - self.$grid.addClass('is-invalid'); + this.$grid.find('li') + .on('mouseenter', + function() { + const dateBeginNum = parseInt( + $(this) + .parent() + .attr('data-year') + $(this).attr('data-month') + ); + const dateEndNum = parseInt( + $dateEnd.parent().attr('data-year') + $dateEnd.attr('data-month') + ); + + if (dateBeginNum <= dateEndNum) { + self.$grid.removeClass('is-invalid'); + self.handleDateGridRange($(this), $dateEnd); + } else { + self.$grid.addClass('is-invalid'); + } } - }, - function() { - self.handleDateGridRange($dateBegin, $dateEnd); - $dateBegin.addClass('is-active'); - } - ); + ) + .on('mouseleave', + function() { + self.handleDateGridRange($dateBegin, $dateEnd); + $dateBegin.addClass('is-active'); + } + ); }; DateFilter.prototype.handleMaxDateSelect = function() { @@ -276,31 +279,34 @@ DateFilter.prototype.handleMaxDateSelect = function() { this.$grid.find('.is-active').removeClass('is-active'); $dateEnd.addClass('is-active'); - this.$grid.find('li').hover( // TODO: jQuery deprecation - function() { - // turn dates to numbers for comparsion - // to make sure hover date range is valid - var dateBeginNum = parseInt( - $dateBegin.parent().attr('data-year') + $dateBegin.attr('data-month') - ); - var dateEndNum = parseInt( - $(this) - .parent() - .attr('data-year') + $(this).attr('data-month') - ); - - if (dateBeginNum <= dateEndNum) { - self.$grid.removeClass('is-invalid'); - self.handleDateGridRange($dateBegin, $(this)); - } else { - self.$grid.addClass('is-invalid'); + this.$grid.find('li') + .on('mouseenter', + function() { + // turn dates to numbers for comparison + // to make sure hover date range is valid + var dateBeginNum = parseInt( + $dateBegin.parent().attr('data-year') + $dateBegin.attr('data-month') + ); + var dateEndNum = parseInt( + $(this) + .parent() + .attr('data-year') + $(this).attr('data-month') + ); + + if (dateBeginNum <= dateEndNum) { + self.$grid.removeClass('is-invalid'); + self.handleDateGridRange($dateBegin, $(this)); + } else { + self.$grid.addClass('is-invalid'); + } } - }, - function() { - self.handleDateGridRange($dateBegin, $dateEnd); - $dateEnd.addClass('is-active'); - } - ); + ) + .on('mouseleave', + function() { + self.handleDateGridRange($dateBegin, $dateEnd); + $dateEnd.addClass('is-active'); + } + ); }; DateFilter.prototype.handleGridItemSelect = function(e) { @@ -331,7 +337,7 @@ DateFilter.prototype.handleGridItemSelect = function(e) { ? this.$maxDate : this.$submit; this.$grid.removeClass('pick-min pick-max'); - this.$grid.find('li').unbind('mouseenter mouseleave'); // TODO: jQuery deprecation (.unbind()) + this.$grid.find('li').off('mouseenter mouseleave'); this.setValue(value); this.$grid.addClass('is-invalid'); $nextItem.focus(); // TODO: jQuery deprecation From 6dc727e9d1f3d9b1bdc0173d9896b90d8db72bec Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 11 Apr 2025 08:27:29 -0400 Subject: [PATCH 04/11] Migrate jQuery.bind, --- fec/fec/static/js/pages/datatable-audit.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fec/fec/static/js/pages/datatable-audit.js b/fec/fec/static/js/pages/datatable-audit.js index f872d823d1..1a1bd67419 100644 --- a/fec/fec/static/js/pages/datatable-audit.js +++ b/fec/fec/static/js/pages/datatable-audit.js @@ -7,11 +7,7 @@ import { audit as cols_audit } from '../modules/columns.js'; import { DataTable_FEC, modalRenderRow } from '../modules/tables.js'; // for sub category filter-tag and results -$(document).bind( // TODO: jQuery deprecation - 'ready ajaxComplete', - '#sub_category_id', - showSubCategory -); +$(document).on('ready ajaxComplete', '#sub_category_id', showSubCategory); $(function() { auditCategorySubcategory(); From 17ce5edb7c1fe8b82c53986194a466cca3c9fef1 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 11 Apr 2025 08:27:41 -0400 Subject: [PATCH 05/11] Migrate jQuery.trim --- fec/fec/static/js/modules/helpers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fec/fec/static/js/modules/helpers.js b/fec/fec/static/js/modules/helpers.js index 66689869fd..4aa183a4c2 100644 --- a/fec/fec/static/js/modules/helpers.js +++ b/fec/fec/static/js/modules/helpers.js @@ -613,9 +613,9 @@ export function sanitizeQueryParams(query) { export function getCookie(name) { let cookieValue = null; if (document.cookie && document.cookie != '') { - let cookies = document.cookie.split(';'); + const cookies = document.cookie.split(';'); for (let i = 0; i < cookies.length; i++) { - let cookie = $.trim(cookies[i]); // TODO: remove jQuery.trim as it's been deprecated + const cookie = cookies[i].trim(); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == name + '=') { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); From 7527a2641f8e6d3311ace3c7564fb2d8ebfa624e Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 11 Apr 2025 08:36:25 -0400 Subject: [PATCH 06/11] Migrate jQuery.keyCode --- fec/fec/static/js/modules/calendar.js | 2 +- fec/fec/static/js/modules/dropdowns.js | 4 ++-- fec/fec/static/js/modules/filters/filter-typeahead.js | 2 +- fec/fec/static/js/modules/search.js | 2 +- fec/fec/static/js/modules/skip-nav.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fec/fec/static/js/modules/calendar.js b/fec/fec/static/js/modules/calendar.js index bdda2ea1cb..d1820a06e3 100644 --- a/fec/fec/static/js/modules/calendar.js +++ b/fec/fec/static/js/modules/calendar.js @@ -338,7 +338,7 @@ Calendar.prototype.handleEventClick = function(calEvent, jsEvent) { // Simulate clicks when hitting enter on certain full-calendar elements Calendar.prototype.simulateClick = function(e) { - if (e.keyCode === 13) { + if (e.which === 13) { $(e.target).click(); // TODO: jQuery deprecation } }; diff --git a/fec/fec/static/js/modules/dropdowns.js b/fec/fec/static/js/modules/dropdowns.js index f91035ba8c..0d44665252 100644 --- a/fec/fec/static/js/modules/dropdowns.js +++ b/fec/fec/static/js/modules/dropdowns.js @@ -117,7 +117,7 @@ Dropdown.prototype.handleFocusAway = function(e) { }; Dropdown.prototype.handleKeyup = function(e) { - if (e.keyCode === KEYCODE_ESC) { + if (e.which === KEYCODE_ESC) { if (this.isOpen) { this.hide(); this.$button.focus(); // TODO: jQuery deprecation @@ -126,7 +126,7 @@ Dropdown.prototype.handleKeyup = function(e) { }; Dropdown.prototype.handleCheckKeyup = function(e) { - if (e.keyCode === KEYCODE_ENTER) { + if (e.which === KEYCODE_ENTER) { $(e.target) .prop('checked', true) .change(); // TODO: jQuery deprecation diff --git a/fec/fec/static/js/modules/filters/filter-typeahead.js b/fec/fec/static/js/modules/filters/filter-typeahead.js index 8827e5fca3..ecbe375432 100644 --- a/fec/fec/static/js/modules/filters/filter-typeahead.js +++ b/fec/fec/static/js/modules/filters/filter-typeahead.js @@ -180,7 +180,7 @@ FilterTypeahead.prototype.handleKeypress = function(e) { this.$field.attr('aria-expanded', 'false'); } - if (e.keyCode === 13 || e.code === 'Enter') { // 13 = enter/return but .keyCode has been deprecated + if (e.which === 13 || e.code === 'Enter') { // 13 = enter/return this.handleSubmit(e); } }; diff --git a/fec/fec/static/js/modules/search.js b/fec/fec/static/js/modules/search.js index 07340a9d0a..12a9ff52d8 100644 --- a/fec/fec/static/js/modules/search.js +++ b/fec/fec/static/js/modules/search.js @@ -31,7 +31,7 @@ export default function Search($el, opts) { $(document.body).on('keyup', function(e) { // Focus search on "/" - if (e.keyCode === KEYCODE_SLASH) { + if (e.which === KEYCODE_SLASH) { $input.first().focus(); // TODO: jQuery deprecation } }); diff --git a/fec/fec/static/js/modules/skip-nav.js b/fec/fec/static/js/modules/skip-nav.js index f2b315c0f2..d8b1e20289 100644 --- a/fec/fec/static/js/modules/skip-nav.js +++ b/fec/fec/static/js/modules/skip-nav.js @@ -26,7 +26,7 @@ Skipnav.prototype.findTarget = function() { Skipnav.prototype.focusOnTarget = function(e) { e.preventDefault(); - if (e.keyCode === 13 || e.type === 'click') { + if (e.which === 13 || e.type === 'click') { this.$target.attr('tabindex', '0'); this.$target.focus(); // TODO: jQuery deprecation } From c2351ee627a2eb7fd32d370b157d75eaf8ac546d Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 11 Apr 2025 08:42:09 -0400 Subject: [PATCH 07/11] Migrate jQuery.keyCode/.which tests --- fec/fec/tests/js/dropdowns.js | 2 +- fec/fec/tests/js/skip-nav.js | 3 ++- fec/fec/tests/js/typeahead-filter.js | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fec/fec/tests/js/dropdowns.js b/fec/fec/tests/js/dropdowns.js index 2c89bca298..b77209bf8c 100644 --- a/fec/fec/tests/js/dropdowns.js +++ b/fec/fec/tests/js/dropdowns.js @@ -175,7 +175,7 @@ describe('dropdown', function() { it('hides on ESC', function(){ this.dropdown.show(); - this.dropdown.handleKeyup({ keyCode: 27 }); + this.dropdown.handleKeyup({ keyCode: 27, which: 27 }); // TODO: keyCode has been deprecated expect(isClosed(this.dropdown)).to.be.true; }); }); diff --git a/fec/fec/tests/js/skip-nav.js b/fec/fec/tests/js/skip-nav.js index c3fd7d02ca..5f364937b3 100644 --- a/fec/fec/tests/js/skip-nav.js +++ b/fec/fec/tests/js/skip-nav.js @@ -34,7 +34,8 @@ describe('Skip nav link', function() { }); it('focuses on the target when enter pressed', function() { - var e = { keyCode: 13, preventDefault: function() {} }; // eslint-disable-line no-empty-function + // TODO: keyCode has been deprecated + var e = { keyCode: 13, which: 13, preventDefault: function() {} }; // eslint-disable-line no-empty-function this.skipNav.focusOnTarget(e); expect($(document.activeElement).is(this.skipNav.$target)).to.be.true; }); diff --git a/fec/fec/tests/js/typeahead-filter.js b/fec/fec/tests/js/typeahead-filter.js index 7879c3d51d..e286aacaf9 100644 --- a/fec/fec/tests/js/typeahead-filter.js +++ b/fec/fec/tests/js/typeahead-filter.js @@ -112,8 +112,8 @@ describe('FilterTypeahead', function() { it('should submit on enter', function() { var handleSubmit = spy(this.FilterTypeahead, 'handleSubmit'); - this.FilterTypeahead.handleKeypress({ keyCode: 13 }); - expect(handleSubmit).to.have.been.calledWith({ keyCode: 13 }); + this.FilterTypeahead.handleKeypress({ keyCode: 13, which: 13 }); // TODO: keyCode has been deprecated + expect(handleSubmit).to.have.been.calledWith({ keyCode: 13, which: 13 }); // TODO: keyCode has been deprecated this.FilterTypeahead.handleSubmit.restore(); }); From c5f04fc490254ed542e3bf9f88cd5bd37c06365a Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 11 Apr 2025 11:15:02 -0400 Subject: [PATCH 08/11] Make SkipNav tabbable where it should have been --- fec/fec/templates/base.html | 2 +- fec/fec/templates/home_base.html | 2 +- fec/fec/tests/js/skip-nav.js | 2 +- fec/home/templates/purgecss-homepage/banners.html | 2 +- fec/home/templates/purgecss-homepage/full.html | 2 +- fec/home/templates/purgecss-homepage/navs.html | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fec/fec/templates/base.html b/fec/fec/templates/base.html index 6930afcbd3..f69ec697e7 100644 --- a/fec/fec/templates/base.html +++ b/fec/fec/templates/base.html @@ -34,7 +34,7 @@

Your web browser is not supported

{% if not request.is_preview %}{% include 'partials/google-tag-manager-noscript.html' %}{% endif %} {% wagtailuserbar %} - skip navigation + skip navigation {# env-specific banner #} {% include 'partials/env-banner.html' %} {# .gov banner #} diff --git a/fec/fec/templates/home_base.html b/fec/fec/templates/home_base.html index c916579667..a47ffd4b26 100644 --- a/fec/fec/templates/home_base.html +++ b/fec/fec/templates/home_base.html @@ -35,7 +35,7 @@

Your web browser is not supported

{% if not request.is_preview %}{% include 'partials/google-tag-manager-noscript.html' %}{% endif %} {% wagtailuserbar %} - skip navigation + skip navigation {# env-specific banner #} {% include 'partials/env-banner.html' %} {# .gov banner #} diff --git a/fec/fec/tests/js/skip-nav.js b/fec/fec/tests/js/skip-nav.js index 5f364937b3..08babfd0ee 100644 --- a/fec/fec/tests/js/skip-nav.js +++ b/fec/fec/tests/js/skip-nav.js @@ -8,7 +8,7 @@ use(sinonChai); import SkipNav from '../../static/js/modules/skip-nav.js'; -const DOM = 'Skip

Welcome

'; +const DOM = 'Skip

Welcome

'; describe('Skip nav link', function() { before(function() { diff --git a/fec/home/templates/purgecss-homepage/banners.html b/fec/home/templates/purgecss-homepage/banners.html index 7c7b1f906b..7cd07bac71 100644 --- a/fec/home/templates/purgecss-homepage/banners.html +++ b/fec/home/templates/purgecss-homepage/banners.html @@ -2,7 +2,7 @@ - skip navigation + skip navigation - skip navigation + skip navigation - skip navigation + skip navigation From 063046addc22f44fe8554c190958c7e9a5cc6522 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 11 Apr 2025 11:20:52 -0400 Subject: [PATCH 09/11] correcting a unique > sortUnique --- fec/fec/static/js/modules/election-map.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fec/fec/static/js/modules/election-map.js b/fec/fec/static/js/modules/election-map.js index 384ed2a88f..db09ee92b3 100644 --- a/fec/fec/static/js/modules/election-map.js +++ b/fec/fec/static/js/modules/election-map.js @@ -166,7 +166,7 @@ ElectionMap.prototype.drawBackgroundDistricts = function(districts) { .map(function(district) { return Math.floor(district / 100); }) - .sortUnique() + .unique() .value(); var stateDistricts = _filter(districtFeatures.features, function( feature From bd1cdc817199fdca9cb3d16862a274f563f4da06 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 11 Apr 2025 13:38:10 -0400 Subject: [PATCH 10/11] Update jQuery deprecation notes --- fec/fec/static/js/legal.js | 2 +- fec/fec/static/js/modules/form-nav.js | 2 +- fec/fec/static/js/modules/typeahead.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fec/fec/static/js/legal.js b/fec/fec/static/js/legal.js index 04ad75b9be..12a28be5f9 100644 --- a/fec/fec/static/js/legal.js +++ b/fec/fec/static/js/legal.js @@ -46,7 +46,7 @@ KeywordModal.prototype.handleSubmit = function(e) { e.preventDefault(); var queryString = this.generateQueryString(); this.$hiddenField.val(queryString); - this.$form.submit(); // TODO: jQuery deprecation? (.submit() ) + this.$form.submit(); // TODO: jQuery deprecation (.submit() ) }; /** diff --git a/fec/fec/static/js/modules/form-nav.js b/fec/fec/static/js/modules/form-nav.js index 099fdf4980..7802dbe830 100644 --- a/fec/fec/static/js/modules/form-nav.js +++ b/fec/fec/static/js/modules/form-nav.js @@ -27,5 +27,5 @@ FormNav.prototype.clearNamesIfNull = function(e) { } } - if (e.type == 'change') this.form.submit(); // TODO: jQuery deprecation + if (e.type == 'change') this.form.submit(); }; diff --git a/fec/fec/static/js/modules/typeahead.js b/fec/fec/static/js/modules/typeahead.js index 135bd56875..9a8b9ead54 100644 --- a/fec/fec/static/js/modules/typeahead.js +++ b/fec/fec/static/js/modules/typeahead.js @@ -490,5 +490,5 @@ Typeahead.prototype.searchSite = function(query) { const action = $form.attr('action'); this.$input.val(query); $form.attr('action', action); - $form.submit(); + $form.submit(); // TODO: jQuery deprecation (.submit() ) }; From e92c57cb0419d489f8f8dfe446229ab5b516ae73 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 11 Apr 2025 13:50:23 -0400 Subject: [PATCH 11/11] Migrate jQuery.submit --- fec/fec/static/js/legal.js | 2 +- fec/fec/static/js/modules/typeahead.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fec/fec/static/js/legal.js b/fec/fec/static/js/legal.js index 12a28be5f9..e6f5f2cdbb 100644 --- a/fec/fec/static/js/legal.js +++ b/fec/fec/static/js/legal.js @@ -46,7 +46,7 @@ KeywordModal.prototype.handleSubmit = function(e) { e.preventDefault(); var queryString = this.generateQueryString(); this.$hiddenField.val(queryString); - this.$form.submit(); // TODO: jQuery deprecation (.submit() ) + this.$form.trigger('submit'); }; /** diff --git a/fec/fec/static/js/modules/typeahead.js b/fec/fec/static/js/modules/typeahead.js index 9a8b9ead54..665cf1939a 100644 --- a/fec/fec/static/js/modules/typeahead.js +++ b/fec/fec/static/js/modules/typeahead.js @@ -490,5 +490,5 @@ Typeahead.prototype.searchSite = function(query) { const action = $form.attr('action'); this.$input.val(query); $form.attr('action', action); - $form.submit(); // TODO: jQuery deprecation (.submit() ) + $form.trigger('submit'); };