This repository has been archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo-dev.js
111 lines (85 loc) · 2.44 KB
/
video-dev.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
(function (Crafty) {
Crafty.c('Video', {
poster: '',
videos: {},
once: false,
videoElem: null,
init: function () {
this.videoElem = document.createElement('video');
Crafty('FullVideo').each(function () {
this.destroyVideo();
});
},
destroyVideo: function () {
if (this.videoElem) {
this.videoElem.remove();
this.destroy();
}
},
setFullScreenStyle: function () {
this.videoElem.style.position = 'fixed';
this.videoElem.style.right = 0;
this.videoElem.style.bottom = 0;
this.videoElem.style.minWidth = '100%';
this.videoElem.style.minHeight = '100%';
this.videoElem.style.width = 'auto';
this.videoElem.style.height = 'auto';
this.videoElem.style.zIndex = -100;
this.videoElem.style.backgroundSize = 'cover';
if (!!this.poster) {
this.videoElem.style.background = 'url(' + this.poster + ') no-repeat';
}
Crafty.stage.elem.appendChild(this.videoElem);
},
setInnerScreenStyle: function () {
this.videoElem.style.position = 'absolute';
this.videoElem.style.left = 0;
this.videoElem.style.top = 0;
this.videoElem.style.minWidth = '100%';
this.videoElem.style.minHeight = '100%';
this.videoElem.style.width = 'auto'//Crafty.stage.elem.offsetWidth + 'px';
this.videoElem.style.height = Crafty.stage.elem.offsetHeight + 'px';
this.videoElem.style.zIndex = -100;
this.videoElem.style.backgroundSize = 'cover';
if (!!this.poster) {
this.videoElem.style.background = 'url(' + this.poster + ') no-repeat';
}
Crafty.stage.inner.style.zIndex = 0;
Crafty.stage.inner.appendChild(this.videoElem);
},
createVideo: function () {
var self = this;
function appendChild() {
for (var source in self.videos) {
var srcElem = document.createElement('source');
srcElem.src = self.videos[source];
srcElem.type = 'video/' + source;
self.videoElem.appendChild(srcElem);
}
}
function setAttr() {
if (self.once === true) {
} else {
self.videoElem.loop = true;
}
self.videoElem.autoplay = true;
if (!!self.poster) {
self.videoElem.poster = self.poster;
}
}
function setEvents() {
self.videoElem.addEventListener('loadedmetadata', function () {
}, false);
self.videoElem.addEventListener('ended', function () {
if (self.once === true) {
self.destroyVideo();
}
}, false);
}
appendChild();
setAttr();
setEvents();
return this;
}
});
}(Crafty));