-
Notifications
You must be signed in to change notification settings - Fork 1
/
video.js
80 lines (70 loc) · 2.44 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
if (!RedactorPlugins) var RedactorPlugins = {};
(function($)
{
RedactorPlugins.video = function()
{
return {
reUrlYoutube: /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w.-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/ig,
reUrlVimeo: /https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/,
langs: {
en: {
"video": "Video",
"video-html-code": "Video Embed Code or Youtube/Vimeo Link"
}
},
getTemplate: function()
{
return String()
+ '<div class="modal-section" id="redactor-modal-video-insert">'
+ '<section>'
+ '<label>' + this.lang.get('video-html-code') + '</label>'
+ '<textarea id="redactor-insert-video-area" style="height: 160px;"></textarea>'
+ '</section>'
+ '</div>';
},
init: function()
{
var button = this.button.addAfter('image', 'video', this.lang.get('video'));
this.button.addCallback(button, this.video.show);
},
show: function()
{
var self = this;
this.modal.addTemplate('video', this.video.getTemplate());
this.modal.load('video', this.lang.get('video'), 700);
this.modal.createCancelButton();
var button = this.modal.createActionButton('Insert');
button.on('click', function() {
self.video.insert();
});
this.modal.show();
$('#redactor-insert-video-area').focus();
},
insert: function()
{
var data = $('#redactor-insert-video-area').val();
if (!data.match(/<iframe|<video/gi))
{
data = this.clean.stripTags(data);
// parse if it is link on youtube & vimeo
var iframeStart = '<iframe style="width: 500px; height: 281px;" src="',
iframeEnd = '" frameborder="0" allowfullscreen></iframe>';
if (data.match(this.video.reUrlYoutube))
{
data = data.replace(this.video.reUrlYoutube, iframeStart + '//www.youtube.com/embed/$1' + iframeEnd);
}
else if (data.match(this.video.reUrlVimeo))
{
data = data.replace(this.video.reUrlVimeo, iframeStart + '//player.vimeo.com/video/$2' + iframeEnd);
}
}
this.modal.close();
this.placeholder.remove();
// buffer
this.buffer.set();
// insert
this.insert.html(data);
}
};
};
})(jQuery);