-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.js
61 lines (36 loc) · 1.05 KB
/
demo.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
50
51
52
53
54
55
56
57
58
59
60
61
import SpringSolverDemo from "./spring-solver-demo.js"
import GeometricSolverDemo from "./geometric-solver-demo.js"
import DynamicSolverDemo from "./dynamic-solver-demo.js"
$(function(){
var demos = [
new SpringSolverDemo(),
new GeometricSolverDemo(),
new DynamicSolverDemo()
];
const activeClass = "active";
var currentDemo = null;
for (let i=0; i<demos.length; i++) {
let demo = demos[i];
let demoButton = $("<div>").addClass("demo-button").text(demo.name);
demo.button = demoButton;
let targetDemo = demo;
$("#demo-list").append(demoButton);
demoButton.click(function(e){
location.hash = `demo${i+1}`
if(currentDemo)
currentDemo.clear();
$(".demo-button").removeClass(activeClass);
$(this).addClass(activeClass);
currentDemo = targetDemo;
currentDemo.init();
currentDemo.animate();
});
}
var locationHash = location.hash.match(/\#demo[1-3]/);
var demoNum = 1;
if(locationHash){
var s = locationHash.toString();
demoNum = s[s.length-1];
}
demos[demoNum -1].button.click();
});