-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedactor.embedCode.plugin.js
More file actions
executable file
·85 lines (65 loc) · 2.71 KB
/
Redactor.embedCode.plugin.js
File metadata and controls
executable file
·85 lines (65 loc) · 2.71 KB
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
(function($) {
$.Redactor.prototype.embedCode = function () {
return {
langs: {
en: {
'embed-code': 'Embed Code'
}
},
getTemplate: function ()
{
return String()
+ '<div class="modal-section" id="redactor-modal-embed-code-insert">'
+ '<section>'
+ '<label>' + this.lang.get('embed-code') + '</label>'
+ '<textarea id="redactor-insert-embed-code-area" style="height: 160px;"></textarea>'
+ '</section>'
+ '<section>'
+ '<button id="redactor-modal-button-action">Insert</button>'
+ '<button id="redactor-modal-button-cancel">Cancel</button>'
+ '</section>'
+ '</div>';
},
init: function ()
{
var button = this.button.addAfter('image', 'embedCode', this.lang.get('embed-code'));
this.button.setIcon(button, '<i class="fa fa-code"></i>');
this.button.addCallback(button, this.embedCode.show);
},
show: function ()
{
this.modal.addTemplate('embedCode', this.embedCode.getTemplate());
this.modal.load('embedCode', this.lang.get('embed-code'), 700);
// action button
this.modal.getActionButton().text(this.lang.get('insert')).on('click', this.embedCode.insert);
this.modal.show();
// focus
if (this.detect.isDesktop()) {
setTimeout(function () {
$('#redactor-insert-embed-code-area').focus();
}, 1);
}
},
insert: function()
{
var data = $('#redactor-insert-embed-code-area').val();
var matches = data.match(/<iframe/gi);
if (matches && matches.length !== 0) {
var allowed = ['iframe'];
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;
data = data.replace(tags, function ($0, $1) {
return (allowed.indexOf($1.toLowerCase()) === -1) ? '' : $0;
});
data = '<div class="embed-code-container">' + data + '</div>';
}
this.modal.close();
this.placeholder.hide();
// buffer
this.buffer.set();
// insert
this.air.collapsed();
this.insert.raw(data);
}
};
};
})(jQuery);