loadStylesIntoDisplay() {
if (this.displayStylesLoaded) return;
- this.displayDoc.documentElement.className = 'markdown-editor-display';
+ this.displayDoc.documentElement.classList.add('markdown-editor-display');
+ // Set display to be dark mode if parent is
+
+ if (document.documentElement.classList.contains('dark-mode')) {
+ this.displayDoc.documentElement.style.backgroundColor = '#222';
+ this.displayDoc.documentElement.classList.add('dark-mode');
+ }
this.displayDoc.head.innerHTML = '';
const styles = document.head.querySelectorAll('style,link[rel=stylesheet]');
});
}
+ getDrawioUrl() {
+ const drawioUrlElem = document.querySelector('[drawio-url]');
+ return drawioUrlElem ? drawioUrlElem.getAttribute('drawio-url') : false;
+ }
+
// Show draw.io if enabled and handle save.
actionStartDrawing() {
- if (document.querySelector('[drawio-enabled]').getAttribute('drawio-enabled') !== 'true') return;
- let cursorPos = this.cm.getCursor('from');
+ const url = this.getDrawioUrl();
+ if (!url) return;
+
+ const cursorPos = this.cm.getCursor('from');
- DrawIO.show(() => {
+ DrawIO.show(url,() => {
return Promise.resolve('');
}, (pngData) => {
- // let id = "image-" + Math.random().toString(16).slice(2);
- // let loadingImage = window.baseUrl('/loading.gif');
- let data = {
+
+ const data = {
image: pngData,
uploaded_to: Number(document.getElementById('page-editor').getAttribute('page-id'))
};
// Show draw.io if enabled and handle save.
actionEditDrawing(imgContainer) {
- const drawingDisabled = document.querySelector('[drawio-enabled]').getAttribute('drawio-enabled') !== 'true';
- if (drawingDisabled) {
+ const drawioUrl = this.getDrawioUrl();
+ if (!drawioUrl) {
return;
}
const cursorPos = this.cm.getCursor('from');
const drawingId = imgContainer.getAttribute('drawio-diagram');
- DrawIO.show(() => {
+ DrawIO.show(drawioUrl, () => {
return DrawIO.load(drawingId);
}, (pngData) => {
const prependLineCount = markdown.split('\n').length;
this.cm.setCursor(cursorPos.line + prependLineCount, cursorPos.ch);
});
+
+ // Focus on editor
+ window.$events.listen('editor::focus', () => {
+ this.cm.focus();
+ });
}
}