-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (49 loc) · 1.49 KB
/
script.js
File metadata and controls
60 lines (49 loc) · 1.49 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
$("select").on("click", function () {
$(this).parent(".select-box").toggleClass("open");
});
$(document).mouseup(function (e) {
var container = $(".select-box");
if (container.has(e.target).length === 0) {
container.removeClass("open");
}
});
var turn = $("input[type='radio']:checked").val();
var instance = new Caesar("ru");
var shift = 1;
var value = "";
$("input[type='radio']").on("change", function (){
turn = $("input[type='radio']:checked").val();
$("#res").text(code(value, shift));
});
$("select").on("change", function () {
var selection = $(this).find("option:selected").text(),
labelFor = $(this).attr("id"),
label = $("[for='" + labelFor + "']");
instance = new Caesar($(this).find("option:selected").val());
label.find(".label-desc").html(selection);
});
$("#data").keyup(function (event) {
value = $('#data').val();
$("#res").text(code(value, shift));
}).keydown(function (event) {
if (event.which === 13) {
event.preventDefault();
}
});
$("#num").keyup(function (event) {
shift = $('#num').val();
$("#res").text(code(value, shift));
}).keydown(function (event) {
if (event.which === 13) {
event.preventDefault();
}
}).on("change", function () {
shift = $('#num').val();
$("#res").text(code(value, shift));
});
function code(val, shift) {
if (turn == "e")
return instance.encrypt(val, Math.abs(shift));
else
return instance.decrypt(val, Math.abs(shift))
}