-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortUtils.js
More file actions
73 lines (64 loc) · 2.11 KB
/
sortUtils.js
File metadata and controls
73 lines (64 loc) · 2.11 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
const sorts = []
function addSort(name, starter) {
const newSort = {
name,
starter
}
sorts.push(newSort)
const sortSelector = $(".sort-selector")
sortSelector.empty()
for (let i = 0; i < sorts.length; i++) {
sortSelector.append(`<option${i === 0 ? " selected" : ""}>${sorts[i].name}</option>`)
}
}
function getExplanationUnit(text, bgColor, borderColor) {
return "<div class=\"explanation-unit\">" +
"<span class=\"explanation-element-wrap\">" +
`<div class=\"explanation-element-example\" style=\"background-color:${bgColor}; border-color:${borderColor};\"></div>` +
`<span class=\"explanation-unit-text\"> - ${text}</span>` +
"</span>" +
"</div>"
}
function handleIfCanciled(config) {
if (config.canciled) {
handleNewState(GENERATED_STATE)
return true
}
return false
}
function handleIfStoped(config, temp) {
if (config.stopped) {
config.noticeFunction = temp
} else {
temp()
}
}
function changeElement(index, bgColor, borderColor) {
let element = getElement(index)
element.css("background-color", bgColor)
element.css("border-color", borderColor)
}
function getElement(index) {
return $(`.element:nth-child(${referenceArray[index] + 1})`)
}
function setElementHeight(index, height) {
getElement(index).css("height", `${(height + 1) * 100.0 / currentRoundConfig.maxElement}%`)
}
function setAllElementsStateToNormal() {
let e = $(".element")
e.css("background-color", "black")
e.css("border-color", "white")
}
function swap(index1, index2) {
let difference = referenceArray[index2] - referenceArray[index1]
transformArray[index1] += difference
transformArray[index2] -= difference
let c = array[index1]
array[index1] = array[index2]
array[index2] = c
c = referenceArray[index1]
referenceArray[index1] = referenceArray[index2]
referenceArray[index2] = c
getElement(index1).css("left", `${-transformArray[index1] / array.length * 100}%`)
getElement(index2).css("left", `${-transformArray[index2] / array.length * 100}%`)
}