Skip to content

Commit

Permalink
Add button to insert HTML snippets into WYSIWYG editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jul 13, 2022
1 parent 77bc8a7 commit df31426
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
38 changes: 36 additions & 2 deletions frontend/src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@
</footer>
</div>
</b-modal>

<b-modal scroll="keep" :width="750"
:aria-modal="true" :active.sync="isInsertHTMLVisible">
<div>
<section expanded class="modal-card-body preview">
<html-editor v-model="insertHTMLSnippet" />
</section>
<footer class="modal-card-foot has-text-right">
<b-button @click="onFormatRichtextHTML">{{ $t('campaigns.formatHTML') }}</b-button>
<b-button @click="() => { this.isInsertHTMLVisible = false; }">
{{ $t('globals.buttons.close') }}
</b-button>
<b-button @click="onInsertHTML" class="is-primary">
{{ $t('globals.buttons.insert') }}
</b-button>
</footer>
</div>
</b-modal>
</template>

<!-- raw html editor //-->
Expand Down Expand Up @@ -173,6 +191,8 @@ export default {
isReady: false,
isRichtextReady: false,
isRichtextSourceVisible: false,
isInsertHTMLVisible: false,
insertHTMLSnippet: '',
isTrackLink: false,
richtextConf: {},
richTextSourceBody: '',
Expand Down Expand Up @@ -214,6 +234,12 @@ export default {
tooltip: 'Source code',
onAction: this.onRichtextViewSource,
});
editor.ui.registry.addButton('insert-html', {
icon: 'code-sample',
tooltip: 'Insert HTML',
onAction: this.onOpenInsertHTML,
});
},
browser_spellcheck: true,
Expand All @@ -229,7 +255,7 @@ export default {
toolbar: `undo redo | formatselect styleselect fontsizeselect |
bold italic underline strikethrough forecolor backcolor subscript superscript |
alignleft aligncenter alignright alignjustify |
bullist numlist table image | outdent indent | link hr removeformat |
bullist numlist table image insert-html | outdent indent | link hr removeformat |
html fullscreen help`,
fontsize_formats: '10px 11px 12px 14px 15px 16px 18px 24px 36px',
skin: false,
Expand Down Expand Up @@ -285,12 +311,20 @@ export default {
return u;
},
onRichtextViewSource() {
this.richTextSourceBody = this.form.body;
this.isRichtextSourceVisible = true;
},
onOpenInsertHTML() {
this.isInsertHTMLVisible = true;
},
onInsertHTML() {
this.isInsertHTMLVisible = false;
window.tinymce.editors[0].execCommand('mceInsertContent', false, this.insertHTMLSnippet);
},
onFormatRichtextHTML() {
this.richTextSourceBody = this.beautifyHTML(this.richTextSourceBody);
},
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/HTMLEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export default {
// Set the initial value.
this.flask.updateCode(body);
this.$nextTick(() => {
document.querySelector('code-flask').shadowRoot.querySelector('textarea').focus();
});
},
},
Expand Down
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"forms.selectHelp": "Select lists to add to the form.",
"forms.title": "Forms",
"globals.buttons.add": "Add",
"globals.buttons.insert": "Insert",
"globals.buttons.addNew": "Add new",
"globals.buttons.back": "Back",
"globals.buttons.cancel": "Cancel",
Expand Down

0 comments on commit df31426

Please sign in to comment.