in src/main/resources/SLING-INF/etc/clientlibs/repl/script.js [49:115]
function Editor(DOMElement, reloadOutputCallback) {
var that = this;
var element = $(DOMElement);
var editor = ace.edit(DOMElement);
var mode = element.data('mode');
var url = element.data('src');
var isWriteable = element.is('[data-writeable]');
function attachSaveHandler() {
if (isWriteable) {
editor.session.on('change', debounce(function () {
that.saveChanges();
}), 500);
}
}
function init() {
Editor.all[element.attr('id')] = that;
editor.renderer.setShowGutter(false);
editor.setHighlightActiveLine(false);
editor.setShowPrintMargin(false);
editor.setReadOnly(!isWriteable);
editor.session.setUseWorker(false);
editor.session.setMode(mode);
if (element.is(':visible')) {
that.loadContent(attachSaveHandler);
} else {
attachSaveHandler();
}
}
that.saveChanges = function (cb) {
if (isWriteable) {
$.ajax({
url: url,
type: 'PUT',
data: editor.getValue(),
contentType: 'plain/text',
success: reloadOutputCallback,
complete: cb
});
}
};
that.loadContent = function (cb) {
$.ajax(url, {
type: 'GET',
dataType: 'text',
cache: false,
processData: false,
success: function (data) {
editor.setValue(data);
editor.clearSelection();
},
error: function (req, textStatus, message) {
editor.setValue(req.responseText);
editor.clearSelection();
console.error(message);
},
complete: cb
});
};
init();
}