@4site/engrid-scripts 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.js +226 -0
- package/LICENSE +24 -0
- package/dist/a11y.d.ts +6 -0
- package/dist/a11y.js +46 -0
- package/dist/add-name-to-message.d.ts +5 -0
- package/dist/add-name-to-message.js +49 -0
- package/dist/advocacy.d.ts +7 -0
- package/dist/advocacy.js +34 -0
- package/dist/amount-label.d.ts +6 -0
- package/dist/amount-label.js +29 -0
- package/dist/app.d.ts +19 -0
- package/dist/app.js +340 -0
- package/dist/apple-pay.d.ts +13 -0
- package/dist/apple-pay.js +169 -0
- package/dist/auto-country-select.d.ts +10 -0
- package/dist/auto-country-select.js +63 -0
- package/dist/auto-year.d.ts +7 -0
- package/dist/auto-year.js +35 -0
- package/dist/autocomplete.d.ts +5 -0
- package/dist/autocomplete.js +38 -0
- package/dist/autosubmit.d.ts +5 -0
- package/dist/autosubmit.js +14 -0
- package/dist/branding-html.d.ts +14 -0
- package/dist/branding-html.js +70 -0
- package/dist/capitalize-fields.d.ts +7 -0
- package/dist/capitalize-fields.js +22 -0
- package/dist/click-to-expand.d.ts +4 -0
- package/dist/click-to-expand.js +39 -0
- package/dist/cookie.d.ts +53 -0
- package/dist/cookie.js +76 -0
- package/dist/country-disable.d.ts +4 -0
- package/dist/country-disable.js +22 -0
- package/dist/country-redirect.d.ts +7 -0
- package/dist/country-redirect.js +61 -0
- package/dist/custom-currency.d.ts +9 -0
- package/dist/custom-currency.js +112 -0
- package/dist/data-attributes.d.ts +5 -0
- package/dist/data-attributes.js +122 -0
- package/dist/data-hide.d.ts +15 -0
- package/dist/data-hide.js +66 -0
- package/dist/data-layer.d.ts +23 -0
- package/dist/data-layer.js +312 -0
- package/dist/data-replace.d.ts +26 -0
- package/dist/data-replace.js +76 -0
- package/dist/debug-hidden-fields.d.ts +4 -0
- package/dist/debug-hidden-fields.js +42 -0
- package/dist/debug-panel.d.ts +27 -0
- package/dist/debug-panel.js +508 -0
- package/dist/deprecated.d.ts +5 -0
- package/dist/deprecated.js +40 -0
- package/dist/digital-wallets.d.ts +8 -0
- package/dist/digital-wallets.js +143 -0
- package/dist/ecard-to-target.d.ts +11 -0
- package/dist/ecard-to-target.js +73 -0
- package/dist/ecard.d.ts +8 -0
- package/dist/ecard.js +61 -0
- package/dist/embedded-ecard.d.ts +18 -0
- package/dist/embedded-ecard.js +267 -0
- package/dist/en-validators.d.ts +10 -0
- package/dist/en-validators.js +89 -0
- package/dist/engrid.d.ts +49 -0
- package/dist/engrid.js +547 -0
- package/dist/event-tickets.d.ts +3 -0
- package/dist/event-tickets.js +24 -0
- package/dist/events/country.d.ts +12 -0
- package/dist/events/country.js +42 -0
- package/dist/events/donation-amount.d.ts +16 -0
- package/dist/events/donation-amount.js +119 -0
- package/dist/events/donation-frequency.d.ts +17 -0
- package/dist/events/donation-frequency.js +115 -0
- package/dist/events/en-form.d.ts +20 -0
- package/dist/events/en-form.js +52 -0
- package/dist/events/index.d.ts +6 -0
- package/dist/events/index.js +6 -0
- package/dist/events/processing-fees.d.ts +20 -0
- package/dist/events/processing-fees.js +92 -0
- package/dist/events/remember-me-events.d.ts +18 -0
- package/dist/events/remember-me-events.js +36 -0
- package/dist/exit-intent-lightbox.d.ts +14 -0
- package/dist/exit-intent-lightbox.js +145 -0
- package/dist/expand-region-name.d.ts +7 -0
- package/dist/expand-region-name.js +44 -0
- package/dist/fast-form-fill.d.ts +8 -0
- package/dist/fast-form-fill.js +75 -0
- package/dist/freshaddress.d.ts +18 -0
- package/dist/freshaddress.js +204 -0
- package/dist/give-by-select.d.ts +9 -0
- package/dist/give-by-select.js +82 -0
- package/dist/iframe.d.ts +16 -0
- package/dist/iframe.js +217 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.js +84 -0
- package/dist/input-has-value-and-focus.d.ts +9 -0
- package/dist/input-has-value-and-focus.js +50 -0
- package/dist/input-placeholders.d.ts +7 -0
- package/dist/input-placeholders.js +82 -0
- package/dist/interfaces/ecard-to-target-options.d.ts +9 -0
- package/dist/interfaces/ecard-to-target-options.js +8 -0
- package/dist/interfaces/embedded-ecard-options.d.ts +8 -0
- package/dist/interfaces/embedded-ecard-options.js +7 -0
- package/dist/interfaces/exit-intent-options.d.ts +13 -0
- package/dist/interfaces/exit-intent-options.js +13 -0
- package/dist/interfaces/options.d.ts +147 -0
- package/dist/interfaces/options.js +50 -0
- package/dist/interfaces/translate-options.d.ts +7 -0
- package/dist/interfaces/translate-options.js +42 -0
- package/dist/interfaces/upsell-options.d.ts +24 -0
- package/dist/interfaces/upsell-options.js +33 -0
- package/dist/live-currency.d.ts +15 -0
- package/dist/live-currency.js +140 -0
- package/dist/live-frequency.d.ts +13 -0
- package/dist/live-frequency.js +109 -0
- package/dist/live-variables.d.ts +21 -0
- package/dist/live-variables.js +147 -0
- package/dist/loader.d.ts +10 -0
- package/dist/loader.js +175 -0
- package/dist/logger.d.ts +16 -0
- package/dist/logger.js +84 -0
- package/dist/media-attribution.d.ts +4 -0
- package/dist/media-attribution.js +66 -0
- package/dist/menu.d.ts +0 -0
- package/dist/menu.js +1 -0
- package/dist/min-max-amount.d.ts +13 -0
- package/dist/min-max-amount.js +71 -0
- package/dist/mobile-cta.d.ts +9 -0
- package/dist/mobile-cta.js +71 -0
- package/dist/modal.d.ts +19 -0
- package/dist/modal.js +129 -0
- package/dist/neverbounce.d.ts +23 -0
- package/dist/neverbounce.js +244 -0
- package/dist/other-amount.d.ts +6 -0
- package/dist/other-amount.js +70 -0
- package/dist/page-background.d.ts +7 -0
- package/dist/page-background.js +55 -0
- package/dist/plaid.d.ts +6 -0
- package/dist/plaid.js +49 -0
- package/dist/postal-code-validator.d.ts +20 -0
- package/dist/postal-code-validator.js +118 -0
- package/dist/premium-gift.d.ts +10 -0
- package/dist/premium-gift.js +115 -0
- package/dist/progress-bar.d.ts +3 -0
- package/dist/progress-bar.js +40 -0
- package/dist/remember-me.d.ts +61 -0
- package/dist/remember-me.js +358 -0
- package/dist/required-if-visible.d.ts +8 -0
- package/dist/required-if-visible.js +60 -0
- package/dist/set-attr.d.ts +4 -0
- package/dist/set-attr.js +31 -0
- package/dist/set-recurr-freq.d.ts +7 -0
- package/dist/set-recurr-freq.js +70 -0
- package/dist/show-hide-radio-checkboxes.d.ts +13 -0
- package/dist/show-hide-radio-checkboxes.js +161 -0
- package/dist/show-if-amount.d.ts +15 -0
- package/dist/show-if-amount.js +117 -0
- package/dist/show-if-present.d.ts +7 -0
- package/dist/show-if-present.js +79 -0
- package/dist/skip-link.d.ts +4 -0
- package/dist/skip-link.js +36 -0
- package/dist/src-defer.d.ts +6 -0
- package/dist/src-defer.js +70 -0
- package/dist/supporter-hub.d.ts +9 -0
- package/dist/supporter-hub.js +75 -0
- package/dist/swap-amounts.d.ts +45 -0
- package/dist/swap-amounts.js +81 -0
- package/dist/thank-you-page-conditional-content.d.ts +8 -0
- package/dist/thank-you-page-conditional-content.js +46 -0
- package/dist/ticker.d.ts +11 -0
- package/dist/ticker.js +66 -0
- package/dist/tidycontact.d.ts +46 -0
- package/dist/tidycontact.js +1202 -0
- package/dist/translate-fields.d.ts +12 -0
- package/dist/translate-fields.js +548 -0
- package/dist/universal-opt-in.d.ts +7 -0
- package/dist/universal-opt-in.js +91 -0
- package/dist/upsell-lightbox.d.ts +31 -0
- package/dist/upsell-lightbox.js +363 -0
- package/dist/url-params-to-body-attrs.d.ts +5 -0
- package/dist/url-params-to-body-attrs.js +14 -0
- package/dist/url-to-form.d.ts +7 -0
- package/dist/url-to-form.js +32 -0
- package/dist/us-only-form.d.ts +4 -0
- package/dist/us-only-form.js +30 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/dist/vgs.d.ts +16 -0
- package/dist/vgs.js +250 -0
- package/dist/welcome-back.d.ts +10 -0
- package/dist/welcome-back.js +112 -0
- package/package.json +32 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { DonationAmount, EnForm, DonationFrequency, ProcessingFees, } from "./events";
|
|
2
|
+
import { ENGrid, OptionsDefaults } from ".";
|
|
3
|
+
export class LiveVariables {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
var _a;
|
|
6
|
+
this._amount = DonationAmount.getInstance();
|
|
7
|
+
this._fees = ProcessingFees.getInstance();
|
|
8
|
+
this._frequency = DonationFrequency.getInstance();
|
|
9
|
+
this._form = EnForm.getInstance();
|
|
10
|
+
this.multiplier = 1 / 12;
|
|
11
|
+
this.options = Object.assign(Object.assign({}, OptionsDefaults), options);
|
|
12
|
+
this.submitLabel =
|
|
13
|
+
((_a = document.querySelector(".en__submit button")) === null || _a === void 0 ? void 0 : _a.innerHTML) || "Donate";
|
|
14
|
+
this._amount.onAmountChange.subscribe(() => this.changeSubmitButton());
|
|
15
|
+
this._amount.onAmountChange.subscribe(() => this.changeLiveAmount());
|
|
16
|
+
this._amount.onAmountChange.subscribe(() => this.changeLiveUpsellAmount());
|
|
17
|
+
this._fees.onFeeChange.subscribe(() => this.changeLiveAmount());
|
|
18
|
+
this._fees.onFeeChange.subscribe(() => this.changeLiveUpsellAmount());
|
|
19
|
+
this._fees.onFeeChange.subscribe(() => this.changeSubmitButton());
|
|
20
|
+
this._frequency.onFrequencyChange.subscribe(() => this.changeLiveFrequency());
|
|
21
|
+
this._frequency.onFrequencyChange.subscribe(() => this.changeRecurrency());
|
|
22
|
+
this._frequency.onFrequencyChange.subscribe(() => this.changeSubmitButton());
|
|
23
|
+
this._form.onSubmit.subscribe(() => {
|
|
24
|
+
if (ENGrid.getPageType() !== "SUPPORTERHUB")
|
|
25
|
+
ENGrid.disableSubmit("Processing...");
|
|
26
|
+
});
|
|
27
|
+
this._form.onError.subscribe(() => ENGrid.enableSubmit());
|
|
28
|
+
// Watch the monthly-upsell links
|
|
29
|
+
document.addEventListener("click", (e) => {
|
|
30
|
+
const element = e.target;
|
|
31
|
+
if (element) {
|
|
32
|
+
if (element.classList.contains("monthly-upsell")) {
|
|
33
|
+
this.upsold(e);
|
|
34
|
+
}
|
|
35
|
+
else if (element.classList.contains("form-submit")) {
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
this._form.submitForm();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getAmountTxt(amount = 0) {
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
|
+
const symbol = (_a = ENGrid.getCurrencySymbol()) !== null && _a !== void 0 ? _a : "$";
|
|
45
|
+
const dec_separator = (_b = this.options.DecimalSeparator) !== null && _b !== void 0 ? _b : ".";
|
|
46
|
+
const thousands_separator = (_c = this.options.ThousandsSeparator) !== null && _c !== void 0 ? _c : "";
|
|
47
|
+
const dec_places = amount % 1 == 0 ? 0 : (_d = this.options.DecimalPlaces) !== null && _d !== void 0 ? _d : 2;
|
|
48
|
+
const amountTxt = ENGrid.formatNumber(amount, dec_places, dec_separator, thousands_separator);
|
|
49
|
+
return amount > 0
|
|
50
|
+
? (`<span class="live-variable-currency">${symbol}</span><span class="live-variable-amount">${amountTxt}</span>`)
|
|
51
|
+
: "";
|
|
52
|
+
}
|
|
53
|
+
getUpsellAmountTxt(amount = 0) {
|
|
54
|
+
var _a, _b, _c, _d;
|
|
55
|
+
const symbol = (_a = ENGrid.getCurrencySymbol()) !== null && _a !== void 0 ? _a : "$";
|
|
56
|
+
const dec_separator = (_b = this.options.DecimalSeparator) !== null && _b !== void 0 ? _b : ".";
|
|
57
|
+
const thousands_separator = (_c = this.options.ThousandsSeparator) !== null && _c !== void 0 ? _c : "";
|
|
58
|
+
const dec_places = amount % 1 == 0 ? 0 : (_d = this.options.DecimalPlaces) !== null && _d !== void 0 ? _d : 2;
|
|
59
|
+
const amountTxt = ENGrid.formatNumber(Math.ceil(amount / 5) * 5, dec_places, dec_separator, thousands_separator);
|
|
60
|
+
return amount > 0 ? symbol + amountTxt : "";
|
|
61
|
+
}
|
|
62
|
+
getUpsellAmountRaw(amount = 0) {
|
|
63
|
+
const amountRaw = Math.ceil(amount / 5) * 5;
|
|
64
|
+
return amount > 0 ? amountRaw.toString() : "";
|
|
65
|
+
}
|
|
66
|
+
changeSubmitButton() {
|
|
67
|
+
const submit = document.querySelector(".en__submit button");
|
|
68
|
+
const amount = this.getAmountTxt(this._amount.amount + this._fees.fee);
|
|
69
|
+
const frequency = this._frequency.frequency == "onetime"
|
|
70
|
+
? ""
|
|
71
|
+
: this._frequency.frequency == "annual"
|
|
72
|
+
? "annually"
|
|
73
|
+
: this._frequency.frequency;
|
|
74
|
+
let label = this.submitLabel;
|
|
75
|
+
if (amount) {
|
|
76
|
+
label = label.replace("$AMOUNT", amount);
|
|
77
|
+
label = label.replace("$FREQUENCY", `<span class="live-variable-frequency">${frequency}</span>`);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
label = label.replace("$AMOUNT", "");
|
|
81
|
+
label = label.replace("$FREQUENCY", "");
|
|
82
|
+
}
|
|
83
|
+
if (submit && label) {
|
|
84
|
+
submit.innerHTML = label;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
changeLiveAmount() {
|
|
88
|
+
const value = this._amount.amount + this._fees.fee;
|
|
89
|
+
const live_amount = document.querySelectorAll(".live-giving-amount");
|
|
90
|
+
live_amount.forEach((elem) => (elem.innerHTML = this.getAmountTxt(value)));
|
|
91
|
+
}
|
|
92
|
+
changeLiveUpsellAmount() {
|
|
93
|
+
const value = (this._amount.amount + this._fees.fee) * this.multiplier;
|
|
94
|
+
const live_upsell_amount = document.querySelectorAll(".live-giving-upsell-amount");
|
|
95
|
+
live_upsell_amount.forEach((elem) => (elem.innerHTML = this.getUpsellAmountTxt(value)));
|
|
96
|
+
const live_upsell_amount_raw = document.querySelectorAll(".live-giving-upsell-amount-raw");
|
|
97
|
+
live_upsell_amount_raw.forEach((elem) => (elem.innerHTML = this.getUpsellAmountRaw(value)));
|
|
98
|
+
}
|
|
99
|
+
changeLiveFrequency() {
|
|
100
|
+
const live_frequency = document.querySelectorAll(".live-giving-frequency");
|
|
101
|
+
live_frequency.forEach((elem) => (elem.innerHTML =
|
|
102
|
+
this._frequency.frequency == "onetime"
|
|
103
|
+
? ""
|
|
104
|
+
: this._frequency.frequency));
|
|
105
|
+
}
|
|
106
|
+
changeRecurrency() {
|
|
107
|
+
const recurrpay = document.querySelector("[name='transaction.recurrpay']");
|
|
108
|
+
if (recurrpay && recurrpay.type != "radio") {
|
|
109
|
+
recurrpay.value = this._frequency.frequency == "onetime" ? "N" : "Y";
|
|
110
|
+
this._frequency.recurring = recurrpay.value;
|
|
111
|
+
if (ENGrid.getOption("Debug"))
|
|
112
|
+
console.log("Recurpay Changed!");
|
|
113
|
+
// Trigger the onChange event for the field
|
|
114
|
+
const event = new Event("change", { bubbles: true });
|
|
115
|
+
recurrpay.dispatchEvent(event);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Watch for a clicks on monthly-upsell link
|
|
119
|
+
upsold(e) {
|
|
120
|
+
// Find and select monthly giving
|
|
121
|
+
const enFieldRecurrpay = document.querySelector(".en__field--recurrpay input[value='Y']");
|
|
122
|
+
if (enFieldRecurrpay) {
|
|
123
|
+
enFieldRecurrpay.checked = true;
|
|
124
|
+
}
|
|
125
|
+
// Find the hidden radio select that needs to be selected when entering an "Other" amount
|
|
126
|
+
const enFieldOtherAmountRadio = document.querySelector(".en__field--donationAmt input[value='other']");
|
|
127
|
+
if (enFieldOtherAmountRadio) {
|
|
128
|
+
enFieldOtherAmountRadio.checked = true;
|
|
129
|
+
}
|
|
130
|
+
// Enter the other amount and remove the "en__field__item--hidden" class from the input's parent
|
|
131
|
+
const enFieldOtherAmount = document.querySelector("input[name='transaction.donationAmt.other']");
|
|
132
|
+
if (enFieldOtherAmount) {
|
|
133
|
+
enFieldOtherAmount.value = this.getUpsellAmountRaw(this._amount.amount * this.multiplier);
|
|
134
|
+
this._amount.load();
|
|
135
|
+
this._frequency.load();
|
|
136
|
+
if (enFieldOtherAmount.parentElement) {
|
|
137
|
+
enFieldOtherAmount.parentElement.classList.remove("en__field__item--hidden");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const target = e.target;
|
|
141
|
+
if (target && target.classList.contains("form-submit")) {
|
|
142
|
+
e.preventDefault();
|
|
143
|
+
// Form submit
|
|
144
|
+
this._form.submitForm();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
package/dist/loader.d.ts
ADDED
package/dist/loader.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Ref: https://app.getguru.com/card/iMgx968T/ENgrid-Loader
|
|
2
|
+
import { ENGrid, EngridLogger } from ".";
|
|
3
|
+
export class Loader {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.logger = new EngridLogger("Loader", "gold", "black", "🔁");
|
|
6
|
+
this.cssElement = document.querySelector('link[href*="engrid."][rel="stylesheet"]');
|
|
7
|
+
this.jsElement = document.querySelector('script[src*="engrid."]');
|
|
8
|
+
}
|
|
9
|
+
// Returns true if ENgrid should reload (that means the current ENgrid is not the right one)
|
|
10
|
+
// Returns false if ENgrid should not reload (that means the current ENgrid is the right one)
|
|
11
|
+
reload() {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
const assets = this.getOption("assets");
|
|
14
|
+
const isLoaded = ENGrid.getBodyData("loaded");
|
|
15
|
+
let shouldSkipCss = this.getOption("engridcss") === "false";
|
|
16
|
+
let shouldSkipJs = this.getOption("engridjs") === "false";
|
|
17
|
+
if (isLoaded || !assets) {
|
|
18
|
+
if (shouldSkipCss && this.cssElement) {
|
|
19
|
+
this.logger.log("engridcss=false | Removing original stylesheet:", this.cssElement);
|
|
20
|
+
this.cssElement.remove();
|
|
21
|
+
}
|
|
22
|
+
if (shouldSkipJs && this.jsElement) {
|
|
23
|
+
this.logger.log("engridjs=false | Removing original script:", this.jsElement);
|
|
24
|
+
this.jsElement.remove();
|
|
25
|
+
}
|
|
26
|
+
if (shouldSkipCss) {
|
|
27
|
+
this.logger.log("engridcss=false | adding top banner CSS");
|
|
28
|
+
this.addENgridCSSUnloadedCSS();
|
|
29
|
+
}
|
|
30
|
+
if (shouldSkipJs) {
|
|
31
|
+
this.logger.log("engridjs=false | Skipping JS load.");
|
|
32
|
+
this.logger.success("LOADED");
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
this.logger.success("LOADED");
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
// Load the right ENgrid
|
|
39
|
+
this.logger.log("RELOADING");
|
|
40
|
+
ENGrid.setBodyData("loaded", "true"); // Set the loaded flag, so the next time we don't reload
|
|
41
|
+
// Fetch the desired repo, assets location, and override JS/CSS
|
|
42
|
+
const theme = ENGrid.getBodyData("theme");
|
|
43
|
+
const engrid_repo = (_a = this.getOption("repo-name")) !== null && _a !== void 0 ? _a : `engrid-${theme}`;
|
|
44
|
+
let engrid_js_url = "";
|
|
45
|
+
let engrid_css_url = "";
|
|
46
|
+
switch (assets) {
|
|
47
|
+
case "local":
|
|
48
|
+
this.logger.log("LOADING LOCAL");
|
|
49
|
+
ENGrid.setBodyData("assets", "local");
|
|
50
|
+
engrid_js_url = `https://${engrid_repo}.test/dist/engrid.js`;
|
|
51
|
+
engrid_css_url = `https://${engrid_repo}.test/dist/engrid.css`;
|
|
52
|
+
break;
|
|
53
|
+
case "flush":
|
|
54
|
+
this.logger.log("FLUSHING CACHE");
|
|
55
|
+
const timestamp = Date.now();
|
|
56
|
+
const jsCurrentURL = new URL(((_b = this.jsElement) === null || _b === void 0 ? void 0 : _b.getAttribute("src")) || "");
|
|
57
|
+
jsCurrentURL.searchParams.set("v", timestamp.toString());
|
|
58
|
+
engrid_js_url = jsCurrentURL.toString();
|
|
59
|
+
const cssCurrentURL = new URL(((_c = this.cssElement) === null || _c === void 0 ? void 0 : _c.getAttribute("href")) || "");
|
|
60
|
+
cssCurrentURL.searchParams.set("v", timestamp.toString());
|
|
61
|
+
engrid_css_url = cssCurrentURL.toString();
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
this.logger.log("LOADING EXTERNAL");
|
|
65
|
+
engrid_js_url = `https://s3.amazonaws.com/engrid-dev.4sitestudios.com/${engrid_repo}/${assets}/engrid.js`;
|
|
66
|
+
engrid_css_url = `https://s3.amazonaws.com/engrid-dev.4sitestudios.com/${engrid_repo}/${assets}/engrid.css`;
|
|
67
|
+
}
|
|
68
|
+
if (shouldSkipCss && this.cssElement) {
|
|
69
|
+
this.logger.log("engridcss=false | Removing original stylesheet:", this.cssElement);
|
|
70
|
+
this.cssElement.remove();
|
|
71
|
+
}
|
|
72
|
+
if (shouldSkipCss && engrid_css_url && engrid_css_url !== "") {
|
|
73
|
+
this.logger.log("engridcss=false | Skipping injection of stylesheet:", engrid_css_url);
|
|
74
|
+
}
|
|
75
|
+
if (shouldSkipCss) {
|
|
76
|
+
this.logger.log("engridcss=false | adding top banner CSS");
|
|
77
|
+
this.addENgridCSSUnloadedCSS();
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.setCssFile(engrid_css_url);
|
|
81
|
+
}
|
|
82
|
+
if (shouldSkipJs && this.jsElement) {
|
|
83
|
+
this.logger.log("engridjs=false | Removing original script:", this.jsElement);
|
|
84
|
+
this.jsElement.remove();
|
|
85
|
+
}
|
|
86
|
+
if (shouldSkipJs && engrid_js_url && engrid_js_url !== "") {
|
|
87
|
+
this.logger.log("engridjs=false | Skipping injection of script:", engrid_js_url);
|
|
88
|
+
}
|
|
89
|
+
if (!shouldSkipJs) {
|
|
90
|
+
this.setJsFile(engrid_js_url);
|
|
91
|
+
}
|
|
92
|
+
// If custom assets aren't defined, we don't need to reload.
|
|
93
|
+
if (!assets) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
getOption(key) {
|
|
99
|
+
const urlParam = ENGrid.getUrlParameter(key);
|
|
100
|
+
if (urlParam && ["assets", "engridcss", "engridjs"].includes(key)) {
|
|
101
|
+
return urlParam;
|
|
102
|
+
}
|
|
103
|
+
else if (window.EngridLoader && window.EngridLoader.hasOwnProperty(key)) {
|
|
104
|
+
return window.EngridLoader[key];
|
|
105
|
+
}
|
|
106
|
+
else if (this.jsElement && this.jsElement.hasAttribute("data-" + key)) {
|
|
107
|
+
return this.jsElement.getAttribute("data-" + key);
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
setCssFile(url) {
|
|
112
|
+
if (url === "") {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (this.cssElement) {
|
|
116
|
+
this.logger.log("Replacing stylesheet:", url);
|
|
117
|
+
this.cssElement.setAttribute("href", url);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
this.logger.log("Injecting stylesheet:", url);
|
|
121
|
+
const link = document.createElement("link");
|
|
122
|
+
link.setAttribute("rel", "stylesheet");
|
|
123
|
+
link.setAttribute("type", "text/css");
|
|
124
|
+
link.setAttribute("media", "all");
|
|
125
|
+
link.setAttribute("href", url);
|
|
126
|
+
document.head.appendChild(link);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
setJsFile(url) {
|
|
130
|
+
if (url === "") {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this.logger.log("Injecting script:", url);
|
|
134
|
+
const script = document.createElement("script");
|
|
135
|
+
script.setAttribute("src", url);
|
|
136
|
+
document.head.appendChild(script);
|
|
137
|
+
}
|
|
138
|
+
addENgridCSSUnloadedCSS() {
|
|
139
|
+
document.body.insertAdjacentHTML("beforeend", `<style>
|
|
140
|
+
html,
|
|
141
|
+
body {
|
|
142
|
+
background-color: #ffffff;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
body {
|
|
146
|
+
opacity: 1;
|
|
147
|
+
margin: 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
body:before {
|
|
151
|
+
content: "ENGRID CSS UNLOADED";
|
|
152
|
+
display: flex;
|
|
153
|
+
justify-content: center;
|
|
154
|
+
align-items: center;
|
|
155
|
+
width: 100%;
|
|
156
|
+
background-color: #ffff00;
|
|
157
|
+
padding: 1rem;
|
|
158
|
+
margin-bottom: 1rem;
|
|
159
|
+
font-family: sans-serif;
|
|
160
|
+
font-weight: 600;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.en__component--advrow {
|
|
164
|
+
flex-direction: column;
|
|
165
|
+
max-width: 600px;
|
|
166
|
+
margin: 0 auto;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.en__component--advrow * {
|
|
170
|
+
max-width: 100%;
|
|
171
|
+
height: auto;
|
|
172
|
+
}
|
|
173
|
+
</style>`);
|
|
174
|
+
}
|
|
175
|
+
}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A better logger. It only works if debug is enabled.
|
|
3
|
+
*/
|
|
4
|
+
export declare class EngridLogger {
|
|
5
|
+
prefix: string;
|
|
6
|
+
color: string;
|
|
7
|
+
background: string;
|
|
8
|
+
emoji: string;
|
|
9
|
+
constructor(prefix?: string, color?: string, background?: string, emoji?: string);
|
|
10
|
+
get log(): Function;
|
|
11
|
+
get success(): Function;
|
|
12
|
+
get danger(): Function;
|
|
13
|
+
get warn(): Function;
|
|
14
|
+
get dir(): Function;
|
|
15
|
+
get error(): Function;
|
|
16
|
+
}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ENGrid } from ".";
|
|
2
|
+
/**
|
|
3
|
+
* A better logger. It only works if debug is enabled.
|
|
4
|
+
*/
|
|
5
|
+
export class EngridLogger {
|
|
6
|
+
constructor(prefix, color, background, emoji) {
|
|
7
|
+
this.prefix = "";
|
|
8
|
+
this.color = "black";
|
|
9
|
+
this.background = "white";
|
|
10
|
+
this.emoji = "";
|
|
11
|
+
if (emoji) {
|
|
12
|
+
this.emoji = emoji;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
switch (color) {
|
|
16
|
+
case "red":
|
|
17
|
+
this.emoji = "🔴";
|
|
18
|
+
break;
|
|
19
|
+
case "green":
|
|
20
|
+
this.emoji = "🟢";
|
|
21
|
+
break;
|
|
22
|
+
case "blue":
|
|
23
|
+
this.emoji = "🔵";
|
|
24
|
+
break;
|
|
25
|
+
case "yellow":
|
|
26
|
+
this.emoji = "🟡";
|
|
27
|
+
this.background = "black";
|
|
28
|
+
break;
|
|
29
|
+
case "purple":
|
|
30
|
+
this.emoji = "🟣";
|
|
31
|
+
break;
|
|
32
|
+
case "black":
|
|
33
|
+
default:
|
|
34
|
+
this.emoji = "⚫";
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (prefix) {
|
|
39
|
+
this.prefix = `[ENgrid ${prefix}]`;
|
|
40
|
+
}
|
|
41
|
+
if (color) {
|
|
42
|
+
this.color = color;
|
|
43
|
+
}
|
|
44
|
+
if (background) {
|
|
45
|
+
this.background = background;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
get log() {
|
|
49
|
+
if (!ENGrid.debug && ENGrid.getUrlParameter("debug") !== "log") {
|
|
50
|
+
return () => { };
|
|
51
|
+
}
|
|
52
|
+
return console.log.bind(window.console, "%c" + this.emoji + " " + this.prefix + " %s", `color: ${this.color}; background-color: ${this.background}; font-size: 1.2em; padding: 4px; border-radius: 2px; font-family: monospace;`);
|
|
53
|
+
}
|
|
54
|
+
get success() {
|
|
55
|
+
if (!ENGrid.debug) {
|
|
56
|
+
return () => { };
|
|
57
|
+
}
|
|
58
|
+
return console.log.bind(window.console, "%c ✅ " + this.prefix + " %s", `color: green; background-color: white; font-size: 1.2em; padding: 4px; border-radius: 2px; font-family: monospace;`);
|
|
59
|
+
}
|
|
60
|
+
get danger() {
|
|
61
|
+
if (!ENGrid.debug) {
|
|
62
|
+
return () => { };
|
|
63
|
+
}
|
|
64
|
+
return console.log.bind(window.console, "%c ⛔️ " + this.prefix + " %s", `color: red; background-color: white; font-size: 1.2em; padding: 4px; border-radius: 2px; font-family: monospace;`);
|
|
65
|
+
}
|
|
66
|
+
get warn() {
|
|
67
|
+
if (!ENGrid.debug) {
|
|
68
|
+
return () => { };
|
|
69
|
+
}
|
|
70
|
+
return console.warn.bind(window.console, "%c" + this.emoji + " " + this.prefix + " %s", `color: ${this.color}; background-color: ${this.background}; font-size: 1.2em; padding: 4px; border-radius: 2px; font-family: monospace;`);
|
|
71
|
+
}
|
|
72
|
+
get dir() {
|
|
73
|
+
if (!ENGrid.debug) {
|
|
74
|
+
return () => { };
|
|
75
|
+
}
|
|
76
|
+
return console.dir.bind(window.console, "%c" + this.emoji + " " + this.prefix + " %s", `color: ${this.color}; background-color: ${this.background}; font-size: 1.2em; padding: 4px; border-radius: 2px; font-family: monospace;`);
|
|
77
|
+
}
|
|
78
|
+
get error() {
|
|
79
|
+
if (!ENGrid.debug) {
|
|
80
|
+
return () => { };
|
|
81
|
+
}
|
|
82
|
+
return console.error.bind(window.console, "%c" + this.emoji + " " + this.prefix + " %s", `color: ${this.color}; background-color: ${this.background}; font-size: 1.2em; padding: 4px; border-radius: 2px; font-family: monospace;`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Looks for specially crafted <img> links and will transform its markup to display an attribution overlay on top of the image
|
|
3
|
+
Depends on "_engrid-media-attribution.scss" for styling
|
|
4
|
+
|
|
5
|
+
Example Image Input
|
|
6
|
+
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAQAAABeK7cBAAAADUlEQVR42mO8/5+BAQAGgwHgbKwW2QAAAABJRU5ErkJggg==" data-src="https://via.placeholder.com/300x300" data-attribution-source="© Jane Doe 1">
|
|
7
|
+
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAQAAABeK7cBAAAADUlEQVR42mO8/5+BAQAGgwHgbKwW2QAAAABJRU5ErkJggg==" data-src="https://via.placeholder.com/300x300" data-attribution-source="© John Doe 2" data-attribution-source-link="https://www.google.com/">
|
|
8
|
+
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAQAAABeK7cBAAAADUlEQVR42mO8/5+BAQAGgwHgbKwW2QAAAABJRU5ErkJggg==" data-src="https://via.placeholder.com/300x300" data-attribution-source="© Max Doe 3" data-attribution-source-link="https://www.google.com/" data-attribution-hide-overlay>
|
|
9
|
+
|
|
10
|
+
Example Video Input (Doesn't currently visually display)
|
|
11
|
+
@TODO Video tags are processed but their <figcaption> is not visually displayed. Need to update "_engrid-media-attribution.scss"
|
|
12
|
+
<video poster="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAQAAABeK7cBAAAADUlEQVR42mO8/5+BAQAGgwHgbKwW2QAAAABJRU5ErkJggg==" data-attribution-source="© Jane Doe 1" data-attribution-source-link="https://www.google.com/"> <source data-src="https://player.vimeo.com/external/123456789.hd.mp4?s=987654321&profile_id=123" type="video/mp4"></video>
|
|
13
|
+
|
|
14
|
+
Example Image Output
|
|
15
|
+
<figure class="media-with-attribution"><img src="https://via.placeholder.com/300x300" data-src="https://via.placeholder.com/300x300" data-attribution-source="Jane Doe 1"><figattribution class="attribution-bottomright">Jane Doe 1</figattribution></figure>
|
|
16
|
+
*/
|
|
17
|
+
import { ENGrid } from ".";
|
|
18
|
+
const tippy = require("tippy.js").default;
|
|
19
|
+
export class MediaAttribution {
|
|
20
|
+
constructor() {
|
|
21
|
+
// Find all images with attribution but not with the "data-attribution-hide-overlay" attribute
|
|
22
|
+
this.mediaWithAttribution = document.querySelectorAll("img[data-attribution-source]:not([data-attribution-hide-overlay]), video[data-attribution-source]:not([data-attribution-hide-overlay])");
|
|
23
|
+
this.mediaWithAttribution.forEach((element) => {
|
|
24
|
+
if (ENGrid.debug)
|
|
25
|
+
console.log("The following image was found with data attribution fields on it. It's markup will be changed to add caption support.", element);
|
|
26
|
+
// Creates the wapping <figure> element
|
|
27
|
+
let figure = document.createElement("figure");
|
|
28
|
+
figure.classList.add("media-with-attribution");
|
|
29
|
+
// Moves the <img> inside its <figure> element
|
|
30
|
+
let mediaWithAttributionParent = element.parentNode;
|
|
31
|
+
if (mediaWithAttributionParent) {
|
|
32
|
+
mediaWithAttributionParent.insertBefore(figure, element);
|
|
33
|
+
figure.appendChild(element);
|
|
34
|
+
let mediaWithAttributionElement = element;
|
|
35
|
+
// Append the <figcaption> element after the <img> and conditionally add the Source's Link to it
|
|
36
|
+
let attributionSource = mediaWithAttributionElement.dataset.attributionSource;
|
|
37
|
+
if (attributionSource) {
|
|
38
|
+
let attributionSourceLink = mediaWithAttributionElement.dataset.attributionSourceLink;
|
|
39
|
+
if (attributionSourceLink) {
|
|
40
|
+
mediaWithAttributionElement.insertAdjacentHTML("afterend", '<figattribution><a href="' +
|
|
41
|
+
decodeURIComponent(attributionSourceLink) +
|
|
42
|
+
'" target="_blank" tabindex="-1">' +
|
|
43
|
+
attributionSource +
|
|
44
|
+
"</a></figure>");
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
mediaWithAttributionElement.insertAdjacentHTML("afterend", "<figattribution>" + attributionSource + "</figure>");
|
|
48
|
+
}
|
|
49
|
+
const attributionSourceTooltip = "attributionSourceTooltip" in mediaWithAttributionElement.dataset
|
|
50
|
+
? mediaWithAttributionElement.dataset.attributionSourceTooltip
|
|
51
|
+
: false;
|
|
52
|
+
if (attributionSourceTooltip) {
|
|
53
|
+
tippy(mediaWithAttributionElement.nextSibling, {
|
|
54
|
+
content: attributionSourceTooltip,
|
|
55
|
+
arrow: true,
|
|
56
|
+
arrowType: "default",
|
|
57
|
+
placement: "left",
|
|
58
|
+
trigger: "click mouseenter focus",
|
|
59
|
+
interactive: true,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
package/dist/menu.d.ts
ADDED
|
File without changes
|
package/dist/menu.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class MinMaxAmount {
|
|
2
|
+
private _form;
|
|
3
|
+
private _amount;
|
|
4
|
+
private minAmount;
|
|
5
|
+
private maxAmount;
|
|
6
|
+
private minAmountMessage;
|
|
7
|
+
private maxAmountMessage;
|
|
8
|
+
private logger;
|
|
9
|
+
constructor();
|
|
10
|
+
shouldRun(): boolean;
|
|
11
|
+
enOnValidate(): void;
|
|
12
|
+
liveValidate(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// This script adds an erros message to the page if the amount is greater than the max amount or less than the min amount.
|
|
2
|
+
import { DonationAmount, EnForm, ENGrid, EngridLogger } from ".";
|
|
3
|
+
export class MinMaxAmount {
|
|
4
|
+
constructor() {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
this._form = EnForm.getInstance();
|
|
7
|
+
this._amount = DonationAmount.getInstance();
|
|
8
|
+
this.minAmount = (_a = ENGrid.getOption("MinAmount")) !== null && _a !== void 0 ? _a : 1;
|
|
9
|
+
this.maxAmount = (_b = ENGrid.getOption("MaxAmount")) !== null && _b !== void 0 ? _b : 100000;
|
|
10
|
+
this.minAmountMessage = ENGrid.getOption("MinAmountMessage");
|
|
11
|
+
this.maxAmountMessage = ENGrid.getOption("MaxAmountMessage");
|
|
12
|
+
this.logger = new EngridLogger("MinMaxAmount", "white", "purple", "🔢");
|
|
13
|
+
if (!this.shouldRun()) {
|
|
14
|
+
// If we're not on a Donation Page, get out
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this._amount.onAmountChange.subscribe((s) => window.setTimeout(this.liveValidate.bind(this), 1000) // Wait 1 second for the amount to be updated
|
|
18
|
+
);
|
|
19
|
+
this._form.onValidate.subscribe(this.enOnValidate.bind(this));
|
|
20
|
+
}
|
|
21
|
+
// Should we run the script?
|
|
22
|
+
shouldRun() {
|
|
23
|
+
return ENGrid.getPageType() === "DONATION";
|
|
24
|
+
}
|
|
25
|
+
// Don't submit the form if the amount is not valid
|
|
26
|
+
enOnValidate() {
|
|
27
|
+
if (!this._form.validate)
|
|
28
|
+
return;
|
|
29
|
+
const otherAmount = document.querySelector("[name='transaction.donationAmt.other']");
|
|
30
|
+
if (this._amount.amount < this.minAmount) {
|
|
31
|
+
this.logger.log("Amount is less than min amount: " + this.minAmount);
|
|
32
|
+
if (otherAmount) {
|
|
33
|
+
otherAmount.focus();
|
|
34
|
+
}
|
|
35
|
+
this._form.validate = false;
|
|
36
|
+
}
|
|
37
|
+
else if (this._amount.amount > this.maxAmount) {
|
|
38
|
+
this.logger.log("Amount is greater than max amount: " + this.maxAmount);
|
|
39
|
+
if (otherAmount) {
|
|
40
|
+
otherAmount.focus();
|
|
41
|
+
}
|
|
42
|
+
this._form.validate = false;
|
|
43
|
+
}
|
|
44
|
+
window.setTimeout(this.liveValidate.bind(this), 300);
|
|
45
|
+
}
|
|
46
|
+
// Disable Submit Button if the amount is not valid
|
|
47
|
+
liveValidate() {
|
|
48
|
+
const amount = ENGrid.cleanAmount(this._amount.amount.toString());
|
|
49
|
+
const activeElement = document.activeElement;
|
|
50
|
+
if (activeElement &&
|
|
51
|
+
activeElement.tagName === "INPUT" &&
|
|
52
|
+
"name" in activeElement &&
|
|
53
|
+
activeElement.name === "transaction.donationAmt.other" &&
|
|
54
|
+
amount === 0) {
|
|
55
|
+
// Don't validate if the other amount has focus and the amount is 0
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.logger.log(`Amount: ${amount}`);
|
|
59
|
+
if (amount < this.minAmount) {
|
|
60
|
+
this.logger.log("Amount is less than min amount: " + this.minAmount);
|
|
61
|
+
ENGrid.setError(".en__field--withOther", this.minAmountMessage || "Invalid Amount");
|
|
62
|
+
}
|
|
63
|
+
else if (amount > this.maxAmount) {
|
|
64
|
+
this.logger.log("Amount is greater than max amount: " + this.maxAmount);
|
|
65
|
+
ENGrid.setError(".en__field--withOther", this.maxAmountMessage || "Invalid Amount");
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
ENGrid.removeError(".en__field--withOther");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|