Skip to content

Commit

Permalink
Fix - Refactor attribute id to data selector to fix duplicate ids (#1…
Browse files Browse the repository at this point in the history
…1866)

* Refactor attribute id to data selector to fix duplicate ids

* lint:js

* prettier

---------

Co-authored-by: Ben Morse <[email protected]>
Co-authored-by: Mavis Ou <[email protected]>
  • Loading branch information
3 people committed Feb 29, 2024
1 parent e8de847 commit 8d3da0b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion maintenance/maintenance.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</div>
</div>
<div class="donate-btn-wrapper">
<a id="donate-header-btn" class="tw-btn-pop" href="?form=donate">Donate</a>
<a data-donate-header-button class="tw-btn-pop" href="?form=donate">Donate</a>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions maintenance/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -8258,12 +8258,12 @@ a.text-gray-dark:focus, a.text-gray-dark:hover {
#primary-nav-container .menu-container {
padding: 16px 0; } }

#primary-nav-container #donate-header-btn {
#primary-nav-container [data-donate-header-button] {
font-size: 17px;
line-height: 1.35294;
color: #000000;
font-weight: 700; }
#primary-nav-container #donate-header-btn:hover {
#primary-nav-container [data-donate-header-button]:hover {
color: #0d10bf;
cursor: pointer; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
{% endwith %}
{% routablepageurl home_page 'about-why-view' as about_why_url %}
<a class="{{ class }} {% bg_active_nav request.get_full_path about_why_url %}" href="{{ about_why_url }}">{% trans "About" %}</a>
<a id="donate-header-btn" class="{{ class }}" href="?form=donate&utm_medium=FMO&utm_source=PNI&utm_campaign=23-PNI&utm_content=header&c_id=7014x000000eQOD">{% trans "Donate" %}</a>
<a data-donate-header-button class="{{ class }}" href="?form=donate&utm_medium=FMO&utm_source=PNI&utm_campaign=23-PNI&utm_content=header&c_id=7014x000000eQOD">{% trans "Donate" %}</a>
{{ post }}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

{% block donate_and_newsletter %}
<div class="d-flex align-items-center">
<a id="donate-header-btn" class="primary-nav-special-link tw-heart-glyph tw-flex" href="?form=donate">{% trans "Donate" %}</a>
<a data-donate-header-button class="primary-nav-special-link tw-heart-glyph tw-flex" href="?form=donate">{% trans "Donate" %}</a>
{% if page.signup == None %}<button class="tw-btn-secondary btn-newsletter d-none d-lg-block ml-md-3">{% trans "Newsletter" %}</button>{% endif %}
</div>
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</div>
</div>
<div class="donate-btn-wrapper">
<a id="donate-header-btn" class="tw-btn-pop" href="?form=donate">Donate</a>
<a data-donate-header-button class="tw-btn-pop" href="?form=donate">Donate</a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion source/js/buyers-guide/analytics-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ReactGA, GoogleAnalytics } from "../common";
function getQuerySelectorEvents(pageTitle, productName) {
return {
// "site-wide" events
"#donate-header-btn": {
"[data-donate-header-button]": {
category: `buyersguide`,
action: `donate tap`,
label: `${pageTitle} donate header`,
Expand Down
20 changes: 12 additions & 8 deletions source/js/common/template-js-handles/header-donate-button.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { ReactGA } from "../../common";

/**
* Bind click handler to #donate-header-btn
* Bind click handler to data-donate-header-button
* ("Donate" button on primary nav)
*/
export default () => {
let donateHeaderBtn = document.getElementById(`donate-header-btn`);
if (donateHeaderBtn) {
donateHeaderBtn.addEventListener(`click`, () => {
ReactGA.event({
category: `donate`,
action: `donate button tap`,
label: `${document.title} header`,
const donateHeaderBtn = document.querySelectorAll(
"[data-donate-header-button]"
);
if (donateHeaderBtn.length > 0) {
donateHeaderBtn.forEach((element) => {
element.addEventListener(`click`, () => {
ReactGA.event({
category: `donate`,
action: `donate button tap`,
label: `${document.title} header`,
});
});
});
}
Expand Down

0 comments on commit 8d3da0b

Please sign in to comment.