From ab63a55d6064f5b9ca8f51f9301c1f6fa06f00d9 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Wed, 23 Sep 2020 22:51:50 -0400 Subject: [PATCH] Mithril 2 Update (#19) Update for Mithril 2 --- .../js/src/forum/components/MarkdownButton.js | 20 ++++++++++--------- .../src/forum/components/MarkdownToolbar.js | 12 +++++------ extensions/markdown/js/src/forum/index.js | 14 ++++++------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/extensions/markdown/js/src/forum/components/MarkdownButton.js b/extensions/markdown/js/src/forum/components/MarkdownButton.js index 6ad05e094..cd88699af 100644 --- a/extensions/markdown/js/src/forum/components/MarkdownButton.js +++ b/extensions/markdown/js/src/forum/components/MarkdownButton.js @@ -5,17 +5,19 @@ import apply from '../util/apply'; const modifierKey = navigator.userAgent.match(/Macintosh/) ? '⌘' : 'ctrl'; export default class MarkdownButton extends Component { - config(isInitialized) { - if (isInitialized) return; + oncreate(vnode) { + super.oncreate(vnode); this.$().tooltip(); } view() { - return ; + return ( + + ); } keydown(event) { @@ -26,13 +28,13 @@ export default class MarkdownButton extends Component { } click() { - return apply(this.element, this.props.style); + return apply(this.element, this.attrs.style); } title() { - let tooltip = this.props.title; + let tooltip = this.attrs.title; - if (this.props.hotkey) tooltip += ` <${modifierKey}-${this.props.hotkey}>`; + if (this.attrs.hotkey) tooltip += ` <${modifierKey}-${this.attrs.hotkey}>`; return tooltip; } diff --git a/extensions/markdown/js/src/forum/components/MarkdownToolbar.js b/extensions/markdown/js/src/forum/components/MarkdownToolbar.js index 525fdc2bc..e59e8313e 100644 --- a/extensions/markdown/js/src/forum/components/MarkdownToolbar.js +++ b/extensions/markdown/js/src/forum/components/MarkdownToolbar.js @@ -3,17 +3,17 @@ import Component from 'flarum/Component'; const modifierKey = navigator.userAgent.match(/Macintosh/) ? 'Meta' : 'Control'; export default class MarkdownToolbar extends Component { - config(isInitialized) { - if (isInitialized) return; + oncreate(vnode) { + super.oncreate(vnode); - const field = document.getElementById(this.props.for); + const field = document.getElementById(this.attrs.for); field.addEventListener('keydown', this.shortcut.bind(this)); } - view() { - return
- {this.props.children} + view(vnode) { + return
+ {vnode.children}
; } diff --git a/extensions/markdown/js/src/forum/index.js b/extensions/markdown/js/src/forum/index.js index 1c1662758..d50afbe56 100644 --- a/extensions/markdown/js/src/forum/index.js +++ b/extensions/markdown/js/src/forum/index.js @@ -17,7 +17,7 @@ import MarkdownButton from './components/MarkdownButton'; app.initializers.add('flarum-markdown', function(app) { let index = 1; - extend(TextEditor.prototype, 'init', function() { + extend(TextEditor.prototype, 'oninit', function() { this.textareaId = 'textarea'+(index++); }); @@ -25,19 +25,17 @@ app.initializers.add('flarum-markdown', function(app) { vdom.children[0].attrs.id = this.textareaId; }); - extend(TextEditor.prototype, 'configTextarea', function(value, element, isInitialized, context) { - if (isInitialized) return; - - const editor = new MarkdownArea(element, { + extend(TextEditor.prototype, 'oncreate', function() { + this.editor = new MarkdownArea(this.$('textarea')[0], { keyMap: { indent: ['Ctrl+m'], outdent: ['Ctrl+M'] } }); + }); - context.onunload = function() { - editor.destroy(); - }; + extend(TextEditor.prototype, 'onremove', function () { + this.editor.destroy(); }); extend(TextEditor.prototype, 'toolbarItems', function(items) {