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
*
@ -87,10 +100,10 @@ $config['cron_key'] = '';
* @string yourls
* @string gwgd
* @string googl
* @string bitly
* @string bitly
* @string random - Randomly chose any of upper API-s !WARNING! May be slow! For maximum performanse, it's recommended to either set all API keys or use random_url_engines to list working engines.
* @string none - same as off
*
*
* random_url_engines:
* - This variable sets list of APIs to be considered for usage if url_shortening_use is set to 'random'
* To consider all API-s, either leave it empty (as empty array or string) or type all apis available (yourls,gwgd,googl,bitly)
@ -102,7 +115,7 @@ $config['cron_key'] = '';
* - If input is @string it must be comma delimited, otherwise will be ignored.
* - Script will accept minimum of 2 APIs, ignored otherwise
* - Only alphanumeric characters and "." are allowed. Everything else is filtered out.
*
*
* -------------------------------------------------------------------------------------------------------------
* yourls_url: Your own instance of yourls URL-shortener (Download: http://yourls.org/)
* Example: http://example.com/yourls/
@ -113,12 +126,12 @@ $config['cron_key'] = '';
* gwgd_url: Your own instance of the gw.gd URL-shortener (Download: https://github.com/neofutur/gwgd)
* Default: http://gw.gd/
*
* googl_url_api: URL shortening service provided by Google Inc. (API: http://code.google.com/apis/console/)
* googl_url_api: URL shortening service provided by Google Inc. (API: http://code.google.com/apis/console/)
* Usage: Your API key
*
*
* bitly_url_api: Famous URL shortening service (API: http://dev.bitly.com/get_started.html)
* Usage: Your API key
*
*
**/
$config['url_shortening_use'] = 'off';
$config['random_url_engines'] = 'googl,bitly'; // Used only in random mode, read comment above for more info
@ -241,9 +254,9 @@ $config['unknown_title'] = 'Untitled';
* Weather to require LDAP authenticaiton or not.
* Set to either 'true' to require authentication or 'false' not to.
* NOTE: if changed, set LDAP settings in auth_ldap.php
**/
**/
$config['require_auth'] = false;
/**
* Override the displayed URL
*

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');
$this->carabiner->js('ace/ace.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');
$this->carabiner->js('ace/ace.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');