// requires JQuery
sclass HTMLAceEditor {
S text;
S name = "text";
S id;
Map divParams;
*() {}
*(S *text) {}
S headStuff() {
ret hscriptsrc("https://botcompany.de/ace-builds/src-noconflict/ace.js")
+ hscriptsrc("https://botcompany.de/ace-builds/src-noconflict/ext-language_tools.js")
+ hcomment("need JQuery");
}
S html() {
id = "ace_" + name;
ret div(htmlEncode2(text), params_stylePlus("display: none", paramsPlus(mapToParams(divParams), +id)))
+ hhiddenWithIDAndName(name)
+ hscript(replaceDollarVars([[ (function() {
ace.require("ace/ext/language_tools");
var editor = ace.edit($id);
editor.setTheme("ace/theme/ambience");
editor.getSession().setTabSize(2);
editor.getSession().setUseSoftTabs(true);
editor.getSession().setUseWrapMode(true);
document.getElementById($id).style.fontSize='15px';
editor.setOptions({
enableBasicAutocompletion: true
});
var hiddenVal = document.getElementById($name);
function updateHidden() {
//hiddenVal.value = editor.getValue();
var newVal = editor.getValue();
if (hiddenVal.value != newVal)
$(hiddenVal).val(newVal).trigger('change');
}
updateHidden();
editor.session.on('change', updateHidden);
var div = $("#" + $id);
div.show();
//editor.focus();
})() ]], id := jsQuote(id), name := jsQuote(name));
}
}