1$(document).ready(function() {
 2
 3  var $editor = $('#editor');
 4  var modes = {
 5    coffeescript: 'coffee',
 6    javascript: 'javascript',
 7    ruby: 'ruby'
 8  }
 9
10  if ($editor.length > 0) {
11    var editor = ace.edit('editor');
12    var firstFocus = true;
13    editor.setTheme("ace/theme/twilight");
14    editor.getSession().setTabSize(2);
15    editor.setFontSize(22);
16
17    var initialMode = modes[$('form input[name*="language"]').val()];
18    editor.getSession().setMode("ace/mode/" + initialMode);
19
20    editor.on("focus", function () {
21      if ($editor.hasClass('problem')) {
22        if (firstFocus) editor.setValue('');
23        firstFocus = false;
24      }
25    });
26
27    $('.mode-toggle').click(function(event) {
28      event.preventDefault();
29      var language = $(this).data().language;
30      var mode = modes[language];
31      var display = $(this).html();
32
33      editor.getSession().setMode("ace/mode/" + mode);
34      $('form input[name*="language"]').val(language);
35      $('span.language').html(display);
36    });
37
38    $editor.closest('form').submit(function() {
39      var code = editor.getValue();
40      $(this).find('input[name*="[code]"]').val(code);
41    });
42  }
43});
44

What's a better way of storing the mappings of language display name to the stored language string and ACE editor mode?

posted Dec 19 '14 at 17:53

0 Refactors