Skip to content

Commit d1c24f9

Browse files
Fjernet unødvednig listener og fikset onclick listener (trykk utenfor array og deselect)
1 parent fb801c6 commit d1c24f9

File tree

6 files changed

+32
-110
lines changed

6 files changed

+32
-110
lines changed

Heap/js/View.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ var View = /** @class */ (function () {
152152
View.prototype.addNode = function (val) {
153153
control.addNode(val);
154154
setOnClickListener();
155-
setKeyListener();
156155
setupRadio();
157156
};
158157
View.prototype.removeNode = function () {
@@ -339,7 +338,6 @@ var View = /** @class */ (function () {
339338
$("#play").text("Pause");
340339
}
341340
else if (manager.nextEvents.length > 0) {
342-
console.log("hello woorld");
343341
return;
344342
}
345343
else {

Heap/js/View.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ class View {
175175
addNode(val: number) {
176176
control.addNode(val);
177177
setOnClickListener();
178-
setKeyListener();
179178
setupRadio();
180179
}
181180

@@ -391,7 +390,6 @@ class View {
391390
lockBackForward(true);
392391
$("#play").text("Pause");
393392
} else if (manager.nextEvents.length > 0) {
394-
console.log("hello woorld");
395393
return;
396394
} else {
397395
lockPlay(true);

Heap/js/drawGraph.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,3 @@ function centerDivWidthNodes(time) {
206206
window.addEventListener('resize', function () {
207207
centerDivWidthNodes(animationTime);
208208
});
209-
function getGraphState() {
210-
var state = [];
211-
for (var nodeIndex = 0; nodeIndex < allNodes.length; nodeIndex++) {
212-
state.push(new Array);
213-
for (var childIndex = 0; childIndex < allNodes[nodeIndex].children.length; childIndex++) {
214-
state[nodeIndex].push(allNodes[nodeIndex].children[childIndex].id);
215-
}
216-
}
217-
return JSON.stringify(state).toString();
218-
}
219-
function getArrayState() {
220-
var state = [];
221-
for (var i = 0; i < allNodes.length; i++) {
222-
state.push(parseInt($("#arrayElem" + i + " div.content").text()));
223-
}
224-
return JSON.stringify(state).toString();
225-
}

Heap/js/drawGraph.ts

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class GraphNode {
104104

105105
moveSideways(newLeftValue: number, time: number) {
106106
this.left = newLeftValue;
107-
$("#node" + this.id).clearQueue().animate({left: newLeftValue + "px"}, time);
107+
$("#node" + this.id).clearQueue().animate({ left: newLeftValue + "px" }, time);
108108
for (var i: number = 0; i < this.connectedLines.length; i++) {
109109
this.connectedLines[i].animateLinePoint(this, time);
110110
}
@@ -113,7 +113,7 @@ class GraphNode {
113113
moveBothDirections(newLeftValue: number, newTopValue: number, time: number) {
114114
this.left = newLeftValue;
115115
this.top = newTopValue;
116-
$("#node" + this.id).clearQueue().animate({left: newLeftValue + "px", top: newTopValue + "px"}, time);
116+
$("#node" + this.id).clearQueue().animate({ left: newLeftValue + "px", top: newTopValue + "px" }, time);
117117
for (var i: number = 0; i < this.connectedLines.length; i++) {
118118
this.connectedLines[i].animateLinePoint(this, time);
119119
}
@@ -160,27 +160,27 @@ class Line {
160160
var $line = $("#line" + this.id);
161161
var parentPoint: boolean = (this.parent.id == node.id);
162162
if (parentPoint) {
163-
$({x1: $line.attr('x1')})
164-
.animate({x1: this.parent.left + width / 2}, {
163+
$({ x1: $line.attr('x1') })
164+
.animate({ x1: this.parent.left + width / 2 }, {
165165
duration: animationTime, step: function (now) {
166166
$line.attr('x1', now);
167167
}
168168
});
169-
$({y1: $line.attr('y1')})
170-
.animate({y1: this.parent.top + width / 2}, {
169+
$({ y1: $line.attr('y1') })
170+
.animate({ y1: this.parent.top + width / 2 }, {
171171
duration: animationTime, step: function (now) {
172172
$line.attr('y1', now);
173173
}
174174
});
175175
} else {
176-
$({x2: $line.attr('x2')})
177-
.animate({x2: this.child.left + width / 2}, {
176+
$({ x2: $line.attr('x2') })
177+
.animate({ x2: this.child.left + width / 2 }, {
178178
duration: animationTime, step: function (now) {
179179
$line.attr('x2', now);
180180
}
181181
});
182-
$({y2: $line.attr('y2')})
183-
.animate({y2: this.child.top + width / 2}, {
182+
$({ y2: $line.attr('y2') })
183+
.animate({ y2: this.child.top + width / 2 }, {
184184
duration: animationTime, step: function (now) {
185185
$line.attr('y2', now);
186186
}
@@ -257,30 +257,9 @@ function getSpaceBetweenDivAndLeftNode() {
257257

258258
function centerDivWidthNodes(time: number): void {
259259
$("#graphUL").finish(); // if already animating, finish animation
260-
$("#graphUL").animate({left: getSpaceBetweenDivAndLeftNode()}, time);
260+
$("#graphUL").animate({ left: getSpaceBetweenDivAndLeftNode() }, time);
261261
}
262262

263263
window.addEventListener('resize', function () {
264264
centerDivWidthNodes(animationTime)
265265
});
266-
267-
function getGraphState(): string {
268-
var state: Array<Array<number>> = [];
269-
for (var nodeIndex: number = 0; nodeIndex < allNodes.length; nodeIndex++) {
270-
state.push(new Array);
271-
for (var childIndex: number = 0; childIndex < allNodes[nodeIndex].children.length; childIndex++) {
272-
state[nodeIndex].push(allNodes[nodeIndex].children[childIndex].id);
273-
}
274-
}
275-
return JSON.stringify(state).toString();
276-
}
277-
278-
function getArrayState(): string {
279-
var state: Array<number> = [];
280-
281-
for (var i = 0; i < allNodes.length; i++) {
282-
state.push(parseInt($("#arrayElem" + i + " div.content").text()));
283-
}
284-
285-
return JSON.stringify(state).toString();
286-
}

Heap/js/methods.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* @author Øyvind
77
*
88
*/
9-
//declare var javaBinder; // Used to communicate with java
109
var firstSelected = -1;
1110
var locked = false;
1211
var contentHidden = false;
@@ -15,6 +14,13 @@ function displayArray(jsonString) {
1514
var $array = $.parseJSON(jsonString);
1615
createAndDrawNodes($array);
1716
}
17+
$(window).click(function (e) {
18+
if ($(e.target).closest("#arrayUL li").length > 0) {
19+
return false;
20+
}
21+
deselectArrayElemSelections();
22+
deselectNodeSelections();
23+
});
1824
// Setup nodes and array elements to activate algorithm when clicked
1925
function setOnClickListener() {
2026
$("#arrayUL li").each(function () {
@@ -36,32 +42,12 @@ function setOnClickListener() {
3642
});
3743
});
3844
}
45+
setOnClickListener();
3946
function isHighlighted(id) {
4047
if ($("#arrayElem" + id).hasClass("selected"))
4148
return true;
4249
return false;
4350
}
44-
setOnClickListener();
45-
function setKeyListener() {
46-
this.addEventListener("keyup", function (e) {
47-
if (locked) {
48-
return;
49-
}
50-
var key = e.which || e.keyCode;
51-
// Enter (reset algorithm)
52-
if (key == 13) {
53-
resetElementSelections();
54-
viewer.changeToCurrentAlgorithm();
55-
}
56-
else if (key == 37) {
57-
viewer.stepBack();
58-
}
59-
else if (key == 39) {
60-
viewer.stepForward();
61-
}
62-
});
63-
}
64-
setKeyListener();
6551
// Selects an element. If method==find call method, else wait for second element before union or connected
6652
function selectElement(index) {
6753
// Set new class for selected index

Heap/js/methods.ts

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@
66
* @author Øyvind
77
*
88
*/
9-
//declare var javaBinder; // Used to communicate with java
10-
var firstSelected: number = -1;
11-
var locked: boolean = false;
12-
var contentHidden: boolean = false;
9+
let firstSelected: number = -1;
10+
let locked: boolean = false;
11+
let contentHidden: boolean = false;
1312

1413
// Displays new array
1514
function displayArray(jsonString: string): void {
1615
var $array = $.parseJSON(jsonString);
1716
createAndDrawNodes($array);
1817
}
1918

19+
$(window).click(function (e) {
20+
if ($(e.target).closest("#arrayUL li").length > 0) {
21+
return false;
22+
}
23+
deselectArrayElemSelections();
24+
deselectNodeSelections();
25+
});
26+
2027
// Setup nodes and array elements to activate algorithm when clicked
2128
function setOnClickListener() {
2229
$("#arrayUL li").each(function () {
@@ -39,41 +46,14 @@ function setOnClickListener() {
3946
});
4047
}
4148

49+
setOnClickListener();
50+
4251
function isHighlighted(id: number): boolean {
4352
if ($("#arrayElem" + id).hasClass("selected"))
4453
return true;
4554
return false;
4655
}
4756

48-
setOnClickListener();
49-
50-
function setKeyListener() {
51-
this.addEventListener("keyup", function (e) {
52-
if (locked) {
53-
return;
54-
}
55-
var key = e.which || e.keyCode;
56-
57-
// Enter (reset algorithm)
58-
if (key == 13) {
59-
resetElementSelections();
60-
viewer.changeToCurrentAlgorithm();
61-
}
62-
63-
// left arrow (step back)
64-
else if (key == 37) {
65-
viewer.stepBack();
66-
}
67-
68-
// right arrow (step forward)
69-
else if (key == 39) {
70-
viewer.stepForward();
71-
}
72-
});
73-
}
74-
75-
setKeyListener();
76-
7757
// Selects an element. If method==find call method, else wait for second element before union or connected
7858
function selectElement(index: number) {
7959

@@ -136,7 +116,6 @@ function setValueAtSortIndex(i: number, value) {
136116
$elem.append("" + value);
137117
}
138118

139-
140119
// Add a new element to the array
141120
function insertNewElem(i: number, val: number): void {
142121
$("#arrayUL").append("<li id='arrayElem" + i + "'><div class='index'>" + i + "</div><div class='content' id='arrayContent" + i + "'>" + val + "</div></li>");
@@ -193,7 +172,6 @@ function removeNode(i: number) {
193172
});
194173

195174
allNodes[i].parent.removeChild(allNodes[i]);
196-
//allNodes[i].reset();
197175
allNodes.pop();
198176
}
199177

0 commit comments

Comments
 (0)