-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpfm.js
362 lines (318 loc) · 8.72 KB
/
pfm.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
// pfm.js - JavaScript library for PFM
// Mario R. De Tore, SLAC National Accelerator Laboratory
function getSelectedText(el) {
if (typeof el.selectionStart == "number") {
return el.value.slice(el.selectionStart, el.selectionEnd);
} else if (typeof document.selection != "undefined") {
var range = document.selection.createRange();
if (range.parentElement() == el) {
return range.text;
}
}
return "";
}
function copySelected() {
var srcTextarea = document.getElementById("converted");
var destTextarea = document.getElementById("original");
destTextarea.value = getSelectedText(srcTextarea);
}
function updateChainArgs()
{
var chain = document.getElementById("chain");
var args = document.getElementById("args");
current = chain[chain.selectedIndex].text
if (current.indexOf(" ") > -1)
{
current = current.substring(0,current.indexOf(" "));
}
chain[chain.selectedIndex].text = current + " " + args.value
chain[chain.selectedIndex].value = current + " " + args.value
}
function updateArgsBox()
{
var chain = document.getElementById("chain");
var args = document.getElementById("args");
if (chain.value.indexOf(" ") > -1)
{
args.value = chain.value.substring(chain.value.indexOf(" ") + 1);
}
else
{
args.value = ""
}
}
function toggleHeader()
{
footer = document.getElementById("footer");
row2 = document.getElementById("row2");
minimize = document.getElementById("minimize");
info = document.getElementById("alertDiv");
if (row2.style.display != "none")
{
row2.style.display = "none";
footer.style.display = "none";
minimize.style.display = "none";
info.style.display = "none";
}
else
{
row2.style.display = "block";
footer.style.display = "block";
minimize.style.display = "block";
if (info.innerHTML != "")
{
info.style.display = "block";
}
}
}
function saveChain()
{
var xmlhttp;
xmlhttp=new XMLHttpRequest();
var output = "";
var chain=document.getElementById("chain")
for (var i=0; i<chain.length; i++){
output += btoa(chain.options[i].text) + ",";
}
output = btoa(output.substring(0,output.length - 1));
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(document.URL.substring(0,document.URL.indexOf(".py") + 3 ) + xmlhttp.responseText);
}
}
xmlhttp.open("GET","pfm.py?savechain=" + output,true);
xmlhttp.send();
}
function hideInput()
{
document.getElementById("original").style.display = "none";
document.getElementById("btnInputHide").style.display = "none";
document.getElementById("btnInputFile").style.display = "none";
document.getElementById("btnInputClear").style.display = "none";
document.getElementById("btnInputShow").style.display = "inline";
}
function showInput()
{
document.getElementById("original").style.display = "inline";
document.getElementById("btnInputHide").style.display = "inline";
document.getElementById("btnInputFile").style.display = "inline";
document.getElementById("btnInputClear").style.display = "inline";
document.getElementById("btnInputShow").style.display = "none";
}
function clearInput()
{
document.getElementById("original").value = "";
document.getElementById("btnInputFile").value = null
document.getElementById('original').disabled = false;
}
function moveToInput()
{
input = document.getElementById("original");
output = document.getElementById("converted");
input.value = output.value
output.value = ""
document.getElementById("output").style.display = "none";
showInput();
autoGrow(input);
if (input.clientHeight > 312)
{
input.style.height = 298 + "px";
}
}
function autoGrow (oField)
{
if (oField.scrollHeight > oField.clientHeight) {
oField.style.height = oField.scrollHeight + "px";
}
}
function toggleText()
{
converted = document.getElementById("converted");
info = document.getElementById("alertDiv");
input = document.getElementById("original");
output = document.getElementById("output");
if (converted.value == "")
{
output.style.display = "none";
}
else {
output.style.display = "inline";
input.style.height = "1px";
autoGrow(input);
if (input.clientHeight > 312)
{
input.style.height = 298 + "px";
}
autoGrow(document.getElementById("converted"));
//document.getElementById("input").style.display = "none";
}
if (converted.value == "" && input.value != "")
{
alert("Conversion failed! Check input.");
}
if (info.innerHTML != "")
{
info.style.display = "inline";
}
}
function checkSize()
{
chain = document.getElementById("chain");
if (chain.length == 0){
chain.style.width = "55px";
}
else {
chain.style.width = "";
}
}
function selectAll()
{
chain = document.getElementById("chain");
chain.multiple = true;
for (var i = 0; i < chain.length; i++)
{
if (chain[i].value == "0"){
continue;
}
else {
chain[i].selected = true;
}
}
}
function moveUp(){
try {
var chain = document.getElementById("chain");
var index = chain.selectedIndex;
var temp = chain[index - 1].value;
var temp_txt = chain[index - 1].text;
chain[index - 1].value = chain[index].value;
chain[index - 1].text = chain[index].text;
chain[index].value = temp;
chain[index].text = temp_txt;
chain.selectedIndex = index - 1;
}
catch(err){}
}
function moveDown(){
try {
var chain = document.getElementById("chain");
var index = chain.selectedIndex;
var temp = chain[index + 1].value;
var temp_txt = chain[index + 1].text;
chain[index + 1].value = chain[index].value;
chain[index + 1].text = chain[index].text;
chain[index].value = temp;
chain[index].text = temp_txt;
chain.selectedIndex = index + 1;
}
catch(err){}
}
function remove_from_chain(){
try{
var chain = document.getElementById("chain");
index = chain.selectedIndex
chain.remove(index);
chain.selectedIndex = index - 1;
checkSize();
}
catch(err){}
}
function clearChain(){
var chain = document.getElementById("chain");
var length = chain.length;
for (i = length; i >= 0; i--) {
chain.remove(i);
}
checkSize();
}
function AddToChain(head) {
var dropdown = document.getElementById("select" + head);
var opt_text = dropdown.options[dropdown.selectedIndex].text
var chain = document.getElementById("chain");
var args = document.getElementById("args");
try {
if (chain[0].value == "0"){
clearChain();
}
}
catch(err) {}
var option = document.createElement("option");
if (args.value == "" && opt_text.indexOf(" *") != -1){
popup(dropdown.value);
return;
}
option.text = opt_text.replace(" *", "") + " " + args.value;
chain.add(option);
dropdown.selectedIndex = "0";
args.value = "";
checkSize();
}
function toggle(div_id) {
var el = document.getElementById(div_id);
if ( el.style.display == 'none' ) { el.style.display = 'block';}
else {el.style.display = 'none';}
}
function blanket_size() {
if (typeof window.innerWidth != 'undefined') {
viewportheight = window.innerHeight;
} else {
viewportheight = document.documentElement.clientHeight;
}
if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
blanket_height = viewportheight;
} else {
if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
blanket_height = document.body.parentNode.clientHeight;
} else {
blanket_height = document.body.parentNode.scrollHeight;
}
}
var blanket = document.getElementById('blanket');
blanket.style.height = blanket_height + 'px';
}
function popup(text)
{
var windowname = document.getElementById('popUpDiv');
text = text + windowname.innerHTML;
windowname.innerHTML = text;
blanket_size();
toggle('blanket');
toggle('popUpDiv');
document.getElementById("popupargs").focus();
// Bug: user can tab out of popup and interact with the page leading to unexpected
// input.
}
function closePopup()
{
var windowname = document.getElementById("popUpDiv");
var text = windowname.innerHTML;
text = text.substring(text.indexOf("<br>"));
var dropdown = document.getElementById("selectDo");
var args = document.getElementById("args");
args.value = document.getElementById("popupargs").value;
windowname.innerHTML = text;
toggle('blanket');
toggle('popUpDiv');
if (args.value == ""){
alert(dropdown.value);
dropdown.selectedIndex = "0";
return;
}
else {
AddToChain("Do");
}
}
function theTime(gmt) {
var timefield = document.getElementById("header");
now=new Date();
if (gmt) {
now.setTime(gmt);
}
hour=now.getUTCHours();
min=now.getUTCMinutes();
if (min<=9) { min="0"+min; }
timefield.innerHTML = ((hour<=9) ? "0"+hour : hour) + ":" + min + " GMT";
setTimeout("theTime()", 1000);
}