Skip to content

Commit 6da36e0

Browse files
committed
feat(video): Added the feature to embed basic video and use video.js to support in multiple places.
1 parent a8326e6 commit 6da36e0

5 files changed

Lines changed: 62 additions & 17 deletions

File tree

src/embed.es6

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
//SOFTWARE.
2121

22-
23-
// require('./modules/vendor/runtime'); // required at runtime for supporting ES7
24-
2522
import utils from './modules/utils.es6';
2623
import Emoji from './modules/emoticons/emoji.es6';
2724
import Smiley from './modules/emoticons/smiley.es6';
@@ -31,6 +28,7 @@ import Video from './modules/video/video.es6';
3128
import Twitter from './modules/twitter/twitter.es6';
3229
import Audio from './modules/audio/audio.es6';
3330
import Image from './modules/image/image.es6';
31+
import BasicVideo from './modules/video/basic.es6';
3432

3533
import helper from './modules/video/helper.es6';
3634

@@ -45,6 +43,8 @@ import helper from './modules/video/helper.es6';
4543
emoji : true,
4644
fontIcons : true,
4745
highlightCode : true,
46+
videoJS : false,
47+
videojsOptions : {},
4848
tweetsEmbed : true,
4949
tweetOptions : {
5050
maxWidth : 550,
@@ -81,7 +81,8 @@ import helper from './modules/video/helper.es6';
8181
beforeEmbedJSApply : function(){},
8282
afterEmbedJSApply : function(){},
8383
onVideoShow : function(){},
84-
onTweetsLoad : function(){}
84+
onTweetsLoad : function(){},
85+
videojsCallback : function(){}
8586
};
8687

8788
class EmbedJS {
@@ -122,13 +123,17 @@ import helper from './modules/video/helper.es6';
122123
render(result) {
123124
this.options.element.innerHTML = result;
124125

125-
//Load twitter data with styling
126-
twttr.widgets.load(this.options.element);
126+
if(twttr){
127+
//Load twitter data with styling
128+
twttr.widgets.load(this.options.element);
129+
130+
//Execute the function after the widget is loaded
131+
twttr.events.bind('loaded', ()=>{
132+
this.options.onTweetsLoad();
133+
});
134+
}
127135

128-
//Execute the function after the widget is loaded
129-
twttr.events.bind('loaded', ()=>{
130-
this.options.onTweetsLoad();
131-
})
136+
BasicVideo.postProcess(this.options);
132137

133138
helper.play('ejs-video-thumb', this.options);
134139
this.options.afterEmbedJSApply();

src/modules/twitter/twitter.es6

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import utils from '../utils.es6';
22

33
class Twitter {
44
constructor(input, options, embeds) {
5-
this.input = input;
5+
this.input = input;
66
this.options = options;
7-
this.embeds = embeds;
8-
this.regex = /https:\/\/twitter\.com\/\w+\/\w+\/\d+/gi;
7+
this.embeds = embeds;
8+
this.regex = /https:\/\/twitter\.com\/\w+\/\w+\/\d+/gi;
99
}
1010

1111
/**
@@ -14,8 +14,8 @@ class Twitter {
1414
* @return {object} data containing the tweet info
1515
*/
1616
async tweetData(url) {
17-
let config = this.options.tweetOptions;
18-
let apiUrl = `https://api.twitter.com/1/statuses/oembed.json?omit_script=true&url=${url}&maxwidth=${config.maxWidth}&hide_media=${config.hideMedia}&hide_thread=${config.hideThread}&align=${config.align}&lang=${config.lang}`;
17+
let config = this.options.tweetOptions;
18+
let apiUrl = `https://api.twitter.com/1/statuses/oembed.json?omit_script=true&url=${url}&maxwidth=${config.maxWidth}&hide_media=${config.hideMedia}&hide_thread=${config.hideThread}&align=${config.align}&lang=${config.lang}`;
1919
let response = await fetchJsonp(apiUrl, {
2020
credentials: 'include'
2121
});

src/modules/video/basic.es6

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import utils from '../utils.es6';
2+
import Base from '../base.es6';
3+
4+
class BasicVideo extends Base {
5+
constructor(input, options, embeds) {
6+
super(input, options, embeds);
7+
this.regex = /(?:https?):\/\/\S*\.(?:ogv|webm|mp4)/gi;
8+
}
9+
10+
template(match) {
11+
var template =
12+
`<div class="ejs-video">
13+
<div class="ejs-video-player">
14+
<div class="ejs-player">
15+
<video src="${match}" class="ejs-basic-video video-js" controls></video>
16+
</div>
17+
</div>
18+
</div>`;
19+
return template;
20+
}
21+
22+
static postProcess(options) {
23+
let dimensions=utils.dimensions(options);
24+
options.videojsOptions.width = dimensions.width;
25+
options.videojsOptions.height = dimensions.height;
26+
if (options.videoJS) {
27+
if (!window.videojs) {
28+
throw new ReferenceError("You have enabled videojs but you haven't loaded the library.Find it at http://videojs.com/");
29+
}
30+
var elements = options.element.getElementsByClassName('ejs-basic-video');
31+
for(var i=0;i<elements.length;i++){
32+
videojs(elements[i], options.videojsOptions, () => options.videojsCallback());
33+
}
34+
}
35+
}
36+
}
37+
38+
module.exports = BasicVideo;

src/modules/video/liveleak.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import utils from '../utils.es6';
2-
import base from '../base.es6';
2+
import Base from '../base.es6';
33

4-
class LiveLeak extends base{
4+
class LiveLeak extends Base{
55
constructor(input,options, embeds){
66
super(input, options, embeds);
77
this.regex = /liveleak.com\/view\?i=[a-zA-Z0-9_]+/gi;

src/modules/video/video.es6

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import LiveLeak from './liveleak.es6';
77
import Vine from './vine.es6';
88
import Youtube from './youtube.es6';
99
import Vimeo from './vimeo.es6';
10+
import BasicVideo from './basic.es6';
1011

1112
class Video {
1213
constructor(input, output, options, embeds) {
@@ -24,6 +25,7 @@ class Video {
2425
embeds = utils.ifEmbed(this.options, 'dailymotion') ? (new Dailymotion(input, this.options, embeds).process()) : output;
2526
embeds = utils.ifEmbed(this.options, 'ustream') ? (new Ustream(input, this.options, embeds).process()) : output;
2627
embeds = utils.ifEmbed(this.options, 'liveleak') ? (new LiveLeak(input, this.options, embeds).process()) : output;
28+
embeds = utils.ifEmbed(this.options, 'basic-video') ? (new BasicVideo(input, this.options, embeds).process()) : output;
2729
embeds = utils.ifEmbed(this.options, 'vine') ? (new Vine(input, this.options, embeds).process()) : output;
2830
embeds = utils.ifEmbed(this.options, 'youtube') ? await (new Youtube(input, this.options, embeds).process()) : output;
2931
embeds = utils.ifEmbed(this.options, 'vimeo') ? await (new Vimeo(input, this.options, embeds).process()) : output;

0 commit comments

Comments
 (0)