Merge branch 'master' into editor-frontend-refactor
Conflicts: app/assets/javascripts/editor.js.erb app/views/exercises/implement.html.slim
This commit is contained in:
55
app/assets/javascripts/editor_edit.js
Normal file
55
app/assets/javascripts/editor_edit.js
Normal file
@ -0,0 +1,55 @@
|
||||
$(function() {
|
||||
var ACE_FILES_PATH = '/assets/ace/';
|
||||
var THEME = 'ace/theme/textmate';
|
||||
|
||||
var configureEditors = function() {
|
||||
_.each(['modePath', 'themePath', 'workerPath'], function(attribute) {
|
||||
ace.config.set(attribute, ACE_FILES_PATH);
|
||||
});
|
||||
};
|
||||
|
||||
var initializeEditors = function() {
|
||||
$('.editor').each(function(index, element) {
|
||||
var editor = ace.edit(element);
|
||||
|
||||
var document = editor.getSession().getDocument();
|
||||
// insert pre-existing code into editor. we have to use insertLines, otherwise the deltas are not properly added
|
||||
var file_id = $(element).data('file-id');
|
||||
var content = $('.editor-content[data-file-id=' + file_id + ']');
|
||||
|
||||
document.insertLines(0, content.text().split(/\n/));
|
||||
// remove last (empty) that is there by default line
|
||||
document.removeLines(document.getLength() - 1, document.getLength() - 1);
|
||||
editor.setReadOnly($(element).data('read-only') !== undefined);
|
||||
editor.setShowPrintMargin(false);
|
||||
editor.setTheme(THEME);
|
||||
|
||||
var textarea = $('textarea[id="exercise_files_attributes_'+index+'_content"]');
|
||||
var content = textarea.val();
|
||||
|
||||
if (content != undefined)
|
||||
{
|
||||
editor.getSession().setValue(content);
|
||||
editor.getSession().on('change', function(){
|
||||
textarea.val(editor.getSession().getValue());
|
||||
});
|
||||
}
|
||||
|
||||
editor.commands.bindKey("ctrl+alt+0", null);
|
||||
var session = editor.getSession();
|
||||
session.setMode($(element).data('mode'));
|
||||
session.setTabSize($(element).data('indent-size'));
|
||||
session.setUseSoftTabs(true);
|
||||
session.setUseWrapMode(true);
|
||||
|
||||
var file_id = $(element).data('id');
|
||||
}
|
||||
)};
|
||||
|
||||
if ($('#editor-edit').isPresent()) {
|
||||
configureEditors();
|
||||
initializeEditors();
|
||||
$('.frame').show();
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user