Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions packages/scripts/dist/remember-me.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { EnForm, RememberMeEvents } from "./events";
export declare class RememberMe {
_form: EnForm;
_events: RememberMeEvents;
private _frequency;
private remoteUrl;
private cookieName;
private fieldNames;
Expand All @@ -15,7 +14,6 @@ export declare class RememberMe {
private fieldDonationAmountRadioName;
private fieldDonationAmountOtherName;
private fieldDonationRecurrPayRadioName;
private fieldDonationRecurrFreqRadioName;
private fieldDonationAmountOtherCheckboxID;
private fieldOptInSelectorTarget;
private fieldOptInSelectorTargetLocation;
Expand All @@ -31,7 +29,6 @@ export declare class RememberMe {
fieldDonationAmountRadioName?: string;
fieldDonationAmountOtherName?: string;
fieldDonationRecurrPayRadioName?: string;
fieldDonationRecurrFreqRadioName?: string;
fieldDonationAmountOtherCheckboxID?: string;
fieldOptInSelectorTarget?: string;
fieldOptInSelectorTargetLocation?: string;
Expand Down Expand Up @@ -104,25 +101,5 @@ export declare class RememberMe {
* @param overwrite - A boolean indicating whether to overwrite the existing value of the fields. Defaults to false.
*/
private writeFields;
/**
* SwapAmounts replaces the donationAmt radio DOM nodes ~1 second after page
* load (triggered by DonationFrequency.load() setTimeout). When that happens
* the selection the RememberMe just wrote gets wiped out.
*
* This method subscribes to the first onFrequencyChange event and, after a
* short delay to let SwapAmounts finish its DOM update, re-applies only the
* donation amount. It unsubscribes immediately so it only fires once.
*
* To avoid overwriting a manual donor interaction, the handler checks
* whether the current amount selection is empty/wiped (as SwapAmounts does)
* OR still matches what writeFields originally set. If the donor already
* picked a different amount, we skip re-application.
*/
private reapplyDonationAmtAfterSwap;
/**
* Returns the currently selected donation amount value, or null if nothing
* is selected. Checks both predefined radio buttons and the "Other" text input.
*/
private getCurrentSelectedAmount;
private isJson;
}
124 changes: 7 additions & 117 deletions packages/scripts/dist/remember-me.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
import * as cookie from "./cookie";
import { EnForm, RememberMeEvents, DonationFrequency } from "./events";
import { EnForm, RememberMeEvents } from "./events";
import { ENGrid } from "./engrid";
const tippy = require("tippy.js").default;
// localStorage key used to cache the per-device AES-GCM encryption key.
Expand All @@ -18,7 +18,6 @@ export class RememberMe {
constructor(options) {
this._form = EnForm.getInstance();
this._events = RememberMeEvents.getInstance();
this._frequency = DonationFrequency.getInstance();
this.iframe = null;
this.encryptData = options.encryptData ? options.encryptData : false;
this.hide = options.hide ? options.hide : false;
Expand All @@ -41,10 +40,6 @@ export class RememberMe {
options.fieldDonationRecurrPayRadioName
? options.fieldDonationRecurrPayRadioName
: "transaction.recurrpay";
this.fieldDonationRecurrFreqRadioName =
options.fieldDonationRecurrFreqRadioName
? options.fieldDonationRecurrFreqRadioName
: "transaction.recurrfreq";
this.fieldDonationAmountOtherCheckboxID =
options.fieldDonationAmountOtherCheckboxID
? options.fieldDonationAmountOtherCheckboxID
Expand Down Expand Up @@ -106,7 +101,6 @@ export class RememberMe {
}
else {
this.insertClearRememberMeLink();
this.reapplyDonationAmtAfterSwap();
}
}
});
Expand All @@ -126,9 +120,6 @@ export class RememberMe {
this.insertClearRememberMeLink();
}
this.writeFields();
if (hasFieldData) {
this.reapplyDonationAmtAfterSwap();
}
this._form.onSubmit.subscribe(() => {
if (this.rememberMeOptIn) {
this.readFields();
Expand All @@ -147,9 +138,6 @@ export class RememberMe {
this.insertClearRememberMeLink();
}
this.writeFields();
if (hasFieldData) {
this.reapplyDonationAmtAfterSwap();
}
this._form.onSubmit.subscribe(() => {
if (this.rememberMeOptIn) {
this.readFields();
Expand Down Expand Up @@ -483,17 +471,6 @@ export class RememberMe {
if (type === "radio" || type === "checkbox") {
field = document.querySelector(fieldSelector + ":checked");
}
// When the donation amount radio is set to "Other", save the actual
// custom value from the .other text input instead of "Other".
if (this.fieldNames[i] === this.fieldDonationAmountRadioName &&
field &&
field.value.toLowerCase() === "other") {
const otherField = document.querySelector("input[name='" + this.fieldDonationAmountOtherName + "']");
if (otherField && otherField.value) {
this.fieldData[this.fieldNames[i]] = encodeURIComponent(otherField.value);
continue;
}
}
this.fieldData[this.fieldNames[i]] = encodeURIComponent(field.value);
}
else if (field.tagName === "SELECT") {
Expand Down Expand Up @@ -577,36 +554,17 @@ export class RememberMe {
field.click();
}
}
else if (this.fieldNames[i] === this.fieldDonationRecurrFreqRadioName) {
// recurrfreq is a radio group — find the specific radio with the saved value and click it
const savedValue = this.fieldData[this.fieldNames[i]];
if (savedValue) {
const freqRadio = document.querySelector(fieldSelector + "[value='" + CSS.escape(savedValue) + "']");
if (freqRadio) {
freqRadio.click();
}
}
}
else if (this.fieldDonationAmountRadioName === this.fieldNames[i]) {
const savedAmt = this.fieldData[this.fieldNames[i]];
const escapedAmt = CSS.escape(savedAmt);
field = document.querySelector(fieldSelector + "[value='" + escapedAmt + "']");
field = document.querySelector(fieldSelector +
"[value='" +
this.fieldData[this.fieldNames[i]] +
"']");
if (field) {
// Saved value matches a predefined radio option — just click it
field.click();
}
else {
// No matching radio: the value is a custom amount.
// Click the "Other" radio first so the text input becomes active,
// then fill in the numeric value.
const otherRadio = document.querySelector(fieldSelector + "[value='Other'], " +
fieldSelector + "[value='other'], " +
fieldSelector + "[value='OTHER']");
if (otherRadio) {
otherRadio.click();
}
const otherField = document.querySelector("input[name='" + this.fieldDonationAmountOtherName + "']");
this.setFieldValue(otherField, savedAmt, true);
field = document.querySelector("input[name='" + this.fieldDonationAmountOtherName + "']");
this.setFieldValue(field, this.fieldData[this.fieldNames[i]], true);
}
}
else {
Expand All @@ -619,74 +577,6 @@ export class RememberMe {
}
}
}
/**
* SwapAmounts replaces the donationAmt radio DOM nodes ~1 second after page
* load (triggered by DonationFrequency.load() setTimeout). When that happens
* the selection the RememberMe just wrote gets wiped out.
*
* This method subscribes to the first onFrequencyChange event and, after a
* short delay to let SwapAmounts finish its DOM update, re-applies only the
* donation amount. It unsubscribes immediately so it only fires once.
*
* To avoid overwriting a manual donor interaction, the handler checks
* whether the current amount selection is empty/wiped (as SwapAmounts does)
* OR still matches what writeFields originally set. If the donor already
* picked a different amount, we skip re-application.
*/
reapplyDonationAmtAfterSwap() {
const savedAmt = this.fieldData[this.fieldDonationAmountRadioName];
if (!savedAmt)
return;
// Capture the amount that writeFields just set so we can detect manual changes
const amountAtRegistration = this.getCurrentSelectedAmount();
const handler = () => {
// SwapAmounts calls _amount.load() after swapList — give it a tick to settle
window.setTimeout(() => {
const currentAmt = this.getCurrentSelectedAmount();
// Only re-apply if the selection is now empty (DOM was swapped out)
// or still matches what we originally wrote. If the donor manually
// selected a different amount, respect their choice.
const selectionWiped = currentAmt === null || currentAmt === "";
const selectionUnchanged = currentAmt === amountAtRegistration;
if (!selectionWiped && !selectionUnchanged) {
return;
}
const fieldSelector = "[name='" + this.fieldDonationAmountRadioName + "']";
const escapedAmt = CSS.escape(savedAmt);
let radio = document.querySelector(fieldSelector + "[value='" + escapedAmt + "']");
if (radio) {
radio.click();
}
else {
// Custom amount: click "Other" radio then fill the text input
const otherRadio = document.querySelector(fieldSelector + "[value='Other'], " +
fieldSelector + "[value='other'], " +
fieldSelector + "[value='OTHER']");
if (otherRadio)
otherRadio.click();
const otherField = document.querySelector("input[name='" + this.fieldDonationAmountOtherName + "']");
this.setFieldValue(otherField, savedAmt, true);
}
}, 200);
};
// Subscribe once: fires on the first frequency change then auto-unsubscribes
this._frequency.onFrequencyChange.one(handler);
}
/**
* Returns the currently selected donation amount value, or null if nothing
* is selected. Checks both predefined radio buttons and the "Other" text input.
*/
getCurrentSelectedAmount() {
const fieldSelector = "[name='" + this.fieldDonationAmountRadioName + "']";
const checkedRadio = document.querySelector(fieldSelector + ":checked");
if (!checkedRadio)
return null;
if (checkedRadio.value.toLowerCase() === "other") {
const otherField = document.querySelector("input[name='" + this.fieldDonationAmountOtherName + "']");
return otherField ? otherField.value : null;
}
return checkedRadio.value;
}
isJson(str) {
try {
JSON.parse(str);
Expand Down
Loading
Loading