@@ -18,7 +18,7 @@ class vidbg {
18
18
* @param {object } options The options for the plugin
19
19
* @param {object } attributes The attributes for the HTML5 <video> attribute
20
20
*/
21
- constructor ( selector , options , attributes ) {
21
+ constructor ( selector , options , attributes ) {
22
22
if ( ! selector ) {
23
23
console . error ( 'Please provide a selector' )
24
24
return false
@@ -27,6 +27,11 @@ class vidbg {
27
27
// The element
28
28
this . el = document . querySelector ( selector )
29
29
30
+ if ( ! this . el ) {
31
+ console . error ( `The selector you specified, "${ selector } ", does not exist!` )
32
+ return false
33
+ }
34
+
30
35
// These are the default options for vidbg
31
36
const defaultOptions = {
32
37
mp4 : null ,
@@ -68,7 +73,7 @@ class vidbg {
68
73
/**
69
74
* init the video background to the DOM.
70
75
*/
71
- init ( ) {
76
+ init ( ) {
72
77
this . el . style . position = 'relative'
73
78
this . el . style . zIndex = 1
74
79
@@ -101,7 +106,7 @@ class vidbg {
101
106
if ( this . options . overlay ) {
102
107
const [ r , g , b ] = convert ( this . options . overlayColor , { format : 'array' } )
103
108
const rgba = [ r , g , b , this . options . overlayAlpha ]
104
-
109
+
105
110
this . overlayEl . style . backgroundColor = `rgba(${ rgba . join ( ', ' ) } )`
106
111
}
107
112
@@ -165,7 +170,7 @@ class vidbg {
165
170
*/
166
171
let playPromise = this . videoEl . play ( )
167
172
168
- if ( playPromise !== undefined ) {
173
+ if ( playPromise !== undefined ) {
169
174
playPromise
170
175
. catch ( err => {
171
176
console . error ( err )
@@ -196,6 +201,20 @@ class vidbg {
196
201
this . videoEl . remove ( )
197
202
}
198
203
204
+ /**
205
+ * Get the HTML <video> element
206
+ */
207
+ getVideo = ( ) => {
208
+ return this . videoEl
209
+ }
210
+
211
+ /**
212
+ * Destroy the vidbg instance
213
+ */
214
+ destroy = ( ) => {
215
+ this . containerEl . remove ( )
216
+ }
217
+
199
218
/**
200
219
* Our resize method on initial load and browser resize.
201
220
*/
0 commit comments