-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdndScript.js
130 lines (106 loc) · 3.55 KB
/
dndScript.js
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
import "./functions.js";
var counter = 0;
$(document).on('mouseover', '.order', function () {
let related_stroke = $(this).data('rel')
$("#" + related_stroke).children().addClass("filter-blue")
})
$(document).on('mouseleave', '.order', function () {
let related_stroke = $(this).data('rel')
$("#" + related_stroke).children().removeClass("filter-blue")
})
$(document).on('click', '#reset', function () {
var options = $("#options")
var landing = $("#landing")
$(".stroke").each(function (index) {
if ($(this).parent().attr("id") === "landing") {
options.append($(this))
}
});
counter = 0;
$('.order-area').empty()
$('.stroke').removeClass('filter-green')
$('.stroke').removeClass('filter-red')
$('.options div').randomize();
})
//finds the first non-incrementing element
const findBreakingElement = arr => {
for (let i = 1; i < arr.length; i++) {
if (arr[i] - arr[i - 1] > 1) {
return arr[i]
}
}
return false;
}
function isAscending(arr) {
return arr.every(function (x, i) {
return i === 0 || x >= arr[i - 1];
});
}
$(document).on('click', '#valid', function () {
var listItems = []
var numItems = $('.stroke').length
var el;
var correct;
var color;
$(".stroke").each(function () {
listItems.push(parseInt($(this).attr("id").substring(7, 20)))
});
console.log(numItems)
el = findBreakingElement(listItems)
console.log(listItems)
console.log(el)
if (el != false) {
correct = listItems.splice(0, listItems.indexOf(el));
for (var j = 0; j < listItems.length; j++) {
$("#stroke-" + listItems[j]).addClass("filter-red")
}
for (var j = 0; j < correct.length; j++) {
$("#stroke-" + correct[j]).addClass("filter-green")
}
}
else {
color = "filter-green"
if (!isAscending(listItems)) color = "filter-red"
for (var j = 0; j < listItems.length; j++) {
$("#stroke-" + listItems[j]).addClass(color)
}
}
})
$(document).on('click', '.stroke', function () {
var options = $("#options")
var landing = $("#landing")
if ($(this).parent().attr("id") === "options") {
landing.append($(this))
counter++;
$('.order-area').append("<p class='order' data-rel= '" + $(this).attr("id") + "'>" + counter + "</p>")
}
})
$(document).on('mouseover', '.stroke', function () {
// let related_stroke = $(this).data('rel')
// $("#" + related_stroke).children().addClass("filter-blue")
if ($(this).parent().attr("id") === "options") {
$(this).addClass("dragged")
$("#landing").addClass('landing_notification')
}
})
$(document).on('mouseleave', '.stroke', function () {
// let related_stroke = $(this).data('rel')
// $("#" + related_stroke).children().removeClass("filter-blue")
$("#landing").removeClass('landing_notification')
$(this).removeClass("dragged")
})
$(document).on('click', '#generate', function () {
$(".hints").hide();
var hanzi = $('#generate-text').val().split("")[0];
$('.options').empty()
$('.hints').empty()
$('.landing').empty()
$('.order-area').empty()
findStrokes(hanziByID(hanzi));
$('.options div').randomize();
counter = 0
})
$(document).on('click', '#hint', function () {
$(".hints").slideDown();
setTimeout(() => $(".hints").slideUp(), 5000)
})