mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +02:00
moved emberjs to gui folder
This commit is contained in:
parent
6a18d18f91
commit
dc49dbbeff
999 changed files with 677 additions and 651 deletions
129
gui/app/components/section/markdown/type-editor.js
Normal file
129
gui/app/components/section/markdown/type-editor.js
Normal file
|
@ -0,0 +1,129 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
import Ember from 'ember';
|
||||
import TooltipMixin from '../../../mixins/tooltip';
|
||||
|
||||
const {
|
||||
inject: { service }
|
||||
} = Ember;
|
||||
|
||||
export default Ember.Component.extend(TooltipMixin, {
|
||||
link: service(),
|
||||
pageBody: "",
|
||||
pagePreview: "",
|
||||
editMode: true,
|
||||
codeSyntax: null,
|
||||
codeEditor: null,
|
||||
editorId: Ember.computed('page', function () {
|
||||
let page = this.get('page');
|
||||
return `markdown-editor-${page.id}`;
|
||||
}),
|
||||
previewId: Ember.computed('page', function () {
|
||||
let page = this.get('page');
|
||||
return `markdown-preview-${page.id}`;
|
||||
}),
|
||||
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
this.set('pageBody', this.get('meta.rawBody').trim());
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
this.attachEditor();
|
||||
this.addTooltip(document.getElementById(this.get('tooltipId')));
|
||||
},
|
||||
|
||||
willDestroyElement() {
|
||||
let editor = this.get('codeEditor');
|
||||
|
||||
if (this.get('editMode')) {
|
||||
editor.toTextArea();
|
||||
editor = null;
|
||||
}
|
||||
|
||||
this.set('codeEditor', null);
|
||||
this.destroyTooltips();
|
||||
},
|
||||
|
||||
getBody() {
|
||||
return this.get('codeEditor').getDoc().getValue().trim();
|
||||
},
|
||||
|
||||
attachEditor() {
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById(this.get('editorId')), {
|
||||
theme: "default",
|
||||
mode: "markdown",
|
||||
lineNumbers: false,
|
||||
lineWrapping: true,
|
||||
indentUnit: 4,
|
||||
tabSize: 4,
|
||||
value: "",
|
||||
dragDrop: false,
|
||||
extraKeys: {"Enter": "newlineAndIndentContinueMarkdownList"}
|
||||
});
|
||||
|
||||
CodeMirror.commands.save = function(/*instance*/){
|
||||
Mousetrap.trigger('ctrl+s');
|
||||
};
|
||||
|
||||
this.set('codeEditor', editor);
|
||||
|
||||
let syntax = this.get("codeSyntax");
|
||||
|
||||
if (is.not.undefined(syntax)) {
|
||||
CodeMirror.autoLoadMode(editor, "markdown");
|
||||
editor.setOption("mode", "markdown");
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
onPreview() {
|
||||
this.set('editMode', !this.get('editMode'));
|
||||
|
||||
Ember.run.schedule('afterRender', () => {
|
||||
if (this.get('editMode')) {
|
||||
this.attachEditor();
|
||||
} else {
|
||||
this.set('pageBody',this.getBody());
|
||||
let md = window.markdownit({ linkify: true });
|
||||
let result = md.render(this.getBody());
|
||||
|
||||
this.set('pagePreview', result);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onInsertLink(link) {
|
||||
let linkMarkdown = this.get('link').buildLink(link);
|
||||
this.get('codeEditor').getDoc().replaceSelection(linkMarkdown);
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
isDirty() {
|
||||
return this.get('codeEditor').getDoc().isClean() === false;
|
||||
},
|
||||
|
||||
onCancel() {
|
||||
this.attrs.onCancel();
|
||||
},
|
||||
|
||||
onAction(title) {
|
||||
let page = this.get('page');
|
||||
let meta = this.get('meta');
|
||||
page.set('title', title);
|
||||
meta.set('rawBody', this.getBody());
|
||||
|
||||
this.attrs.onAction(page, meta);
|
||||
}
|
||||
}
|
||||
});
|
14
gui/app/components/section/markdown/type-renderer.js
Normal file
14
gui/app/components/section/markdown/type-renderer.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Component.extend({});
|
Loading…
Add table
Add a link
Reference in a new issue