var questListEN = [
  { link:"title-1.html", title:"Ch 1. Say hi to vim!", levels: [
    { link:"level-1-1.html", text:"Level 1-1. Exit vim. :q" },
    { link:"level-1-2.html", text:"Level 1-2. Save file. :w" },
  ]},
  { link:"title-2.html", title:"Ch 2. Writing something", levels: [
    { link:"level-2-1.html", text:"Level 2-1. Insert mode. i, Esc" },
    { link:"level-2-2.html", text:"Level 2-2. Advanced insert modes. A, o" },
  ]},
  { link:"title-3.html", title:"Ch 3. Select and edit", levels: [
    { link:"level-3-1.html", text:"Level 3-1. Visual mode & delete. v, d" },
  ]},
];

function Tutorial(questList_) {

  var questList = questList_;

  var verifier = function() { return true; };
  var nextFile = "level0.html";

  var setVerifier = function(func, file) {
    verifier = func;
    nextFile = file;
  };

  var goTutorial = function(filename) {
    $.ajax({
      url: "levels/" + filename,
    }).done(function(data) {
      $("#tutorial").html(data);
    }).fail(function() {
      throw "file levels/" + filename + " not found";
    });
  };

  var focused = true;

  var initVimOverlay = function() {
    var cm = $(".CodeMirror");
    var ov = $("#vim-overlay");
    ov.css("z-index",1000);
    ov.css("position","absolute");
    ov.offset(cm.offset());
    ov.outerHeight(cm.outerHeight());
    ov.outerWidth(cm.outerWidth());

    $("#vim-overlay").click(function() {
      editor.focus();
      if (!focused) {
        $("#vim-overlay").css("opacity","0.0");
      }
    });

    CodeMirror.on(editor, 'vim-quit', function() {
      focused = false;
      $("#vim-overlay").css("opacity","0.7");
    });

    CodeMirror.commands.save = function() {
      var result = verifier();
      if (result) {
        alert("Good job! going to next level.");
        goTutorial(nextFile);
      }
      else {
        alert("Awww.. try again.");
      }
    };
  };

  var getClickHandler = function(link) {
    return function() {
      goTutorial(link);
    }
  }

  var initQuestList = function() {

    for (var i = 0; i < questList.length; i ++) {
      var chapter = questList[i];

      var a = $("<a></a>")
        .addClass("quest-chapter")
        .click(getClickHandler(chapter.link))
        .html(chapter.title);
      var ul = $("<ul></ul>");

      var levels = chapter.levels;
      for (var j = 0; j < levels.length; j ++) {
        var level = levels[j];
        var b = $("<a></a>")
          .addClass("quest-level")
          .click(getClickHandler(level.link))
          .html(level.text);
        var li = $("<li></li>");
        li.append(b);
        ul.append(li);
      }

      $("#quest-list").append(a);
      $("#quest-list").append(ul);
    }
  }

  var init = function() {
    initVimOverlay();
    initQuestList();
  };

  return {
    init: init,
    setVerifier: setVerifier,
  };
}

var tutorial = new Tutorial(questListEN);


@@ -1,597 +1,4 @@
-var questListEN = %5B%0A  %7B link:%22title-1.html%22, title:%22Ch 1. Say hi to vim!%22, levels: %5B%0A    %7B link:%22level-1-1.html%22, text:%22Level 1-1. Exit vim. :q%22 %7D,%0A    %7B link:%22level-1-2.html%22, text:%22Level 1-2. Save file. :w%22 %7D,%0A  %5D%7D,%0A  %7B link:%22title-2.html%22, title:%22Ch 2. Writing something%22, levels: %5B%0A    %7B link:%22level-2-1.html%22, text:%22Level 2-1. Insert mode. i, Esc%22 %7D,%0A    %7B link:%22level-2-2.html%22, text:%22Level 2-2. Advanced insert modes. A, o%22 %7D,%0A  %5D%7D,%0A  %7B link:%22title-3.html%22, title:%22Ch 3. Select and edit%22, levels: %5B%0A    %7B link:%22level-3-1.html%22, text:%22Level 3-1. Visual mode & delete. v, d%22 %7D,%0A  %5D%7D,%0A%5D;%0A%0A
 func
