this.display = this.$refs.display;
this.input = this.$refs.input;
+ this.settingContainer = this.$refs.settingContainer;
this.editor = null;
initEditor({
text: {
serverUploadLimit: this.serverUploadLimitText,
imageUploadError: this.imageUploadErrorText,
- }
+ },
+ settings: this.loadSettings(),
}).then(editor => {
this.editor = editor;
this.setupListeners();
toolbarLabel.closest('.markdown-editor-wrap').classList.add('active');
});
+ // Setting changes
+ this.settingContainer.addEventListener('change', e => {
+ const actualInput = e.target.parentNode.querySelector('input[type="hidden"]');
+ const name = actualInput.getAttribute('name');
+ const value = actualInput.getAttribute('value');
+ window.$http.patch('/preferences/update-boolean', {name, value});
+ this.editor.settings.set(name, value === 'true');
+ });
+
// Refresh CodeMirror on container resize
const resizeDebounced = debounce(() => this.editor.cm.refresh(), 100, false);
const observer = new ResizeObserver(resizeDebounced);
observer.observe(this.elem);
}
+ loadSettings() {
+ const settings = {};
+ const inputs = this.settingContainer.querySelectorAll('input[type="hidden"]');
+
+ for (const input of inputs) {
+ settings[input.getAttribute('name')] = input.value === 'true';
+ }
+
+ return settings;
+ }
+
scrollToTextIfNeeded() {
const queryParams = (new URL(window.location)).searchParams;
const scrollText = queryParams.get('content-text');