Skip to content

Commit f31081e

Browse files
adamzapbmispelon
authored andcommitted
Check for elements in donate page JavaScript
This patch ensures that `addEventListener` will not be called on `null`, which generates a JavaScript error. This approach already exists in the file. Thankfully the error is inert since any page it will be thrown on doesn't need the remainder of the code in `djangoproject.js` to be run.
1 parent f382469 commit f31081e

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

djangoproject/static/js/djangoproject.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,29 @@ document.querySelectorAll('.btn-clipboard').forEach(function (el) {
185185
})();
186186

187187
// Update donate button text on fundraising page based on interval selection
188-
document
189-
.querySelector('#donate #id_interval')
190-
.addEventListener('change', function () {
188+
(function () {
189+
const el = document.querySelector('#donate #id_interval');
190+
191+
if (!el) {
192+
return;
193+
}
194+
195+
el.addEventListener('change', function () {
191196
const text = this.value === 'onetime' ? 'Donate' : `Donate ${this.value}`;
192197

193198
document.getElementById('donate-button').value = text;
194199
});
200+
})();
195201

196202
// Manage custom donation amount input on fundraising page
197-
document
198-
.querySelector('#donate #id_amount')
199-
.addEventListener('change', function () {
203+
(function () {
204+
const el = document.querySelector('#donate #id_amount');
205+
206+
if (!el) {
207+
return;
208+
}
209+
210+
el.addEventListener('change', function () {
200211
if (this.value !== 'custom') {
201212
return;
202213
}
@@ -216,3 +227,4 @@ document
216227
input_el.focus();
217228
input_el.value = '25';
218229
});
230+
})();

0 commit comments

Comments
 (0)