forked from roland-vachter/n-video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
26 lines (25 loc) · 811 Bytes
/
main.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
const factory = require('./src/models/video-factory');
const init = opts => {
const options = opts || {};
const defaultOpts = {
context: document.body,
selector: '*'
};
for (let defaultOpt in defaultOpts) {
if (defaultOpts.hasOwnProperty(defaultOpt) && !options.hasOwnProperty(defaultOpt)) {
options[defaultOpt] = defaultOpts[defaultOpt];
}
}
const context = options.context instanceof HTMLElement ? options.context : document.querySelector(opts.context);
const videoPromises = [].map.call(context.querySelectorAll(options.selector + ':not([data-n-video-js])[data-n-component~="n-video"]'), videoEl => {
return factory(videoEl, options)
.init()
// don't fail all if a video errors
.catch(() => { });
});
return Promise.all(videoPromises);
}
module.exports = {
init,
factory
};