Added code editor mode selection

pull/2/head
NGPixel 8 years ago
parent 97602b51c8
commit 3212b62435

File diff suppressed because one or more lines are too long

@ -5,15 +5,30 @@
if($('#mk-editor').length === 1) {
require.config({paths: { "ace" : "/assets/js/ace"}});
let codeEditor = ace.edit("codeblock-editor");
codeEditor.setTheme("ace/theme/tomorrow_night");
codeEditor.getSession().setMode("ace/mode/markdown");
codeEditor.setOption('fontSize', '14px');
codeEditor.setOption('hScrollBarAlwaysVisible', false);
codeEditor.setOption('wrap', true);
let scEditor = ace.edit("codeblock-editor");
scEditor.setTheme("ace/theme/tomorrow_night");
scEditor.getSession().setMode("ace/mode/markdown");
scEditor.setOption('hScrollBarAlwaysVisible', false);
scEditor.setOption('wrap', true);
let modelist = ace.require("ace/ext/modelist");
var modelist = ace.require("ace/ext/modelist");
let vueCodeBlock = new Vue({
el: '#modal-editor-codeblock',
data: {
modes: modelist.modesByName,
modeSelected: 'text'
},
watch: {
modeSelected: (val, oldVal) => {
loadAceMode(val).done(() => {
ace.require("ace/mode/" + val);
codeEditor.getSession().setMode("ace/mode/" + val);
});
}
}
});
var mde = new SimpleMDE({
autofocus: true,
@ -115,8 +130,8 @@ if($('#mk-editor').length === 1) {
name: "code-block",
action: (editor) => {
$('#modal-editor-codeblock').slideDown(400, () => {
scEditor.resize();
scEditor.focus();
codeEditor.resize();
codeEditor.focus();
});
},
className: "fa fa-code",
@ -166,4 +181,23 @@ $('.btn-edit-save').on('click', (ev) => {
alerts.pushError('Something went wrong', 'Save operation failed.');
});
});
});
// ACE - Mode Loader
let modelistLoaded = [];
let loadAceMode = (m) => {
return $.ajax({
url: '/js/ace/mode-' + m + '.js',
dataType: "script",
cache: true,
beforeSend: () => {
if(_.includes(modelistLoaded, m)) {
return false;
}
},
success: () => {
modelistLoaded.push(m);
}
});
}

@ -100,10 +100,8 @@ gulp.task("scripts-libs", function () {
return merge(
gulp.src(paths.scriptlibs)
.pipe(plumber())
.pipe(concat('libs.js'))
.pipe(uglify({ mangle: false }))
.pipe(plumber.stop())
.pipe(gulp.dest("./assets/js")),
gulp.src(paths.scriptlibs_acemodes)

@ -112,7 +112,6 @@
"mocha": "^3.0.2",
"mocha-lcov-reporter": "^1.2.0",
"nodemon": "^1.10.2",
"requirejs": "^2.3.1",
"sticky-js": "^1.0.5",
"twemoji-awesome": "^1.0.4",
"vue": "^1.0.26"

@ -8,9 +8,8 @@
.column.is-narrow
p.control
span.select
select(style={width: '300px'})
option Plain text
option C#
select(style={width: '300px'}, v-model='modeSelected')
option(v-for="mode in modes" v-bind:value='mode.name') {{ mode.caption }}
.column.is-narrow
a.button.is-warning.is-outlined Cancel
.column.is-narrow

@ -18,6 +18,7 @@ block rootNavRight
block content
#page-type-create(data-entrypath=pageData.meta.path)
textarea#mk-editor= pageData.markdown
.editor-area
textarea#mk-editor= pageData.markdown
include ../modals/create-discard.pug

@ -18,7 +18,8 @@ block rootNavRight
block content
#page-type-edit(data-entrypath=pageData.meta.path)
textarea#mk-editor= pageData.markdown
.editor-area
textarea#mk-editor= pageData.markdown
include ../modals/edit-discard.pug
include ../modals/editor-link.pug

Loading…
Cancel
Save