-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.js
More file actions
36 lines (33 loc) · 1.43 KB
/
Copy pathmenu.js
File metadata and controls
36 lines (33 loc) · 1.43 KB
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
import initCanvas from './visualization/index.js';
import initAst from './ast.js';
window.addEventListener('load', function() {
const options = document.querySelectorAll('.option');
const highlight = document.querySelector('.highlight');
const right = document.getElementById('right');
options.forEach((option, index) => {
option.addEventListener('click', (event) => {
const width = option.offsetWidth;
const left = parseInt(option.offsetLeft) - 10;
highlight.style.transform = `translateX(${left}px)`;
highlight.style.width = width + 'px';
options.forEach((o, i) => {
if(i != index) o.className = 'option';
});
option.className += " active";
let is_nfa= event.target.innerText == 'NFA';
if(is_nfa) {
const is_canvas = right.innerHTML.includes('canvas');
right.innerHTML = `<canvas id="canvas"></canvas>`;
if(!is_canvas) initCanvas();
}
else {
right.innerHTML = `<div class="chart" id="OrganiseChart-simple"></div>`;
initAst();
}
});
});
const nfa = document.getElementById('nfa');
const style = (value) => window.getComputedStyle(nfa).getPropertyValue(value);
nfa.click();
highlight.style.height = (parseInt(style('height')) + 2*parseInt(style('padding'))) + 'px';
});