Skip to content

Commit bae44c3

Browse files
committed
Error handling and helper methods
1 parent 3861b8c commit bae44c3

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

dist/vidbg.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vidbg.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class vidbg {
1818
* @param {object} options The options for the plugin
1919
* @param {object} attributes The attributes for the HTML5 <video> attribute
2020
*/
21-
constructor (selector, options, attributes) {
21+
constructor(selector, options, attributes) {
2222
if (!selector) {
2323
console.error('Please provide a selector')
2424
return false
@@ -27,6 +27,11 @@ class vidbg {
2727
// The element
2828
this.el = document.querySelector(selector)
2929

30+
if (!this.el) {
31+
console.error(`The selector you specified, "${selector}", does not exist!`)
32+
return false
33+
}
34+
3035
// These are the default options for vidbg
3136
const defaultOptions = {
3237
mp4: null,
@@ -68,7 +73,7 @@ class vidbg {
6873
/**
6974
* init the video background to the DOM.
7075
*/
71-
init () {
76+
init() {
7277
this.el.style.position = 'relative'
7378
this.el.style.zIndex = 1
7479

@@ -101,7 +106,7 @@ class vidbg {
101106
if (this.options.overlay) {
102107
const [r, g, b] = convert(this.options.overlayColor, { format: 'array' })
103108
const rgba = [r, g, b, this.options.overlayAlpha]
104-
109+
105110
this.overlayEl.style.backgroundColor = `rgba(${rgba.join(', ')})`
106111
}
107112

@@ -165,7 +170,7 @@ class vidbg {
165170
*/
166171
let playPromise = this.videoEl.play()
167172

168-
if(playPromise !== undefined) {
173+
if (playPromise !== undefined) {
169174
playPromise
170175
.catch(err => {
171176
console.error(err)
@@ -196,6 +201,20 @@ class vidbg {
196201
this.videoEl.remove()
197202
}
198203

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+
199218
/**
200219
* Our resize method on initial load and browser resize.
201220
*/

0 commit comments

Comments
 (0)