-
Notifications
You must be signed in to change notification settings - Fork 2
/
_note.js
701 lines (651 loc) · 23.9 KB
/
_note.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
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
// ------- declare variables ----------
var noteBody = document.getElementById('noteBody');
var inputDiv = document.getElementById('inputDiv');
var inputBox = document.getElementById('inputBox');
var newNoteDiv = document.getElementById('newNoteDiv');
var noteTitle = document.getElementById('noteTitle');
var optionsDiv = document.getElementById('optionsDiv');
var aboutDiv = document.getElementById('aboutDiv');
var backupDiv = document.getElementById('backupDiv');
var backupDispDiv = document.getElementById('backupDispDiv');
var newNoteInputBox = document.getElementById('newNoteInputBox');
var coords = document.getElementById('coords');
var undeleteButton = document.getElementById('undeleteButton');
var statusBar = document.getElementById('statusBar');
var statusBarText = document.getElementById('statusBarText');
var localFontDiv = [
document.getElementById('localFontDiv0'),
document.getElementById('localFontDiv1'),
document.getElementById('localFontDiv2'),
document.getElementById('localFontDiv3')
];
var localFontCheckBox = [
document.getElementById('localFontCheckBox0'),
document.getElementById('localFontCheckBox1'),
document.getElementById('localFontCheckBox2'),
document.getElementById('localFontCheckBox3')
];
var localFontForm = [
document.getElementById('localFontForm0'),
document.getElementById('localFontForm1'),
document.getElementById('localFontForm2'),
document.getElementById('localFontForm3')
];
var localFontBox = [
document.getElementById('localFontBox0'),
document.getElementById('localFontBox1'),
document.getElementById('localFontBox2'),
document.getElementById('localFontBox3')
];
var localFontShow = [
document.getElementById('localFontShow0'),
document.getElementById('localFontShow1'),
document.getElementById('localFontShow2'),
document.getElementById('localFontShow3')
];
var localFontShowP = [
document.getElementById('localFontShowP0'),
document.getElementById('localFontShowP1'),
document.getElementById('localFontShowP2'),
document.getElementById('localFontShowP3')
];
var localFontSetButton = [
document.getElementById('localFontSetButton0'),
document.getElementById('localFontSetButton1'),
document.getElementById('localFontSetButton2'),
document.getElementById('localFontSetButton3'),
];
var inputs = [];
var items = [];
var uFont = ['', '', '', ''];
var delItem = {
text: '',
num: '',
note: '' }
var xElBeg = "<button class='x smallFont moveButtons' onclick='DelLine(this)' id='X";
var xElEnd = "'>X</button>";
var renButtonHTML = "<button class='upperRightButton' onclick='RenameThisNote()'>Rename</button>";
var delButtonHTML = "<button class='upperRightButton' onclick='deleteNote();'>Delete</button>";
var moveButtonsHTMLBeg = "<button class='moveButtons smallFont uBut' id='u";
var moveButtonsHTMLMid = "' onclick='MoveUp(this)'>↑</button> <button class='moveButtons smallFont dBut' id='d";
var moveButtonsHTMLEnd = "' onclick='MoveDown(this)'>↓</button>";
var lineStartHTML = "<span class='serif'>⋅ </span>";
var statusBarHTML = " ";
var noteFont = 'serif';
var fgColor = 'black';
var firstCoordCheck = true;
var selectedFlag = [false, false, false, false];
var uneditedString = '';
var currentVer = 'Note v' + Note.version + '\nPublic Domain';
var timer = 0;
var lastScrollPos = 0;
var currentNote, dummyVar, bgColor, i, currentX, currentY, oldX, oldY, offsetX, offsetY;
var lastLine, itemToEdit, itemTotal, statusTimer, prevNote;
var done;
// ------- declare functions ----------
function applyOptions() {
// apply options on load & on change
if (!!CheckForOptionsFile()) { GetOptions(dummyVar) }
else { return; }
fgColor = 'black';
switch (Opt2) {
case "yellow":
bgColor = "#f0f0b3";
break;
case "white":
bgColor = "fefefe";
break;
case "pink":
bgColor = "#ff90aa";
break;
case "green":
bgColor = "#bfe9bf";
break;
case "blue":
bgColor = "#a9d6df";
break;
case "charcoal":
bgColor = "#555555";
fgColor = "#ffffff";
break;
case "black":
bgColor = "#222222";
fgColor = "#eeeeee";
break;
default:
bgColor = "lightgray";
break;
}
document.body.style.backgroundColor = bgColor;
document.body.style.color = fgColor;
document.getElementById('clock').style.color = fgColor;
switch (Opt3) {
case "uf0":
noteFont = Opt5;
break;
case "uf1":
noteFont = Opt6;
break;
case "uf2":
noteFont = Opt7;
break;
case "uf3":
noteFont = Opt8;
break;
case "p2":
noteFont = 'sans-serif';
break;
default:
noteFont = 'serif';
}
if (noteFont == '') { noteFont = 'serif'; Opt3 = 'p1'; }
uFont[0] = Opt5;
uFont[1] = Opt6;
uFont[2] = Opt7;
uFont[3] = Opt8;
if (Opt9 == 'cc') { currentX = Opt10; currentY = Opt11; }
if (Opt12 == 'hide') { statusBar.style.display = 'none'; }
else { statusBar.style.display = 'inline-block'; }
}
function saveOptions() {
// save options to disk on change
// option 2 - background color
if (document.getElementsByName('bg')[0].checked) { Opt2 = 'gray' }
else if (document.getElementsByName('bg')[1].checked) { Opt2 = 'yellow'; }
else if (document.getElementsByName('bg')[2].checked) { Opt2 = 'white'; }
else if (document.getElementsByName('bg')[3].checked) { Opt2 = 'pink'; }
else if (document.getElementsByName('bg')[4].checked) { Opt2 = 'green'; }
else if (document.getElementsByName('bg')[5].checked) { Opt2 = 'blue'; }
else if (document.getElementsByName('bg')[6].checked) { Opt2 = 'charcoal'; }
else if (document.getElementsByName('bg')[7].checked) { Opt2 = 'black'; }
// option 3 - font
Opt3 = 'p1';
if (localFontCheckBox[0].checked) { Opt3 = 'uf0'; }
if (localFontCheckBox[1].checked) { Opt3 = 'uf1'; }
if (localFontCheckBox[2].checked) { Opt3 = 'uf2'; }
if (localFontCheckBox[3].checked) { Opt3 = 'uf3'; }
if (document.getElementById('sansRadio').checked) { Opt3 = 'p2'; }
// option 4 - font size
if (document.getElementsByName('textSize')[0].checked) { Opt4='small'; }
else if (document.getElementsByName('textSize')[1].checked) { Opt4='medium'; }
else if (document.getElementsByName('textSize')[2].checked) { Opt4='large'; }
// option 5 - user font 0
Opt5 = uFont[0];
// option 6 - user font 1
Opt6 = uFont[1];
// option 7 - user font 2
Opt7 = uFont[2];
// option 8 - user font 3
Opt8 = uFont[3];
if (document.getElementsByName('screenPos')[1].checked) {
Opt9='cc';
Opt10 = currentX - offsetX;
Opt11 = currentY - offsetY;
}
else { Opt9 = 'mm'; Opt10 = 0; Opt11 = 0; }
if (document.getElementsByName('statusOption')[0].checked) { Opt12 = 'hide'; }
else { Opt12 = 'show'; }
WriteOptions()
applyOptions();
showOptions();
}
function savePos() {
// stripped-down save function to only save screen position
if (document.getElementsByName('screenPos')[1].checked) { Opt9 = 'cc'; }
else { Opt9 = 'mm'; }
Opt10 = currentX - offsetX;
Opt11 = currentY - offsetY;
WriteOptions()
if (optionsDiv.style.display != 'none') { showOptions(); }
}
function showOptions() {
clearAll();
noteBody.style.display='none';
noteTitle.innerText = 'Options:';
optionsDiv.style.display='block';
for (i = 0; i<document.getElementsByTagName('td').length; i++) {
if (document.getElementsByTagName('td')[i].className == 'optionsColumn') {
document.getElementsByTagName('td')[i].style.width = (document.documentElement.clientWidth / 3);
}
}
switch (Opt2) {
case "gray":
document.getElementsByName('bg')[0].checked=true;
break;
case "yellow":
document.getElementsByName('bg')[1].checked=true;
break;
case "white":
document.getElementsByName('bg')[2].checked=true;
break;
case "pink":
document.getElementsByName('bg')[3].checked=true;
break;
case "green":
document.getElementsByName('bg')[4].checked=true;
break;
case "blue":
document.getElementsByName('bg')[5].checked=true;
break;
case "charcoal":
document.getElementsByName('bg')[6].checked=true;
break;
case "black":
document.getElementsByName('bg')[7].checked=true;
break;
}
var fonts = document.getElementsByName('font');
// populate user font boxes, if they've been saved
var foundFont = false;
for (i = 0; i < uFont.length; i++) {
if (fonts[i].value.toLowerCase() == Opt3) { fonts[i].checked=true; foundFont = true; }
if (uFont[i]=='') {
localFontShow[i].style.display='none';
localFontDiv[i].style.display='inline';
}
else {
localFontDiv[i].style.display='none';
localFontShow[i].style.display='inline';
if (uFont[i].length>=14) { localFontShowP[i].innerText=uFont[i].slice(0,11)+"..."; }
else { localFontShowP[i].innerText=uFont[i]; }
localFontShowP[i].style.fontFamily="'"+uFont[i]+"', serif";
}
}
if (Opt3 == 'p2') { fonts[4].checked=true; noteFont = 'sans-serif'; foundFont = true; }
if (!foundFont) { fonts[5].checked=true; noteFont = 'serif'; }
var sizes = document.getElementsByName('textSize');
// ---- use this method for other options too ----
for (i = 0; i < sizes.length; i++) {
if (sizes[i].value == Opt4) { sizes[i].checked=true; }
}
if (Opt9 == 'cc') { document.getElementsByName('screenPos')[1].checked = true; }
else { document.getElementsByName('screenPos')[0].checked = true; }
if (Opt12 == 'hide') { document.getElementsByName('statusOption')[0].checked = true; }
else { document.getElementsByName('statusOption')[1].checked = true; }
checkCoords();
showCoords();
}
function clearAll() {
// clear all text/fields
GetFileList()
newNoteDiv.style.display = 'none';
optionsDiv.style.display='none';
inputDiv.style.display = 'none';
aboutDiv.style.display = 'none';
backupDiv.style.display = 'none';
noteBody.style.display='block';
noteBody.innerText = '';
noteTitle.innerText = '';
newNoteInputBox.value = '';
inputBox.value='';
items[0] = 'clear';
for (i in items) {
items[i] = '';
}
for (i = 0; i < localFontBox.length; i++) {
localFontBox[i].value=uFont[i];
}
itemTotal = 0;
}
function showNotes(cNote) {
// load note file
clearAll();
prevNote = currentNote;
currentNote = cNote;
editing = false;
window[currentNote].className='noteButton activeNote';
var currentNoteDisplay = currentNote;
if (currentNote == "&") { currentNoteDisplay = "&"; } // to deal w/ & as only char in title
noteTitle.innerHTML = "<div id='delBox'>" + renButtonHTML + delButtonHTML + "</div>" + currentNoteDisplay;
getLines(currentNote);
if (currentNote == prevNote) {
// if reloading the same note
noteBody.scrollTop = lastScrollPos;
}
else { noteBody.scrollTop = 0; }
var firstBut = document.getElementById('u0');
var lastBut = window['d' + (lastLine-1)];
if (firstBut != null) {
document.getElementById('u0').disabled = true;
document.getElementById('u0').style.filter = "alpha(opacity = 25)";
document.getElementById('u0').style.opacity = .25;
}
if (lastBut != null) {
window['d' + (lastLine-1)].disabled = true;
window['d' + (lastLine-1)].style.filter = "alpha(opacity = 25)";
window['d' + (lastLine-1)].style.opacity = .25;
}
inputDiv.style.display='block';
inputBox.focus();
}
function getLines(thisNote) {
// loop through file, get each line from note and add X and arrow buttons to it, wrap it in a <tr> and add it to the HTML
noteBody.innerHTML = noteBody.innerHTML + "<div><table id='itemTable'>";
var currentLine;
var noteNum = 0;
lastLine = 0;
var FileEnd = false;
var localFontHTML = " style='font-family: "" + noteFont + "", serif;'";
var currentClasses = 'item ' + Opt4 + 'Font';
OpenRFile(thisNote)
while (!FileEnd) {
currentLine = GetLine(dummyVar)
if (currentLine == EOFConst) {
FileEnd = true;
lastLine = noteNum;
}
else if (currentLine != "") {
// check input string for < or >, repl w/ > or <
currentLine = currentLine.replace(/</g, "<");
currentLine = currentLine.replace(/>/g, ">");
noteBody.innerHTML = noteBody.innerHTML + "<tr class='" + currentClasses + "' id='item" + noteNum + "'" + localFontHTML + "><td>" + xElBeg + noteNum + xElEnd + " " + moveButtonsHTMLBeg + noteNum + moveButtonsHTMLMid + noteNum + moveButtonsHTMLEnd + lineStartHTML + "</td><td id='text" + noteNum + "' ondblclick='goEdit(this);'>" + currentLine + "</td></tr>";
checkOverflow("item" + noteNum);
noteNum++;
}
}
itemTotal = noteNum;
CloseRFile(currentNote);
noteBody.innerHTML = noteBody.innerHTML + "</table></div>";
}
function onSubmitted(tempVar) {
event.returnValue = false;
AddNote(tempVar)
}
function showX(self) {
// show X to right of each item, on mouseover
thisX = "X" + self.id.slice(4);
document.getElementById(thisX).style.visibility = 'visible';
}
function hideX(self) {
// hide X on mouseout
thisX = "X" + self.id.slice(4);
document.getElementById(thisX).style.visibility = 'hidden';
}
function showNewNoteBox() {
clearAll();
noteBody.style.display='none';
noteTitle.innerText = 'Name for new note:';
newNoteDiv.style.display = 'block';
newNoteInputBox.focus();
}
function createNewNote(newNoteName) {
// create a new note file
event.returnValue = false;
newNoteName = checkForLeadingSpaces(newNoteName);
newNoteName = checkForTrailingSpaces(newNoteName);
if (newNoteName == '') { showNewNoteBox(); showStatus("No text entered"); return; }
var fileCreated = CreateNewFile(newNoteName)
if (!!fileCreated) { showNotes(newNoteName); showStatus("New note, " + AbbrevText(newNoteName) + " created"); }
else { newNoteInputBox.value = ''; }
}
function getLocalFont(n) {
localFontShow[n].style.display='none';
localFontDiv[n].style.display='inline';
localFontCheckBox[n].onclick='setLocalFont(' + n + ');';
localFontBox[n].value=uFont[n];
localFontBox[n].select();
selectedFlag[n] = true;
checkLocalFontInput(n);
}
function setLocalFont(n) {
event.returnValue = false;
localFontBox[n].value = localFontBox[n].value.replace(/</g, "");
localFontBox[n].value = localFontBox[n].value.replace(/>/g, "");
localFontBox[n].value = localFontBox[n].value.replace(/'/g, "");
localFontBox[n].value = localFontBox[n].value.replace(/"/g, "");
localFontBox[n].value = localFontBox[n].value.replace(/!/g, "");
localFontBox[n].value = localFontBox[n].value.replace(/\\/g, "");
localFontBox[n].value = localFontBox[n].value.replace(/\//g, "");
localFontBox[n].value = localFontBox[n].value.replace(/%/g, "");
localFontBox[n].value = checkForLeadingSpaces(localFontBox[n].value);
localFontBox[n].value = checkForTrailingSpaces(localFontBox[n].value);
if (localFontBox[n].value != '') {
uFont[n]=localFontBox[n].value;
localFontCheckBox[n].checked=true;
saveOptions();
}
}
function checkForLeadingSpaces(str) {
while (str.slice(0,1)==" ") {
// remove any spaces from before text
if (str.length > 1) { str=str.slice(1); }
else { str = ''; break; }
}
return str;
}
function checkForTrailingSpaces(str) {
while (str.slice(-1)==" ") {
// remove any spaces from after text
if (str.length > 1) { str=str.slice(0,-1); }
else { str = ''; break; }
}
return str;
}
function checkLocal(n) {
if (uFont[n] == '') { getLocalFont(n); }
else { saveOptions(); }
}
function checkLocalFontInput(n) {
// check to see there is any value in local font text box; if not, Set button remains disabled
if (!selectedFlag[n]) { localFontBox[n].value = checkForLeadingSpaces(localFontBox[n].value); }
selectedFlag[n] = false;
if (localFontBox[n].value != '') { localFontSetButton[n].disabled = false; }
else { localFontSetButton[n].disabled = true; }
}
function deleteNote() {
// confirm, then call a sub in VBScript to delete currentNote
var conf='';
if (confirm("Are you sure you want to delete\n" + currentNote + "?", conf)) { DeleteThisNote() }
else { return; }
}
function displayAbout() {
// display license info/help file
clearAll();
noteBody.style.display='none';
noteTitle.innerText = "About Note";
aboutDiv.style.display = 'block';
document.getElementById('versionInfo').innerText = currentVer;
}
function checkCoords() {
// check current coordinates, also check current size to adjust div heights
if ((screen.availHeight > 650) && (document.documentElement.clientHeight > 380)) {
noteBody.style.height = document.documentElement.clientHeight - 350;
optionsDiv.style.height = document.documentElement.clientHeight - 300;
noteList.style.display = 'block';
if (Opt12 == 'show') { statusBar.style.display = 'inline-block'; }
}
else {
noteBody.style.height = 290;
noteList.style.display = 'none';
statusBar.style.display = 'none';
}
noteBody.style.width = document.documentElement.clientWidth * 0.96;
var tempSize = 100 - (((NoteWidth - document.documentElement.clientWidth) / NoteWidth) * 100);
if (tempSize > 100) { tempSize = 100; }
inputBox.size = tempSize;
oldX = currentX;
oldY = currentY;
getCoords();
if (!firstCoordCheck) {
if ((oldX != currentX) || (oldY != currentY)) {
if (Opt9 == 'cc') { showCoords(); savePos(); }
else {
Opt9 = 'cc';
document.getElementsByName('screenPos')[1].checked = true;
showCoords();
savePos();
}
}
}
else { firstCoordCheck = false; }
}
function checkTimer() {
// check status timer & clock
if (statusBarText.innerHTML != statusBarHTML) {
statusTimer = statusTimer + 0.5;
if (statusTimer > 6.5) { clearStatus(); }
}
timer = timer + 0.5;
if (timer % 10 == 0) { getTime(); }
if (timer >= 1000) { timer = 0; }
checkCoords();
}
function getCoords() {
currentX = window.screenLeft;
currentY = window.screenTop;
}
function showCoords() {
getCoords();
coords.innerText = "[" + (currentX - offsetX) + ", " + (currentY - offsetY) + "]";
}
function getOffset() {
// determine x & y offset amt at start
var nowX = window.screenLeft;
var nowY = window.screenTop;
window.moveTo(nowX, nowY);
offsetX = window.screenLeft - nowX;
offsetY = window.screenTop - nowY;
}
function goEdit(itemObj) {
// add an input box to edit current note item
itemToEdit = itemObj.id;
uneditedString = itemObj.innerText;
if (!!editing) { showNotes(currentNote); }
editing = true;
var editBoxHTML = "<form name='editForm' onsubmit='event.returnValue=false;SubmitEdit(editBox.value);' action='#'><input type='text' size=50 id='editBox' /><input type='submit' style='color: green; margin-left: 2px;' value='Change' /><input type='button' style='color: red; margin-left: 2px;' value='Cancel' onclick='canceledEdit();' /></form>";
document.getElementById(itemToEdit).innerHTML = editBoxHTML;
document.getElementById('editBox').value = uneditedString;
document.getElementById('editBox').focus();
document.getElementById('editBox').select();
}
function canceledEdit() {
showNotes(currentNote);
showStatus("Edit canceled");
}
function insertItem() {
// let user pick where to insert new note
var insertClass = 'insertBlack';
if (fgColor != 'black') { insertClass = 'insertWhite'; }
for (i=0; i<itemTotal; i++) {
// add "insert" class to item text <td> elements, and onclick handler for insertion
document.getElementById('text' + i).className = insertClass;
document.getElementById('text' + i).onclick = function() {
if (inputBox.value == "") { showNotes(currentNote); showStatus("Nothing to insert"); return; }
EditedString = inputBox.value;
WriteModifiedFile((this.id).slice(4), -1)
showStatus(AbbrevText(EditedString) + " inserted at line #" + (1 * (this.id).slice(4) + 1));
};
}
}
function showStatus(statusStr) {
// show a status message at bottom of window
if (Opt12 == 'show') {
statusBarText.innerHTML = statusStr;
statusTimer = 0;
}
}
function clearStatus() {
// clear status bar
statusBarText.innerHTML = statusBarHTML;
statusTimer = 0;
}
function focusInput() {
// call from VBS file to refocus on inputBox after a status msg display
inputBox.focus();
}
function highlight(tempNum) {
// highlight recently-restored note item for a couple seconds
var tempHL = document.getElementById(('text'+tempNum));
tempHL.style.backgroundColor = 'yellow';
if (fgColor != 'black') {
var tempColor = fgColor;
tempHL.style.color = 'black';
}
setTimeout(function(){
tempHL.style.backgroundColor = bgColor;
tempHL.style.color = fgColor;
}, 2000);
}
function dispBackupDiv() {
// show backup div: backup button, current backup dir, button to change dir
clearAll();
noteBody.style.display='none';
noteTitle.innerText = "Backup";
backupDiv.style.display = 'block';
var Opt13Display = Opt13;
if (Opt13 == Default13) { Opt13Display = showDefaultBackup() }
if (Opt13Display.length > 50) { Opt13Display = abbrevBackup(Opt13Display); }
backupDispDiv.innerText = Opt13Display;
}
function abbrevBackup(rawText) {
// abbreviate backup file path for display
return rawText.slice(0, 23) + " ... " + rawText.slice(rawText.length-24);
}
function getTime() {
// get current time & display it
var nowDate = new Date();
var nowTime = nowDate.toLocaleTimeString();
var timeSections = nowTime.split(":");
document.getElementById('clock').innerHTML = timeSections[0] + ":" + timeSections[1] + " " + "<span id='clockText'>" + timeSections[2].slice(-2) + "</span>";
}
function checkOverflow(thisLine) {
// check to see if just-added line causes horizontal scroll
if (noteBody.scrollWidth > noteBody.offsetWidth) {
document.getElementById(thisLine).className = document.getElementById(thisLine).className + " overflowClass";
}
}
// ----------- declare event handlers ----------
// option button handlers
inputs = document.getElementsByTagName('input');
for (i=0; i<inputs.length; i++) {
if (inputs[i].value.slice(0,2).toLowerCase() == 'uf') {
switch (inputs[i].value.slice(2)) {
case "0":
inputs[i].attachEvent('onclick', function() { checkLocal(0); });
break;
case "1":
inputs[i].attachEvent('onclick', function() { checkLocal(1); });
break;
case "2":
inputs[i].attachEvent('onclick', function() { checkLocal(2); });
break;
case "3":
inputs[i].attachEvent('onclick', function() { checkLocal(3); });
break;
}
}
else if (inputs[i].value == "mm") {
inputs[i].attachEvent('onclick', function() { showCoords(); savePos(); setPos(); showCoords(); });
}
else if (inputs[i].value == "cc") {
inputs[i].attachEvent('onclick', function() { showCoords(); savePos(); });
}
else if (inputs[i].className == "optionInput") {
inputs[i].attachEvent('onclick', saveOptions);
}
}
for (i=0;i<localFontBox.length;i++) {
switch (i) {
case 0:
localFontBox[i].attachEvent('onkeyup', function() { checkLocalFontInput(0); });
break;
case 1:
localFontBox[i].attachEvent('onkeyup', function() { checkLocalFontInput(1); });
break;
case 2:
localFontBox[i].attachEvent('onkeyup', function() { checkLocalFontInput(2); });
break;
case 3:
localFontBox[i].attachEvent('onkeyup', function() { checkLocalFontInput(3); });
break;
}
}
// to get current scroll position:
noteBody.attachEvent('onscroll', function() { setTimeout(function(){lastScrollPos = noteBody.scrollTop;}, 250); });
// --------- execution -----------------
clearAll();
getOffset();
applyOptions();
setPos();
var checkTimerInt = setInterval(checkTimer, 500);
getTime();