-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
101 lines (97 loc) · 2.8 KB
/
test.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
var vector = [];
$('#classify').on("click", function(event) {
var div = $('#demo-container');
var textarea = $('textarea');
textarea.hide();
console.log(textarea.val());
var classificationType = $("select").val();
var textDivider;
if (classificationType == 0) {
textDivider = " ";
}
else {
textDivider = "";
}
var text = textarea.val().split(textDivider);
if (classificationType == 0) {
for (i = 0; i < text.length; i++) {
if (i%2 == 0) {
text.splice(i, 0, " ");
}
}
}
vector = Array.apply(null, Array(text.length)).map(Number.prototype.valueOf,0);
for (i=0; i<text.length; i++) {
div.append( "<span class='text' id=" + String(i) + ">" + text[i]);}
$(".text").each(function() {
$(this)
.mouseover(function(){
$(this).css("background-color", "grey");
$(this).toggleClass("moused");
})
.mouseout(function() {
$(this).css("background-color", "white");
$(this).toggleClass("moused");
})
})
$('#save').show();
$('#save').on("click", function(e) {
console.log(vector);
})
$('#reenter').on("click", function(e) {
div.children().each(function(i) {
$(this).remove();
})
textarea.show();
$('#classify').show();
$('#reenter').hide();
})
$('#reenter').show();
$('#classify').hide();
var bootstrap_enabled = (typeof $().modal == 'function');
console.log("bootstrap is " + bootstrap_enabled);
});
$(document).keydown(function(e) {
if ($(".moused")) {
var code = e.KeyCode || e.which;
var char = String.fromCharCode(code);
var id = Number($('.moused').attr('id'));
console.log("vector[" + String(id) +"] is " + String(vector[id]));
if (vector[id] == Number(char)) {
$('.moused').toggleClass("class_" + char);
vector[id] = 0;
}
else {
if (vector[id] == 0) {
$('.moused').toggleClass("class_" + char);
vector[id] = Number(char);
}
else {
$('.moused').toggleClass("class_" + String(vector[id]));
vector[id] = Number(char);
$('.moused').toggleClass("class_" + char);
}
}
console.log("Afterwards, vector[" + String(id) +"] is " + String(vector[id]));
/*$('.moused').hasClass("classified") {
if ($(".moused").hasClass("class_" + char)) {
$(".moused").toggleClass("class_" + char);
}
else {
$(".moused").attr("class", "moused class_" + char);
}
if ($(".moused").attr("class").split(" ").length > 1) {
if ($(".moused").hasClass("class_" + char)) {
$(".moused").toggleClass("class_" + char);
}
else {
$(".moused").attr("class", "moused class_" + char);
}
}
else {
$(".moused").toggleClass("class_" + char);
console.log("Set class to" + "class_" + char)
}*/
}
console.log($(".moused").attr("class").split(" "));
})