@4site/engrid-scripts 0.25.12 → 0.25.13

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/dist/app.js CHANGED
@@ -180,6 +180,8 @@ export class App extends ENGrid {
180
180
  new CustomCurrency();
181
181
  // Auto Country Select
182
182
  new AutoCountrySelect();
183
+ // Page Background
184
+ new PageBackground(this.options.UseBodyBannerImageAsBackground);
183
185
  // Add Image Attribution
184
186
  if (this.options.MediaAttribution)
185
187
  new MediaAttribution();
@@ -230,8 +232,6 @@ export class App extends ENGrid {
230
232
  new A11y();
231
233
  new AddNameToMessage();
232
234
  new ExpandRegionName();
233
- // Page Background
234
- new PageBackground();
235
235
  // Url Params to Form Fields
236
236
  new UrlToForm();
237
237
  // Required if Visible Fields
package/dist/engrid.js CHANGED
@@ -171,7 +171,7 @@ export class ENGrid {
171
171
  return null;
172
172
  }
173
173
  static isThankYouPage() {
174
- return this.getPageNumber() === this.getPageCount();
174
+ return (this.getPageNumber() === this.getPageCount() && this.getPageCount() > 1);
175
175
  }
176
176
  // Return the current page ID
177
177
  static getPageID() {
@@ -1,5 +1,6 @@
1
1
  export interface Options {
2
2
  backgroundImage?: string | string[];
3
+ UseBodyBannerImageAsBackground?: boolean;
3
4
  MediaAttribution?: boolean;
4
5
  applePay?: boolean;
5
6
  CapitalizeFields?: boolean;
@@ -54,4 +54,5 @@ export const OptionsDefaults = {
54
54
  "rightright1col",
55
55
  "none",
56
56
  ],
57
+ UseBodyBannerImageAsBackground: false,
57
58
  };
@@ -1,12 +1,18 @@
1
1
  export declare class PageBackground {
2
2
  private pageBackground;
3
+ private bodyBanner;
4
+ private bodyBannerImage;
3
5
  private mutationObserver;
4
6
  private logger;
5
- constructor();
7
+ constructor(useBodyBannerImage?: boolean);
8
+ private findBodyBannerImage;
6
9
  /**
7
10
  * Initialize background image by finding and setting CSS custom property
8
11
  */
9
12
  private initializeBackgroundImage;
13
+ private getBackgroundImage;
14
+ private useBodyBannerAsBackground;
15
+ private getImageSource;
10
16
  /**
11
17
  * Set the background image URL as a CSS custom property
12
18
  */
@@ -1,11 +1,16 @@
1
1
  import { ENGrid, EngridLogger } from ".";
2
2
  export class PageBackground {
3
- constructor() {
3
+ constructor(useBodyBannerImage = false) {
4
4
  // @TODO: Change page-backgroundImage to page-background
5
5
  this.pageBackground = document.querySelector(".page-backgroundImage");
6
+ this.bodyBanner = document.querySelector(".body-banner");
7
+ this.bodyBannerImage = null;
6
8
  this.mutationObserver = null;
7
9
  this.logger = new EngridLogger("PageBackground", "lightblue", "darkblue", "🖼️");
8
- if (!this.pageBackground) {
10
+ if (useBodyBannerImage) {
11
+ this.bodyBannerImage = this.findBodyBannerImage();
12
+ }
13
+ if (!this.pageBackground && !this.bodyBannerImage) {
9
14
  this.logger.log("A background image set in the page was not found, any default image set in the theme on --engrid__page-backgroundImage_url will be used");
10
15
  return;
11
16
  }
@@ -14,28 +19,66 @@ export class PageBackground {
14
19
  this.processAttributionPositioning();
15
20
  this.setupMutationObserver();
16
21
  }
22
+ findBodyBannerImage() {
23
+ var _a;
24
+ if (!this.bodyBanner) {
25
+ return null;
26
+ }
27
+ return ((_a = this.bodyBanner.querySelector("img.preferred-image")) !== null && _a !== void 0 ? _a : this.bodyBanner.querySelector("img"));
28
+ }
17
29
  /**
18
30
  * Initialize background image by finding and setting CSS custom property
19
31
  */
20
32
  initializeBackgroundImage() {
21
- if (!this.pageBackground)
33
+ const backgroundImg = this.getBackgroundImage();
34
+ if (!backgroundImg) {
35
+ this.logger.log("No image found in page background and no body banner image found (or pageBackground is already occupied), any default image set in the theme on --engrid__page-backgroundImage_url will be used");
22
36
  return;
23
- const pageBackgroundImg = this.pageBackground.querySelector("img");
24
- if (!pageBackgroundImg) {
25
- this.logger.log("A background image set in the page was not found, any default image set in the theme on --engrid__page-backgroundImage_url will be used");
37
+ }
38
+ const imageSource = this.getImageSource(backgroundImg);
39
+ if (!imageSource) {
40
+ this.logger.log("A background image set in the page was found but without a data-src or src value, no action taken", backgroundImg);
26
41
  return;
27
42
  }
28
- const dataSrc = pageBackgroundImg.getAttribute("data-src");
29
- const src = pageBackgroundImg.src;
30
- if (dataSrc) {
31
- this.setBackgroundImageUrl(dataSrc, "data-src");
43
+ this.setBackgroundImageUrl(imageSource.url, imageSource.sourceType);
44
+ }
45
+ getBackgroundImage() {
46
+ if (!this.pageBackground) {
47
+ return null;
32
48
  }
33
- else if (src) {
34
- this.setBackgroundImageUrl(src, "src");
49
+ const existingImage = this.pageBackground.querySelector("img");
50
+ if (existingImage) {
51
+ return existingImage;
35
52
  }
36
- else {
37
- this.logger.log("A background image set in the page was found but without a data-src or src value, no action taken", pageBackgroundImg);
53
+ if (this.bodyBannerImage && this.pageBackground.children.length === 0) {
54
+ return this.useBodyBannerAsBackground();
55
+ }
56
+ return null;
57
+ }
58
+ useBodyBannerAsBackground() {
59
+ var _a;
60
+ if (!this.pageBackground || !this.bodyBanner) {
61
+ return null;
62
+ }
63
+ this.logger.log("No image found in page background, using body banner image as background image instead");
64
+ const clonedBodyBanner = this.bodyBanner.cloneNode(true);
65
+ while (clonedBodyBanner.firstChild) {
66
+ this.pageBackground.appendChild(clonedBodyBanner.firstChild);
67
+ }
68
+ document.body.removeAttribute("data-engrid-no-page-backgroundImage");
69
+ ENGrid.setBodyData("use-body-banner-background", "");
70
+ return ((_a = this.pageBackground.querySelector("img.preferred-image")) !== null && _a !== void 0 ? _a : this.pageBackground.querySelector("img"));
71
+ }
72
+ getImageSource(backgroundImg) {
73
+ const dataSrc = backgroundImg.getAttribute("data-src");
74
+ if (dataSrc) {
75
+ return { sourceType: "data-src", url: dataSrc };
76
+ }
77
+ const src = backgroundImg.src;
78
+ if (src) {
79
+ return { sourceType: "src", url: src };
38
80
  }
81
+ return null;
39
82
  }
40
83
  /**
41
84
  * Set the background image URL as a CSS custom property
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AppVersion = "0.25.12";
1
+ export declare const AppVersion = "0.25.13";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const AppVersion = "0.25.12";
1
+ export const AppVersion = "0.25.13";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4site/engrid-scripts",
3
- "version": "0.25.12",
3
+ "version": "0.25.13",
4
4
  "description": "Scripts for the ENGRID Project",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "strongly-typed-events": "^2.0.9"
26
26
  },
27
27
  "homepage": "https://github.com/4site-interactive-studios/engrid#readme",
28
- "gitHead": "79a43bee4e541f226dd438124f7a0d14f3169586",
28
+ "gitHead": "6e3e2a64fd59921011967c02bd5c68fa2aaa3a65",
29
29
  "devDependencies": {
30
30
  "nodemon": "^2.0.20"
31
31
  }