From 3d275b143dd78284763762994523e3ace149be96 Mon Sep 17 00:00:00 2001 From: rfultz Date: Thu, 6 May 2021 14:38:43 -0400 Subject: [PATCH 01/12] Preload the homepage hero image --- fec/fec/templates/home_base.html | 1 + 1 file changed, 1 insertion(+) diff --git a/fec/fec/templates/home_base.html b/fec/fec/templates/home_base.html index 8c30630303..a14e031bc0 100644 --- a/fec/fec/templates/home_base.html +++ b/fec/fec/templates/home_base.html @@ -4,6 +4,7 @@ {% include 'partials/meta-tags.html' %} + {% include 'partials/meta-tags-preloads.html' %} {% if settings.FEC_CMS_ENVIRONMENT == 'PRODUCTION' %} {% include 'partials/meta-tags-preconnects.html' %} From a8475f53f6ec7f07b3f52495e8180d69137abc62 Mon Sep 17 00:00:00 2001 From: rfultz Date: Thu, 6 May 2021 14:39:18 -0400 Subject: [PATCH 02/12] Defer JavaScript files --- fec/data/templates/election-lookup.jinja | 4 ++-- fec/data/templates/elections.jinja | 4 ++-- fec/data/templates/landing.jinja | 4 ++-- fec/home/templates/home/home_page.html | 9 ++++----- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/fec/data/templates/election-lookup.jinja b/fec/data/templates/election-lookup.jinja index 3ed6763b38..ed0cad1e1b 100644 --- a/fec/data/templates/election-lookup.jinja +++ b/fec/data/templates/election-lookup.jinja @@ -112,6 +112,6 @@ var context = { } }; - - + + {% endblock %} diff --git a/fec/data/templates/elections.jinja b/fec/data/templates/elections.jinja index 40c7bcd4b6..48521d1981 100644 --- a/fec/data/templates/elections.jinja +++ b/fec/data/templates/elections.jinja @@ -62,7 +62,7 @@ var context = { }; - - + + {% endblock %} diff --git a/fec/data/templates/landing.jinja b/fec/data/templates/landing.jinja index 8237d94d0a..06a139372b 100644 --- a/fec/data/templates/landing.jinja +++ b/fec/data/templates/landing.jinja @@ -301,6 +301,6 @@ {% endblock %} {% block scripts %} - - + + {% endblock %} diff --git a/fec/home/templates/home/home_page.html b/fec/home/templates/home/home_page.html index 68107c3594..7785c98463 100644 --- a/fec/home/templates/home/home_page.html +++ b/fec/home/templates/home/home_page.html @@ -109,12 +109,11 @@

Commissioners

