Browse Source

Added code editor mode selection

pull/2/head
NGPixel 8 years ago
parent
commit
3212b62435
7 changed files with 51 additions and 19 deletions
  1. 2
      assets/js/app.js
  2. 54
      client/js/components/editor.js
  3. 2
      gulpfile.js
  4. 1
      package.json
  5. 5
      views/modals/editor-codeblock.pug
  6. 3
      views/pages/create.pug
  7. 3
      views/pages/edit.pug

2
assets/js/app.js
File diff suppressed because it is too large
View File

54
client/js/components/editor.js

@ -5,15 +5,30 @@
if($('#mk-editor').length === 1) { 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({ var mde = new SimpleMDE({
autofocus: true, autofocus: true,
@ -115,8 +130,8 @@ if($('#mk-editor').length === 1) {
name: "code-block", name: "code-block",
action: (editor) => { action: (editor) => {
$('#modal-editor-codeblock').slideDown(400, () => { $('#modal-editor-codeblock').slideDown(400, () => {
scEditor.resize();
scEditor.focus();
codeEditor.resize();
codeEditor.focus();
}); });
}, },
className: "fa fa-code", className: "fa fa-code",
@ -166,4 +181,23 @@ $('.btn-edit-save').on('click', (ev) => {
alerts.pushError('Something went wrong', 'Save operation failed.'); 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);
}
});
}

2
gulpfile.js

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

1
package.json

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

5
views/modals/editor-codeblock.pug

@ -8,9 +8,8 @@
.column.is-narrow .column.is-narrow
p.control p.control
span.select 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 .column.is-narrow
a.button.is-warning.is-outlined Cancel a.button.is-warning.is-outlined Cancel
.column.is-narrow .column.is-narrow

3
views/pages/create.pug

@ -18,6 +18,7 @@ block rootNavRight
block content block content
#page-type-create(data-entrypath=pageData.meta.path) #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 include ../modals/create-discard.pug

3
views/pages/edit.pug

@ -18,7 +18,8 @@ block rootNavRight
block content block content
#page-type-edit(data-entrypath=pageData.meta.path) #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/edit-discard.pug
include ../modals/editor-link.pug include ../modals/editor-link.pug
Loading…
Cancel
Save