mirror of
https://github.com/flarum/framework.git
synced 2024-11-26 02:10:09 +08:00
parent
5081cd47c1
commit
ab63a55d60
|
@ -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 <button className="Button Button--icon Button--link" title={this.title()} data-hotkey={this.props.hotkey}
|
||||
onclick={this.click.bind(this)} onkeydown={this.keydown.bind(this)}>
|
||||
{icon(this.props.icon)}
|
||||
</button>;
|
||||
return (
|
||||
<button className="Button Button--icon Button--link" title={this.title()} data-hotkey={this.attrs.hotkey}
|
||||
onclick={this.click.bind(this)} onkeydown={this.keydown.bind(this)}>
|
||||
{icon(this.attrs.icon)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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 <div id="MarkdownToolbar" data-for={this.props.for} style={{ display: 'inline-block' }}>
|
||||
{this.props.children}
|
||||
view(vnode) {
|
||||
return <div id="MarkdownToolbar" data-for={this.attrs.for} style={{ display: 'inline-block' }}>
|
||||
{vnode.children}
|
||||
</div>;
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user