sfc-utils 1.4.119 → 1.4.121

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/regwall.js +60 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sfc-utils",
3
- "version": "1.4.119",
3
+ "version": "1.4.121",
4
4
  "author": "ewagstaff <evanjwagstaff@gmail.com>",
5
5
  "dependencies": {
6
6
  "archieml": "^0.4.2",
package/regwall.js ADDED
@@ -0,0 +1,60 @@
1
+ // NOTE: Script meant to be called when the regwall is requested
2
+ // This script will listen for a successful registration, then run a function passed to it
3
+ const listenForRegSuccess = (resultFunc, resultParams) => {
4
+ return new Promise((resolve, reject) => {
5
+ if (window) {
6
+ let attempts = 0;
7
+ const checkForTarget = (innerResolve) => {
8
+ // Select the target element
9
+ const targetElement = document.querySelector(".bc_regwall_box");
10
+ if (targetElement) {
11
+ // Set up intersection observer
12
+ // Define the callback function
13
+ const observerCallback = (entries, observer) => {
14
+ entries.forEach((entry) => {
15
+ if (!entry.isIntersecting) {
16
+ // Wait for element to leave view, run the provided function
17
+ console.log("Element is out of view!");
18
+ // Perform your action here
19
+ resultFunc(resultParams);
20
+ innerResolve(true);
21
+ }
22
+ });
23
+ };
24
+
25
+ // Create a new IntersectionObserver
26
+ const observerOptions = {
27
+ root: null, // Use the viewport as the root
28
+ threshold: 0, // 0 means trigger when the element is out of view
29
+ };
30
+ const observer = new IntersectionObserver(
31
+ observerCallback,
32
+ observerOptions
33
+ );
34
+
35
+ // Start observing the target element
36
+ observer.observe(targetElement);
37
+ } else {
38
+ // If the target element isn't found, try again
39
+ attempts++;
40
+ if (attempts < 20) {
41
+ // Check for target every second
42
+ setTimeout(() => {
43
+ checkForTarget(innerResolve);
44
+ }, 200);
45
+ } else {
46
+ innerResolve("Regwall: No target found after many attempts");
47
+ }
48
+ }
49
+ };
50
+ // Kick off check
51
+ checkForTarget(resolve);
52
+ } else {
53
+ resolve("Regwall: No window found");
54
+ }
55
+ });
56
+ };
57
+
58
+ module.exports = {
59
+ listenForRegSuccess,
60
+ };