forked from prettydiff/prettydiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprettydiff-webtool.ts
4783 lines (4758 loc) · 288 KB
/
prettydiff-webtool.ts
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*global ace*/
/*jshint laxbreak: true*/
/*jslint for: true*/
/*****************************************************************************
This is written by Austin Cheney on 3 Mar 2009.
Please see the license.txt file associated with the Pretty Diff
application for license information.
****************************************************************************/
if ((/^http:\/\/((\w|-)+\.)*prettydiff\.com/).test(location.href) === true || location.href.indexOf("www.prettydiff.com") > -1) {
let loc:string = location.href.replace("http", "https").replace("https://www.", "https://");
location.replace(loc);
}
(function dom_init():void {
"use strict";
const id = function dom_id(x:string):any {
if (document.getElementById === undefined) {
return;
}
return document.getElementById(x);
},
page = (function dom__dataPage():HTMLDivElement {
const divs:HTMLCollectionOf<HTMLDivElement> = document.getElementsByTagName("div");
if (divs.length === 0) {
return null;
}
return divs[0];
}()),
textarea = {
codeIn: id("input"),
codeOut: id("output"),
},
aceStore:any = {
codeIn: {},
codeOut: {},
height: 0
},
method:domMethods = {
app: {},
event: {}
},
data:any = {
commentString: [],
langvalue: ["javascript", "javascript", "JavaScript"],
mode: "diff",
settings: {
report: {
code: {},
feed: {},
stat: {}
}
},
tabtrue: false,
zIndex: 0
},
report = {
code: {
body: null,
box: id("codereport")
},
feed: {
body: null,
box: id("feedreport")
},
stat: {
body: null,
box: id("statreport")
}
},
test = {
// delect if Ace Code Editor is supported
ace : (location.href.toLowerCase().indexOf("ace=false") < 0 && typeof ace === "object"),
// get the lowercase useragent string
agent : (typeof navigator === "object")
? navigator
.userAgent
.toLowerCase()
: "",
// test for standard web audio support
audio : ((typeof AudioContext === "function" || typeof AudioContext === "object") && AudioContext !== null)
? new AudioContext()
: null,
// delays the toggling of test.load to false for asynchronous code sources
delayExecution: false,
// am I served from the Pretty Diff domain
domain : (location.href.indexOf("prettydiff.com") < 15 && location.href.indexOf("prettydiff.com") > -1),
// If the output is too large the report must open and minimize in a single step
filled : {
code: false,
feed: false,
stat: false
},
// test for support of the file api
fs : (typeof FileReader === "function"),
// stores keypress state to avoid execution of event.execute from certain key
// combinations
keypress : false,
keysequence : [],
// supplement to ensure keypress is returned to false only after other keys
// other than ctrl are released
keystore : [],
// some operations should not occur as the page is initially loading
load : true,
// whether to save things locally
store : (id("localStorage-no") !== null && id("localStorage-no").checked === true)
? false
: true,
// supplies alternate keyboard navigation to editable text areas
tabesc : []
},
load = function dom_load():void {
const pages:string = (page === null || page === undefined || page.getAttribute("id") === null)
? ""
: page.getAttribute("id"),
security = function dom_load_security():void {
const scripts:HTMLCollectionOf<HTMLScriptElement> = document.getElementsByTagName("script"),
exclusions:string[] = [
"js/webtool.js",
"browser-demo.js",
"node_modules/ace-builds"
],
len:number = scripts.length,
exlen:number = exclusions.length;
let a:number = 0,
b:number = 0,
src:string = "";
// this prevents errors, but it also means you are executing too early.
if (len > 0) {
do {
src = scripts[a].getAttribute("src");
if (src === null) {
break;
}
if (src.indexOf("?") > 0) {
src = src.slice(0, src.indexOf("?"));
}
b = 0;
do {
if (src.indexOf(exclusions[b]) > -1) {
break;
}
b = b + 1;
} while (b < exlen);
if (b === exlen) {
break;
}
a = a + 1;
} while (a < len);
if (a < len) {
let warning:HTMLDivElement = document.createElement("div");
warning.setAttribute("id", "security-warning");
warning.innerHTML = `<h1>Warning</h1><h2>This page contains unauthorized script and may be a security risk.</h2><code>${(src === null) ? scripts[a].innerHTML : src}</code>`;
document.getElementsByTagName("body")[0].insertBefore(warning, document.getElementsByTagName("body")[0].firstChild);
}
}
};
if (pages === "webtool") {
let a:number = 0,
x:HTMLInputElement,
inputs:HTMLCollectionOf<HTMLInputElement>,
selects:HTMLCollectionOf<HTMLSelectElement>,
buttons:HTMLCollectionOf<HTMLButtonElement>,
inputsLen:number = 0,
idval:string = "",
name:string = "",
type:string = "",
parent:HTMLElement;
const aceApply = function dom_load_aceApply(nodeName:string, maxWidth:boolean):any {
const div:HTMLDivElement = document.createElement("div"),
node:HTMLDivElement = textarea[nodeName],
parent:HTMLElement = <HTMLElement>node.parentNode.parentNode,
labels:HTMLCollectionOf<HTMLLabelElement> = parent.getElementsByTagName("label"),
label:HTMLLabelElement = labels[labels.length - 1],
attributes:NamedNodeMap = node.attributes,
p:HTMLParagraphElement = document.createElement("p"),
dollar:string = "$",
len:number = attributes.length;
let a:number = 0,
edit:any = {};
do {
if (attributes[a].name !== "rows" && attributes[a].name !== "cols" && attributes[a].name !== "wrap") {
div.setAttribute(attributes[a].name, attributes[a].value);
}
a = a + 1;
} while (a < len);
label.parentNode.removeChild(label);
p.appendChild(label);
p.setAttribute("class", "inputLabel");
parent.appendChild(p);
parent.appendChild(div);
parent.removeChild(node.parentNode);
if (maxWidth === true) {
div.style.width = "100%";
}
div.style.fontSize = "1.4em";
edit = ace.edit(div);
textarea[nodeName] = div.getElementsByTagName("textarea")[0];
edit[`${dollar}blockScrolling`] = Infinity;
if (nodeName === "codeIn") {
const slider:HTMLElement = document.createElement("span"),
span:HTMLElement = document.createElement("span"),
p:HTMLElement = document.createElement("p"),
description:string = "Slide this control left and right to adjust the 'options.wrap' value for word wrapping the code.";
p.innerHTML = description;
p.setAttribute("id", "ace-slider-description");
p.style.display = "none";
span.innerHTML = `<button title="${description}" aria-describedby="ace-slider-description">\u25bc</button>`;
slider.appendChild(span);
slider.appendChild(p);
slider.setAttribute("id", "slider");
span.onmousedown = method.event.aceSlider;
parent.insertBefore(slider, div);
}
return edit;
},
aces = function dom_load_aces(event:Event):void {
const el:HTMLInputElement = <HTMLInputElement>event.srcElement || <HTMLInputElement>event.target,
elId:string = el.getAttribute("id"),
acedisable = function dom_load_aces_acedisable():void {
let addy:string = "",
loc:number = location
.href
.indexOf("ace=false"),
place:string[] = [],
symbol:string = "?";
method.app.options(event);
if (elId === "ace-yes" && loc > 0) {
place = location
.href
.split("ace=false");
if (place[1].indexOf("&") < 0 && place[1].indexOf("%26") < 0) {
place[0] = place[0].slice(0, place[0].length - 1);
}
location.replace(place.join(""));
} else if (elId === "ace-no" && loc < 0) {
addy = location.href;
addy = addy.slice(0, addy.indexOf("#") + 1);
if (location.href.indexOf("?") < location.href.length - 1 && location.href.indexOf("?") > 0) {
symbol = "&";
}
location.replace(`${addy + symbol}ace=false`);
}
};
if (el.checked === true) {
acedisable();
}
},
areaShiftUp = function dom_load_areaShiftUp(event:KeyboardEvent):void {
if (event.keyCode === 16 && test.tabesc.length > 0) {
test.tabesc = [];
}
if (event.keyCode === 17 || event.keyCode === 224) {
data.tabtrue = true;
}
},
areaTabOut = function dom_load_areaTabOut(event:KeyboardEvent):void {
const node:HTMLElement = <HTMLElement>event.srcElement || <HTMLElement>event.target;
let len:number = test.tabesc.length,
esc:boolean = false,
key:number = 0;
key = event.keyCode;
if (key === 17 || key === 224) {
if (data.tabtrue === false && (test.tabesc[0] === 17 || test.tabesc[0] === 224 || len > 1)) {
return;
}
data.tabtrue = false;
}
if (node.nodeName.toLowerCase() === "textarea") {
if (test.ace === true) {
if (node === textarea.codeOut) {
esc = true;
}
}
if (node === textarea.codeIn) {
esc = true;
}
}
if (esc === true) {
esc = false;
data.tabtrue = false;
if ((len === 1 && test.tabesc[0] !== 16 && key !== test.tabesc[0]) || (len === 2 && key !== test.tabesc[1])) {
test.tabesc = [];
return;
}
if (len === 0 && (key === 16 || key === 17 || key === 224)) {
test
.tabesc
.push(key);
return;
}
if (len === 1 && (key === 17 || key === 224)) {
if (test.tabesc[0] === 17 || test.tabesc[0] === 224) {
esc = true;
} else {
test
.tabesc
.push(key);
return;
}
} else if (len === 2 && (key === 17 || key === 224)) {
esc = true;
} else if (len > 0) {
test.tabesc = [];
}
if (esc === true) {
if (len === 2) {
//back tab
if (node === textarea.codeIn) {
id("inputfile").focus();
} else if (node === textarea.codeOut) {
textarea
.codeIn
.focus();
}
} else {
//forward tab
if (node === textarea.codeOut) {
id("button-primary")
.getElementsByTagName("button")[0]
.focus();
} else if (node === textarea.codeIn) {
textarea
.codeOut
.focus();
}
}
if (test.tabesc[0] === 16) {
test.tabesc = [16];
} else {
test.tabesc = [];
}
}
}
method
.event
.sequence(event);
},
backspace = function dom_load_backspace(event:KeyboardEvent):boolean {
const bb:Element = <Element>event.srcElement || <Element>event.target;
if (event.keyCode === 8) {
if (bb.nodeName === "textarea" || (bb.nodeName === "input" && (bb.getAttribute("type") === "text" || bb.getAttribute("type") === "password"))) {
return true;
}
return false;
}
if (event.type === "keydown") {
method.event.sequence(event);
}
return true;
},
clearComment = function dom_load_clearComment():void {
const comment = id("commentString");
localStorage.setItem("commentString", "[]");
data.commentString = [];
if (comment !== null) {
comment.innerHTML = "/*prettydiff.com \u002a/";
}
},
feeds = function dom_load_feeds(el:HTMLInputElement):void {
const feedradio = function dom_load_feeds_feedradio(event:Event):boolean {
let parent:HTMLElement,
aa:number,
radios:HTMLCollectionOf<HTMLInputElement>;
const elly:HTMLElement = <HTMLElement>event.srcElement || <HTMLElement>event.target,
item:HTMLElement = <HTMLElement>elly.parentNode,
radio:HTMLInputElement = item.getElementsByTagName("input")[0];
parent = <HTMLElement>item.parentNode;
radios = parent.getElementsByTagName("input");
aa = radios.length - 1;
do {
parent = <HTMLElement>radios[aa].parentNode;
parent.removeAttribute("class");
radios[aa].checked = false;
aa = aa - 1;
} while (aa > -1);
radio.checked = true;
radio.focus();
item.setAttribute("class", "active-focus");
method.app.options(event);
event.preventDefault();
return false;
};
el.onfocus = feedradio;
el.onblur = function dom_load_feeds_feedblur():void {
const item = <HTMLElement>el.parentNode;
item.setAttribute("class", "active");
},
el.onclick = feedradio;
parent = <HTMLElement>x.parentNode;
parent = parent.getElementsByTagName("label")[0];
parent.onclick = feedradio;
},
feedsubmit = function dom_load_feedsubmit():void {
let a:number = 0;
const datapack:any = {},
namecheck:any = (localStorage.getItem("settings") !== undefined && localStorage.getItem("settings") !== null)
? JSON.parse(localStorage.getItem("settings"))
: {},
radios:HTMLCollectionOf<HTMLInputElement> = id("feedradio1")
.parentNode
.parentNode
.getElementsByTagName("input"),
text = (id("feedtextarea") === null)
? ""
:id("feedtextarea")
.value,
email:string = (id("feedemail") === null)
? ""
: id("feedemail")
.value,
xhr:XMLHttpRequest = new XMLHttpRequest(),
sendit = function dom_load_feedsubmit_sendit():void {
const node:HTMLElement = id("feedintro");
xhr.withCredentials = true;
xhr.open("POST", "https://prettydiff.com:8000/feedback/", true);
xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
xhr.send(JSON.stringify(datapack));
report
.feed
.box
.getElementsByTagName("button")[1]
.click();
if (node !== null) {
node.innerHTML = "Please feel free to submit feedback about Pretty Diff at any time by answering t" +
"he following questions.";
}
};
if (id("feedradio1") === null || namecheck.knownname !== data.settings.knownname) {
return;
}
a = radios.length - 1;
if (a > 0) {
do {
if (radios[a].checked === true) {
break;
}
a = a - 1;
} while (a > -1);
}
if (a < 0) {
return;
}
datapack.comment = text;
datapack.email = email;
datapack.name = data.settings.knownname;
datapack.rating = a + 1;
datapack.settings = data.settings;
datapack.type = "feedback";
sendit();
},
file = function dom_load_file(event:Event):void {
const input:HTMLInputElement = <HTMLInputElement>event.srcElement || <HTMLInputElement>event.target;
let a:number = 0,
id:string = "",
files:FileList,
textareaEl:HTMLTextAreaElement,
parent:HTMLElement,
reader:FileReader,
fileStore:string[] = [],
fileCount:number = 0;
id = input.getAttribute("id");
files = input.files;
if (test.fs === true && files[0] !== null && typeof files[0] === "object") {
if (input.nodeName === "input") {
parent = <HTMLElement>input.parentNode.parentNode;
textareaEl = parent.getElementsByTagName("textarea")[0];
}
const fileLoad = function dom_event_file_onload(event:Event):void {
const tscheat:string = "result";
fileStore.push(event.target[tscheat]);
if (a === fileCount) {
if (test.ace === true) {
if (id === "outputfile") {
aceStore
.codeOut
.setValue(fileStore.join("\n\n"));
aceStore
.codeOut
.clearSelection();
} else {
aceStore
.codeIn
.setValue(fileStore.join("\n\n"));
aceStore
.codeIn
.clearSelection();
}
} else {
textarea.codeIn.value = fileStore.join("\n\n");
}
if (options.mode !== "diff") {
method
.event
.execute();
}
}
};
fileCount = files.length;
do {
reader = new FileReader();
reader.onload = fileLoad;
reader.onerror = function dom_event_file_onerror(event:any):void {
if (textareaEl !== undefined) {
textareaEl.value = `Error reading file:\n\nThis is the browser's description: ${event.error.name}`;
}
fileCount = -1;
};
if (files[a] !== undefined) {
reader.readAsText(files[a], "UTF-8");
}
a = a + 1;
} while (a < fileCount);
if (options.mode !== "diff") {
method
.event
.execute();
}
}
},
fixHeight = function dom_load_fixHeight():void {
const input:HTMLElement = id("input"),
output:HTMLElement = id("output"),
headlineNode:HTMLElement = id("headline"),
height:number = window.innerHeight || document.getElementsByTagName("body")[0].clientHeight;
let math:number = 0,
headline:number = 0;
if (headlineNode !== null && headlineNode.style.display === "block") {
headline = 3.8;
}
if (test.ace === true) {
math = (height / 14) - (15.81 + headline);
aceStore.height = math;
if (input !== null) {
input.style.height = `${math}em`;
aceStore
.codeIn
.setStyle(`height:${math}em`);
aceStore
.codeIn
.resize();
}
if (output !== null) {
output.style.height = `${math}em`;
aceStore
.codeOut
.setStyle(`height:${math}em`);
aceStore
.codeOut
.resize();
}
} else {
math = (height / 14.4) - (15.425 + headline);
if (input !== null) {
input.style.height = `${math}em`;
}
if (output !== null) {
output.style.height = `${math}em`;
}
}
},
indentchar = function dom_load_indentchar():void {
const insize:HTMLInputElement = id("option-indent_size"),
inchar:HTMLInputElement = id("option-indent_char"),
tabSizeNumber:number = (insize === null || isNaN(Number(insize.value)) === true)
? 4
: Number(insize.value),
tabSize:number = (tabSizeNumber < 1)
? 4
: tabSizeNumber;
if (test.ace === true) {
if (inchar !== null && inchar.value === " ") {
aceStore
.codeIn
.getSession()
.setUseSoftTabs(true);
aceStore
.codeOut
.getSession()
.setUseSoftTabs(true);
aceStore
.codeIn
.getSession()
.setTabSize(tabSize);
aceStore
.codeOut
.getSession()
.setTabSize(tabSize);
} else {
aceStore
.codeIn
.getSession()
.setUseSoftTabs(false);
aceStore
.codeOut
.getSession()
.setUseSoftTabs(false);
}
}
},
insize = function dom_load_insize():void {
const insize:HTMLInputElement = id("option-indent_size"),
tabSizeNumber:number = (insize === null || isNaN(Number(insize.value)) === true)
? 4
: Number(insize.value),
tabSize:number = (tabSizeNumber < 1)
? 4
: tabSizeNumber;
if (test.ace === true) {
aceStore
.codeIn
.getSession()
.setTabSize(tabSize);
aceStore
.codeOut
.getSession()
.setTabSize(tabSize);
}
},
modes = function dom_load_modes(event:Event):void {
const elly:HTMLElement = <HTMLElement>event.target || <HTMLElement>event.srcElement,
mode = elly.getAttribute("id").replace("mode", "");
method.event.modeToggle(mode);
method.app.options(event);
},
numeric = function dom_load_numeric(event:Event):void {
const el:HTMLInputElement = <HTMLInputElement>event.srcElement || <HTMLInputElement>event.target;
let val = el.value,
negative:boolean = (/^(\s*-)/).test(val),
split:string[] = val.replace(/\s|-/g, "").split(".");
if (split.length > 1) {
val = `${split[0].replace(/\D/g, "")}.${split[1].replace(/\D/, "")}`;
} else {
val = split[0].replace(/\D/g, "");
}
if (negative === true) {
val = `-${val}`;
}
el.value = val;
if (el === id("option-indent_char")) {
indentchar();
} else if (el === id("option-indent_size")) {
insize();
}
if (test.load === false) {
method.app.options(event);
}
},
prepBox = function dom_load_prepBox(boxName:string):void {
if (report[boxName].box === null || (test.domain === false && boxName === "feed")) {
return;
}
const jsscope = id("option-jsscope"),
buttonGroup:HTMLElement = report[boxName]
.box
.getElementsByTagName("p")[0],
title:HTMLButtonElement = report[boxName]
.box
.getElementsByTagName("h3")[0]
.getElementsByTagName("button")[0],
filedrop = function dom_load_prepBox_filedrop(event:Event):void {
event.stopPropagation();
event.preventDefault();
file(event);
},
filenull = function dom_load_prepBox_filenull(event:Event):void {
event.stopPropagation();
event.preventDefault();
};
if (test.fs === true) {
report[boxName].box.ondragover = filenull;
report[boxName].box.ondragleave = filenull;
report[boxName].box.ondrop = filedrop;
}
report[boxName].body.onmousedown = function dom_load_prepBox_top():void {
method.app.zTop(report[boxName].body.parentNode);
};
parent = <HTMLElement>title.parentNode;
title.onmousedown = method.event.grab;
title.ontouchstart = method.event.grab;
title.onfocus = method.event.minimize;
title.onblur = function dom_load_prepBox_blur():void {
title.onclick = null;
};
if (data.settings.report[boxName] === undefined) {
data.settings.report[boxName] = {};
}
if (boxName === "code" && jsscope !== null && jsscope[jsscope.selectedIndex].value === "report" && buttonGroup.innerHTML.indexOf("save") < 0) {
if (test.agent.indexOf("firefox") > 0 || test.agent.indexOf("presto") > 0) {
let saveNode:HTMLElement = document.createElement("a");
saveNode.setAttribute("href", "#");
saveNode.onclick = method.event.save;
saveNode.innerHTML = "<button class='save' title='Convert report to text that can be saved.' tabindex=" +
"'-1'>S</button>";
buttonGroup.insertBefore(saveNode, buttonGroup.firstChild);
} else {
let saveNode:HTMLElement = document.createElement("button");
saveNode.setAttribute("class", "save");
saveNode.setAttribute("title", "Convert report to text that can be saved.");
saveNode.innerHTML = "S";
buttonGroup.insertBefore(saveNode, buttonGroup.firstChild);
}
}
if (data.settings.report[boxName].min === false) {
buttonGroup.style.display = "block";
title.style.cursor = "move";
if (buttonGroup.innerHTML.indexOf("save") > 0) {
buttonGroup.getElementsByTagName("button")[1].innerHTML = "\u035f";
if (test.agent.indexOf("macintosh") > 0) {
parent.style.width = `${(data.settings.report[boxName].width / 10) - 8.15}em`;
} else {
parent.style.width = `${(data.settings.report[boxName].width / 10) - 9.75}em`;
}
} else {
buttonGroup.getElementsByTagName("button")[0].innerHTML = "\u035f";
if (test.agent.indexOf("macintosh") > 0) {
parent.style.width = `${(data.settings.report[boxName].width / 10) - 5.15}em`;
} else {
parent.style.width = `${(data.settings.report[boxName].width / 10) - 6.75}em`;
}
}
if (data.settings.report[boxName].top < 15) {
data.settings.report[boxName].top = 15;
}
report[boxName].box.style.right = "auto";
report[boxName].box.style.left = `${data.settings.report[boxName].left / 10}em`;
report[boxName].box.style.top = `${data.settings.report[boxName].top / 10}em`;
report[boxName].body.style.width = `${data.settings.report[boxName].width / 10}em`;
report[boxName].body.style.height = `${data.settings.report[boxName].height / 10}em`;
report[boxName].body.style.display = "block";
}
if (boxName === "feed") {
id("feedsubmit").onclick = feedsubmit;
}
},
select = function dom_load_select(event:Event):void {
const elly:HTMLSelectElement = <HTMLSelectElement>event.target || <HTMLSelectElement>event.srcElement;
selectDescription(elly);
method.app.options(event);
if (elly.getAttribute("id") === "option-color") {
method.event.colorScheme(event);
}
},
selectDescription = function dom_load_selectDescription(el:HTMLSelectElement):void {
const opts:HTMLCollectionOf<HTMLOptionElement> = el.getElementsByTagName("option"),
desc:string = opts[el.selectedIndex].getAttribute("data-description"),
opt:HTMLOptionElement = <HTMLOptionElement>el[el.selectedIndex],
value:string = opt.value,
parent:HTMLElement = <HTMLElement>el.parentNode,
span:HTMLSpanElement = parent.getElementsByTagName("span")[0];
span.innerHTML = ` <strong>${value}</strong> \u2014 ${desc}`;
},
textareablur = function dom_load_textareablur(event:Event):void {
const el:HTMLElement = <HTMLElement>event.srcElement || <HTMLElement>event.target,
tabkey = id("textareaTabKey");
if (tabkey === null) {
return;
}
tabkey.style.display = "none";
if (test.ace === true) {
const item = <HTMLElement>el.parentNode;
item.setAttribute("class", item.getAttribute("class").replace(" filefocus", ""));
}
},
textareafocus = function dom_load_textareafocus(event:Event):void {
const el:HTMLElement = <HTMLElement>event.srcElement || <HTMLElement>event.target,
tabkey:HTMLElement = id("textareaTabKey"),
aria:HTMLElement = id("arialive");
if (tabkey === null) {
return;
}
tabkey.style.zIndex = String(data.zIndex + 10);
if (aria !== null) {
aria.innerHTML = tabkey.innerHTML;
}
if (options.mode === "diff") {
tabkey.style.right = "51%";
tabkey.style.left = "auto";
} else {
tabkey.style.left = "51%";
tabkey.style.right = "auto";
}
tabkey.style.display = "block";
if (test.ace === true) {
let item = <HTMLElement>el.parentNode;
item.setAttribute("class", `${item.getAttribute("class")} filefocus`);
}
};
// prep default announcement text
{
const headline = id("headline"),
headtext = (headline === null)
? null
: headline.getElementsByTagName("p")[0],
x = Math.random(),
circulation = [
"Available in your editor with <a href=\"https://unibeautify.com/\">Unibeautify</a>",
"Updated to <a href=\"https://www.npmjs.com/package/prettydiff\">NPM</a>.",
"Check out the <a href=\"https://sparser.io/demo/\">parsing utility</a> that makes this possible.",
"Supporting <a href=\"documentation.xhtml#languages\">45 languages</a> as of version 101.0.11"
];
if (headline !== null) {
headtext.innerHTML = circulation[Math.floor(x * circulation.length)];
if (location.href.indexOf("ignore") > 0) {
headline.innerHTML = "<h2>BETA TEST SITE.</h2> <p>Official Pretty Diff is at <a href=\"https://prettydiff.com/\">https://prettydiff.com/</a></p> <span class=\"clear\"></span>";
}
}
}
// changing the default value of diff_format and complete_document for the browser tool
{
let el:HTMLElement = document.getElementById("option-diff_format"),
ops:HTMLCollectionOf<HTMLOptionElement> = el.getElementsByTagName("option"),
sel:HTMLSelectElement,
a:number = 0;
options.diff_format = "html";
sel = <HTMLSelectElement>el;
if (ops[0].innerHTML !== "html") {
do {
a = a + 1;
} while (a < ops.length && ops[a].innerHTML !== "html");
}
if (a < ops.length) {
sel.selectedIndex = a;
}
}
// build the Ace editors
if (test.ace === true) {
const insize:HTMLInputElement = id("option-indent_size"),
tabSizeNumber:number = (insize === null || isNaN(Number(insize.value)) === true)
? 4
: Number(insize.value),
tabSize:number = (tabSizeNumber < 1)
? 4
: tabSizeNumber;
if (textarea.codeIn !== null) {
aceStore.codeIn = aceApply("codeIn", true);
}
if (textarea.codeOut !== null) {
aceStore.codeOut = aceApply("codeOut", true);
}
aceStore
.codeIn
.getSession()
.setTabSize(tabSize);
aceStore
.codeOut
.getSession()
.setTabSize(tabSize);
}
x = id("ace-no");
if (test.ace === false && x !== null && x.checked === false) {
x.checked = true;
}
// preps stored settings
// should come after events are assigned
if (localStorage.getItem("settings") !== undefined && localStorage.getItem("settings") !== null) {
if (localStorage.getItem("settings").indexOf(":undefined") > 0 && test.store === true) {
localStorage.setItem("settings", localStorage.getItem("settings").replace(/:undefined/g, ":false"));
}
data.settings = JSON.parse(localStorage.getItem("settings"));
const keys:string[] = Object.keys(data.settings),
keylen:number = keys.length;
let a:number = 0,
el:HTMLElement,
sel:HTMLSelectElement,
name:string,
opt:HTMLOptionElement,
numb:number;
do {
if (keys[a] !== "report" && keys[a] !== "knownname" && keys[a] !== "feedback") {
el = id(keys[a]) || id(data.settings[keys[a]]);
if (el !== null) {
name = el.nodeName.toLowerCase();
if (name === "select") {
sel = <HTMLSelectElement>el;
sel.selectedIndex = data.settings[keys[a]];
opt = <HTMLOptionElement>sel[sel.selectedIndex];
options[keys[a].replace("option-", "")] = opt.value;
if (keys[a] === "option-color") {
method.event.colorScheme(null);
}
} else {
if (keys[a] === "mode") {
id(data.settings[keys[a]]).checked = true;
options.mode = data.settings[keys[a]].replace("mode", "");
method.event.modeToggle(options.mode);
} else if (typeof data.settings[keys[a]] === "string" && data.settings[keys[a]].indexOf("option-true-") === 0) {
id(data.settings[keys[a]]).checked = true;
options[keys[a].replace("option-", "")] = true;
} else if (typeof data.settings[keys[a]] === "string" && data.settings[keys[a]].indexOf("option-false-") === 0) {
id(data.settings[keys[a]]).checked = true;
} else if (keys[a].indexOf("option-") === 0) {
if (id(keys[a]).getAttribute("data-type") === "number") {
numb = Number(data.settings[keys[a]]);
if (isNaN(numb) === false) {
id(keys[a]).value = data.settings[keys[a]];
options[keys[a].replace("option-", "")] = numb;
if (test.ace === true && keys[a] === "option-wrap") {
if (numb < 1) {
numb = 80;
}
aceStore.codeIn.setPrintMarginColumn(numb);
aceStore.codeOut.setPrintMarginColumn(numb);
}
}
} else {
id(keys[a]).value = data.settings[keys[a]];
options[keys[a].replace("option-", "")] = data.settings[keys[a]];
}
if (keys[a] === "option-indent_size") {
insize();
} else if (keys[a] === "option-indent_char") {
indentchar();
}
} else if (id(data.settings[keys[a]]) !== null) {
id(data.settings[keys[a]]).checked = true;
}
}
}
}
a = a + 1;
} while (a < keylen)
if (data.settings.report === undefined) {
data.settings.report = {
code: {},
feed: {},
stat: {}
};
}
if (data.settings.knownname === undefined && test.store === true) {
data.settings.knownname = `${Math
.random()
.toString()
.slice(2) + Math
.random()
.toString()
.slice(2)}`;
localStorage.setItem("settings", JSON.stringify(data.settings));
}
} else {
data.settings.knownname = `${Math
.random()
.toString()
.slice(2) + Math
.random()
.toString()
.slice(2)}`;
}
if (options.diff === undefined) {
options.diff = "";
}
if (localStorage.getItem("source") !== undefined && localStorage.getItem("source") !== null) {
options.source = localStorage.getItem("source");
if (test.ace === true) {
aceStore.codeIn.setValue(options.source);
} else {
textarea.codeIn.value = options.source;
}
}
if (localStorage.getItem("diff") !== undefined && localStorage.getItem("diff") !== null) {
options.diff = localStorage.getItem("diff");
if (options.mode === "diff") {
if (test.ace === true) {
aceStore.codeOut.setValue(options.diff);
} else {
textarea.codeOut.value = options.diff;
}
}
}
// feedback dialogue config data (current disabled)
if (data.settings.feedback === undefined) {
data.settings.feedback = {};
data.settings.feedback.newb = false;
data.settings.feedback.veteran = false;
}
x = id("feedsubmit");
if (x !== null) {
x.onclick = feedsubmit;
}
// assigns event handlers to input elements
inputs = document.getElementsByTagName("input");
inputsLen = inputs.length;
a = 0;
do {
x = inputs[a];
type = x.getAttribute("type");
idval = x.getAttribute("id");
if (type === "radio") {
name = x.getAttribute("name");
if (id === data.settings[name]) {
x.checked = true;
}
if (idval.indexOf("feedradio") === 0) {
feeds(x);
} else if (name === "mode") {