-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
180 lines (162 loc) · 6.19 KB
/
test.html
File metadata and controls
180 lines (162 loc) · 6.19 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
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html>
<head>
<title>Stack Test</title>
<link rel="stylesheet" type="text/css" href="_stacks/assets/css/animator.css">
<style>
.p-2 {
padding: 0.5rem;
}
.mb-2 {
margin-bottom: 0.5rem;
}
.mb-4 {
margin-bottom: 1rem;
}
.text-center {
text-align: center;
}
.btn {
cursor: pointer;
padding: 0.5rem 0.75rem;
border-radius: 6px;
border: 1px solid;
}
.btn-primary {
background-color: rgb(126, 34, 206);
color: #FFF;
}
.btn-primary:hover {
background-color: rgba(126, 34, 206, 0.9);
}
.d-none {
display: none;
}
#final-output {
display: inline-block;
border-radius: 4px;
border: 2px solid rgb(234,88,12);
}
</style>
</head>
<body>
<div>
<div class="solution-result-display mb-4">
<h4>Input:</h4>
<div class="mb-2">
<label>Please enter the input array</label>
<input type="text" class="sv-input sv-input-array" name="">
<div class="sv-input-feedback d-none">Enter the array elements followed by a comma</div>
</div>
<div class="mb-2">
<label>Please enter the input string</label>
<input type="text" class="sv-input" name="" validation=".?\[.+\]">
<div class="sv-input-feedback d-none">This is the custom help text for this input</div>
</div>
<div class="mb-2">
<label>Please enter the start index</label>
<input type="text" class="sv-input sv-input-number" name="">
<div class="sv-input-feedback d-none">This is the custom help text for this input</div>
</div>
<div class="mb-2">
<button class="btn btn-primary" id="btn-show-visualization">Show Visualization</button>
</div>
<h4>Output:</h4>
<div class="mb-2 p-2" id="final-output">
</div>
</div>
<div class="sv-comment text-center p-2 mb-2"></div>
<div id="stack-visualizer">
</div>
</div>
<template id="stack-template">
<div class="stack-wrapper">
<div class="stack-ops">
<strong>
<span class="text-underline"> PUSH </span>
</strong>
<span></span>
<strong>
<small>Last</small> <br>
<span class="text-underline"> POP </span>
</strong>
</div>
<div class="stack-ops-values">
<div class="stack-item hidden push-element">5</div>
<span></span>
<div class="stack-item pop-element"> </div>
</div>
<div class="stack-container">
<span></span>
<div class="stack"></div>
<span></span>
</div>
<div class="stack-description">
<h4></h4>
<p></p>
</div>
</div>
</template>
<script src="_stacks/assets/js/stack-displayer.js"></script>
<script src="_stacks/assets/js/animator-module.js"></script>
<script src="_stacks/assets/js/stack.js"></script>
<script src="_stacks/assets/js/index-of-closing-bracket.js"></script>
<script>
// On click
let showVisualizationBtn = document.getElementById('btn-show-visualization');
showVisualizationBtn.addEventListener('click', () => {
// Validate the inputs
let inputs = document.getElementsByClassName('sv-input');
let args = [];
for (let input of inputs) {
let feedbackElement = input.nextElementSibling;
feedbackElement.classList.add('d-none');
if (input.classList.contains('sv-input-array')) {
// Remove last comma
let arrayValue = input.value.replace(/,\s*$/, "");
if (! /^\s*\d+\s*(,\s*\d+\s*)*$/.test(arrayValue)) {
// feedbackElement.innerText = 'Please enter the array elements followed by a comma';
// feedbackElement.classList.remove('d-none');
} else {
feedbackElement.classList.add('d-none');
let array = arrayValue.split(',');
array.forEach((value, index) => {
array[index] = parseInt(value.trim());
});
args.push(array);
}
} else {
if (input.getAttribute('validation')) {
let regex = new RegExp(input.getAttribute('validation'));
if (! regex.test(input.value)) {
feedbackElement.innerText = 'Please enter the string in correct format';
feedbackElement.classList.remove('d-none');
return;
}
}
args.push(input.value);
}
}
document.getElementById('final-output')
.innerHTML = ' ';
document.getElementById('stack-visualizer')
.innerHTML = '';
animatorModule.clearAnimations();
// Call the solution function with the inputs
stackSolution(args);
});
function highlightCharacter(string, index) {
let highlightText = '<div class="sv-comment-highlight">';
highlightText += string.substr(0, index);
highlightText += '<span class="sv-comment-highlight-char">'+ string.substr(index, 1) +'</span>';
highlightText += string.substr(index + 1);
highlightText += '</div>';
return highlightText;
}
</script>
<script>
animatorModule.setAnimationSpeed(1.5);
</script>
</body>
</html>