-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
192 lines (180 loc) · 4.9 KB
/
functions.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
MathJax = {
tex: {
inlineMath: [['$', '$']],
displayMath: [['$$','$$']]
},
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
},
svg: {
fontCache: 'global'
}
};
var click_count1 = 0;
var click_count2 = 0;
var click_count3 = 0;
var click_count4 = 0;
function show(obj)
{
identifier = obj.getAttribute("data-id");
switch (identifier)
{
case "a": click_count1++;show_more(click_count1, obj);break;
case "b": click_count2++;show_more(click_count2, obj);break;
case "c": click_count3++;show_more(click_count3, obj);break;
case "d": click_count4++;show_more(click_count4, obj);break;
}
}
function show_more(click, obj)
{
if (click % 2 == 1)
{obj.children[0].style.transform="rotate(90deg)";
obj.nextElementSibling.style.height="fit-content";}
else
{obj.children[0].style.transform="rotate(0deg)";
obj.nextElementSibling.style.height="0";}
}
var click = 0;
function show_search()
{
click++;
var fmc = document.getElementById("fmc");
var search = document.getElementById("search");
if (click % 2 == 1)
{
fmc.style.display = "none";
search.style.display = "block";
}
else
{
fmc.style.display = "block";
search.style.display = "none";
}
}
function add(obj)
{
var tc = document.getElementById("wordbox");
var tclen = tc.value.length;
var pos = getPosition(tc);
var str = obj.name;
var strlen = str.length;
tc.focus();
if(typeof document.selection != "undefined")
{
document.selection.createRange().text = str;
}
else
{
tc.value = tc.value.substr(0,tc.selectionStart)+str+tc.value.substring(tc.selectionStart,tclen);
}
setCaretPosition(tc, pos+strlen);
render();
}
function add_double(obj)
{
var tc = document.getElementById("wordbox");
var tclen = tc.value.length;
var pos = getPosition(tc);
var str = obj.name;
var strlen = str.length;
tc.focus();
if(typeof document.selection != "undefined")
{
document.selection.createRange().text = str;
}
else
{
tc.value = tc.value.substr(0,tc.selectionStart)+str+tc.value.substring(tc.selectionStart,tclen);
}
setCaretPosition(tc, pos+(strlen / 2));
render();
}
function copy()
{
let input = document.getElementById('wordbox');
input.select();
if(document.execCommand('copy')){
document.execCommand('copy');
document.getElementById('copy').innerHTML = "<font style='color: #43cea2;'>Copied!</font>";
}
else{
document.getElementById('copy').innerHTML = "<font style='color: red;'>Failed</font>";
}
}
window.onload = function()
{
var text = document.querySelector("#wordbox");
var out = document.querySelector("#outputBox");
$("#clear").click(function(){
text.value = "";
out.innerHTML = "";
setCaretPosition(text, 0);
$("#copy").html("Copy");
});
$("#wordbox").focus();
}
function render()
{
if (AutoRender == true)
{
var out = document.querySelector("#outputBox");
out.innerHTML = document.querySelector("#wordbox").value;
MathJax.Hub.Queue(["Typeset",MathJax.Hub,out]);
}
else
{
if (event.keyCode == 91 || event.keyCode == 93 || event.keyCode == 17 || event.keyCode == 224)
{
var out = document.querySelector("#outputBox");
out.innerHTML = document.querySelector("#wordbox").value;
MathJax.Hub.Queue(["Typeset",MathJax.Hub,out]);
}
}
}
const getPosition = function (element) {
let cursorPos = 0;
if (document.selection) {
var selectRange = document.selection.createRange();
selectRange.moveStart('character', -element.value.length);
cursorPos = selectRange.text.length;
} else if (element.selectionStart || element.selectionStart == '0') {
cursorPos = element.selectionStart;
}
return cursorPos;
}
function setCaretPosition(textDom, pos) {
if (textDom.setSelectionRange)
{
// IE Support
textDom.focus();
textDom.setSelectionRange(pos, pos);
}
else if (textDom.createTextRange)
{
// Firefox support
var range = textDom.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
var AutoRender = true;
function change_render_mode(obj)
{
if (AutoRender == true)
{
AutoRender = false;
obj.innerHTML = "ManualRender";
obj.style.backgroundColor = "rgba(232, 232, 232, 0.678)";
obj.style.color = "black";
}
else
{
AutoRender = true;
obj.innerHTML = "AutoRender";
obj.style.backgroundColor = "rgba(76, 0, 130, 0.5)";
obj.style.color = "whitesmoke";
}
}