codemirror/ace switcher

This commit is contained in:
Claude 2016-09-02 18:29:27 +02:00
parent 8531d66b8a
commit d010a828d6
5 changed files with 73 additions and 78 deletions

View File

@ -54,6 +54,19 @@ $config['db_prefix'] = '';
*/
$config['theme'] = 'default';
/**
* JavaScript-Editor
*
* Which editor to use
* CodeMirror, ACE or none
*
* none: ~130kb JS
* CodeMirror: ~300kb JS
* ACE: >800kb JS
*
*/
$config['js_editor'] = ''; // codemirror, ace, ''
/**
* Language
*

View File

@ -1,65 +0,0 @@
var CM = window.CM || {}
CM.enabled = false;
CM.init = function() {
var $enable_codemirror = $('#enable_codemirror');
var lang_enablesynhl = $enable_codemirror.data('lang-enablesynhl');
$enable_codemirror.text(lang_enablesynhl);
CM.modes = $.parseJSON($('#codemirror_modes').text());
$enable_codemirror.click(function() {
$('#lang').change(function() {
CM.set_language();
});
CM.toggle();
CM.set_language();
return false;
});
};
CM.toggle = function() {
var $enable_codemirror = $('#enable_codemirror');
var lang_enablesynhl = $enable_codemirror.data('lang-enablesynhl');
var lang_disablesynhl = $enable_codemirror.data('lang-disablesynhl');
if (CM.enabled) {
CM.editor.toTextArea();
CM.editor = undefined;
$('#lang').unbind();
$enable_codemirror.text(lang_enablesynhl);
CM.enabled = false;
} else {
if (typeof CM.editor == 'undefined') {
CM.editor = CodeMirror.fromTextArea(document.getElementById('code'), {
lineNumbers: true,
lineWrapping: true,
});
}
$enable_codemirror.text(lang_disablesynhl);
CM.enabled = true;
}
};
CM.set_language = function() {
if (CM.enabled) {
var lang = $('#lang').val();
mode = CM.modes[lang];
$.get(base_url + 'main/get_cm_js/' + lang,
function(data) {
if (data != '') {
CM.set_syntax(mode);
} else {
CM.set_syntax(null);
}
},
'script');
}
};
CM.set_syntax = function(mode) {
CM.editor.setOption('mode', mode);
};
$(document).ready(function() {
CM.init();
});

View File

@ -239,15 +239,19 @@ ST.filereader = function() {
});
}
ST.ace = function() {
ST.ace_init = function() {
// prepare the editor, needs to be a div
var $code = $('#code');
// exit if there is no code textarea
// exit if there is no #code textarea
if ($code.length < 1) {
return false;
}
if (typeof ace == 'undefined') {
return false;
}
// replace textarea
$code.after('<div id="editor" style="left: 10px; width: 703px; height: 312px;"></div>');
$code.hide();
@ -263,6 +267,38 @@ ST.ace = function() {
});
}
ST.codemirror_init = function() {
if (typeof CodeMirror == 'undefined') {
return false;
}
ST.cm_modes = $.parseJSON($('#codemirror_modes').text());
$('#lang').change(function() {
ST.codemirror_setlang();
});
if (typeof ST.cm_editor == 'undefined') {
ST.cm_editor = CodeMirror.fromTextArea(document.getElementById('code'), {
lineNumbers: true,
lineWrapping: true,
});
}
ST.codemirror_setlang();
}
ST.codemirror_setlang = function() {
var lang = $('#lang').val();
mode = ST.cm_modes[lang];
$.get(base_url + 'main/get_cm_js/' + lang,
function(data) {
if (data != '') {
ST.cm_editor.setOption('mode', mode);
} else {
ST.cm_editor.setOption('mode', null);
}
},
'script');
}
ST.init = function() {
ST.expand();
ST.show_embed();
@ -270,7 +306,8 @@ ST.init = function() {
ST.line_highlighter();
ST.crypto();
ST.filereader();
ST.ace();
ST.codemirror_init();
ST.ace_init();
};
$(document).ready(function() {

View File

@ -16,7 +16,12 @@ $this->carabiner->js('jquery.timers.js');
$this->carabiner->js('crypto-js/rollups/aes.js');
$this->carabiner->js('lz-string-1.3.3-min.js');
$this->carabiner->js('filereader.js');
if(config_item('js_editor') == 'codemirror') {
$this->carabiner->js('codemirror/codemirror.js');
}
if(config_item('js_editor') == 'ace') {
$this->carabiner->js('ace/ace.js');
}
$this->carabiner->js('stikked.js');
$this->carabiner->display('js');

View File

@ -10,7 +10,12 @@ $this->carabiner->js('jquery.timers.js');
$this->carabiner->js('crypto-js/rollups/aes.js');
$this->carabiner->js('lz-string-1.3.3-min.js');
$this->carabiner->js('filereader.js');
if(config_item('js_editor') == 'codemirror') {
$this->carabiner->js('codemirror/codemirror.js');
}
if(config_item('js_editor') == 'ace') {
$this->carabiner->js('ace/ace.js');
}
$this->carabiner->js('stikked.js');
$this->carabiner->display('js');