document.head.appendChild(pfScriptElem); } - - - - + + + + {# Global javascript #} - - + + - + + {% block extra_js %} From 8fb6ebc58cccbc441245333c8738da0c842a82d4 Mon Sep 17 00:00:00 2001 From: rfultz Date: Tue, 18 May 2021 11:42:42 -0400 Subject: [PATCH 04/12] Remove commented script tag --- fec/home/templates/home/home_page.html | 1 - 1 file changed, 1 deletion(-) diff --git a/fec/home/templates/home/home_page.html b/fec/home/templates/home/home_page.html index 7785c98463..40aad615ad 100644 --- a/fec/home/templates/home/home_page.html +++ b/fec/home/templates/home/home_page.html @@ -111,7 +111,6 @@

Commissioners

- - {% endblock %} From 0e18cd5d525405378acae4883204dc50c20c1266 Mon Sep 17 00:00:00 2001 From: rfultz Date: Tue, 18 May 2021 12:51:34 -0400 Subject: [PATCH 06/12] Add timer to remove query params for homepage --- fec/fec/static/js/pages/home.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/fec/fec/static/js/pages/home.js b/fec/fec/static/js/pages/home.js index 4c6dd3b278..2301dda0c9 100644 --- a/fec/fec/static/js/pages/home.js +++ b/fec/fec/static/js/pages/home.js @@ -8,10 +8,11 @@ require('../vendor/tablist').init(); // Home Page: Events and deadlines new homepageEvents.HomepageEvents(); -//remove competing/confusing querystrings on homepage -function cleanURI() { - const uri = window.location.toString(); +// We don't want the homepage to have any query parameters +function scrubURI() { + const uri = window.location.href.toString(); if (uri.indexOf('?') > 0) { + stopWatchingHref(); // Stop the automatic check after we've found one window.history.replaceState( {}, document.title, @@ -20,14 +21,27 @@ function cleanURI() { } } -cleanURI(); +// Start a timer to watch until we have a query parameter to remove +// (election-search.html will add them when it loads) +let hrefInterval = null; +function startWatchingHref() { + hrefInterval = window.setInterval(scrubURI, 100); +} +function stopWatchingHref() { + if (hrefInterval) { + window.clearInterval(hrefInterval); + hrefInterval = null; + } +} +startWatchingHref(); +// For any elements who want to add query parameters to the URL, remove 'em let inputs = document.querySelectorAll('#main input, #main select'); inputs.forEach(element => { - element.addEventListener('change', cleanURI); + element.addEventListener('change', scrubURI); }); -//handle Chrome inconsistency with History API +// let offices = document.querySelectorAll('.js-office'); offices.forEach(element => { element.value = 'S'; From 6fcdf9fdc5579caedf9bc73ce3dedb91207b5595 Mon Sep 17 00:00:00 2001 From: rfultz Date: Thu, 20 May 2021 10:53:51 -0400 Subject: [PATCH 07/12] Remove timer, remove params after everything is loaded --- fec/fec/static/js/pages/home.js | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/fec/fec/static/js/pages/home.js b/fec/fec/static/js/pages/home.js index 2301dda0c9..1cc405b8c4 100644 --- a/fec/fec/static/js/pages/home.js +++ b/fec/fec/static/js/pages/home.js @@ -9,10 +9,10 @@ require('../vendor/tablist').init(); new homepageEvents.HomepageEvents(); // We don't want the homepage to have any query parameters +// but election-search wants to add them function scrubURI() { const uri = window.location.href.toString(); if (uri.indexOf('?') > 0) { - stopWatchingHref(); // Stop the automatic check after we've found one window.history.replaceState( {}, document.title, @@ -20,20 +20,10 @@ function scrubURI() { ); } } - -// Start a timer to watch until we have a query parameter to remove -// (election-search.html will add them when it loads) -let hrefInterval = null; -function startWatchingHref() { - hrefInterval = window.setInterval(scrubURI, 100); -} -function stopWatchingHref() { - if (hrefInterval) { - window.clearInterval(hrefInterval); - hrefInterval = null; - } -} -startWatchingHref(); +// Let's remove any query params after the page and all resources are loaded +window.addEventListener('load', () => { + scrubURI(); +}); // For any elements who want to add query parameters to the URL, remove 'em let inputs = document.querySelectorAll('#main input, #main select'); From 46baeadcbc6e9c31f3be2295936ecc40f29ecc47 Mon Sep 17 00:00:00 2001 From: rfultz Date: Thu, 20 May 2021 16:07:17 -0400 Subject: [PATCH 08/12] Move the listeners into home.js --- fec/fec/static/js/pages/home.js | 47 ++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/fec/fec/static/js/pages/home.js b/fec/fec/static/js/pages/home.js index 1cc405b8c4..b61ac3023e 100644 --- a/fec/fec/static/js/pages/home.js +++ b/fec/fec/static/js/pages/home.js @@ -20,29 +20,32 @@ function scrubURI() { ); } } -// Let's remove any query params after the page and all resources are loaded +// After all the files are loaded and ready, window.addEventListener('load', () => { + // Let's remove any query params after the page scrubURI(); -}); - -// For any elements who want to add query parameters to the URL, remove 'em -let inputs = document.querySelectorAll('#main input, #main select'); -inputs.forEach(element => { - element.addEventListener('change', scrubURI); -}); - -// -let offices = document.querySelectorAll('.js-office'); -offices.forEach(element => { - element.value = 'S'; -}); - -let years = document.querySelectorAll('.js-election-year'); -years.forEach(element => { - element.value = '2022'; -}); -let toggles = document.querySelectorAll('.js-chart-toggle[value=receipts]'); -toggles.forEach(element => { - element.checked = true; + // and make sure no interactive elements add a query param + let inputs = document.querySelectorAll('#main input, #main select'); + inputs.forEach(element => { + element.addEventListener('change', scrubURI); + }); + + // Set the default office value + let offices = document.querySelectorAll('.js-office'); + offices.forEach(element => { + element.value = 'S'; + }); + + // Set the default election cycle + let years = document.querySelectorAll('.js-election-year'); + years.forEach(element => { + element.value = window.DEFAULT_ELECTION_YEAR; + }); + + // Set the chart toggle to receipts + let toggles = document.querySelectorAll('.js-chart-toggle[value=receipts]'); + toggles.forEach(element => { + element.checked = true; + }); }); From d992b0057ea29b0c4170945bedc6e9a09738e780 Mon Sep 17 00:00:00 2001 From: rfultz Date: Mon, 24 May 2021 10:35:46 -0400 Subject: [PATCH 09/12] Move scrubURI from home.js to home_page.html --- fec/fec/static/js/pages/home.js | 42 ------------------ fec/home/templates/home/home_page.html | 60 +++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/fec/fec/static/js/pages/home.js b/fec/fec/static/js/pages/home.js index b61ac3023e..73c0a51227 100644 --- a/fec/fec/static/js/pages/home.js +++ b/fec/fec/static/js/pages/home.js @@ -7,45 +7,3 @@ require('../vendor/tablist').init(); // Home Page: Events and deadlines new homepageEvents.HomepageEvents(); - -// We don't want the homepage to have any query parameters -// but election-search wants to add them -function scrubURI() { - const uri = window.location.href.toString(); - if (uri.indexOf('?') > 0) { - window.history.replaceState( - {}, - document.title, - window.location.href.split('?')[0] - ); - } -} -// After all the files are loaded and ready, -window.addEventListener('load', () => { - // Let's remove any query params after the page - scrubURI(); - - // and make sure no interactive elements add a query param - let inputs = document.querySelectorAll('#main input, #main select'); - inputs.forEach(element => { - element.addEventListener('change', scrubURI); - }); - - // Set the default office value - let offices = document.querySelectorAll('.js-office'); - offices.forEach(element => { - element.value = 'S'; - }); - - // Set the default election cycle - let years = document.querySelectorAll('.js-election-year'); - years.forEach(element => { - element.value = window.DEFAULT_ELECTION_YEAR; - }); - - // Set the chart toggle to receipts - let toggles = document.querySelectorAll('.js-chart-toggle[value=receipts]'); - toggles.forEach(element => { - element.checked = true; - }); -}); diff --git a/fec/home/templates/home/home_page.html b/fec/home/templates/home/home_page.html index 4165e5f50b..e639d502d2 100644 --- a/fec/home/templates/home/home_page.html +++ b/fec/home/templates/home/home_page.html @@ -18,7 +18,7 @@

Protecting the integrity of the campaign finance process - {% comment %} + {% comment %} Below is for featured icon+links in Wagtail html block only...for now. {% endcomment %} {% for block in self.body %} @@ -105,6 +105,7 @@

Commissioners

if (!canSkipPolyfills) { var pfScriptElem = document.createElement('script'); pfScriptElem.async = false; + pfScriptElem.defer = false; pfScriptElem.src = "{% asset_for_js 'polyfills.js' %}"; document.head.appendChild(pfScriptElem); } @@ -112,4 +113,61 @@

Commissioners

+ {% endblock %} From 1eefc42b359038af111b9b46265ad07e0c0266a7 Mon Sep 17 00:00:00 2001 From: John Carroll Date: Fri, 28 May 2021 11:09:47 -0400 Subject: [PATCH 10/12] add win.onload to make sure jquery cleanURI script works with defer on home page --- fec/home/templates/home/home_page.html | 71 ++++++-------------------- 1 file changed, 17 insertions(+), 54 deletions(-) diff --git a/fec/home/templates/home/home_page.html b/fec/home/templates/home/home_page.html index e639d502d2..7b108b2c47 100644 --- a/fec/home/templates/home/home_page.html +++ b/fec/home/templates/home/home_page.html @@ -114,60 +114,23 @@

Commissioners

{% endblock %} From 9ef5020b2e21fe9cd93648acbfd7c54061b68e0a Mon Sep 17 00:00:00 2001 From: rfultz Date: Tue, 1 Jun 2021 16:16:22 -0400 Subject: [PATCH 11/12] Fix errors when election-map is on homepage --- fec/fec/static/js/modules/election-map.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fec/fec/static/js/modules/election-map.js b/fec/fec/static/js/modules/election-map.js index e908d2a6d3..c36cb9c509 100644 --- a/fec/fec/static/js/modules/election-map.js +++ b/fec/fec/static/js/modules/election-map.js @@ -234,8 +234,9 @@ ElectionMap.prototype.handleReset = function(e) { */ ElectionMap.prototype.hide = function() { this.elm.setAttribute('aria-hidden', 'true'); - this.mapMessage.setAttribute('aria-hidden', 'false'); - this.mapApproxMessage.setAttribute('aria-hidden', 'true'); + if (this.mapMessage) this.mapMessage.setAttribute('aria-hidden', 'false'); + if (this.mapApproxMessage) + this.mapApproxMessage.setAttribute('aria-hidden', 'true'); }; /** @@ -243,8 +244,9 @@ ElectionMap.prototype.hide = function() { */ ElectionMap.prototype.show = function() { this.elm.setAttribute('aria-hidden', 'false'); - this.mapMessage.setAttribute('aria-hidden', 'true'); - this.mapApproxMessage.setAttribute('aria-hidden', 'false'); + if (this.mapMessage) this.mapMessage.setAttribute('aria-hidden', 'true'); + if (this.mapApproxMessage) + this.mapApproxMessage.setAttribute('aria-hidden', 'false'); }; module.exports = { From 594c179e1ebb0df3899a66c61ab63acf98654292 Mon Sep 17 00:00:00 2001 From: rfultz Date: Tue, 1 Jun 2021 16:17:00 -0400 Subject: [PATCH 12/12] Another attempt at a native solution --- fec/home/templates/home/home_page.html | 44 ++++++++++++++++---------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/fec/home/templates/home/home_page.html b/fec/home/templates/home/home_page.html index 7b108b2c47..2a05c7b599 100644 --- a/fec/home/templates/home/home_page.html +++ b/fec/home/templates/home/home_page.html @@ -114,23 +114,33 @@

Commissioners

{% endblock %}