notify-me-wl 1.2.1 → 1.3.0
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/README.md +170 -161
- package/index.html +1 -1
- package/index.js +147 -141
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
This JavaScript widget allows users to register their interest in a product that is either "coming soon" or "out of stock". Depending on the `data-type` attribute provided, the widget will display appropriate messages and functionality.
|
|
4
4
|
|
|
5
5
|
#### Features:
|
|
6
|
-
- Dynamically display a form to collect user information (
|
|
6
|
+
- Dynamically display a form to collect user information (mobile, first name, last name).
|
|
7
7
|
- Adjust form and button text based on the widget type (`notify-me` or `coming-soon`).
|
|
8
8
|
- Submit user data to a specified API endpoint with email or mobile as a path parameter and appropriate query parameters.
|
|
9
9
|
|
|
@@ -21,19 +21,19 @@ Add a button to your HTML where you want the widget to appear. The button should
|
|
|
21
21
|
|
|
22
22
|
```html
|
|
23
23
|
<div id="notification-widget"></div>
|
|
24
|
-
<button id="popup-open" data-fields='["
|
|
24
|
+
<button id="popup-open" data-fields='["mobile", "firstName", "lastName"]' data-type="notify-me">Open Popup</button>
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
### Configuration
|
|
28
28
|
|
|
29
|
-
- `data-fields`: A JSON array specifying the fields to include in the form. Possible values are `"
|
|
29
|
+
- `data-fields`: A JSON array specifying the fields to include in the form. Possible values are `"mobile"`, `"firstName"`, and `"lastName"`.
|
|
30
30
|
- `data-type`: Specifies the type of the widget. Possible values are `"notify-me"` and `"coming-soon"`.
|
|
31
31
|
|
|
32
32
|
### Example
|
|
33
33
|
|
|
34
34
|
```html
|
|
35
35
|
<div id="notification-widget"></div>
|
|
36
|
-
<button id="popup-open" data-fields='["
|
|
36
|
+
<button id="popup-open" data-fields='["mobile"]' data-type="notify-me">Open Popup</button>
|
|
37
37
|
|
|
38
38
|
<script>
|
|
39
39
|
// The script provided will be included here
|
|
@@ -46,30 +46,27 @@ Add a button to your HTML where you want the widget to appear. The button should
|
|
|
46
46
|
2. **Styles Injection**: It injects necessary styles for the modal and form elements.
|
|
47
47
|
3. **Modal Creation**: Creates the modal structure and appends it to the `notification-widget` div.
|
|
48
48
|
4. **Dynamic Content**: Based on the `data-type`, it sets the appropriate messages and button text.
|
|
49
|
-
5. **Form Submission**: Collects form data and submits it to the API with the email
|
|
49
|
+
5. **Form Submission**: Collects form data and submits it to the API with the mandatory email field and other possible fields.
|
|
50
50
|
|
|
51
|
-
### API Request Example
|
|
51
|
+
### API Request Example
|
|
52
52
|
|
|
53
|
-
For email:
|
|
54
53
|
```
|
|
55
|
-
https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
For mobile:
|
|
59
|
-
```
|
|
60
|
-
https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest/{mobile}?isMobile=true
|
|
54
|
+
https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest
|
|
61
55
|
```
|
|
62
56
|
|
|
63
57
|
### Full Script
|
|
64
58
|
|
|
65
59
|
```javascript
|
|
66
|
-
|
|
60
|
+
// Access token for the API
|
|
61
|
+
const ACCESS_TOKEN = "123"; // Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
|
|
62
|
+
const TENANT_ID = "viktoria-woods"; // Replace `TENANT_ID` with your actual tenant ID.
|
|
67
63
|
|
|
68
64
|
document.addEventListener("DOMContentLoaded", function () {
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
const wrapper = document.getElementById("notification-widget");
|
|
66
|
+
if (!wrapper) return;
|
|
71
67
|
|
|
72
|
-
|
|
68
|
+
// Define and apply styles for the popup and button
|
|
69
|
+
const styles = `
|
|
73
70
|
.notification-btn {
|
|
74
71
|
background-color: #fff;
|
|
75
72
|
border: 1px solid black;
|
|
@@ -184,13 +181,14 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
184
181
|
}
|
|
185
182
|
`;
|
|
186
183
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
184
|
+
const styleSheet = document.createElement("style");
|
|
185
|
+
styleSheet.type = "text/css";
|
|
186
|
+
styleSheet.innerText = styles;
|
|
187
|
+
document.head.appendChild(styleSheet);
|
|
191
188
|
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
// Create and append the overlay for the popup
|
|
190
|
+
const overlay = document.createElement("div");
|
|
191
|
+
overlay.innerHTML = `
|
|
194
192
|
<div id="popup-body" class="overlay">
|
|
195
193
|
<div id="popup-wrapper">
|
|
196
194
|
<h3 id="popup-title"></h3>
|
|
@@ -201,151 +199,162 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
201
199
|
<select name="select-size" required>
|
|
202
200
|
</select>
|
|
203
201
|
</div>
|
|
202
|
+
<input name="email" placeholder="Email" type="email" required />
|
|
204
203
|
</form>
|
|
205
204
|
</div>
|
|
206
205
|
</div>
|
|
207
206
|
`;
|
|
208
207
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
type="
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
formData.isMobile = true;
|
|
315
|
-
contactInfo = formData.mobile;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
let url = `https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest/${contactInfo}?notifyMe=true`;
|
|
319
|
-
if (formData.isMobile) {
|
|
320
|
-
url += "&isMobile=true";
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
fetch(url, {
|
|
324
|
-
method: "POST",
|
|
325
|
-
headers: {
|
|
326
|
-
"Content-Type": "application/json",
|
|
327
|
-
Authorization: ACCESS_TOKEN,
|
|
328
|
-
},
|
|
329
|
-
body: JSON.stringify(formData),
|
|
330
|
-
})
|
|
331
|
-
.then((response) => {
|
|
332
|
-
if (response.ok) {
|
|
333
|
-
alert("Form submitted");
|
|
334
|
-
hidePopup();
|
|
335
|
-
} else {
|
|
336
|
-
alert("Form submission failed");
|
|
337
|
-
}
|
|
338
|
-
})
|
|
339
|
-
.catch((error) => {
|
|
340
|
-
console.error("Error submitting form:", error);
|
|
341
|
-
alert("Form submission failed");
|
|
342
|
-
});
|
|
208
|
+
wrapper.appendChild(overlay);
|
|
209
|
+
|
|
210
|
+
const popupBody = document.getElementById("popup-body");
|
|
211
|
+
const popupClose = document.getElementById("popup-close");
|
|
212
|
+
const popupOpenButton = document.getElementById("popup-open");
|
|
213
|
+
const popupTitle = document.getElementById("popup-title");
|
|
214
|
+
const popupText = document.getElementById("popup-text");
|
|
215
|
+
const sizeSelect = document.querySelector("select[name='select-size']");
|
|
216
|
+
const form = overlay.querySelector("#popup-form");
|
|
217
|
+
|
|
218
|
+
if (!popupBody || !popupClose || !popupOpenButton || !popupTitle || !sizeSelect) return;
|
|
219
|
+
|
|
220
|
+
// Parse fields and type to be included in the form from data attribute
|
|
221
|
+
const fields = JSON.parse(popupOpenButton.getAttribute("data-fields") || '["email"]');
|
|
222
|
+
const type = popupOpenButton.getAttribute("data-type") || "notify-me";
|
|
223
|
+
const typeConfig = {
|
|
224
|
+
"notify-me": {
|
|
225
|
+
text: "Register to receive a notification as soon as this item is back in stock",
|
|
226
|
+
buttonText: "Notify me",
|
|
227
|
+
},
|
|
228
|
+
"coming-soon": {
|
|
229
|
+
text: "Register your interest to hear more about this item",
|
|
230
|
+
buttonText: "Register Interest",
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// Get product data from Shopify's global variable
|
|
235
|
+
const productData = window.Shopify?.product || {
|
|
236
|
+
id: "6786188247105",
|
|
237
|
+
title: "THE ATG SCULPT FLARES TALL",
|
|
238
|
+
product_option_value: {
|
|
239
|
+
name: "BUTTER BLACK",
|
|
240
|
+
},
|
|
241
|
+
variants: [
|
|
242
|
+
{ id: 1, title: "S" },
|
|
243
|
+
{ id: "40216683806854", title: "M" },
|
|
244
|
+
{ id: 3, title: "L" },
|
|
245
|
+
{ id: 4, title: "XL" },
|
|
246
|
+
],
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// Set the popup title and populate the size dropdown
|
|
250
|
+
popupTitle.innerHTML = productData.title + "<br/>" + productData.product_option_value.name;
|
|
251
|
+
productData.variants.forEach((variant) => {
|
|
252
|
+
const option = document.createElement("option");
|
|
253
|
+
option.value = variant.title;
|
|
254
|
+
option.textContent = variant.title;
|
|
255
|
+
sizeSelect.appendChild(option);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// Map for form fields
|
|
259
|
+
popupText.innerText = typeConfig[type].text;
|
|
260
|
+
|
|
261
|
+
const fieldMap = {
|
|
262
|
+
email: `<input name="email" placeholder="Email" type="email" required />`,
|
|
263
|
+
mobile: `<input name="mobile" placeholder="Mobile" type="tel" />`,
|
|
264
|
+
firstName: `<input name="firstName" placeholder="First name" type="text" />`,
|
|
265
|
+
lastName: `<input name="lastName" placeholder="Last name" type="text" />`,
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// Add fields to the form based on the parsed fields
|
|
269
|
+
fields.forEach((field) => {
|
|
270
|
+
if (fieldMap[field]) {
|
|
271
|
+
form.insertAdjacentHTML("beforeend", fieldMap[field]);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
form.insertAdjacentHTML("beforeend", `<div id="checkbox-wrapper"></div>`);
|
|
276
|
+
const checkboxWrapper = document.getElementById("checkbox-wrapper");
|
|
277
|
+
checkboxWrapper.insertAdjacentHTML("beforeend", `<input type="checkbox" name="mailList" id="mailList" />`);
|
|
278
|
+
checkboxWrapper.insertAdjacentHTML("beforeend", `<label for="mailList">Subscribe to our mailing list</label>`);
|
|
279
|
+
form.insertAdjacentHTML("beforeend", `<button type="submit">${typeConfig[type].buttonText}</button>`);
|
|
280
|
+
|
|
281
|
+
// Show/hide the popup
|
|
282
|
+
function showPopup() {
|
|
283
|
+
popupBody.style.visibility = "visible";
|
|
284
|
+
popupBody.style.opacity = 1;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function hidePopup() {
|
|
288
|
+
popupBody.style.visibility = "hidden";
|
|
289
|
+
popupBody.style.opacity = 0;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
popupOpenButton.addEventListener("click", showPopup);
|
|
293
|
+
popupClose.addEventListener("click", hidePopup);
|
|
294
|
+
|
|
295
|
+
// Form submission handler
|
|
296
|
+
if (form) {
|
|
297
|
+
form.addEventListener("submit", function (event) {
|
|
298
|
+
event.preventDefault();
|
|
299
|
+
|
|
300
|
+
const selectedSize = sizeSelect.value;
|
|
301
|
+
const selectedVariant = productData.variants.find((variant) => variant.title === selectedSize);
|
|
302
|
+
|
|
303
|
+
if (selectedVariant) {
|
|
304
|
+
const formData = {
|
|
305
|
+
variantRef: selectedVariant.id,
|
|
306
|
+
email: form.querySelector("input[name='email']").value,
|
|
307
|
+
subscribe: form.querySelector("input[name='mailList']").checked,
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
if (type === "coming-soon") {
|
|
311
|
+
formData.comingSoon = true;
|
|
312
|
+
formData.productRef = productData.id;
|
|
343
313
|
} else {
|
|
344
|
-
|
|
314
|
+
formData.notifyMe = true;
|
|
315
|
+
}
|
|
316
|
+
if (fields.includes("firstName")) {
|
|
317
|
+
formData.firstName = form.querySelector("input[name='firstName']").value;
|
|
345
318
|
}
|
|
346
|
-
|
|
347
|
-
|
|
319
|
+
if (fields.includes("lastName")) {
|
|
320
|
+
formData.lastName = form.querySelector("input[name='lastName']").value;
|
|
321
|
+
}
|
|
322
|
+
if (fields.includes("mobile")) {
|
|
323
|
+
formData.mobile = form.querySelector("input[name='mobile']").value;
|
|
324
|
+
formData.phone = form.querySelector("input[name='mobile']").value;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
let url = `https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest`;
|
|
328
|
+
|
|
329
|
+
fetch(url, {
|
|
330
|
+
method: "POST",
|
|
331
|
+
headers: {
|
|
332
|
+
"Content-Type": "application/json",
|
|
333
|
+
Authorization: ACCESS_TOKEN,
|
|
334
|
+
"X-Twc-Tenant": TENANT_ID,
|
|
335
|
+
},
|
|
336
|
+
body: JSON.stringify(formData),
|
|
337
|
+
})
|
|
338
|
+
.then((response) => {
|
|
339
|
+
if (response.ok) {
|
|
340
|
+
alert("Form submitted");
|
|
341
|
+
hidePopup();
|
|
342
|
+
} else {
|
|
343
|
+
alert("Form submission failed");
|
|
344
|
+
}
|
|
345
|
+
})
|
|
346
|
+
.catch((error) => {
|
|
347
|
+
console.error("Error submitting form:", error);
|
|
348
|
+
alert("Form submission failed");
|
|
349
|
+
});
|
|
350
|
+
} else {
|
|
351
|
+
alert("Selected variant not found");
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
}
|
|
348
355
|
});
|
|
356
|
+
|
|
349
357
|
```
|
|
350
358
|
|
|
351
|
-
Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
|
|
359
|
+
Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
|
|
360
|
+
Replace `TENANT_ID` with your actual tenant to authenticate API requests.
|
package/index.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="notification-widget">
|
|
17
|
-
<button id="popup-open" class="notification-btn" type="button" data-type="notify-me" data-fields='["
|
|
17
|
+
<button id="popup-open" class="notification-btn" type="button" data-type="notify-me" data-fields='["mobile", "firstName", "lastName"]'>Notify Me - Join Waitlist</button>
|
|
18
18
|
</div>
|
|
19
19
|
</body>
|
|
20
20
|
<script src="/index.js"></script>
|
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Access token for the API
|
|
2
2
|
const ACCESS_TOKEN = "123"; // Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
|
|
3
|
+
const TENANT_ID = "viktoria-woods"; // Replace `TENANT_ID` with your actual tenant ID.
|
|
3
4
|
|
|
4
5
|
document.addEventListener("DOMContentLoaded", function () {
|
|
5
6
|
const wrapper = document.getElementById("notification-widget");
|
|
@@ -7,119 +8,119 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
7
8
|
|
|
8
9
|
// Define and apply styles for the popup and button
|
|
9
10
|
const styles = `
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
11
|
+
.notification-btn {
|
|
12
|
+
background-color: #fff;
|
|
13
|
+
border: 1px solid black;
|
|
14
|
+
color: black;
|
|
15
|
+
padding: 12px 24px;
|
|
16
|
+
text-align: center;
|
|
17
|
+
width: 100%;
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
text-transform: uppercase;
|
|
20
|
+
}
|
|
21
|
+
#popup-body.overlay {
|
|
22
|
+
position: fixed;
|
|
23
|
+
top: 0;
|
|
24
|
+
bottom: 0;
|
|
25
|
+
left: 0;
|
|
26
|
+
right: 0;
|
|
27
|
+
background: rgba(0, 0, 0, 0.7);
|
|
28
|
+
transition: opacity 200ms;
|
|
29
|
+
visibility: hidden;
|
|
30
|
+
opacity: 0;
|
|
31
|
+
}
|
|
32
|
+
#popup-wrapper {
|
|
33
|
+
margin: 70px auto;
|
|
34
|
+
padding: 15px;
|
|
35
|
+
background: #fff;
|
|
36
|
+
border-radius: 5px;
|
|
37
|
+
max-width: 360px;
|
|
38
|
+
position: relative;
|
|
39
|
+
}
|
|
40
|
+
#popup-close {
|
|
41
|
+
position: absolute;
|
|
42
|
+
top: 5px;
|
|
43
|
+
right: 15px;
|
|
44
|
+
transition: all 200ms;
|
|
45
|
+
font-size: 30px;
|
|
46
|
+
font-weight: bold;
|
|
47
|
+
text-decoration: none;
|
|
48
|
+
color: #333;
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
}
|
|
51
|
+
#popup-close:hover {
|
|
52
|
+
color: #d80606;
|
|
53
|
+
}
|
|
54
|
+
#popup-title {
|
|
55
|
+
margin: 0;
|
|
56
|
+
font-size: 20px;
|
|
57
|
+
max-width: 350px;
|
|
58
|
+
text-transform: uppercase;
|
|
59
|
+
}
|
|
60
|
+
#popup-text {
|
|
61
|
+
margin: 10px 0;
|
|
62
|
+
font-size: 14px;
|
|
63
|
+
}
|
|
64
|
+
#popup-form {
|
|
65
|
+
display: flex;
|
|
66
|
+
flex-direction: column;
|
|
67
|
+
gap: 10px;
|
|
68
|
+
}
|
|
69
|
+
#popup-form input {
|
|
70
|
+
padding: 0.475em 1em;
|
|
71
|
+
border: 1px solid #caced1;
|
|
72
|
+
border-radius: 0.25rem;
|
|
73
|
+
font-size: 1.15rem;
|
|
74
|
+
max-width: 100%;
|
|
75
|
+
}
|
|
76
|
+
#popup-form input::placeholder {
|
|
77
|
+
font-size: 1rem;
|
|
78
|
+
}
|
|
79
|
+
#popup-form button {
|
|
80
|
+
font-size: 0.85rem;
|
|
81
|
+
padding: 0.975em 1em;
|
|
82
|
+
font-weight: 600;
|
|
83
|
+
border: none;
|
|
84
|
+
text-transform: uppercase;
|
|
85
|
+
background: #aca475;
|
|
86
|
+
color: #fff;
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
}
|
|
89
|
+
.custom-select {
|
|
90
|
+
position: relative;
|
|
91
|
+
}
|
|
92
|
+
.custom-select select {
|
|
93
|
+
appearance: none;
|
|
94
|
+
width: 100%;
|
|
95
|
+
font-size: 1.15rem;
|
|
96
|
+
padding: 0.475em 1em;
|
|
97
|
+
background-color: #fff;
|
|
98
|
+
border: 1px solid #caced1;
|
|
99
|
+
border-radius: 0.25rem;
|
|
100
|
+
color: #000;
|
|
101
|
+
cursor: pointer;
|
|
102
|
+
}
|
|
103
|
+
.custom-select::before,
|
|
104
|
+
.custom-select::after {
|
|
105
|
+
--size: 0.3rem;
|
|
106
|
+
content: "";
|
|
107
|
+
position: absolute;
|
|
108
|
+
right: 1rem;
|
|
109
|
+
pointer-events: none;
|
|
110
|
+
}
|
|
111
|
+
.custom-select::before {
|
|
112
|
+
border-left: var(--size) solid transparent;
|
|
113
|
+
border-right: var(--size) solid transparent;
|
|
114
|
+
border-bottom: var(--size) solid black;
|
|
115
|
+
top: 40%;
|
|
116
|
+
}
|
|
117
|
+
.custom-select::after {
|
|
118
|
+
border-left: var(--size) solid transparent;
|
|
119
|
+
border-right: var(--size) solid transparent;
|
|
120
|
+
border-top: var(--size) solid black;
|
|
121
|
+
top: 55%;
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
123
124
|
|
|
124
125
|
const styleSheet = document.createElement("style");
|
|
125
126
|
styleSheet.type = "text/css";
|
|
@@ -129,20 +130,21 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
129
130
|
// Create and append the overlay for the popup
|
|
130
131
|
const overlay = document.createElement("div");
|
|
131
132
|
overlay.innerHTML = `
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
</div>
|
|
142
|
-
</form>
|
|
133
|
+
<div id="popup-body" class="overlay">
|
|
134
|
+
<div id="popup-wrapper">
|
|
135
|
+
<h3 id="popup-title"></h3>
|
|
136
|
+
<span id="popup-close">×</span>
|
|
137
|
+
<div id="popup-text"></div>
|
|
138
|
+
<form id="popup-form">
|
|
139
|
+
<div class="custom-select">
|
|
140
|
+
<select name="select-size" required>
|
|
141
|
+
</select>
|
|
143
142
|
</div>
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
<input name="email" placeholder="Email" type="email" required />
|
|
144
|
+
</form>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
`;
|
|
146
148
|
|
|
147
149
|
wrapper.appendChild(overlay);
|
|
148
150
|
|
|
@@ -172,14 +174,14 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
172
174
|
|
|
173
175
|
// Get product data from Shopify's global variable
|
|
174
176
|
const productData = window.Shopify?.product || {
|
|
175
|
-
id: 6786188247105,
|
|
177
|
+
id: "6786188247105",
|
|
176
178
|
title: "THE ATG SCULPT FLARES TALL",
|
|
177
179
|
product_option_value: {
|
|
178
180
|
name: "BUTTER BLACK",
|
|
179
181
|
},
|
|
180
182
|
variants: [
|
|
181
183
|
{ id: 1, title: "S" },
|
|
182
|
-
{ id:
|
|
184
|
+
{ id: "40216683806854", title: "M" },
|
|
183
185
|
{ id: 3, title: "L" },
|
|
184
186
|
{ id: 4, title: "XL" },
|
|
185
187
|
],
|
|
@@ -195,20 +197,13 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
195
197
|
});
|
|
196
198
|
|
|
197
199
|
// Map for form fields
|
|
198
|
-
popupTitle.innerHTML = productData.title + "<br/>" + productData.product_option_value.name;
|
|
199
200
|
popupText.innerText = typeConfig[type].text;
|
|
200
|
-
productData.variants.forEach((variant) => {
|
|
201
|
-
const option = document.createElement("option");
|
|
202
|
-
option.value = variant.title;
|
|
203
|
-
option.textContent = variant.title;
|
|
204
|
-
sizeSelect.appendChild(option);
|
|
205
|
-
});
|
|
206
201
|
|
|
207
202
|
const fieldMap = {
|
|
208
203
|
email: `<input name="email" placeholder="Email" type="email" required />`,
|
|
209
|
-
mobile: `<input name="mobile" placeholder="Mobile" type="tel"
|
|
210
|
-
firstName: `<input name="firstName" placeholder="First name" type="text"
|
|
211
|
-
lastName: `<input name="lastName" placeholder="Last name" type="text"
|
|
204
|
+
mobile: `<input name="mobile" placeholder="Mobile" type="tel" />`,
|
|
205
|
+
firstName: `<input name="firstName" placeholder="First name" type="text" />`,
|
|
206
|
+
lastName: `<input name="lastName" placeholder="Last name" type="text" />`,
|
|
212
207
|
};
|
|
213
208
|
|
|
214
209
|
// Add fields to the form based on the parsed fields
|
|
@@ -217,6 +212,11 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
217
212
|
form.insertAdjacentHTML("beforeend", fieldMap[field]);
|
|
218
213
|
}
|
|
219
214
|
});
|
|
215
|
+
|
|
216
|
+
form.insertAdjacentHTML("beforeend", `<div id="checkbox-wrapper"></div>`);
|
|
217
|
+
const checkboxWrapper = document.getElementById("checkbox-wrapper");
|
|
218
|
+
checkboxWrapper.insertAdjacentHTML("beforeend", `<input type="checkbox" name="mailList" id="mailList" />`);
|
|
219
|
+
checkboxWrapper.insertAdjacentHTML("beforeend", `<label for="mailList">Subscribe to our mailing list</label>`);
|
|
220
220
|
form.insertAdjacentHTML("beforeend", `<button type="submit">${typeConfig[type].buttonText}</button>`);
|
|
221
221
|
|
|
222
222
|
// Show/hide the popup
|
|
@@ -243,12 +243,16 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
243
243
|
|
|
244
244
|
if (selectedVariant) {
|
|
245
245
|
const formData = {
|
|
246
|
-
productRef: productData.id,
|
|
247
246
|
variantRef: selectedVariant.id,
|
|
247
|
+
email: form.querySelector("input[name='email']").value,
|
|
248
|
+
subscribe: form.querySelector("input[name='mailList']").checked,
|
|
248
249
|
};
|
|
249
250
|
|
|
250
|
-
if (
|
|
251
|
-
formData.
|
|
251
|
+
if (type === "coming-soon") {
|
|
252
|
+
formData.comingSoon = true;
|
|
253
|
+
formData.productRef = productData.id;
|
|
254
|
+
} else {
|
|
255
|
+
formData.notifyMe = true;
|
|
252
256
|
}
|
|
253
257
|
if (fields.includes("firstName")) {
|
|
254
258
|
formData.firstName = form.querySelector("input[name='firstName']").value;
|
|
@@ -258,6 +262,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
258
262
|
}
|
|
259
263
|
if (fields.includes("mobile")) {
|
|
260
264
|
formData.mobile = form.querySelector("input[name='mobile']").value;
|
|
265
|
+
formData.phone = form.querySelector("input[name='mobile']").value;
|
|
261
266
|
}
|
|
262
267
|
|
|
263
268
|
let url = `https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest`;
|
|
@@ -267,6 +272,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
|
267
272
|
headers: {
|
|
268
273
|
"Content-Type": "application/json",
|
|
269
274
|
Authorization: ACCESS_TOKEN,
|
|
275
|
+
"X-Twc-Tenant": TENANT_ID,
|
|
270
276
|
},
|
|
271
277
|
body: JSON.stringify(formData),
|
|
272
278
|
})
|