-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
49 lines (41 loc) · 1.36 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$(document).ready(function($) {
var mainSections = new Sections($("#menu a"), $("#mainSections > div"));
var $menuBar = $(".tabBar").first();
var interpreter = new Interpreter($("#interpreter"));
mainSections.Interpreter.addOnShow(interpreter.notifyBecameVisible.bind(interpreter));
var hookUpNavigationLinks = function() {
$("a[href=#spec]").click(function(ev) {
ev.preventDefault();
mainSections.Spec.show();
});
};
hookUpNavigationLinks();
var loadDemoCodeByName = function(name) {
var codeContainer = $('#'+name);
var code = codeContainer.text();
var input = codeContainer.attr("data-input");
interpreter.loadCode(code, input);
mainSections.Interpreter.show();
};
var hookUpDemoLinks = function() {
$("a[data-load-demo]").click(function(ev) {
loadDemoCodeByName($(ev.target).attr("data-load-demo"));
ev.preventDefault();
});
};
hookUpDemoLinks();
var loadDemoIfInUrl = function() {
var match;
if (match = document.location.hash.match(/#interpreter\|(.*)/)) {
loadDemoCodeByName(match[1]);
}
};
loadDemoIfInUrl();
var showMainSectionBasedOnUrlHash = function() {
var currentMainSection = document.location.hash.from(1).camelize();
if (mainSections[currentMainSection]) {
mainSections[currentMainSection].show();
}
};
showMainSectionBasedOnUrlHash();
});