-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtextarea.twig
76 lines (66 loc) · 2.33 KB
/
textarea.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
{##
# {% set variables = { "id": someVar, "name": someVar, "placeholder": someVar, "value": someVar } %}
# {% include "_base/textarea.twig" with variables %}
#
# https://twig.symfony.com/doc/3.x/tags/include.html
#}
{% if required is defined %}
{% set required = "required" %}
{% else %}
{% set required = "" %}
{% endif %}
<textarea id="{{ id }}" name="{{ name }}" placeholder="{{ placeholder }}" class="easyMDE">{{ value|raw }}</textarea>
<script>
(() => {
"use strict";
const easyMDE = new EasyMDE({
// https://github.com/Ionaru/easy-markdown-editor#configuration
element: document.getElementById("{{ id }}"),
autoDownloadFontAwesome: false,
forceSync: true,
inputStyle: "contenteditable",
maxHeight: "20rem",
nativeSpellcheck: true,
renderingConfig: {
codeSyntaxHighlighting: true,
},
/*
toolbar: [
// https://github.com/Ionaru/easy-markdown-editor#toolbar-icons
"bold", "italic", "strikethrough", "heading",
"|", "code", "quote", "unordered-list", "ordered-list", "clean-block",
"|", "link", "image", "table",
"|", "preview", "side-by-side", "fullscreen",
"|", "guide",
{
name: "plain",
action: function customFunction(editor) {
easyMDE.toTextArea();
},
className: "fa fa-power-off",
title: "Plain Text Editor",
},
],
*/
shortcuts: {
// https://github.com/Ionaru/easy-markdown-editor#keyboard-shortcuts
"toggleStrikethrough": "Cmd-Alt-S",
"drawTable": "Cmd-Alt-T",
},
});
// update easymde on textarea change
$("#{{ id }}").on("change", (event) => {
easyMDE.value(
$(event.target).val()
);
});
// update textarea on easymde change
easyMDE.codemirror.on("change", () => {
$("#{{ id }}").val(
easyMDE.value()
);
});
// put the easymde in the global scope
window.{{ id }} = easyMDE;
})();
</script>