Skip to content

Commit 5574b1b

Browse files
committed
Initial pass at styling the donation form
This includes some JS to manipulate the form elements. css will be added via the customizer for now. The added JS will likely load too early, but at least it's there to be called.
1 parent 1f953f7 commit 5574b1b

6 files changed

Lines changed: 80 additions & 4 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array(), 'version' => '1a77530059955fb6eaa5');
1+
<?php return array('dependencies' => array(), 'version' => 'ee5da5bfafd11f296b5b');

themes/osi/assets/js/build/theme.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('jquery'), 'version' => 'e025ea38feca3ffa8690');
1+
<?php return array('dependencies' => array('jquery'), 'version' => '9a08034ec8a2505dbde0');

themes/osi/assets/js/build/vendor.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
document.addEventListener('DOMContentLoaded', function() {
2+
const form = document.getElementById('remoteForm-form-ContributionPage7');
3+
const firstName = document.getElementById('first_name').closest('.form-group');
4+
const lastName = document.getElementById('last_name').closest('.form-group');
5+
const email = document.getElementById('email-primary').closest('.form-group');
6+
const creditCardNumber = document.getElementById('credit_card_number').closest('.form-group');
7+
const cvv = document.getElementById('cvv2').closest('.form-group');
8+
const expMonth = document.getElementById('credit_card_exp_date_M').closest('.form-group');
9+
const expYear = document.getElementById('credit_card_exp_date_Y').closest('.form-group');
10+
const submitButton = document.getElementById('remoteform-submit');
11+
const amountSection = document.querySelector('label.rf-label').parentNode;
12+
const radioInputs = document.querySelectorAll('.form-check-input:not([value="54"])'); // Exclude the OSI membership checkbox
13+
14+
// Create new div for grid layout and set it up for CSS Grid
15+
const gridContainer = document.createElement('div');
16+
gridContainer.className = 'form-check-grid';
17+
amountSection.parentNode.insertBefore(gridContainer, amountSection);
18+
19+
// Move only the radio buttons into the grid container
20+
radioInputs.forEach(radio => {
21+
gridContainer.appendChild(radio.parentNode);
22+
});
23+
24+
// Create new div and append input fields
25+
const newDiv = document.createElement('div');
26+
newDiv.style.display = 'none'; // Initially hidden
27+
newDiv.append(firstName, lastName, email, creditCardNumber, cvv, expMonth, expYear, submitButton);
28+
form.insertBefore(newDiv, amountSection.nextSibling);
29+
30+
// Modify amounts display
31+
document.querySelectorAll('.form-check-label').forEach(label => {
32+
label.textContent = label.textContent.replace(/ - \$[\d\.]+/, '');
33+
});
34+
35+
// Change last radio to checkbox
36+
const memberRadio = document.querySelector('input[value="54"]');
37+
if (memberRadio) { // Check if element exists before changing
38+
memberRadio.type = 'checkbox';
39+
memberRadio.closest('.form-check').querySelector('label').textContent = 'Yes, I want to become an OSI member!';
40+
newDiv.prepend(memberRadio.closest('.form-check'));
41+
}
42+
43+
// Handle button click interactions
44+
radioInputs.forEach(radio => {
45+
const label = radio.nextElementSibling; // Assuming label immediately follows input
46+
label.addEventListener('click', function() {
47+
// Uncheck all other radios
48+
radioInputs.forEach(otherRadio => {
49+
if (otherRadio !== radio) {
50+
otherRadio.checked = false;
51+
}
52+
});
53+
// Check this radio
54+
radio.checked = true;
55+
// Manually trigger the 'change' event if necessary
56+
radio.dispatchEvent(new Event('change'));
57+
});
58+
});
59+
60+
// Add Donate button
61+
const donateButton = document.createElement('button');
62+
donateButton.textContent = 'Contribute';
63+
donateButton.type = 'button';
64+
donateButton.addEventListener('click', () => {
65+
if (newDiv.style.display === 'none') {
66+
newDiv.style.display = 'block';
67+
donateButton.textContent = 'Cancel';
68+
newDiv.style.transition = 'all 0.3s ease';
69+
} else {
70+
newDiv.style.display = 'none';
71+
donateButton.textContent = 'Contribute';
72+
}
73+
});
74+
form.appendChild(donateButton);
75+
});

themes/osi/assets/js/src/theme/theme.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ import './sidebar-nav.js';
99
import './skip-link-focus-fix.js';
1010
import './search-toggle.js';
1111
import './license-header-wrap.js';
12+
import './donation-form.js';

0 commit comments

Comments
 (0)