dynamic loading works. #syntax #highlighting

This commit is contained in:
Claude 2012-04-23 19:44:28 +02:00
parent 1342992636
commit e503c4af89

View File

@ -4,15 +4,12 @@ CM.enabled = false;
CM.init = function() { CM.init = function() {
CM.modes = $.parseJSON($('#codemirror_modes').text()); CM.modes = $.parseJSON($('#codemirror_modes').text());
$enable_codemirror = $('#enable_codemirror'); $('#enable_codemirror').click(function() {
$enable_codemirror.click(function() {
//todo: no rebind
$('#lang').change(function() { $('#lang').change(function() {
CM.set_language(); CM.set_language();
}); });
CM.toggle(); CM.toggle();
CM.set_language();
return false; return false;
}); });
}; };
@ -22,6 +19,7 @@ CM.toggle = function() {
CM.editor.toTextArea(); CM.editor.toTextArea();
CM.editor = undefined; CM.editor = undefined;
$('#lang').unbind(); $('#lang').unbind();
$('#enable_codemirror').text('Enable syntax highlighting');
CM.enabled = false; CM.enabled = false;
} else { } else {
if (typeof CM.editor == 'undefined') { if (typeof CM.editor == 'undefined') {
@ -30,23 +28,26 @@ CM.toggle = function() {
lineWrapping: true, lineWrapping: true,
}); });
} }
$('#enable_codemirror').text('Disable syntax highlighting');
CM.enabled = true; CM.enabled = true;
} }
}; };
CM.set_language = function() { CM.set_language = function() {
var lang = $('#lang').val(); if (CM.enabled) {
mode = CM.modes[lang]; var lang = $('#lang').val();
mode = CM.modes[lang];
$.get(base_url + 'main/get_cm_js/' + lang, $.get(base_url + 'main/get_cm_js/' + lang,
function(data) { function(data) {
if (data != '') { if (data != '') {
CM.set_syntax(mode); CM.set_syntax(mode);
} else { } else {
CM.set_syntax(null); CM.set_syntax(null);
} }
}, },
'script'); 'script');
}
}; };
CM.set_syntax = function(mode) { CM.set_syntax = function(mode) {