Skip to content

Commit 8f3a06b

Browse files
committed
Modularized top menu functionality into its own module
1 parent 709c922 commit 8f3a06b

File tree

7 files changed

+124
-78
lines changed

7 files changed

+124
-78
lines changed

js/dom/setup/setup_top_menu.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const app = require('../../app');
22
const Server = require('../../server');
33
const Toast = require('../toast');
4+
const TopMenu = require('../top_menu');
45

56
module.exports = () => {
67

@@ -31,20 +32,14 @@ module.exports = () => {
3132
const $btnNext = $('#btn_next');
3233
const $btnDesc = $('#btn_desc');
3334

34-
const flowControlBtns = [ $btnPause, $btnPrev, $btnNext ];
35-
36-
const setFlowControlState = (isDisabled) => {
37-
flowControlBtns.forEach($btn => $btn.attr('disabled', isDisabled));
38-
};
39-
4035
// initially, control buttons are disabled
41-
setFlowControlState(true);
36+
TopMenu.disableFlowControl();
4237

4338
$btnRun.click(() => {
4439
$btnTrace.click();
4540
$btnPause.removeClass('active');
4641
$btnRun.addClass('active');
47-
setFlowControlState(false);
42+
TopMenu.enableFlowControl();
4843
var err = app.getEditor().execute();
4944
if (err) {
5045
console.error(err);

js/dom/top_menu.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const flowControlBtns = [ $('#btn_pause'), $('#btn_prev'), $('#btn_next') ];
4+
const setFlowControlState = (isDisabled) => {
5+
flowControlBtns.forEach($btn => $btn.attr('disabled', isDisabled));
6+
};
7+
8+
const enableFlowControl = () => {
9+
setFlowControlState(false);
10+
};
11+
12+
const disableFlowControl = () => {
13+
setFlowControlState(true);
14+
};
15+
16+
const resetTopMenuButtons = () => {
17+
$('.top-menu-buttons button').removeClass('active');
18+
disableFlowControl();
19+
};
20+
21+
module.exports = {
22+
enableFlowControl,
23+
disableFlowControl,
24+
resetTopMenuButtons
25+
};

js/tracer_manager/manager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const TopMenu = require('../dom/top_menu');
4+
35
const stepLimit = 1e6;
46

57
const TracerManager = function () {
@@ -180,7 +182,7 @@ TracerManager.prototype = {
180182

181183
this.timer = setTimeout(() => {
182184
if (!tracer.nextStep(options)) {
183-
$('#btn_run').removeClass('active');
185+
TopMenu.resetTopMenuButtons();
184186
}
185187
}, this.interval);
186188
},
@@ -242,4 +244,4 @@ TracerManager.prototype = {
242244
}
243245
};
244246

245-
module.exports = TracerManager;
247+
module.exports = TracerManager;

0 commit comments

Comments
 (0)