@total_onion/onion-library 3.0.49 → 3.1.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/components/block-post-info-v3/post-info-v3.js +1 -1
- package/components/block-video-content-v3/video-content-v3.js +1 -1
- package/onion-modalcontroller/README.md +2 -0
- package/onion-modalcontroller/onion-modalcontroller.js +183 -0
- package/onion-videocontroller/.prettierrc +22 -0
- package/onion-videocontroller/README.md +89 -0
- package/onion-videocontroller/breakpoints.scss +6 -0
- package/onion-videocontroller/core-functions-v3.scss +30 -0
- package/onion-videocontroller/core-mixins-v3.scss +744 -0
- package/onion-videocontroller/onion-videocontroller.js +240 -0
- package/onion-videocontroller/upload-video.mjs +251 -0
- package/onion-videocontroller/vc-styles.scss +282 -0
- package/onion-videocontroller/vcUtils.mjs +281 -0
- package/onion-videocontroller/vimeo-video.mjs +106 -0
- package/onion-videocontroller/youtube-video.mjs +157 -0
- package/package.json +2 -4
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
@use './core-mixins-v3';
|
|
2
|
+
@use './core-functions-v3';
|
|
3
|
+
@use './breakpoints';
|
|
4
|
+
|
|
5
|
+
@mixin basic() {
|
|
6
|
+
&__video-container {
|
|
7
|
+
display: grid;
|
|
8
|
+
grid-template: 'video' / 1fr;
|
|
9
|
+
grid-area: main;
|
|
10
|
+
opacity: 0;
|
|
11
|
+
pointer-events: none;
|
|
12
|
+
height: 100%;
|
|
13
|
+
width: 100%;
|
|
14
|
+
background-color: black;
|
|
15
|
+
transition: opacity 0.5s, background-color 1s;
|
|
16
|
+
z-index: -1;
|
|
17
|
+
|
|
18
|
+
@include core-mixins-v3.device(breakpoints.$tabPortrait) {
|
|
19
|
+
object-fit: cover;
|
|
20
|
+
grid-area: main;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&.video-playing {
|
|
24
|
+
pointer-events: all;
|
|
25
|
+
opacity: 1;
|
|
26
|
+
z-index: 10;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&.lock-video-aspect-to-image {
|
|
30
|
+
iframe,
|
|
31
|
+
video {
|
|
32
|
+
position: absolute;
|
|
33
|
+
inset: 0;
|
|
34
|
+
width: 100%;
|
|
35
|
+
height: 100%;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&.set-video-to-cover {
|
|
40
|
+
iframe,
|
|
41
|
+
video {
|
|
42
|
+
object-fit: cover;
|
|
43
|
+
object-position: center;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.loading-wrapper {
|
|
48
|
+
position: absolute;
|
|
49
|
+
left: 50%;
|
|
50
|
+
top: 50%;
|
|
51
|
+
transform: translate(-50%, -50%);
|
|
52
|
+
width: core-functions-v3.fluidSize(84);
|
|
53
|
+
height: core-functions-v3.fluidSize(84);
|
|
54
|
+
|
|
55
|
+
--spinner-bg-colour: #ffffff54;
|
|
56
|
+
--spinner-colour: white;
|
|
57
|
+
|
|
58
|
+
&:before {
|
|
59
|
+
content: '';
|
|
60
|
+
top: 0;
|
|
61
|
+
left: 0;
|
|
62
|
+
width: core-functions-v3.fluidSize(84);
|
|
63
|
+
height: core-functions-v3.fluidSize(84);
|
|
64
|
+
position: absolute;
|
|
65
|
+
border-radius: 50%;
|
|
66
|
+
border-right: solid core-functions-v3.fluidSize(5)
|
|
67
|
+
var(--spinner-bg-colour);
|
|
68
|
+
border-left: solid core-functions-v3.fluidSize(5)
|
|
69
|
+
var(--spinner-bg-colour);
|
|
70
|
+
border-top: solid core-functions-v3.fluidSize(5)
|
|
71
|
+
var(--spinner-bg-colour);
|
|
72
|
+
border-bottom: solid core-functions-v3.fluidSize(5)
|
|
73
|
+
var(--spinner-colour);
|
|
74
|
+
animation: rotate 1s linear infinite;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&__video-play-button {
|
|
80
|
+
grid-area: main;
|
|
81
|
+
place-self: center;
|
|
82
|
+
@include playButtonDefault();
|
|
83
|
+
transform: scale(1);
|
|
84
|
+
transition: transform 0.3s 0.5s;
|
|
85
|
+
|
|
86
|
+
&.video-playing {
|
|
87
|
+
transform: scale(0);
|
|
88
|
+
transition: transform 0.5s;
|
|
89
|
+
opacity: 0;
|
|
90
|
+
pointer-events: none;
|
|
91
|
+
max-height: 0px;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&__video-inner-container {
|
|
96
|
+
grid-area: video;
|
|
97
|
+
display: flex;
|
|
98
|
+
width: 100%;
|
|
99
|
+
position: relative;
|
|
100
|
+
|
|
101
|
+
iframe {
|
|
102
|
+
left: 0;
|
|
103
|
+
top: 0;
|
|
104
|
+
width: 100%;
|
|
105
|
+
height: 100%;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&__video-player {
|
|
110
|
+
height: auto;
|
|
111
|
+
object-fit: contain;
|
|
112
|
+
width: 100%;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@mixin modal() {
|
|
117
|
+
&.modal-video-playing {
|
|
118
|
+
overflow-y: hidden;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.cblvc-modal-container {
|
|
122
|
+
position: fixed;
|
|
123
|
+
z-index: 10;
|
|
124
|
+
inset: 0;
|
|
125
|
+
display: grid;
|
|
126
|
+
pointer-events: none;
|
|
127
|
+
grid-template: 'main' / 1fr;
|
|
128
|
+
place-items: center;
|
|
129
|
+
background-color: rgba(0, 0, 0, 0.601);
|
|
130
|
+
padding: var(--global-block-spacing) var(--global-inline-spacing);
|
|
131
|
+
|
|
132
|
+
@include core-mixins-v3.device(breakpoints.$desktop) {
|
|
133
|
+
padding: core-functions-v3.fluidSize(100);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
&.video-playing {
|
|
137
|
+
z-index: 999;
|
|
138
|
+
pointer-events: all;
|
|
139
|
+
|
|
140
|
+
.cblvc-modal-container__modal-close {
|
|
141
|
+
opacity: 1;
|
|
142
|
+
transition: opacity 1s 1s;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.cblvc-modal-container__modal-inner {
|
|
146
|
+
opacity: 1;
|
|
147
|
+
transition: opacity 1s 1s;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
&__modal-inner {
|
|
152
|
+
grid-area: main;
|
|
153
|
+
display: grid;
|
|
154
|
+
grid-template: 'modal' / 1fr;
|
|
155
|
+
background: var(--black);
|
|
156
|
+
opacity: 0;
|
|
157
|
+
transition: opacity 1s;
|
|
158
|
+
width: 100%;
|
|
159
|
+
max-width: core-functions-v3.fluidSize(1000);
|
|
160
|
+
|
|
161
|
+
@include core-mixins-v3.device(breakpoints.$tabPortrait) {
|
|
162
|
+
width: auto;
|
|
163
|
+
max-width: core-functions-v3.fluidSize(1000);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@include core-mixins-v3.device(breakpoints.$tabLandscape) {
|
|
167
|
+
max-width: core-functions-v3.fluidSize(1000);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
&__video-player {
|
|
172
|
+
grid-area: modal;
|
|
173
|
+
height: auto;
|
|
174
|
+
width: 100%;
|
|
175
|
+
max-height: 90vh;
|
|
176
|
+
|
|
177
|
+
@include core-mixins-v3.device(breakpoints.$tabPortrait) {
|
|
178
|
+
max-height: 80vh;
|
|
179
|
+
min-height: 50vh;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
&__modal-close {
|
|
184
|
+
grid-area: modal;
|
|
185
|
+
align-self: flex-start;
|
|
186
|
+
justify-self: flex-end;
|
|
187
|
+
z-index: 99;
|
|
188
|
+
transform: translate(50%, -50%);
|
|
189
|
+
@include closeButtonDefault();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
@mixin playButtonDefault() {
|
|
195
|
+
display: grid;
|
|
196
|
+
place-items: center;
|
|
197
|
+
background-color: white;
|
|
198
|
+
opacity: 1;
|
|
199
|
+
border-radius: 50px;
|
|
200
|
+
width: core-functions-v3.fluidSize(84);
|
|
201
|
+
height: core-functions-v3.fluidSize(84);
|
|
202
|
+
border: none;
|
|
203
|
+
z-index: 100;
|
|
204
|
+
padding: 0;
|
|
205
|
+
position: relative;
|
|
206
|
+
|
|
207
|
+
&:hover {
|
|
208
|
+
cursor: pointer;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
&::before {
|
|
212
|
+
position: absolute;
|
|
213
|
+
content: '';
|
|
214
|
+
height: core-functions-v3.fluidSize(34);
|
|
215
|
+
width: core-functions-v3.fluidSize(25);
|
|
216
|
+
transform: translateX(18%);
|
|
217
|
+
clip-path: polygon(100% 50%, 0 0, 0 100%);
|
|
218
|
+
background-color: black;
|
|
219
|
+
|
|
220
|
+
@supports not (aspect-ratio: 1/1) {
|
|
221
|
+
top: 50%;
|
|
222
|
+
left: 50%;
|
|
223
|
+
transform: translate(-25%, -50%);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
@mixin closeButtonDefault() {
|
|
229
|
+
transition: opacity 1s;
|
|
230
|
+
display: grid;
|
|
231
|
+
place-items: center;
|
|
232
|
+
background-color: white;
|
|
233
|
+
opacity: 1;
|
|
234
|
+
border-radius: 50px;
|
|
235
|
+
width: core-functions-v3.fluidSize(35);
|
|
236
|
+
height: core-functions-v3.fluidSize(35);
|
|
237
|
+
border: none;
|
|
238
|
+
z-index: 100;
|
|
239
|
+
padding: 0;
|
|
240
|
+
position: relative;
|
|
241
|
+
|
|
242
|
+
&:hover {
|
|
243
|
+
cursor: pointer;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
&::before {
|
|
247
|
+
position: absolute;
|
|
248
|
+
content: '';
|
|
249
|
+
height: core-functions-v3.fluidSize(20);
|
|
250
|
+
width: core-functions-v3.fluidSize(20);
|
|
251
|
+
clip-path: polygon(
|
|
252
|
+
15% 0,
|
|
253
|
+
0 15%,
|
|
254
|
+
35% 50%,
|
|
255
|
+
0 85%,
|
|
256
|
+
15% 100%,
|
|
257
|
+
50% 65%,
|
|
258
|
+
85% 100%,
|
|
259
|
+
100% 85%,
|
|
260
|
+
65% 50%,
|
|
261
|
+
100% 15%,
|
|
262
|
+
85% 0,
|
|
263
|
+
50% 35%
|
|
264
|
+
);
|
|
265
|
+
background-color: black;
|
|
266
|
+
|
|
267
|
+
@supports not (aspect-ratio: 1/1) {
|
|
268
|
+
top: 50%;
|
|
269
|
+
left: 50%;
|
|
270
|
+
transform: translate(-25%, -50%);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
@keyframes rotate {
|
|
276
|
+
0% {
|
|
277
|
+
transform: rotate(0deg);
|
|
278
|
+
}
|
|
279
|
+
100% {
|
|
280
|
+
transform: rotate(360deg);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
const enableDebugLogs = false;
|
|
2
|
+
|
|
3
|
+
export function dataLayerPush(eventData = { eventname: "", videoObject }) {
|
|
4
|
+
const videoType = eventData.videoObject.videotype;
|
|
5
|
+
let currentTime;
|
|
6
|
+
let duration;
|
|
7
|
+
let title;
|
|
8
|
+
let src;
|
|
9
|
+
let provider = "MediaLibrary";
|
|
10
|
+
|
|
11
|
+
if (videoType == "upload") {
|
|
12
|
+
currentTime = eventData.videoObject?.videoplayer?.currentTime;
|
|
13
|
+
duration = eventData.videoObject?.videoplayer?.duration;
|
|
14
|
+
src = eventData.videoObject?.videoplayer?.src;
|
|
15
|
+
title = src?.split("/").pop();
|
|
16
|
+
}
|
|
17
|
+
if (videoType == "youtube") {
|
|
18
|
+
provider = "YouTube";
|
|
19
|
+
currentTime = eventData.videoObject?.youtubeplayer?.getCurrentTime();
|
|
20
|
+
duration = eventData.videoObject?.youtubeplayer?.getDuration();
|
|
21
|
+
title = eventData.videoObject.youtubeplayer?.videoTitle;
|
|
22
|
+
src = eventData.videoObject.youtubeplayer.getVideoUrl();
|
|
23
|
+
}
|
|
24
|
+
if (videoType == "vimeo") {
|
|
25
|
+
provider = "Vimeo";
|
|
26
|
+
src = eventData.videoObject?.vimeoplayer?.src;
|
|
27
|
+
}
|
|
28
|
+
if (src.includes("imagekit")) {
|
|
29
|
+
provider = "ImageKit";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const timeDiv = Math.floor((currentTime / duration) * 100);
|
|
33
|
+
let percent;
|
|
34
|
+
if (timeDiv < 25 || !duration) {
|
|
35
|
+
percent = 0;
|
|
36
|
+
if (eventData.videoObject.completed == true) {
|
|
37
|
+
percent = 100;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (timeDiv >= 25 && timeDiv < 50) {
|
|
41
|
+
percent = 25;
|
|
42
|
+
}
|
|
43
|
+
if (timeDiv >= 50 && timeDiv < 75) {
|
|
44
|
+
percent = 50;
|
|
45
|
+
}
|
|
46
|
+
if (timeDiv >= 75 && timeDiv < 100) {
|
|
47
|
+
percent = 75;
|
|
48
|
+
}
|
|
49
|
+
if (currentTime == duration) {
|
|
50
|
+
percent = 100;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let status = eventData.eventname;
|
|
54
|
+
if (eventData.eventname == "play") {
|
|
55
|
+
status = "start";
|
|
56
|
+
}
|
|
57
|
+
if (eventData.eventname == "ended") {
|
|
58
|
+
status = "complete";
|
|
59
|
+
}
|
|
60
|
+
const autoplay = eventData.videoObject.autoplay;
|
|
61
|
+
const loop = eventData.videoObject.loop;
|
|
62
|
+
if (eventData.eventname == "pause" && currentTime == duration) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const dataObj = {
|
|
67
|
+
event: "gcms_video",
|
|
68
|
+
video_title: title,
|
|
69
|
+
video_status: status,
|
|
70
|
+
video_provider: provider,
|
|
71
|
+
video_url: src,
|
|
72
|
+
video_percent: percent,
|
|
73
|
+
video_visible: true,
|
|
74
|
+
video_current_time: currentTime,
|
|
75
|
+
video_duration: duration,
|
|
76
|
+
video_autoplay: autoplay ? true : false,
|
|
77
|
+
video_loop: loop ? true : false,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
window.dataLayer = window.dataLayer || [];
|
|
81
|
+
window.dataLayer.push(dataObj);
|
|
82
|
+
enableDebugLogs && console.log("🚀 ~ dataLayerPush ~ dataObj:", dataObj);
|
|
83
|
+
}
|
|
84
|
+
export function generateModal(videoObject) {
|
|
85
|
+
const { videocontainer, elementType } = videoObject;
|
|
86
|
+
let videoElementType = "";
|
|
87
|
+
switch (videoObject.videotype) {
|
|
88
|
+
case "upload":
|
|
89
|
+
videoElementType = "video";
|
|
90
|
+
break;
|
|
91
|
+
case "youtube":
|
|
92
|
+
videoElementType = "iframe";
|
|
93
|
+
break;
|
|
94
|
+
case "vimeo":
|
|
95
|
+
videoElementType = "iframe";
|
|
96
|
+
break;
|
|
97
|
+
|
|
98
|
+
default:
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
let modalVideoElement = document.createElement(videoElementType);
|
|
102
|
+
if (videocontainer) {
|
|
103
|
+
let videoPlayer = videocontainer.querySelector(elementType);
|
|
104
|
+
modalVideoElement = videoPlayer.cloneNode();
|
|
105
|
+
}
|
|
106
|
+
const modalContainer = document.createElement("div");
|
|
107
|
+
const modalInner = document.createElement("div");
|
|
108
|
+
const modalClose = document.createElement("button");
|
|
109
|
+
modalClose.addEventListener("click", () => {
|
|
110
|
+
stopVideos(videoObject, true);
|
|
111
|
+
});
|
|
112
|
+
modalVideoElement.classList.add("cblvc-modal-container__video-player");
|
|
113
|
+
modalContainer.classList.add("cblvc-modal-container");
|
|
114
|
+
modalInner.classList.add("cblvc-modal-container__modal-inner");
|
|
115
|
+
modalClose.classList.add("cblvc-modal-container__modal-close");
|
|
116
|
+
modalInner.appendChild(modalVideoElement);
|
|
117
|
+
modalInner.appendChild(modalClose);
|
|
118
|
+
modalContainer.appendChild(modalInner);
|
|
119
|
+
document.body.appendChild(modalContainer);
|
|
120
|
+
videoObject.modalcontainer = modalContainer;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function destroyModal(videoObject) {
|
|
124
|
+
const { modalcontainer } = videoObject;
|
|
125
|
+
modalcontainer.remove();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function isWpAdmin() {
|
|
129
|
+
return document.body.classList.contains("wp-admin") ? true : false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function revealVideoElement(videoObject) {
|
|
133
|
+
const {
|
|
134
|
+
videocontainer,
|
|
135
|
+
modal,
|
|
136
|
+
modalcontainer,
|
|
137
|
+
videoid,
|
|
138
|
+
isAdmin,
|
|
139
|
+
parentcontainer,
|
|
140
|
+
} = videoObject;
|
|
141
|
+
if (modal && !isAdmin) {
|
|
142
|
+
document.documentElement.classList.add("modal-video-playing");
|
|
143
|
+
addTriggerClass(videoObject, "video-playing");
|
|
144
|
+
modalcontainer.classList.add("video-playing");
|
|
145
|
+
} else {
|
|
146
|
+
document.body.classList.add("video-playing");
|
|
147
|
+
addTriggerClass(videoObject, "video-playing");
|
|
148
|
+
if (parentcontainer) {
|
|
149
|
+
parentcontainer.classList.add("video-playing");
|
|
150
|
+
}
|
|
151
|
+
videocontainer.classList.add("video-playing");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function hideVideoElement(videoObject) {
|
|
156
|
+
const {
|
|
157
|
+
videocontainer,
|
|
158
|
+
modal,
|
|
159
|
+
modalcontainer,
|
|
160
|
+
isAdmin,
|
|
161
|
+
parentcontainer,
|
|
162
|
+
videoid,
|
|
163
|
+
} = videoObject;
|
|
164
|
+
if (modal && !isAdmin) {
|
|
165
|
+
document.documentElement.classList.remove("modal-video-playing");
|
|
166
|
+
modalcontainer.classList.remove("video-playing");
|
|
167
|
+
setTimeout(() => {
|
|
168
|
+
modalcontainer.remove();
|
|
169
|
+
}, 1000);
|
|
170
|
+
videoObject.youtubeplayer = false;
|
|
171
|
+
removeTriggerClass(videoObject, "video-playing");
|
|
172
|
+
} else {
|
|
173
|
+
document.body.classList.remove("video-playing");
|
|
174
|
+
if (parentcontainer) {
|
|
175
|
+
parentcontainer.classList.remove("video-playing");
|
|
176
|
+
}
|
|
177
|
+
videocontainer.classList.remove("video-playing");
|
|
178
|
+
removeTriggerClass(videoObject, "video-playing");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
export function stopVideos(videoObject, stopEverything = false) {
|
|
182
|
+
const { videoid, instance } = videoObject;
|
|
183
|
+
enableDebugLogs && console.log("stopping all vids", stopEverything);
|
|
184
|
+
if (videoObject.modal && videoObject.modalcontainer && stopEverything) {
|
|
185
|
+
hideVideoElement(videoObject);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (!instance.containerCollection) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const keys = Object.keys(instance.containerCollection);
|
|
192
|
+
keys.forEach((key) => {
|
|
193
|
+
const collectionObject = instance.containerCollection[key];
|
|
194
|
+
if (
|
|
195
|
+
stopEverything ||
|
|
196
|
+
(collectionObject.videoid !== videoid && !collectionObject.autoplay)
|
|
197
|
+
) {
|
|
198
|
+
switch (collectionObject.videotype) {
|
|
199
|
+
case "upload":
|
|
200
|
+
collectionObject.videocontainer.querySelector("video").pause();
|
|
201
|
+
break;
|
|
202
|
+
case "youtube":
|
|
203
|
+
if (collectionObject.youtubeplayer) {
|
|
204
|
+
collectionObject.youtubeplayer.pauseVideo();
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
case "vimeo":
|
|
208
|
+
if (collectionObject.vimeoplayer) {
|
|
209
|
+
collectionObject.vimeoplayer.pause();
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
default:
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function removeTriggerClass(videoObject, classname) {
|
|
220
|
+
const { videoid, triggerScope } = videoObject;
|
|
221
|
+
triggerScope
|
|
222
|
+
.querySelectorAll(`[data-triggerid="${videoid}"]`)
|
|
223
|
+
.forEach((trigger) => {
|
|
224
|
+
trigger.classList.remove(classname);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
export function addTriggerClass(videoObject, classname) {
|
|
228
|
+
const { videoid, triggerScope } = videoObject;
|
|
229
|
+
triggerScope
|
|
230
|
+
.querySelectorAll(`[data-triggerid="${videoid}"]`)
|
|
231
|
+
.forEach((trigger) => {
|
|
232
|
+
trigger.classList.add(classname);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
export function addPlayingStateClasses(elements, classname) {
|
|
236
|
+
elements.forEach((element) => {
|
|
237
|
+
element.classList.add(classname);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
export function removePlayingStateClasses(elements, classname) {
|
|
241
|
+
elements.forEach((element) => {
|
|
242
|
+
element.classList.add(classname);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Function for adding a link tag with preconnect to the head of the document. Very useful if you need to add this dynamically.
|
|
248
|
+
* @param {string} domain The domain you wish to preconnect to.
|
|
249
|
+
* @returns {void} The preconnect will be appended to the head tag.
|
|
250
|
+
*/
|
|
251
|
+
export function appendPreconnect(domain) {
|
|
252
|
+
try {
|
|
253
|
+
if (!domain) {
|
|
254
|
+
console.log("The domain was missing or broken...");
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const link = document.createElement("link");
|
|
258
|
+
link.rel = "preconnect";
|
|
259
|
+
link.href = domain;
|
|
260
|
+
document.head.appendChild(link);
|
|
261
|
+
return;
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.error(error);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Run a function after a window resize event, but only after the alloted time has ended.
|
|
269
|
+
* If another resize even occurs it resets the time window.
|
|
270
|
+
* @param {function} debouncedFunction The function you want to run after a window resize event.
|
|
271
|
+
* @param {number} time The time in ms.
|
|
272
|
+
*/
|
|
273
|
+
export function resizeDebouncer(debouncedFunction, time = 250) {
|
|
274
|
+
let resizeTimer;
|
|
275
|
+
window.addEventListener("resize", () => {
|
|
276
|
+
clearTimeout(resizeTimer);
|
|
277
|
+
resizeTimer = setTimeout(() => {
|
|
278
|
+
debouncedFunction();
|
|
279
|
+
}, time);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import Player from "@vimeo/player";
|
|
2
|
+
import {
|
|
3
|
+
generateModal,
|
|
4
|
+
revealVideoElement,
|
|
5
|
+
hideVideoElement,
|
|
6
|
+
stopVideos,
|
|
7
|
+
resizeDebouncer
|
|
8
|
+
} from "./vcUtils.mjs";
|
|
9
|
+
|
|
10
|
+
const players = new Map();
|
|
11
|
+
|
|
12
|
+
function vimeoInit(videoObject) {
|
|
13
|
+
updateVimeoSource(videoObject);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function updateVimeoSource(videoObject) {
|
|
17
|
+
const { videocontainer, autoplay, muted, controls, loop, globalSettings } = videoObject;
|
|
18
|
+
const desktopUrl = videocontainer.dataset.vimeoDesktopUrl;
|
|
19
|
+
const mobileUrl = videocontainer.dataset.vimeoMobileUrl;
|
|
20
|
+
const srcDesktop = videocontainer.dataset.vimeodesktopid;
|
|
21
|
+
const srcMobile = videocontainer.dataset.vimeomobileid;
|
|
22
|
+
|
|
23
|
+
const vimeoUrl = window.innerWidth < globalSettings.srcBreakpoint && mobileUrl ? mobileUrl : desktopUrl;
|
|
24
|
+
const vimeoId = window.innerWidth < globalSettings.srcBreakpoint && srcMobile ? srcMobile : srcDesktop;
|
|
25
|
+
|
|
26
|
+
if (!vimeoId) {
|
|
27
|
+
console.error("No Vimeo ID found");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const playerId = `vimeo-${videoObject.videoid}-${srcDesktop}`;
|
|
32
|
+
videoObject.playerId = playerId;
|
|
33
|
+
|
|
34
|
+
const options = {
|
|
35
|
+
url: vimeoUrl,
|
|
36
|
+
autopause: autoplay === 1 ? 0 : 1,
|
|
37
|
+
autoplay,
|
|
38
|
+
muted,
|
|
39
|
+
controls,
|
|
40
|
+
loop,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
if (players.has(playerId)) {
|
|
44
|
+
const playerData = players.get(playerId);
|
|
45
|
+
playerData.player.loadVideo(vimeoId);
|
|
46
|
+
} else {
|
|
47
|
+
const player = new Player(playerId, options);
|
|
48
|
+
players.set(playerId, { initialized: true, player, videoObject });
|
|
49
|
+
setupEventListeners(videoObject);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function triggerVimeo(videoObject) {
|
|
54
|
+
const { playerId, modal, isAdmin, globalSettings } = videoObject;
|
|
55
|
+
|
|
56
|
+
if (modal && !isAdmin) {
|
|
57
|
+
generateModal(videoObject);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const playerData = players.get(playerId);
|
|
61
|
+
if (playerData) {
|
|
62
|
+
playerData.player.play();
|
|
63
|
+
globalSettings.enableDebugLogs &&
|
|
64
|
+
console.log(`Playing Vimeo video: ${playerId}`);
|
|
65
|
+
} else {
|
|
66
|
+
console.error(`Vimeo player not initialized for ${playerId}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function setupEventListeners(videoObject) {
|
|
71
|
+
const { playerId, globalSettings } = videoObject;
|
|
72
|
+
const player = players.get(playerId).player;
|
|
73
|
+
|
|
74
|
+
player.on("loadedmetadata", () => {
|
|
75
|
+
videoObject.instance.setVideoReadyState(videoObject, true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
player.on("play", () => {
|
|
79
|
+
globalSettings.enableDebugLogs && console.log("Playing the video");
|
|
80
|
+
stopVideos(videoObject);
|
|
81
|
+
revealVideoElement(videoObject);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
player.on("pause", () => {
|
|
85
|
+
globalSettings.enableDebugLogs && console.log("Pausing the video");
|
|
86
|
+
hideVideoElement(videoObject);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
player.on("ended", () => {
|
|
90
|
+
globalSettings.enableDebugLogs && console.log("Video ended");
|
|
91
|
+
hideVideoElement(videoObject);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
resizeDebouncer(() => {
|
|
96
|
+
players.forEach(({ videoObject }) => {
|
|
97
|
+
updateVimeoSource(videoObject);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const api = {
|
|
102
|
+
vimeoInit,
|
|
103
|
+
triggerVimeo,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default api;
|