$(document).on('click', '.codemirror-toolbar .fa-undo-alt', function(){
window.myCodeMirror.undo();
});
$(document).on('click', '.codemirror-toolbar .fa-redo-alt', function(){
window.myCodeMirror.redo();
});
$(document).on('click', '.codemirror-toolbar .fa-file-image', function(){
$('.modal-image').modal('show');
});
$(document).on('click', '.modal-image img', function(){
let img_src = '';
if(window.mode_markdown){
img_src = '![<%= EscapeUtils.escape_html t.default_alt_img %>](' + $(this).attr('src') + ')';
}
window.myCodeMirror.replaceSelection(img_src);
$('.modal-image').modal('hide');
});
$(document).on('click', '.codemirror-toolbar .fa-heading', function(){
let obj_cursor = window.myCodeMirror.getCursor();
let heading_number = 0;
if($(this).hasClass('cmt-heading-1')){
heading_number = 1;
}else if($(this).hasClass('cmt-heading-2')){
heading_number = 2;
}else if($(this).hasClass('cmt-heading-3')){
heading_number = 3;
}else if($(this).hasClass('cmt-heading-4')){
heading_number = 4;
}else if($(this).hasClass('cmt-heading-5')){
heading_number = 5;
}
let begin_str = '';
end_str = '';
if(window.mode_markdown){
begin_str = '~~';
end_str = '~~';
}
}else if($(this).hasClass('fa-link')){
begin_str = '';
end_str = '';
if(window.mode_markdown){
begin_str = '[';
end_str = '](https://www.example.com/)';
}
}else if($(this).hasClass('fa-quote-left')){
begin_str = '
\n'; if(window.mode_markdown){ begin_str = '>'; end_str = ''; } }else if($(this).hasClass('fa-list')){ begin_str = ''; end_str = '
\n
\n'; end_str = '\n'; if(window.mode_markdown){ begin_str = '```'; end_str = '```'; } } let obj_cursor = window.myCodeMirror.getCursor(); window.myCodeMirror.replaceSelection(begin_str + window.myCodeMirror.getSelection() + end_str); if(!window.myCodeMirror.somethingSelected()){ let moreline = (begin_str.split('\n').length > 1 ? begin_str.split('\n').length / 2 : 0); let morech = (moreline > 0 ? begin_str.split('\n')[begin_str.split('\n').length - 1].length : begin_str.length); window.myCodeMirror.setCursor({ line: obj_cursor.line + moreline, ch: obj_cursor.ch + morech }); } window.myCodeMirror.focus(); });