@unlk/keymaster 1.2.5 → 1.2.6
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/CHANGELOG.md +5 -0
- package/dist/js/keymaster.js +16 -43
- package/dist/js/keymaster.js.map +1 -1
- package/dist/js/keymaster.min.js +6 -6
- package/dist/js/keymaster.min.js.map +1 -1
- package/js/video-modal.js +20 -41
- package/package.json +1 -1
package/js/video-modal.js
CHANGED
|
@@ -5,11 +5,12 @@ import { defineJQueryPlugin } from 'bootstrap/js/src/util/index.js';
|
|
|
5
5
|
|
|
6
6
|
const NAME = 'videoModal';
|
|
7
7
|
const DATA_KEY = 'bs.videoModal';
|
|
8
|
-
const
|
|
8
|
+
const EVENT_SHOW = 'show.bs.modal';
|
|
9
9
|
const EVENT_HIDDEN = 'hidden.bs.modal';
|
|
10
10
|
const SELECTOR_DIALOG = '.modal-dialog-media';
|
|
11
11
|
const SELECTOR_RATIO = '.ratio';
|
|
12
12
|
|
|
13
|
+
// eslint-disable-next-line no-unused-vars
|
|
13
14
|
let youTubeAPIReady = false;
|
|
14
15
|
const youTubeAPIInitPromise = new Promise((resolve) => {
|
|
15
16
|
if (window.YT?.Player) {
|
|
@@ -20,12 +21,14 @@ const youTubeAPIInitPromise = new Promise((resolve) => {
|
|
|
20
21
|
youTubeAPIReady = true;
|
|
21
22
|
resolve();
|
|
22
23
|
};
|
|
24
|
+
|
|
23
25
|
const script = document.createElement('script');
|
|
24
26
|
script.src = 'https://www.youtube.com/iframe_api';
|
|
25
27
|
document.head.append(script);
|
|
26
28
|
}
|
|
27
29
|
});
|
|
28
30
|
|
|
31
|
+
// eslint-disable-next-line no-unused-vars
|
|
29
32
|
let vimeoAPIReady = false;
|
|
30
33
|
const vimeoAPIInitPromise = new Promise((resolve) => {
|
|
31
34
|
if (window.Vimeo?.Player) {
|
|
@@ -38,6 +41,7 @@ const vimeoAPIInitPromise = new Promise((resolve) => {
|
|
|
38
41
|
vimeoAPIReady = true;
|
|
39
42
|
resolve();
|
|
40
43
|
});
|
|
44
|
+
|
|
41
45
|
document.head.append(script);
|
|
42
46
|
}
|
|
43
47
|
});
|
|
@@ -58,7 +62,7 @@ class VideoModal extends BaseComponent {
|
|
|
58
62
|
this._youtubePlayer = null;
|
|
59
63
|
this._vimeoPlayer = null;
|
|
60
64
|
|
|
61
|
-
EventHandler.on(this._element,
|
|
65
|
+
EventHandler.on(this._element, EVENT_SHOW, () => this._onShow());
|
|
62
66
|
EventHandler.on(this._element, EVENT_HIDDEN, () => this._onHide());
|
|
63
67
|
}
|
|
64
68
|
|
|
@@ -67,52 +71,27 @@ class VideoModal extends BaseComponent {
|
|
|
67
71
|
super.dispose();
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
async
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
async _onShow() {
|
|
75
|
+
const { id } = this._element;
|
|
76
|
+
const playerID = `video-${id}-youtube-player`;
|
|
73
77
|
|
|
74
78
|
if (this._vimeoUrl) {
|
|
75
79
|
await vimeoAPIInitPromise;
|
|
76
80
|
const vimeoId = this._getVimeoId(this._vimeoUrl);
|
|
77
|
-
if (!vimeoId) return;
|
|
78
81
|
this._vimeoPlayer = new window.Vimeo.Player(this._container, {
|
|
79
82
|
id: vimeoId,
|
|
80
|
-
autoplay: true
|
|
81
|
-
muted: true,
|
|
82
|
-
playsinline: true,
|
|
83
|
-
dnt: true
|
|
83
|
+
autoplay: true
|
|
84
84
|
});
|
|
85
|
-
|
|
85
|
+
return;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
if (this._youtubeSrc) {
|
|
89
89
|
await youTubeAPIInitPromise;
|
|
90
90
|
const youtubeId = this._getYouTubeId(this._youtubeSrc);
|
|
91
|
-
|
|
92
|
-
console.warn('[VideoModal] No YouTube ID parsed from', this._youtubeSrc);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const playerDiv = document.createElement('div');
|
|
97
|
-
playerDiv.className = 'w-100 h-100';
|
|
98
|
-
this._container.appendChild(playerDiv);
|
|
99
|
-
|
|
91
|
+
const playerDiv = this._container.querySelector(`#${playerID}`);
|
|
100
92
|
this._youtubePlayer = new window.YT.Player(playerDiv, {
|
|
101
93
|
videoId: youtubeId,
|
|
102
|
-
|
|
103
|
-
playerVars: {
|
|
104
|
-
autoplay: 1,
|
|
105
|
-
rel: 0,
|
|
106
|
-
playsinline: 1,
|
|
107
|
-
origin: window.location.origin
|
|
108
|
-
},
|
|
109
|
-
events: {
|
|
110
|
-
onReady: (e) => {
|
|
111
|
-
try { e.target.mute(); } catch {}
|
|
112
|
-
try { e.target.playVideo(); } catch {}
|
|
113
|
-
},
|
|
114
|
-
onError: (e) => console.warn('[VideoModal] YT error', e?.data)
|
|
115
|
-
}
|
|
94
|
+
playerVars: { autoplay: 1, rel: 0 }
|
|
116
95
|
});
|
|
117
96
|
}
|
|
118
97
|
}
|
|
@@ -122,22 +101,22 @@ class VideoModal extends BaseComponent {
|
|
|
122
101
|
this._vimeoPlayer.unload().catch(() => {});
|
|
123
102
|
this._vimeoPlayer = null;
|
|
124
103
|
}
|
|
104
|
+
|
|
125
105
|
if (this._youtubePlayer) {
|
|
126
|
-
|
|
106
|
+
this._youtubePlayer.destroy();
|
|
127
107
|
this._youtubePlayer = null;
|
|
128
108
|
}
|
|
129
|
-
this._container.innerHTML = '';
|
|
130
109
|
}
|
|
131
110
|
|
|
132
111
|
_getYouTubeId(url) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return
|
|
112
|
+
const match = url.match(
|
|
113
|
+
/(?:youtube\.com\/(?:watch\?v=|embed\/|v\/)|youtu\.be\/)([\w-]{11})/
|
|
114
|
+
);
|
|
115
|
+
return match ? match[1] : '';
|
|
137
116
|
}
|
|
138
117
|
|
|
139
118
|
_getVimeoId(url) {
|
|
140
|
-
const match =
|
|
119
|
+
const match = url.match(/vimeo\.com\/(\d+)/);
|
|
141
120
|
return match ? match[1] : '';
|
|
142
121
|
}
|
|
143
122
|
|