-
Notifications
You must be signed in to change notification settings - Fork 11
/
EUCookieLaw-tinymce.js
executable file
·75 lines (65 loc) · 2.04 KB
/
EUCookieLaw-tinymce.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
(function() {
tinymce.PluginManager.add('eucookielaw', function( editor, url ) {
editor.addButton( 'eucookielaw', {
title: 'EUCookieLaw',
icon: 'eucookielaw',
type: 'menubutton',
menu: [
{
text: 'Add reconsider button',
value: 'value 1',
onclick: function() {
editor.windowManager.open( {
title: 'Add reconsider button',
body: [{
type: 'textbox',
name: 'label',
label: 'Label'
}],
onsubmit: function( e ) {
editor.insertContent( '[EUCookieLawReconsider label="' + e.data.label + '"]');
}
});
}
},
{
text: 'Block section',
value: 'value 2',
onclick: function( e ) {
console.log(e);
editor.insertContent('[EUCookieLawBlock]' + tinyMCE.activeEditor.selection.getContent() + '[/EUCookieLawBlock]');
}
}
]
});
var replaceBlockShortcodes = function(content){
return content.replace(
/\[EUCookieLawBlock]([\s\S]*?)\[\/EUCookieLawBlock]/g,
'<div class="eucookielaw-blocked-contents">$1</div>');
},
restoreBlockShortcodes = function(content){
return content.replace( /<div class="eucookielaw-blocked-contents">(.*?)<\/div>/g, '[EUCookieLawBlock]$1[/EUCookieLawBlock]');
},
replaceButtonShortcode = function(content){
return content.replace(
/\[EUCookieLawReconsider( label="(.*?)")?]/g,
'<a class="eucookielaw-button-item">$2</a>');
},
restoreButtonShortcode = function(content){
return content.replace( /<a class="eucookielaw-button-item">(.*?)<\/a>/g, '[EUCookieLawReconsider label="$1"]');
};
editor.on( 'BeforeSetContent', function( event ) {
console.log("here");
event.content = replaceBlockShortcodes(event.content);
event.content = replaceButtonShortcode(event.content);
});
editor.on( 'PostProcess', function( event ) {
console.log("there");
if (event.get) {
console.log("then there");
event.content = restoreBlockShortcodes(event.content);
event.content = restoreButtonShortcode(event.content);
}
});
});
})();