-
Notifications
You must be signed in to change notification settings - Fork 4
/
video.js
150 lines (133 loc) · 8.03 KB
/
video.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
SirTrevor.Blocks.Video = (function(){
return SirTrevor.Block.extend({
// Based on https://gist.github.com/jeffling/a9629ae28e076785a14f
providers: {
vimeo: {
regex: /(?:http[s]?:\/\/)?(?:www.)?vimeo.com\/(.+)/,
html: "<iframe src=\"{{protocol}}//player.vimeo.com/video/{{remote_id}}?title=0&byline=0\" width=\"580\" height=\"320\" frameborder=\"0\"></iframe>"
},
youtube: {
regex: /(?:http[s]?:\/\/)?(?:www.)?(?:(?:youtube.com\/watch\?(?:.*)(?:v=))|(?:youtu.be\/))([^&].+)/,
html: "<iframe src=\"{{protocol}}//www.youtube.com/embed/{{remote_id}}\" width=\"580\" height=\"320\" frameborder=\"0\" allowfullscreen></iframe>"
},
vine: {
regex: /(?:http[s]?:\/\/)?(?:www.)?vine.co\/v\/([^\W]*)/,
html: "<iframe class=\"vine-embed\" src=\"{{protocol}}//vine.co/v/{{remote_id}}/embed/simple\" width=\"{{width}}\" height=\"{{width}}\" frameborder=\"0\"></iframe><script async src=\"http://platform.vine.co/static/scripts/embed.js\" charset=\"utf-8\"></script>",
square: true
},
dailymotion: {
regex: /(?:http[s]?:\/\/)?(?:www.)?dai(?:.ly|lymotion.com\/video)\/([^\W_]*)/,
html: "<iframe src=\"{{protocol}}//www.dailymotion.com/embed/video/{{remote_id}}\" width=\"580\" height=\"320\" frameborder=\"0\"></iframe>"
},
metacafe: {
regex: /(?:http[s]?:\/\/)?(?:www.)?metacafe.com\/watch\/(.+)/,
html: "<iframe src=\"{{protocol}}//www.metacafe.com/embed/{{remote_id}}/\" width=\"540\" height=\"304\" allowFullScreen frameborder=0></iframe>"
},
yahoo: {
regex: /(?:http[s]?:\/\/)(?:.+).yahoo.com\/(?:video\/)?(.+).html/,
html: "<iframe width=\"640\" height=\"360\" scrolling=\"no\" frameborder=\"0\" src=\"{{protocol}}//screen.yahoo.com/embed/{{remote_id}}.html\" allowfullscreen=\"true\" mozallowfullscreen=\"true\" webkitallowfullscreen=\"true\" allowtransparency=\"true\"></iframe>"
},
ustream: {
regex: /(?:http[s]?:\/\/)?(?:www.)?ustream.tv\/channel\/(.+)/,
html: "<iframe width=\"640\" height=\"392\" src=\"{{protocol}}//www.ustream.tv/embed/{{remote_id}}?v=3&wmode=direct\" scrolling=\"no\" frameborder=\"0\" style=\"border: 0px none transparent;\"></iframe>"
},
ustreamrecord: {
regex: /(?:http[s]?:\/\/)?(?:www.)?ustream.tv\/recorded\/(.+)/,
html: "<iframe width=\"640\" height=\"392\" src=\"{{protocol}}//www.ustream.tv/embed/recorded/{{remote_id}}?v=3&wmode=direct\" scrolling=\"no\" frameborder=\"0\" style=\"border: 0px none transparent;\"></iframe>"
},
veoh: {
regex: /(?:http[s]?:\/\/)?(?:www.)?veoh.com\/watch\/([[:alnum:]]*)/,
html: "<object width=\"640\" height=\"532\" id=\"veohFlashPlayer\" name=\"veohFlashPlayer\"><param name=\"movie\" value=\"http://www.veoh.com/swf/webplayer/WebPlayer.swf?version=AFrontend.5.7.0.1444&permalinkId={{remote_id}}&player=videodetailsembedded&videoAutoPlay=0&id=anonymous\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.veoh.com/swf/webplayer/WebPlayer.swf?version=AFrontend.5.7.0.1444&permalinkId={{remote_id}}&player=videodetailsembedded&videoAutoPlay=0&id=anonymous\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"640\" height=\"532\" id=\"veohFlashPlayerEmbed\" name=\"veohFlashPlayerEmbed\"></embed></object>"
},
vevo: {
regex: /(?:http[s]?:\/\/)?(?:www.)?vevo.com\/watch(?:.*)\/(.+)/,
html: "<iframe width=\"575\" height=\"324\" src=\"http://cache.vevo.com/m/html/embed.html?video={{remote_id}}\" frameborder=\"0\" allowfullscreen></iframe>"
},
aol: {
regex: /(?:http[s]?:\/\/)on.aol.com\/video(?:.*)-(.+)(?:\?.*)*/,
html: "<script type=\"text/javascript\" src=\"http://pshared.5min.com/Scripts/PlayerSeed.js?sid=281&width=560&height=345&playList={{remote_id}}\"></script>"
},
metatube: {
regex: /(?:http[s]?:\/\/)?(?:www.)?metatube.com\/(?:.+)\/videos\/(.+)\//,
html: "<iframe width=\"640\" height=\"480\" src=\"http://www.metatube.com/en/videos/{{remote_id}}/embed/\" frameborder=\"0\" allowfullscreen></iframe>"
},
wat: {
regex: /www.wat.tv\/embedframe\/([[:alnum:]]*)/,
html: "<iframe src=\"http://www.wat.tv/embedframe/{{remote_id}}\" frameborder=\"0\" style=\"width: 640px; height: 360px;\"></iframe>"
},
dailymailuk: {
regex: /dailymail.co.uk\/video\/tvshowbiz\/video-(.+)\/(?:.+).html/,
html: "<iframe frameborder=\"0\" width=\"698\" height=\"503\" scrolling=\"no\" id=\"molvideoplayer\" title=\"MailOnline Embed Player\" src=\"http://www.dailymail.co.uk/embed/video/{{remote_id}}.html\"></iframe>"
},
cplus: {
regex: /canalplus.fr\/embed\/\?param=cplus&vid=(.+)"><\/iframe/,
html: "<iframe width=\"640\" height=\"360\" frameborder=\"0\" scrolling=\"no\" src=\"http://player.canalplus.fr/embed/?param=cplus&vid={{remote_id}}\"></iframe>"
},
francetv: {
regex: /api.dmcloud.net\/player\/embed\/(.+)?exported=1/,
html: "<iframe frameborder=\"0\" width=\"640\" height=\"360\" src=\"http://api.dmcloud.net/player/embed/{{remote_id}}?exported=1\"></iframe>"
},
zoomin: {
regex: /zoomin.tv(?:.*)\/video\/([[:alnum:]]*)\//,
html: "<iframe src=\"http://blackbird.zoomin.tv/players/.pla?pid=corporatefr&id={{remote_id}}&w=655&h=433\" style=\"width:655px; height:433px; border:none; overflow:hidden;\" frameborder=\"0\" scrolling=\"no\" allowtransparency=\"yes\"></iframe>"
},
globalnews: {
regex: /globalnews.ca\/video(?:\/embed)?\/([[:alnum:]]*)\//,
html: "<iframe src=\"http://globalnews.ca/video/embed/{{remote_id}}/\" width=\"670\" height=\"437\" frameborder=\"0\" allowfullscreen></iframe>"
},
nhl: {
regex: /nhl.com\/videocenter\/(?:console\?id=)|(?:embed\?playlist=)([[:digit:]]*)/,
html: "<iframe src=\"http://video.nhl.com/videocenter/embed?playlist={{remote_id}}\" frameborder=\"0\" width=\"640\" height=\"395\"></iframe>"
},
livestream: {
regex: /new.livestream.com\/accounts\/(.+)\/player/,
html: "<iframe src=\"http://new.livestream.com/accounts/{{remote_id}}/player?autoPlay=false&height=360&mute=false&width=640\" width=\"640\" height=\"360\" frameborder=\"0\" scrolling=\"no\"></iframe>"
},
ooyala: {
regex: /ooyala.com\/iframe.js#pbid=(.+)"/,
html: "<script height=\"349px\" width=\"620px\" src=\"http://player.ooyala.com/iframe.js#pbid={{remote_id}}\"></script>"
}
},
type: "video",
title: function() { return i18n.t("blocks:video:title"); },
droppable: true,
pastable: true,
icon_name: "video",
loadData: function(data){
if (!this.providers.hasOwnProperty(data.source)) { return; }
if (this.providers[data.source].square) {
this.$editor.addClass("st-block__editor--with-square-media");
} else {
this.$editor.addClass("st-block__editor--with-sixteen-by-nine-media");
}
var embedString = this.providers[data.source].html
.replace("{{protocol}}", window.location.protocol)
.replace("{{remote_id}}", data.remote_id)
.replace("{{width}}", this.$editor.width()); // for videos that can't resize automatically like vine
this.$editor.html(embedString);
},
onContentPasted: function(event){
this.handleDropPaste($(event.target).val());
},
handleDropPaste: function(url){
if(!_.isURI(url)) {
return;
}
var match, data;
_.each(this.providers, function(provider, index) {
match = provider.regex.exec(url);
if(match !== null && !_.isUndefined(match[1])) {
data = {
source: index,
remote_id: match[1]
};
this.setAndLoadData(data);
}
}, this);
},
onDrop: function(transferData){
var url = transferData.getData("text/plain");
this.handleDropPaste(url);
}
});
})();