Update editor

This commit is contained in:
RemiZOffAlex
2020-05-06 15:49:18 +03:00
parent 1ec9e5516b
commit f4358f16af
3 changed files with 49 additions and 16 deletions

View File

@@ -53,7 +53,7 @@ var app = new Vue({
send: function () { send: function () {
/* Сохранить */ /* Сохранить */
let vm = this; let vm = this;
{{ editor.getValue('body', 'vm.page.body', type='tinymce') }} {{ editor.getValue('"body"', 'vm.page.body', type='tinymce') }}
axios.post( axios.post(
'/api', '/api',
{ {
@@ -75,7 +75,7 @@ var app = new Vue({
} }
}, },
mounted: function () { mounted: function () {
{{ editor.tinymce('body') }} {{ editor.tinymce('"body"') }}
} }
}) })
</script> </script>

View File

@@ -36,7 +36,8 @@
{% endblock %} {% endblock %}
{% block script %} {% block script %}
<script type="text/javascript" src="/static/tinymce/tinymce.min.js"></script> {% import 'inc/editor.js' as editor %}
{{ editor.plugin('tinymce') }}
<script type="text/javascript"> <script type="text/javascript">
var app = new Vue({ var app = new Vue({
@@ -48,10 +49,7 @@ var app = new Vue({
send: function () { send: function () {
/* Сохранить */ /* Сохранить */
let vm = this; let vm = this;
var value = CKEDITOR.instances["body"].getData(); {{ editor.getValue('"body"', 'vm.page.body', type='tinymce') }}
if (value != vm.page.body) {
vm.page.body = value;
}
axios.post( axios.post(
'/api', '/api',
{ {
@@ -74,7 +72,7 @@ var app = new Vue({
} }
}, },
mounted: function () { mounted: function () {
{{ editor.tinymce('body') }} {{ editor.tinymce('"body"') }}
} }
}) })
</script> </script>

View File

@@ -1,3 +1,29 @@
{#
Подгрузить скрипт
{% import 'inc/editor.js' as editor %}
{{ editor.plugin('tinymce') }}
Получить данные
{{ editor.getValue('"text"', 'vm.note.text', type='tinymce') }}
{{ editor.getValue('"field" + field.id', 'field.cell.value', type='tinymce') }}
Получить данные
{{ editor.setValue('"text"', 'vm.note.text', type='tinymce') }}
{{ editor.setValue('"field" + field.id', 'field.cell.value', type='tinymce') }}
Инициализировать редактор
{{ editor.tinymce('"text"') }}
{{ editor.tinymce('"field" + field.id') }}
#}
{% macro plugin(type="tinymce") -%} {% macro plugin(type="tinymce") -%}
{% if type=="tinymce" %} {% if type=="tinymce" %}
<script type="text/javascript" src="/static/tinymce/tinymce.min.js"></script> <script type="text/javascript" src="/static/tinymce/tinymce.min.js"></script>
@@ -7,29 +33,38 @@
{%- endmacro %} {%- endmacro %}
{% macro ckeditor(name) -%} {% macro ckeditor(name) -%}
CKEDITOR.replace( '{{ name }}', { CKEDITOR.replace( {{ name }}, {
customConfig: '/static/js/ckeditor-conf.js' customConfig: '/static/js/ckeditor-conf.js'
} ); } );
{%- endmacro %} {%- endmacro %}
{% macro tinymce(name) -%} {% macro tinymce(name) -%}
tinymce.init({ tinymce.init({
selector: 'textarea#{{ name }}', selector: '#' + {{ name }},
height: 400, height: 400,
language: 'ru', language: 'ru',
plugins: "code link image table", plugins: 'code importcss searchreplace autolink save directionality visualblocks visualchars fullscreen image link media table charmap hr pagebreak nonbreaking anchor toc advlist lists wordcount imagetools textpattern noneditable help charmap quickbars',
toolbar: "table tabledelete | tableprops tablerowprops tablecellprops | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol" toolbar: 'code | undo redo | bold italic underline strikethrough removeformat | formatselect | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | pagebreak | fullscreen | link image anchor charmap',
formats: {
img: { selector: 'img', classes: 'img-thumbnail', styles: {} },
table: { selector: 'table', classes: 'table', styles: {} },
},
style_formats: [
{ title: 'Картинка', format: 'img' },
{ title: 'Таблица', format: 'table' },
]
}); });
{%- endmacro %} {%- endmacro %}
{% macro getValue(name, param, type="tinymce") -%} {% macro getValue(name, param, type="tinymce") -%}
{% if type=="tinymce" %} {% if type=="tinymce" %}
let value = tinymce.get("{{ name }}").getContent(); let value = tinymce.get({{ name }}).getContent();
if (value != {{ param }}) { if (value != {{ param }}) {
{{ param }} = value; {{ param }} = value;
} }
{% elif type=="ckeditor" %} {% elif type=="ckeditor" %}
var value = CKEDITOR.instances["{{ name }}"].getData(); var value = CKEDITOR.instances[{{ name }}].getData();
if (value != {{ param }}) { if (value != {{ param }}) {
{{ param }} = value; {{ param }} = value;
} }
@@ -38,8 +73,8 @@ if (value != {{ param }}) {
{% macro setValue(name, param, type="tinymce") -%} {% macro setValue(name, param, type="tinymce") -%}
{% if type=="tinymce" %} {% if type=="tinymce" %}
tinymce.get("{{ name }}").setContent({{ param }}); tinymce.get({{ name }}).setContent({{ param }});
{% elif type=="ckeditor" %} {% elif type=="ckeditor" %}
CKEDITOR.instances["{{ name }}"].setData({{ param }}); CKEDITOR.instances[{{ name }}].setData({{ param }});
{% endif %} {% endif %}
{%- endmacro %} {%- endmacro %}