-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuntext.js
155 lines (133 loc) · 4.26 KB
/
funtext.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
(function() {
window.onload = function() {
console.log("hi!");
var DOM = {
input: document.getElementById("input"),
output: document.getElementById("output"),
mirror_option: document.getElementById("mirror"),
abc_option: document.getElementById("abc"),
gray_option: document.getElementById("gray"),
current_year: document.getElementById("current_year"),
}
DOM.current_year.innerHTML = new Date().getFullYear();
// var transform = new Event("transform");
DOM.mirror_option.transformation = Mirror;
DOM.abc_option.transformation = AbcToZyx;
DOM.gray_option.transformation = GrayScale;
// DOM.mirror_option.addEventListener("transform", TransformText);
// DOM.mirror_option.ontransform = TransformText;
DOM.input.onkeyup = UpdateOutput;
DOM.input.onkeydown = UpdateOutput;
// DOM.mirror_option.onclick = DOM.mirror_option.dispatchEvent(transform);
DOM.mirror_option.onclick = TransformText;
DOM.abc_option.onclick = TransformText;
DOM.gray_option.onclick = TransformText;
function TransformText(event) {
UpdateCSS(event.target);
UpdateOutput();
}
function UpdateCSS(obj) {
DOM.mirror_option.className = "option_button";
DOM.abc_option.className = "option_button";
DOM.gray_option.className = "option_button";
obj.className += " selected";
}
function UpdateOutput() {
DOM.output.innerHTML = document.getElementsByClassName("selected")[0].transformation(DOM.input.value);
}
};
function not_blank(object) {
return !(object === null || object === undefined || object.trim() === "");
}
function Mirror(text) {
if(not_blank(text)) {
return text.split("").reduce(function(acc, val) { return val + acc; });
} else return "";
}
function AbcToZyx(text) {
if(not_blank(text)) {
return text.split("").reduce(function(acc, val) {
return ((acc.length == 1) ? toChart(acc) : acc) + toChart(val);
});
} else return "";
}
function GrayScale(text) {
if(not_blank(text)) {
return text.split("").reduce(function(acc, val) {
return ((acc.length == 1) ? htmlCubes(toGrayChart(acc)) : acc) + htmlCubes(toGrayChart(val));
});
} else return "";
}
function htmlCubes(color) {
return "<div style='background-color:" + color + "; width:35px; height:35px; display:inline-block;'></div>";
}
function toChart(key) {
return (charChart[key] !== undefined) ? charChart[key] : key;
}
function toGrayChart(key) {
return (charGrayChart[key] !== undefined) ? charGrayChart[key] : charGrayChart["null"];
}
var charChart = {
"a": "z", "A": "Z",
"b": "y", "B": "Y",
"c": "x", "C": "X",
"d": "w", "D": "W",
"e": "v", "E": "V",
"f": "u", "F": "U",
"g": "t", "G": "T",
"h": "s", "H": "S",
"i": "r", "I": "R",
"j": "q", "J": "Q",
"k": "p", "K": "P",
"l": "o", "L": "O",
"m": "n", "M": "N",
"n": "m", "N": "M",
"o": "l", "O": "L",
"p": "k", "P": "K",
"q": "j", "Q": "J",
"r": "i", "R": "I",
"s": "h", "S": "H",
"t": "g", "T": "G",
"u": "f", "U": "F",
"v": "e", "V": "E",
"w": "d", "W": "D",
"x": "c", "X": "C",
"y": "b", "Y": "B",
"z": "a", "Z": "A"
};
var charGrayChart = {
"a": "#010101", "A": "#999999",
"b": "#101010", "B": "#a9a9a9",
"c": "#111111", "C": "#9a9a9a",
"d": "#121212", "D": "#aaaaaa",
"e": "#212121", "E": "#ababab",
"f": "#222222", "F": "#bababa",
"g": "#232323", "G": "#bbbbbb",
"h": "#323232", "H": "#bcbcbc",
"i": "#333333", "I": "#cbcbcb",
"j": "#343434", "J": "#cccccc",
"k": "#434343", "K": "#cdcdcd",
"l": "#444444", "L": "#dcdcdc",
"m": "#454545", "M": "#dddddd",
"n": "#545454", "N": "#dedede",
"o": "#555555", "O": "#ededed",
"p": "#565656", "P": "#eeeeee",
"q": "#656565", "Q": "#efefef",
"r": "#666666", "R": "#fefefe",
"s": "#676767", "S": "#ffffff",
"t": "#767676", "T": "#010101",
"u": "#777777", "U": "#101010",
"v": "#787878", "V": "#111111",
"w": "#878787", "W": "#121212",
"x": "#888888", "X": "#212121",
"y": "#898989", "Y": "#222222",
"z": "#989898", "Z": "#232323",
"null": "#000000"
};
// function updateOrientation() {
// var viewport = document.querySelector("meta[name=viewport]");
// viewport.setAttribute('content', 'width=' + window.screen.width + ', initial-scale=1.0;');
// }
//window.addEventListener('orientationchange', updateOrientation);
//updateOrientation();
})();