mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
Implement localStorage and toggling of simple/rich text editor
This commit is contained in:
parent
578bce31b9
commit
3aef0a185e
@ -1,27 +1,3 @@
|
|||||||
<script lang="ts">
|
|
||||||
import CKEditor from "@ckeditor/ckeditor5-vue";
|
|
||||||
import ClassicEditor from "../../module/ckeditor5/editor_config";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: "CommentEditor",
|
|
||||||
components: {
|
|
||||||
ckeditor: CKEditor.component,
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
editor: ClassicEditor,
|
|
||||||
loading: false,
|
|
||||||
lastRecordedContent: null,
|
|
||||||
content: '',
|
|
||||||
richEditor: true,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
props: {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<teleport to="#add-comment">
|
<teleport to="#add-comment">
|
||||||
<div>
|
<div>
|
||||||
@ -31,21 +7,21 @@ export default {
|
|||||||
|
|
||||||
<div class="text-md-end">
|
<div class="text-md-end">
|
||||||
<span class="d-block d-sm-inline-block mb-md-2">
|
<span class="d-block d-sm-inline-block mb-md-2">
|
||||||
<a class="flag-toggle">
|
<a @click="toggleSimpleEditor" class="flag-toggle">
|
||||||
<span :class="{ on: false }">{{ $t("comment.editor_simple") }}</span>
|
<span :class="{ on: isSimple }">{{ $t("comment.editor_simple") }}</span>
|
||||||
<i
|
<i
|
||||||
class="fa"
|
class="fa"
|
||||||
:class="{
|
:class="{
|
||||||
'fa-toggle-on': true,
|
'fa-toggle-on': !isSimple,
|
||||||
'fa-toggle-on fa-flip-horizontal': false,
|
'fa-toggle-on fa-flip-horizontal': isSimple,
|
||||||
}"
|
}"
|
||||||
/>
|
/>
|
||||||
<span :class="{ on: true }">{{ $t("comment.editor_rich") }}</span>
|
<span :class="{ on: !isSimple }">{{ $t("comment.editor_rich") }}</span>
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="richEditor">
|
<div v-if="!isSimple">
|
||||||
<ckeditor
|
<ckeditor
|
||||||
name="content"
|
name="content"
|
||||||
:editor="editor"
|
:editor="editor"
|
||||||
@ -53,10 +29,59 @@ export default {
|
|||||||
tag-name="textarea"
|
tag-name="textarea"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div v-else>
|
||||||
|
<textarea
|
||||||
|
v-model="content"
|
||||||
|
name="content"
|
||||||
|
class="form-control"
|
||||||
|
></textarea>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</teleport>
|
</teleport>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { ref, onMounted } from "vue";
|
||||||
|
import CKEditor from "@ckeditor/ckeditor5-vue";
|
||||||
|
import ClassicEditor from "../../module/ckeditor5/editor_config";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "CommentEditor",
|
||||||
|
components: {
|
||||||
|
ckeditor: CKEditor.component,
|
||||||
|
},
|
||||||
|
setup() {
|
||||||
|
const isSimple = ref(false);
|
||||||
|
const content = ref("");
|
||||||
|
const editor = ClassicEditor;
|
||||||
|
|
||||||
|
const initializeEditorPreference = () => {
|
||||||
|
const storedValue = localStorage.getItem("isSimpleEditor");
|
||||||
|
if (storedValue !== null) {
|
||||||
|
isSimple.value = storedValue === "true"; // Convert string to boolean
|
||||||
|
} else {
|
||||||
|
localStorage.setItem("isSimpleEditor", "false"); // Set default value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleSimpleEditor = () => {
|
||||||
|
isSimple.value = !isSimple.value;
|
||||||
|
localStorage.setItem("isSimpleEditor", String(isSimple.value)); // Update localStorage
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => initializeEditorPreference())
|
||||||
|
|
||||||
|
return {
|
||||||
|
isSimple,
|
||||||
|
content,
|
||||||
|
editor,
|
||||||
|
toggleSimpleEditor,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user