@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,38 @@
|
|
|
1
|
+
// This class adds the autocomplete attribute to
|
|
2
|
+
// the most common input elements
|
|
3
|
+
import { EngridLogger } from ".";
|
|
4
|
+
export class Autocomplete {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.logger = new EngridLogger("Autocomplete", "#330033", "#f0f0f0", "📇");
|
|
7
|
+
this.autoCompleteField('[name="supporter.firstName"]', "given-name");
|
|
8
|
+
this.autoCompleteField('[name="supporter.lastName"]', "family-name");
|
|
9
|
+
this.autoCompleteField("#en__field_transaction_ccexpire", "cc-exp-month");
|
|
10
|
+
this.autoCompleteField('[name="transaction.ccexpire"]:not(#en__field_transaction_ccexpire)', "cc-exp-year");
|
|
11
|
+
this.autoCompleteField('[name="supporter.emailAddress"]', "email");
|
|
12
|
+
this.autoCompleteField('[name="supporter.phoneNumber"]', "tel");
|
|
13
|
+
this.autoCompleteField('[name="supporter.country"]', "country");
|
|
14
|
+
this.autoCompleteField('[name="supporter.address1"]', "address-line1");
|
|
15
|
+
this.autoCompleteField('[name="supporter.address2"]', "address-line2");
|
|
16
|
+
this.autoCompleteField('[name="supporter.city"]', "address-level2");
|
|
17
|
+
this.autoCompleteField('[name="supporter.region"]', "address-level1");
|
|
18
|
+
this.autoCompleteField('[name="supporter.postcode"]', "postal-code");
|
|
19
|
+
// Ignore Autocomplete on the Recipient Email Field & Address ("none" is intentional because "off" doesn't work)
|
|
20
|
+
this.autoCompleteField('[name="transaction.honname"]', "none");
|
|
21
|
+
this.autoCompleteField('[name="transaction.infemail"]', "none");
|
|
22
|
+
this.autoCompleteField('[name="transaction.infname"]', "none");
|
|
23
|
+
this.autoCompleteField('[name="transaction.infadd1"]', "none");
|
|
24
|
+
this.autoCompleteField('[name="transaction.infadd2"]', "none");
|
|
25
|
+
this.autoCompleteField('[name="transaction.infcity"]', "none");
|
|
26
|
+
this.autoCompleteField('[name="transaction.infpostcd"]', "none");
|
|
27
|
+
}
|
|
28
|
+
autoCompleteField(querySelector, autoCompleteValue) {
|
|
29
|
+
let field = document.querySelector(querySelector);
|
|
30
|
+
if (field) {
|
|
31
|
+
field.autocomplete = autoCompleteValue;
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (autoCompleteValue !== "none")
|
|
35
|
+
this.logger.log("Field Not Found", querySelector);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Automatically submits the page if a URL argument is present
|
|
2
|
+
import { ENGrid, EngridLogger, EnForm } from ".";
|
|
3
|
+
export class Autosubmit {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.logger = new EngridLogger("Autosubmit", "#f0f0f0", "#ff0000", "🚀");
|
|
6
|
+
this._form = EnForm.getInstance();
|
|
7
|
+
if (ENGrid.checkNested(window.EngagingNetworks, "require", "_defined", "enjs", "checkSubmissionFailed") &&
|
|
8
|
+
!window.EngagingNetworks.require._defined.enjs.checkSubmissionFailed() &&
|
|
9
|
+
ENGrid.getUrlParameter("autosubmit") === "Y") {
|
|
10
|
+
this.logger.log("Autosubmitting Form");
|
|
11
|
+
this._form.submitForm();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inserts all of the branding HTML from https://github.com/4site-interactive-studios/engrid/tree/main/reference-materials/html/brand-guide-markup
|
|
3
|
+
* into the body-main section of the page.
|
|
4
|
+
*/
|
|
5
|
+
export declare class BrandingHtml {
|
|
6
|
+
private assetBaseUrl;
|
|
7
|
+
private brandingHtmlFiles;
|
|
8
|
+
private bodyMain;
|
|
9
|
+
private htmlFetched;
|
|
10
|
+
private fetchHtml;
|
|
11
|
+
private appendHtml;
|
|
12
|
+
show(): void;
|
|
13
|
+
hide(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Inserts all of the branding HTML from https://github.com/4site-interactive-studios/engrid/tree/main/reference-materials/html/brand-guide-markup
|
|
12
|
+
* into the body-main section of the page.
|
|
13
|
+
*/
|
|
14
|
+
export class BrandingHtml {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.assetBaseUrl = "https://cdn.jsdelivr.net/gh/4site-interactive-studios/engrid@main/reference-materials/html/brand-guide-markup/";
|
|
17
|
+
this.brandingHtmlFiles = [
|
|
18
|
+
"html5-tags.html",
|
|
19
|
+
"en-common-fields.html",
|
|
20
|
+
"survey.html",
|
|
21
|
+
// "en-common-fields-with-errors.html",
|
|
22
|
+
// "en-common-fields-with-fancy-errors.html",
|
|
23
|
+
"donation-page.html",
|
|
24
|
+
"premium-donation.html",
|
|
25
|
+
"ecards.html",
|
|
26
|
+
"email-to-target.html",
|
|
27
|
+
"tweet-to-target.html",
|
|
28
|
+
// "click-to-call.html",
|
|
29
|
+
"petition.html",
|
|
30
|
+
"event.html",
|
|
31
|
+
// "ecommerce.html",
|
|
32
|
+
// "membership.html",
|
|
33
|
+
"styles.html",
|
|
34
|
+
];
|
|
35
|
+
this.bodyMain = document.querySelector(".body-main");
|
|
36
|
+
this.htmlFetched = false;
|
|
37
|
+
}
|
|
38
|
+
fetchHtml() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const htmlRequests = this.brandingHtmlFiles.map((file) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const res = yield fetch(this.assetBaseUrl + file);
|
|
42
|
+
return res.text();
|
|
43
|
+
}));
|
|
44
|
+
const brandingHtmls = yield Promise.all(htmlRequests);
|
|
45
|
+
return brandingHtmls;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
appendHtml() {
|
|
49
|
+
this.fetchHtml().then((html) => html.forEach((h) => {
|
|
50
|
+
var _a;
|
|
51
|
+
const brandingSection = document.createElement("div");
|
|
52
|
+
brandingSection.classList.add("brand-guide-section");
|
|
53
|
+
brandingSection.innerHTML = h;
|
|
54
|
+
(_a = this.bodyMain) === null || _a === void 0 ? void 0 : _a.insertAdjacentElement("beforeend", brandingSection);
|
|
55
|
+
}));
|
|
56
|
+
this.htmlFetched = true;
|
|
57
|
+
}
|
|
58
|
+
show() {
|
|
59
|
+
if (!this.htmlFetched) {
|
|
60
|
+
this.appendHtml();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const guides = document.querySelectorAll(".brand-guide-section");
|
|
64
|
+
guides === null || guides === void 0 ? void 0 : guides.forEach((g) => (g.style.display = "block"));
|
|
65
|
+
}
|
|
66
|
+
hide() {
|
|
67
|
+
const guides = document.querySelectorAll(".brand-guide-section");
|
|
68
|
+
guides === null || guides === void 0 ? void 0 : guides.forEach((g) => (g.style.display = "none"));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// CapitalizeFields is a class that capitalizes the first letter of the fields passed to it.
|
|
2
|
+
// It subscribes to the onSubmit event of the EnForm class and capitalizes the fields on submit.
|
|
3
|
+
import { ENGrid } from ".";
|
|
4
|
+
import { EnForm } from "./events";
|
|
5
|
+
export class CapitalizeFields {
|
|
6
|
+
constructor() {
|
|
7
|
+
this._form = EnForm.getInstance();
|
|
8
|
+
this._form.onSubmit.subscribe(() => this.capitalizeFields("en__field_supporter_firstName", "en__field_supporter_lastName", "en__field_supporter_address1", "en__field_supporter_city"));
|
|
9
|
+
}
|
|
10
|
+
capitalizeFields(...fields) {
|
|
11
|
+
fields.forEach((f) => this.capitalize(f));
|
|
12
|
+
}
|
|
13
|
+
capitalize(f) {
|
|
14
|
+
let field = document.getElementById(f);
|
|
15
|
+
if (field) {
|
|
16
|
+
field.value = field.value.replace(/\w\S*/g, (w) => w.replace(/^\w/, (c) => c.toUpperCase()));
|
|
17
|
+
if (ENGrid.debug)
|
|
18
|
+
console.log("Capitalized", field.value);
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// This class is used to expand content when a user clicks on a div with the class "click-to-expand".
|
|
2
|
+
// The content is shortened by default and will expand when clicked.
|
|
3
|
+
import { ENGrid } from ".";
|
|
4
|
+
// Works when the user has adds ".click-to-expand" as a class to any field
|
|
5
|
+
export class ClickToExpand {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.clickToExpandWrapper = document.querySelectorAll("div.click-to-expand");
|
|
8
|
+
if (this.clickToExpandWrapper.length) {
|
|
9
|
+
this.clickToExpandWrapper.forEach((element) => {
|
|
10
|
+
const content = element.innerHTML;
|
|
11
|
+
const wrapper_html = '<div class="click-to-expand-cta"></div><div class="click-to-expand-text-wrapper" tabindex="0">' +
|
|
12
|
+
content +
|
|
13
|
+
"</div>";
|
|
14
|
+
element.innerHTML = wrapper_html;
|
|
15
|
+
element.addEventListener("click", (event) => {
|
|
16
|
+
if (event) {
|
|
17
|
+
if (ENGrid.debug)
|
|
18
|
+
console.log("A click-to-expand div was clicked");
|
|
19
|
+
element.classList.add("expanded");
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
element.addEventListener("keydown", (event) => {
|
|
23
|
+
if (event.key === "Enter") {
|
|
24
|
+
if (ENGrid.debug)
|
|
25
|
+
console.log("A click-to-expand div had the 'Enter' key pressed on it");
|
|
26
|
+
element.classList.add("expanded");
|
|
27
|
+
}
|
|
28
|
+
else if (event.key === " ") {
|
|
29
|
+
if (ENGrid.debug)
|
|
30
|
+
console.log("A click-to-expand div had the 'Spacebar' key pressed on it");
|
|
31
|
+
element.classList.add("expanded");
|
|
32
|
+
event.preventDefault(); // Prevents the page from scrolling
|
|
33
|
+
event.stopPropagation(); // Prevent a console error generated by LastPass https://github.com/KillerCodeMonkey/ngx-quill/issues/351#issuecomment-476017960
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/cookie.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Example:
|
|
3
|
+
import * as cookie from "./cookie";
|
|
4
|
+
|
|
5
|
+
cookie.set('name', 'value');
|
|
6
|
+
cookie.get('name'); // => 'value'
|
|
7
|
+
cookie.remove('name');
|
|
8
|
+
cookie.set('name', 'value', { expires: 7 }); // 7 Days cookie
|
|
9
|
+
cookie.set('name', 'value', { expires: 7, path: '' }); // Set Path
|
|
10
|
+
cookie.remove('name', { path: '' });
|
|
11
|
+
*/
|
|
12
|
+
export interface CookieAttributes {
|
|
13
|
+
/**
|
|
14
|
+
* A number will be interpreted as days from time of creation
|
|
15
|
+
*/
|
|
16
|
+
expires?: Date | number;
|
|
17
|
+
/**
|
|
18
|
+
* Hosts to which the cookie will be sent
|
|
19
|
+
*/
|
|
20
|
+
domain?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The cookie will only be included in an HTTP request if the request
|
|
23
|
+
* path matches (or is a subdirectory of) the cookie's path attribute.
|
|
24
|
+
*/
|
|
25
|
+
path?: string;
|
|
26
|
+
/**
|
|
27
|
+
* If enabled, the cookie will only be included in an HTTP request
|
|
28
|
+
* if it is transmitted over a secure channel (typically HTTP over TLS).
|
|
29
|
+
*/
|
|
30
|
+
secure?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Only send the cookie if the request originates from the same website the
|
|
33
|
+
* cookie is from. This provides some protection against cross-site request
|
|
34
|
+
* forgery attacks (CSRF).
|
|
35
|
+
*
|
|
36
|
+
* The strict mode witholds the cookie from any kind of cross-site usage
|
|
37
|
+
* (including inbound links from external sites). The lax mode witholds
|
|
38
|
+
* the cookie on cross-domain subrequests (e.g. images or frames), but
|
|
39
|
+
* sends it whenever a user navigates safely from an external site (e.g.
|
|
40
|
+
* by following a link).
|
|
41
|
+
*/
|
|
42
|
+
sameSite?: "strict" | "lax" | "none";
|
|
43
|
+
}
|
|
44
|
+
export declare function encode(name: string, value: string, attributes: CookieAttributes): string;
|
|
45
|
+
export declare function parse(cookieString: string): {
|
|
46
|
+
[name: string]: string;
|
|
47
|
+
};
|
|
48
|
+
export declare function getAll(): {
|
|
49
|
+
[name: string]: string;
|
|
50
|
+
};
|
|
51
|
+
export declare function get(name: string): string | undefined;
|
|
52
|
+
export declare function set(name: string, value: string, attributes?: CookieAttributes): void;
|
|
53
|
+
export declare function remove(name: string, attributes?: CookieAttributes): void;
|
package/dist/cookie.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Example:
|
|
3
|
+
import * as cookie from "./cookie";
|
|
4
|
+
|
|
5
|
+
cookie.set('name', 'value');
|
|
6
|
+
cookie.get('name'); // => 'value'
|
|
7
|
+
cookie.remove('name');
|
|
8
|
+
cookie.set('name', 'value', { expires: 7 }); // 7 Days cookie
|
|
9
|
+
cookie.set('name', 'value', { expires: 7, path: '' }); // Set Path
|
|
10
|
+
cookie.remove('name', { path: '' });
|
|
11
|
+
*/
|
|
12
|
+
function stringifyAttribute(name, value) {
|
|
13
|
+
if (!value) {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
let stringified = "; " + name;
|
|
17
|
+
if (value === true) {
|
|
18
|
+
return stringified; // boolean attributes shouldn't have a value
|
|
19
|
+
}
|
|
20
|
+
return stringified + "=" + value;
|
|
21
|
+
}
|
|
22
|
+
function stringifyAttributes(attributes) {
|
|
23
|
+
if (typeof attributes.expires === "number") {
|
|
24
|
+
let expires = new Date();
|
|
25
|
+
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e5);
|
|
26
|
+
attributes.expires = expires;
|
|
27
|
+
}
|
|
28
|
+
return (stringifyAttribute("Expires", attributes.expires ? attributes.expires.toUTCString() : "") +
|
|
29
|
+
stringifyAttribute("Domain", attributes.domain) +
|
|
30
|
+
stringifyAttribute("Path", attributes.path) +
|
|
31
|
+
stringifyAttribute("Secure", attributes.secure) +
|
|
32
|
+
stringifyAttribute("SameSite", attributes.sameSite));
|
|
33
|
+
}
|
|
34
|
+
export function encode(name, value, attributes) {
|
|
35
|
+
return (encodeURIComponent(name)
|
|
36
|
+
.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent) // allowed special characters
|
|
37
|
+
.replace(/\(/g, "%28")
|
|
38
|
+
.replace(/\)/g, "%29") + // replace opening and closing parens
|
|
39
|
+
"=" +
|
|
40
|
+
encodeURIComponent(value)
|
|
41
|
+
// allowed special characters
|
|
42
|
+
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent) +
|
|
43
|
+
stringifyAttributes(attributes));
|
|
44
|
+
}
|
|
45
|
+
export function parse(cookieString) {
|
|
46
|
+
let result = {};
|
|
47
|
+
let cookies = cookieString ? cookieString.split("; ") : [];
|
|
48
|
+
let rdecode = /(%[\dA-F]{2})+/gi;
|
|
49
|
+
for (let i = 0; i < cookies.length; i++) {
|
|
50
|
+
let parts = cookies[i].split("=");
|
|
51
|
+
let cookie = parts.slice(1).join("=");
|
|
52
|
+
if (cookie.charAt(0) === '"') {
|
|
53
|
+
cookie = cookie.slice(1, -1);
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
let name = parts[0].replace(rdecode, decodeURIComponent);
|
|
57
|
+
result[name] = cookie.replace(rdecode, decodeURIComponent);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
// ignore cookies with invalid name/value encoding
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
export function getAll() {
|
|
66
|
+
return parse(document.cookie);
|
|
67
|
+
}
|
|
68
|
+
export function get(name) {
|
|
69
|
+
return getAll()[name];
|
|
70
|
+
}
|
|
71
|
+
export function set(name, value, attributes) {
|
|
72
|
+
document.cookie = encode(name, value, Object.assign({ path: "/" }, attributes));
|
|
73
|
+
}
|
|
74
|
+
export function remove(name, attributes) {
|
|
75
|
+
set(name, "", Object.assign(Object.assign({}, attributes), { expires: -1 }));
|
|
76
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// This class allows you to disable some countries from the country dropdown list.
|
|
2
|
+
import { ENGrid, EngridLogger } from ".";
|
|
3
|
+
export class CountryDisable {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.logger = new EngridLogger("CountryDisable", "#f0f0f0", "#333333", "🌎");
|
|
6
|
+
const countries = document.querySelectorAll('select[name="supporter.country"], select[name="transaction.shipcountry"], select[name="supporter.billingCountry"], select[name="transaction.infcountry"]');
|
|
7
|
+
const CountryDisable = ENGrid.getOption("CountryDisable");
|
|
8
|
+
// Remove the countries from the dropdown list
|
|
9
|
+
if (countries.length > 0 && CountryDisable.length > 0) {
|
|
10
|
+
const countriesLower = CountryDisable.map((country) => country.toLowerCase());
|
|
11
|
+
countries.forEach((country) => {
|
|
12
|
+
country.querySelectorAll("option").forEach((option) => {
|
|
13
|
+
if (countriesLower.includes(option.value.toLowerCase()) ||
|
|
14
|
+
countriesLower.includes(option.text.toLowerCase())) {
|
|
15
|
+
this.logger.log(`Removing ${option.text} from ${country.getAttribute("name")}`);
|
|
16
|
+
option.remove();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// This component allows you to redirect the user to a different page based on their country.
|
|
2
|
+
// It works by checking the country field on the page and comparing it to the list of countries in the CountryRedirect option.
|
|
3
|
+
// If the country matches one of the countries in the list, the user is redirected to the specified URL only if the URL is not the same as the current page.
|
|
4
|
+
// The CountryRedirect option is an object with the country as the key and the URL as the value.
|
|
5
|
+
// Example:
|
|
6
|
+
//
|
|
7
|
+
// CountryRedirect: {
|
|
8
|
+
// US: "https://example.com/us",
|
|
9
|
+
// CA: "https://example.com/ca",
|
|
10
|
+
// GB: "https://example.com/gb",
|
|
11
|
+
// },
|
|
12
|
+
// The country codes must match the country codes in the country field
|
|
13
|
+
// The CountryRedirect component can also be set at the page level. Useful for Regional Pages, with a Code Block like this:
|
|
14
|
+
//
|
|
15
|
+
// <script>
|
|
16
|
+
// window.EngridPageOptions = window.EngridPageOptions || [];
|
|
17
|
+
// window.EngridPageOptions.CountryRedirect = {
|
|
18
|
+
// US: "https://example.com/us",
|
|
19
|
+
// CA: "https://example.com/ca",
|
|
20
|
+
// GB: "https://example.com/gb",
|
|
21
|
+
// };
|
|
22
|
+
// </script>
|
|
23
|
+
//
|
|
24
|
+
// This will override the default CountryRedirect options for that page.
|
|
25
|
+
//
|
|
26
|
+
import { ENGrid, Country, EngridLogger } from ".";
|
|
27
|
+
export class CountryRedirect {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.logger = new EngridLogger("CountryRedirect", "white", "brown", "🛫");
|
|
30
|
+
this._country = Country.getInstance();
|
|
31
|
+
if (!this.shouldRun())
|
|
32
|
+
return;
|
|
33
|
+
this._country.onCountryChange.subscribe((country) => {
|
|
34
|
+
this.checkRedirect(country);
|
|
35
|
+
});
|
|
36
|
+
this.checkRedirect(this._country.country); // This will check the redirect when the page loads
|
|
37
|
+
}
|
|
38
|
+
shouldRun() {
|
|
39
|
+
// Only run if the CountryRedirect option is not false and the country field is present
|
|
40
|
+
if (!ENGrid.getOption("CountryRedirect") || !this._country.countryField) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
checkRedirect(country) {
|
|
46
|
+
const countryRedirect = ENGrid.getOption("CountryRedirect");
|
|
47
|
+
// Check if the country is in the list and if the current URL is not the same as the redirect URL
|
|
48
|
+
// We are using includes because the URL might have query parameters
|
|
49
|
+
if (countryRedirect &&
|
|
50
|
+
country in countryRedirect &&
|
|
51
|
+
window.location.href.includes(countryRedirect[country]) === false) {
|
|
52
|
+
this.logger.log(`${country}: Redirecting to ${countryRedirect[country]}`);
|
|
53
|
+
let redirectUrl = new URL(countryRedirect[country]);
|
|
54
|
+
// If the redirect URL doesn't contain "?chain", add it
|
|
55
|
+
if (!redirectUrl.search.includes("chain")) {
|
|
56
|
+
redirectUrl.search += (redirectUrl.search ? "&" : "?") + "chain";
|
|
57
|
+
}
|
|
58
|
+
window.location.href = redirectUrl.href;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// This component allows you to customize the currency options in the currency field
|
|
2
|
+
// It is used in the following way:
|
|
3
|
+
//
|
|
4
|
+
// CustomCurrency: {
|
|
5
|
+
// label: "Give with [$$$]",
|
|
6
|
+
// default: {
|
|
7
|
+
// USD: "$",
|
|
8
|
+
// GBP: "£",
|
|
9
|
+
// EUR: "€",
|
|
10
|
+
// },
|
|
11
|
+
// countries: {
|
|
12
|
+
// US: {
|
|
13
|
+
// USD: "$",
|
|
14
|
+
// },
|
|
15
|
+
// GB: {
|
|
16
|
+
// GBP: "£",
|
|
17
|
+
// },
|
|
18
|
+
// DE: {
|
|
19
|
+
// EUR: "€",
|
|
20
|
+
// },
|
|
21
|
+
// },
|
|
22
|
+
// },
|
|
23
|
+
//
|
|
24
|
+
// The label is the text that appears in the currency field
|
|
25
|
+
// The default is the currency options that appear when the selected country does not have a custom option
|
|
26
|
+
// The countries object is a list of countries and their currency options
|
|
27
|
+
// The country codes must match the country codes in the country field
|
|
28
|
+
// Because the CustomCurrency component works with the country field, it's automatically integrated with the AutoCountrySelect component.
|
|
29
|
+
// So if you visit the page from a country that has a custom currency option, the currency field will automatically be updated.
|
|
30
|
+
// The CustomCurrency component can also be set at the page level. Useful for Regional Pages, with a Code Block like this:
|
|
31
|
+
// <script>
|
|
32
|
+
// window.EngridPageOptions = window.EngridPageOptions || [];
|
|
33
|
+
// window.EngridPageOptions.CustomCurrency = {
|
|
34
|
+
// label: "Give with [$$$]",
|
|
35
|
+
// default: {
|
|
36
|
+
// USD: "$",
|
|
37
|
+
// GBP: "£",
|
|
38
|
+
// EUR: "€",
|
|
39
|
+
// },
|
|
40
|
+
// countries: {
|
|
41
|
+
// US: {
|
|
42
|
+
// USD: "$",
|
|
43
|
+
// },
|
|
44
|
+
// GB: {
|
|
45
|
+
// GBP: "£",
|
|
46
|
+
// },
|
|
47
|
+
// DE: {
|
|
48
|
+
// EUR: "€",
|
|
49
|
+
// },
|
|
50
|
+
// },
|
|
51
|
+
// };
|
|
52
|
+
// </script>
|
|
53
|
+
//
|
|
54
|
+
// This will override the default CustomCurrency options for that page.
|
|
55
|
+
//
|
|
56
|
+
import { ENGrid, Country, EngridLogger } from ".";
|
|
57
|
+
export class CustomCurrency {
|
|
58
|
+
constructor() {
|
|
59
|
+
this.logger = new EngridLogger("CustomCurrency", "#1901b1", "#00cc95", "🤑");
|
|
60
|
+
this.currencyElement = document.querySelector("[name='transaction.paycurrency']");
|
|
61
|
+
this._country = Country.getInstance();
|
|
62
|
+
if (!this.shouldRun())
|
|
63
|
+
return;
|
|
64
|
+
this.addEventListeners();
|
|
65
|
+
this.loadCurrencies();
|
|
66
|
+
}
|
|
67
|
+
shouldRun() {
|
|
68
|
+
// Only run if the currency field is present, and the CustomCurrency option is not false
|
|
69
|
+
if (!this.currencyElement || !ENGrid.getOption("CustomCurrency")) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
addEventListeners() {
|
|
75
|
+
if (this._country.countryField) {
|
|
76
|
+
this._country.onCountryChange.subscribe((country) => {
|
|
77
|
+
this.loadCurrencies(country);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Changes the options in the currency field to match the selected country options
|
|
82
|
+
loadCurrencies(country = "default") {
|
|
83
|
+
const options = ENGrid.getOption("CustomCurrency");
|
|
84
|
+
if (!options)
|
|
85
|
+
return;
|
|
86
|
+
const label = options.label || `Give with [$$$]`;
|
|
87
|
+
let currencies = options.default;
|
|
88
|
+
if (options.countries && options.countries[country]) {
|
|
89
|
+
currencies = options.countries[country];
|
|
90
|
+
}
|
|
91
|
+
if (!currencies) {
|
|
92
|
+
this.logger.log(`No currencies found for ${country}`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.logger.log(`Loading currencies for ${country}`);
|
|
96
|
+
this.currencyElement.innerHTML = "";
|
|
97
|
+
for (const currency in currencies) {
|
|
98
|
+
const option = document.createElement("option");
|
|
99
|
+
option.value = currency;
|
|
100
|
+
option.text = label
|
|
101
|
+
.replace("[$$$]", currency)
|
|
102
|
+
.replace("[$]", currencies[currency]);
|
|
103
|
+
option.setAttribute("data-currency-code", currency);
|
|
104
|
+
option.setAttribute("data-currency-symbol", currencies[currency]);
|
|
105
|
+
this.currencyElement.appendChild(option);
|
|
106
|
+
}
|
|
107
|
+
// Set the currency to the first option and trigger a change event
|
|
108
|
+
this.currencyElement.selectedIndex = 0;
|
|
109
|
+
const event = new Event("change", { bubbles: true });
|
|
110
|
+
this.currencyElement.dispatchEvent(event);
|
|
111
|
+
}
|
|
112
|
+
}
|