@@ -15,224 +15,13 @@
 ial(
-questList_
 ) %7B%0A%0A
-  var questList = questList_;%0A%0A  var verifier = function() %7B return true; %7D;%0A  var nextFile = %22level0.html%22;%0A%0A  var setVerifier = function(func, file) %7B%0A    verifier = func;%0A    nextFile = file;%0A  %7D;%0A%0A
   va
@@ -267,1706 +267,447 @@
 var 
-focused = true;%0A%0A  var initVimOverlay = function() %7B%0A    var cm = $(%22.CodeMirror%22);%0A    var ov = $(%22#vim-overlay%22);%0A    ov.css(%22z-index%22,1000);%0A    ov.css(%22position%22,%22absolute%22);%0A    ov.offset(cm.offset());%0A    ov.outerHeight(cm.outerHeight());%0A    ov.outerWidth(cm.outerWidth());%0A%0A    $(%22#vim-overlay%22).click(function() %7B%0A      editor.focus();%0A      if (!focused) %7B%0A        $(%22#vim-overlay%22).css(%22opacity%22,%220.0%22);%0A      %7D%0A    %7D);%0A%0A    CodeMirror.on(editor, 'vim-quit', function() %7B%0A      focused = false;%0A      $(%22#vim-overlay%22).css(%22opacity%22,%220.7%22);%0A    %7D);%0A%0A    CodeMirror.commands.save = function() %7B%0A      var result = verifier();%0A      if (result) %7B%0A        alert(%22Good job! going to next level.%22);%0A        goTutorial(nextFile);%0A      %7D%0A      else %7B%0A        alert(%22Awww.. try again.%22);%0A      %7D%0A    %7D;%0A  %7D;%0A%0A  var getClickHandler = function(link) %7B%0A    return function() %7B%0A      goTutorial(link);%0A    %7D%0A  %7D%0A%0A  var initQuestList = function() %7B%0A%0A    for (var i = 0; i %3C questList.length; i ++) %7B%0A      var chapter = questList%5Bi%5D;%0A%0A      var a = $(%22%3Ca%3E%3C/a%3E%22)%0A        .addClass(%22quest-chapter%22)%0A        .click(getClickHandler(chapter.link))%0A        .html(chapter.title);%0A      var ul = $(%22%3Cul%3E%3C/ul%3E%22);%0A%0A      var levels = chapter.levels;%0A      for (var j = 0; j %3C levels.length; j ++) %7B%0A        var level = levels%5Bj%5D;%0A        var b = $(%22%3Ca%3E%3C/a%3E%22)%0A          .addClass(%22quest-level%22)%0A          .click(getClickHandler(level.link))%0A          .html(level.text);%0A        var li = $(%22%3Cli%3E%3C/li%3E%22);%0A        li.append(b);%0A        ul.append(li);%0A      %7D%0A%0A      $(%22#quest-list%22).append(a);%0A      $(%22#quest-list%22).append(ul);%0A    %7D%0A  %7D%0A%0A  var init = function() %7B%0A    initVimOverlay();%0A    initQuestList();%0A  %7D;
+verifier = function() %7B return true; %7D;%0A  var nextFile = %22basic0.html%22;%0A%0A  var setVerifier = function(func, file) %7B%0A    verifier = func;%0A    nextFile = file;%0A  %7D;%0A%0A  var init = function() %7B%0A    CodeMirror.commands.save = function() %7B%0A      var result = verifier();%0A      if (result) %7B%0A        alert(%22Good job! going to next level.%22);%0A        goTutorial(nextFile);%0A      %7D%0A      else %7B%0A        alert(%22Awww.. try again.%22);%0A      %7D%0A    %7D;%0A  %7D
 %0A%0A  
@@ -801,19 +801,8 @@
 ial(
-questListEN
 );%0A%0A

Clear quest.js