/
tinymce.html.twig
123 lines (123 loc) · 5.54 KB
/
tinymce.html.twig
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
{% set version = "tinymce" %}
{% block label %}
{% if field.label %}
{% set hint = field.help ? 'data-hint="' ~ field.help|tu|raw ~ '"': '' %}
<div class="form-label form-field hint--bottom" {{ hint }}>{{ field.label|tu|raw }}</div>
{% endif %}
{% endblock %}
{% block field %}
<div class="form-field {{ field.classes|default('') }}">
<div class="form-data">
<textarea
class="tinymce"
name="{{ (scope ~ field.name)|fieldName }}"
{% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
{% if field.placeholder %}placeholder="{{ field.placeholder|tu }}"{% endif %}
{% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
{% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
{% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %}
>{{ value|join("\n")|e("html") }}</textarea>
</div>
</div>
<script>
tinymce.init({
selector: "textarea.tinymce",
convert_urls: false,
document_base_url: "{{ (uri.rootUrl(true) ~ admin.page.rawRoute)|e("js") }}/",
language: "{{ url('user://data/tinymce-editor/js/' ~ version ~ '/langs/' ~ grav.user.language ~ '.js')|default(url('user://data/tinymce-editor/js/' ~ version ~ '/langs/' ~ grav.user.language ~ '_' ~ (grav.user.language|upper) ~ '.js')|default(url('plugins://tinymce-editor/js/' ~ version ~ '/langs/' ~ grav.user.language ~ '.js')|default(url('plugins://tinymce-editor/js/' ~ version ~ '/langs/' ~ grav.user.language ~ '_' ~ (grav.user.language|upper) ~ '.js'))))|split('/')|last|split('.')|first }}",
language_url: "{{ url('user://data/tinymce-editor/js/' ~ version ~ '/langs/' ~ grav.user.language ~ '.js')|default(url('user://data/tinymce-editor/js/' ~ version ~ '/langs/' ~ grav.user.language ~ '_' ~ (grav.user.language|upper) ~ '.js')|default(url('plugins://tinymce-editor/js/' ~ version ~ '/langs/' ~ grav.user.language ~ '.js')|default(url('plugins://tinymce-editor/js/' ~ version ~ '/langs/' ~ grav.user.language ~ '_' ~ (grav.user.language|upper) ~ '.js')))) }}",
contextmenu: false,
plugins: "{{ config.plugins["tinymce-editor"].plugins|join(" ")|e("js") }}",
{% for key in config.plugins["tinymce-editor"].parameters|keys %}
"{{ config.plugins["tinymce-editor"].parameters[key].name|e("js") }}": function(x) {
try{return JSON.parse(x)}catch(e){return x}
}("{{ config.plugins["tinymce-editor"].parameters[key].value|e("js") }}"),
{% endfor %}
menubar: {% if config.plugins["tinymce-editor"].menubar %}"{% for key in config.plugins["tinymce-editor"].menu|keys %}{{ config.plugins["tinymce-editor"].menu[key].title|lower|e("js") }} {% endfor %}"{% else %}false{% endif %},
menu: {
{% for key in config.plugins["tinymce-editor"].menu|keys %}
"{{ config.plugins["tinymce-editor"].menu[key].title|lower|e("js") }}":{
title: "{{ config.plugins["tinymce-editor"].menu[key].title|e("js") }}",
items: "{{ config.plugins["tinymce-editor"].menu[key].items|e("js") }}"
},
{% endfor %}
},
toolbar: [
{% for fields in config.plugins["tinymce-editor"].toolbar %}
{% for row in fields %}
'{{ row|e("js") }}',
{% endfor %}
{% endfor %}
],
branding: {% if config.plugins["tinymce-editor"].branding %}true{% else %}false{% endif %},
statusbar: {% if config.plugins["tinymce-editor"].statusbar %}true{% else %}false{% endif %},
setup: function(editor) {
editor.on("init", (function() {
function insert(dir, src) {
var file = new Image();
file.src = dir+src;
file.onload = function() {
tinymce.execCommand("mceImage");
$("div.mce-window input.mce-textbox:first").val(src);
};
file.onerror = function() {
file = new Audio();
file.src = dir+src;
file.ondurationchange = function() {
tinymce.execCommand("mceMedia");
$("div.mce-window input.mce-textbox:first").val(src);
};
file.onerror = function() {
tinymce.execCommand("mceLink");
$("div.mce-window input.mce-textbox:eq(1)").val(src);
$("div.mce-window input.mce-textbox:first").val(src);
return true;
};
return true;
};
}
$("div.dropzone").on("click", "a.dz-insert", function() {
insert($("#grav-dropzone").attr("data-media-path")+"/", encodeURIComponent($(this).parent().find("[data-dz-name]").text()));
});
var isMedia = 0;
var wasMedia = 0;
$("#grav-dropzone").on("dragstart", ".dz-preview", function(e) {
isMedia = 1;
});
editor.on("drop", function(e) {
if(isMedia) {
e.preventDefault();
e.stopPropagation();
var txt = encodeURIComponent(decodeURIComponent(e.dataTransfer.getData("text").split("(").pop()));
insert($("#grav-dropzone").attr("data-media-path")+"/", txt.substring(0, txt.length-1));
wasMedia = 1;
}
});
$("#grav-dropzone").on("dragend", ".dz-preview", function(e) {
isMedia = 0;
});
editor.on("PastePreProcess", function(e) {
if(wasMedia) {
e.content = "";
wasMedia = 0;
}
});
if(!tinymce.settings.allow_html_data_urls && !tinymce.settings.allow_svg_data_urls) {
editor.parser.addNodeFilter("embed,iframe,object", function(nodes) {
nodes.forEach(function(node) {
if(node.attributes) {
node.attributes.forEach(function(attr) {
if(/^data:/i.test(attr.value)) {
node.attr(attr.name, "");
}
});
}
});
});
}
}));
},
{{ config.plugins["tinymce-editor"].evals|raw }}
});
</script>
{% endblock %}