Skip to content

Commit 47e7320

Browse files
committed
made the flow control buttons disabled until the user starts running the algorithm
1 parent 80d0ebd commit 47e7320

8 files changed

Lines changed: 92 additions & 40 deletions

css/stylesheet.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,8 @@ input[type=number]::-webkit-outer-spin-button {
516516
#btn_pause.active > .btn-text:before {
517517
content: 'Resume'
518518
}
519+
520+
button[disabled] {
521+
cursor: not-allowed;
522+
opacity: 0.6;
523+
}

js/dom/setup/setup_top_menu.js

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,52 +24,72 @@ module.exports = () => {
2424

2525
// control
2626

27-
$('#btn_run').click(function() {
28-
$('#btn_trace').click();
29-
$('#btn_pause').removeClass('active');
30-
$(this).addClass('active');
27+
const $btnRun = $('#btn_run');
28+
const $btnTrace = $('#btn_trace');
29+
const $btnPause = $('#btn_pause');
30+
const $btnPrev = $('#btn_prev');
31+
const $btnNext = $('#btn_next');
32+
const $btnDesc = $('#btn_desc');
33+
34+
const flowControlBtns = [ $btnPause, $btnPrev, $btnNext ];
35+
36+
const setFlowControlState = (isDisabled) => {
37+
flowControlBtns.forEach($btn => $btn.attr('disabled', isDisabled));
38+
};
39+
40+
// initially, control buttons are disabled
41+
setFlowControlState(true);
42+
43+
$btnRun.click(() => {
44+
$btnTrace.click();
45+
$btnPause.removeClass('active');
46+
$btnRun.addClass('active');
47+
setFlowControlState(false);
3148
var err = app.getEditor().execute();
3249
if (err) {
3350
console.error(err);
3451
Toast.showErrorToast(err);
3552
}
3653
});
37-
$('#btn_pause').click(function() {
38-
$('#btn_run').toggleClass('active');
39-
$(this).toggleClass('active');
54+
55+
$btnPause.click(() => {
56+
$btnRun.toggleClass('active');
57+
$btnPause.toggleClass('active');
4058
if (app.getTracerManager().isPause()) {
4159
app.getTracerManager().resumeStep();
4260
} else {
4361
app.getTracerManager().pauseStep();
4462
}
4563
});
46-
$('#btn_prev').click(() => {
47-
$('#btn_run').removeClass('active');
48-
$('#btn_pause').addClass('active');
64+
65+
$btnPrev.click(() => {
66+
$btnRun.removeClass('active');
67+
$btnPause.addClass('active');
4968
app.getTracerManager().pauseStep();
5069
app.getTracerManager().prevStep();
5170
});
52-
$('#btn_next').click(() => {
53-
$('#btn_run').removeClass('active');
54-
$('#btn_pause').addClass('active');
71+
72+
$btnNext.click(() => {
73+
$btnRun.removeClass('active');
74+
$btnPause.addClass('active');
5575
app.getTracerManager().pauseStep();
5676
app.getTracerManager().nextStep();
5777
});
5878

5979
// description & trace
6080

61-
$('#btn_desc').click(function() {
81+
$btnDesc.click(() => {
6282
$('.tab_container > .tab').removeClass('active');
6383
$('#tab_desc').addClass('active');
6484
$('.tab_bar > button').removeClass('active');
65-
$(this).addClass('active');
85+
$btnDesc.addClass('active');
6686
});
6787

68-
$('#btn_trace').click(function() {
88+
$btnTrace.click(() => {
6989
$('.tab_container > .tab').removeClass('active');
7090
$('#tab_module').addClass('active');
7191
$('.tab_bar > button').removeClass('active');
72-
$(this).addClass('active');
92+
$btnTrace.addClass('active');
7393
});
7494

7595
};

public/algorithm_visualizer.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,3 +645,8 @@ input[type=number]::-webkit-outer-spin-button {
645645
#btn_pause.active > .btn-text:before {
646646
content: 'Resume'
647647
}
648+
649+
button[disabled] {
650+
cursor: not-allowed;
651+
opacity: 0.6;
652+
}

public/algorithm_visualizer.js

Lines changed: 40 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/algorithm_visualizer.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/algorithm_visualizer.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/algorithm_visualizer.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/algorithm_visualizer.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)