-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtripletiseModal.js
146 lines (130 loc) · 5.99 KB
/
tripletiseModal.js
1
2
3
4
5
6
7
8
9
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
function injectModalHTML() {
const modalHTML = `
<div id="tripletise-modal" class="modal" style="display: none;">
<div class="modal-content">
<div class="modal-body">
<span class="close-btn" style="cursor: pointer; position: absolute; top: 20px; right: 20px; color: black;">
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#000">
<path d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"/>
</svg>
</span>
<span id="chevron-left" style="cursor: pointer; position: absolute; top: 15px; left: 15px; color: black; display: none;">
<svg xmlns="http://www.w3.org/2000/svg" height="40px" viewBox="0 -960 960 960" width="40px" fill="#000">
<path d="M560-240 320-480l240-240 56 56-184 184 184 184-56 56Z"/>
</svg>
</span>
<iframe id="iframe-src" src="" height="100%" width="100%" title="TripleDesign" allow="camera; accelerometer; gyroscope; xr-spatial-tracking; fullscreen"></iframe>
</div>
</div>
</div>
<style>
body.modal-open {
overflow: hidden;
}
.modal {
position: fixed;
z-index: 9999;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: hidden; /* Prevent scrolling */
background-color: rgba(0, 0, 0, 0.7);
margin: 0;
}
.modal-content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: white;
overflow: hidden;
display: flex;
flex-direction: column;
margin: 0;
border-radius: 0;
}
.modal-body {
flex-grow: 1;
position: relative;
padding: 0;
}
</style>
`;
document.body.insertAdjacentHTML('beforeend', modalHTML);
}
function adjustModalMargins() {
const modalContent = document.querySelector('.modal-content');
const chevronLeft = document.getElementById('chevron-left');
const closeBtn = document.querySelector('.close-btn');
// Adjust margins based on screen orientation
if (window.innerHeight > window.innerWidth) {
modalContent.style.margin = '0';
modalContent.style.width = '100%';
modalContent.style.height = '100%';
chevronLeft.style.display = 'block';
closeBtn.style.display = 'none';
} else {
modalContent.style.margin = '20px';
modalContent.style.width = 'calc(100% - 40px)';
modalContent.style.height = 'calc(100% - 40px)';
chevronLeft.style.display = 'none';
closeBtn.style.display = 'block';
}
}
function initializeTripleModal() {
window.tripletiseModal = function (srcUrl) {
const modal = document.getElementById("tripletise-modal");
const iframe = document.getElementById("iframe-src");
// Prevent opening the modal multiple times
if (modal.style.display === "block") {
return; // Modal is already open, no need to open again
}
modal.style.display = "block";
document.body.classList.add('modal-open');
adjustModalMargins();
iframe.src = `https://${srcUrl}`;
// Close button functionality
document.querySelector('.close-btn').onclick = () => closeModal();
// Close modal when clicking outside the content
window.onclick = (event) => {
if (event.target === modal) {
closeModal();
}
};
// Chevron close button functionality
document.getElementById('chevron-left').onclick = () => closeModal();
// Function to close the modal and reset body class
function closeModal() {
modal.style.display = "none";
document.body.classList.remove('modal-open');
}
};
// Automatically open modal if URL parameters are present
const urlParams = new URLSearchParams(window.location.search);
const brand = urlParams.get('brand');
const product = urlParams.get('product');
const id = urlParams.get('id');
const fsid = urlParams.get('fsid');
const data = urlParams.get('data');
if (brand && product) {
let modalUrl = `${brand}-${product}.web.app`; // Base URL for the iframe
// Prioritize fsid over data and id, then check for id or data
if (fsid) {
modalUrl += `?fsid=${fsid}`;
} else if (id) {
modalUrl += `?id=${id}`;
} else if (data) {
modalUrl += `?data=${data}`;
}
// Open the modal with the constructed URL
tripletiseModal(modalUrl);
}
}
// Initialize modal and listen for resize events
if (!document.getElementById("tripletise-modal")) {
injectModalHTML();
initializeTripleModal();
window.addEventListener('resize', adjustModalMargins);
}