Skip to content

Commit 45c6a62

Browse files
adamzappauloxnet
authored andcommitted
Refactor fundraising-index.js
- Stopped using jQuery - Moved refactored code to `djangoproject.js` - Attached only one event handler per `select` element - Simplified custom amount input focussing
1 parent aecd080 commit 45c6a62

File tree

3 files changed

+29
-50
lines changed

3 files changed

+29
-50
lines changed

djangoproject/static/js/djangoproject.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,32 @@ document.querySelectorAll('.btn-clipboard').forEach(function (el) {
183183

184184
window.addEventListener('hashchange', scroll_to_hash);
185185
})();
186+
187+
// Update donate button text on fundraising page based on interval selection
188+
document.getElementById('id_interval').addEventListener('change', function () {
189+
const text = this.value === 'onetime' ? 'Donate' : `Donate ${this.value}`;
190+
191+
document.getElementById('donate-button').value = text;
192+
});
193+
194+
// Manage custom donation amount input on fundraising page
195+
document.getElementById('id_amount').addEventListener('change', function () {
196+
if (this.value !== 'custom') {
197+
return;
198+
}
199+
200+
const input_el = document.createElement('input');
201+
202+
input_el.setAttribute('type', 'number');
203+
input_el.setAttribute('name', 'amount');
204+
205+
const custom_donation_el = document.querySelector('.custom-donation');
206+
207+
custom_donation_el.appendChild(input_el);
208+
custom_donation_el.style.display = 'block';
209+
210+
this.remove();
211+
212+
input_el.focus();
213+
input_el.value = '25';
214+
});

djangoproject/static/js/main.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ define(function () {
1616
if (hasClass('fundraising-heart')) {
1717
mods.push('mod/fundraising-heart');
1818
}
19-
//fundraising donation form
20-
if (hasClass('fundraising-index')) {
21-
mods.push('mod/fundraising-index');
22-
}
2319

2420
if (hasClass('dashboard-index')) {
2521
mods.push('dashboard/index');

djangoproject/static/js/mod/fundraising-index.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)