-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsecondversion.html
1881 lines (1490 loc) · 59.4 KB
/
secondversion.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--
TiddlyWiki 1.1 by Jeremy Ruston, (jeremy [at] osmosoft [dot] com)
Copyright (c) Osmosoft Limited, 20 December 2005
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
Neither the name of the Osmosoft Limited nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
-->
<html>
<head>
<title>TiddlyWiki</title>
<script type="text/javascript">
// ---------------------------------------------------------------------------------
// Main
// ---------------------------------------------------------------------------------
function main()
{
restart();
}
function restart()
{
closeAllTiddlers();
hideMessage();
refreshAll();
var start;
if(window.location.hash)
displayTiddlers(null,decodeURI(window.location.hash.substr(1)),1,null,null);
else if(start = getTiddlerText("DefaultTiddlers"))
displayTiddlers(null,start,1,null,null);
}
// ---------------------------------------------------------------------------------
// Tiddler functions
// ---------------------------------------------------------------------------------
// Display a tiddler with animation and scrolling, as though a link to it has been clicked on
// src = source element object (eg link) for animation effects and positioning
// title = title of tiddler to display
// state = 0 is default or current state, 1 is read only and 2 is edittable
// highlightText = text to highlight in the displayed tiddler
// highlightCaseSensitive = flag for whether the highlight text is case sensitive
function displayTiddler(src,title,state,highlightText,highlightCaseSensitive,slowly)
{
// Figure out the tiddler this one must go after
var after = findContainingTiddler(src);
// Create the tiddler if needed
var theTiddler = createTiddler(title,state,after,highlightText,highlightCaseSensitive);
// Animate from the target of the event that followed the link
if(src)
{
// Start with the tiddler being transparent and fade it up
theTiddler.style.opacity = 0;
// Set the text of the floater to match the title
var floater = document.getElementById("floater");
var floaterTitle = document.createTextNode(title);
floater.replaceChild(floaterTitle,floater.firstChild);
// Animate the floater from the link location to the location of the new tiddler
startZoomer(floater,src,theTiddler,slowly);
}
}
// Display several tiddlers from a list of space separated titles
function displayTiddlers(src,titles,state,highlightText,highlightCaseSensitive,slowly)
{
var tiddlers = titles.split(" ");
for(var t=tiddlers.length-1;t>=0;t--)
displayTiddler(src,tiddlers[t],state,highlightText,highlightCaseSensitive,slowly);
}
// Create a tiddler if it doesn't exist (with no fancy animating). The tiddler is invisible unless it was already visible
// title = title of tiddler to display
// state = 0 is default or current state, 1 is read only and 2 is edittable
// after = optional existing tiddler element to put the new one after
// highlightText = text to highlight in the displayed tiddler
// highlightCaseSensitive = flag for whether the highlight text is case sensitive
function createTiddler(title,state,after,highlightText,highlightCaseSensitive)
{
// See if the tiddler div is already there
var theTiddler = document.getElementById("tiddler" + title);
if(!theTiddler)
{
// If it's not there, create the tiddler header
theTiddler = createTiddlerHeader(title,after,highlightText,highlightCaseSensitive);
// Create the tiddler body appropriately
if(state != 2)
createTiddlerBody(theTiddler,title,highlightText,highlightCaseSensitive);
else
createTiddlerEditor(theTiddler,title);
}
else
{
// If the tiddler does exist, make sure that it's in the right state
var theBody = document.getElementById("body" + title);
var theEditor = document.getElementById("editor" + title);
// Create and delete as appropriate
switch (state)
{
case 0: // For default state, leave everything alone
break;
case 1: // For read-only state, delete any editor
if(!theBody)
{
if(theEditor)
theEditor.parentNode.removeChild(theEditor);
createTiddlerBody(theTiddler,title,highlightText,highlightCaseSensitive);
}
break;
case 2: // For editor state, delete any read-only body
if(!theEditor)
{
if(theBody)
theBody.parentNode.removeChild(theBody);
createTiddlerEditor(theTiddler,title);
}
break;
}
}
// Return the completed tiddler
return(theTiddler);
}
// Create an invisible common header section of a tiddler
// title = title of tiddler to display
// after = optional existing tiddler element to put the new one after
function createTiddlerHeader(title,after,highlightText,highlightCaseSensitive)
{
// Create the tiddler div
theTiddler = createTiddlyElement(null,"div","tiddler",null);
theTiddler.setAttribute("id","tiddler" + title);
theTiddler.onmouseover = onMouseOverTiddler;
theTiddler.onmouseout = onMouseOutTiddler;
theTiddler.ondblclick = onDblClickTiddler;
// Link it in
var place = document.getElementById("tiddlerDisplay");
if(after)
{
if(after.nextSibling)
place.insertBefore(theTiddler,after.nextSibling);
else
place.appendChild(theTiddler);
}
else
{
if(place.firstChild)
place.insertBefore(theTiddler,place.firstChild);
else
place.appendChild(theTiddler);
}
// Create the anchor
var theAnchor = createTiddlyElement(theTiddler,"a",null,null);
theAnchor.setAttribute("name","link" + title);
// Prepare the regexp for the highlighted selection in the title
if(highlightText == "")
highlightText = null;
var highlightRegExp,highlightMatch;
if(highlightText)
{
highlightRegExp = new RegExp(escapeRegExp(highlightText),highlightCaseSensitive ? "mg" : "img");
highlightMatch = highlightRegExp.exec(title);
}
// Create the title with optional highlight
var theTitle = createTiddlyElement(theTiddler,"div","title",null);
highlightMatch = subWikify(theTitle,title,0,title.length,highlightRegExp,highlightMatch);
insertSpacer(theTitle);
theTitle.setAttribute("id","title" + title);
// Get the subtitle
var subtitle = getTiddlerSubtitle(title);
theTitle.title = subtitle;
// Return the created tiddler
return(theTiddler);
}
// Create a tiddler toolbar according to whether it's an editor or not
function createTiddlerToolbar(title,editor)
{
// Delete any existing toolbar
var theToolbar = document.getElementById("toolbar" + title);
if(theToolbar)
theToolbar.parentNode.removeChild(theToolbar);
// Create the toolbar
var theTitle = document.getElementById("title" + title);
var theToolbar = createTiddlyElement(null,"div","toolbar", null);
theTitle.appendChild(theToolbar);
theToolbar.setAttribute("id","toolbar" + title);
// Create each button in turn
insertSpacer(theToolbar);
if(!editor)
{
// Non-editor toolbar
createTiddlyButton(theToolbar,
"close",
"Close this tiddler",
onClickToolbarClose);
insertSpacer(theToolbar);
createTiddlyButton(theToolbar,
"edit",
"Edit this tiddler",
onClickToolbarEdit);
insertSpacer(theToolbar);
createTiddlyButton(theToolbar,
"permalink",
"Permalink for this tiddler",
onClickToolbarPermaLink);
insertSpacer(theToolbar);
createTiddlyButton(theToolbar,
"references",
"Show tiddlers that link to this one",
onClickToolbarBackLink);
}
else
{
// Editor toolbar
createTiddlyButton(theToolbar,
"done",
"Finish changing this tiddler",
onClickToolbarSave);
insertSpacer(theToolbar);
createTiddlyButton(theToolbar,
"undo",
"Undo changes to this tiddler",
onClickToolbarUndo);
insertSpacer(theToolbar);
createTiddlyButton(theToolbar,
"delete",
"Delete this tiddler",
onClickToolbarDelete);
}
insertSpacer(theToolbar);
}
// Create the body section of a read-only tiddler
function createTiddlerBody(place,title,highlightText,highlightCaseSensitive)
{
// Create the toolbar
createTiddlerToolbar(title,false);
// Get the body of the tiddler
var tiddlerText = getTiddlerText(title);
var tiddlerExists = (tiddlerText != null);
if(!tiddlerExists)
tiddlerText = "This tiddler doesn't yet exist. Double-click to create it";
// Create the body
var theBody = createTiddlyElement(place,"div","body",null);
theBody.setAttribute("id","body" + title);
if(!tiddlerExists)
theBody.style.fontStyle = "italic";
// Add the body text wikifing the links
wikify(tiddlerText,theBody,highlightText,highlightCaseSensitive);
}
// Create the body section of a read-only tiddler
function createTiddlerEditor(place,title)
{
// Create the toolbar
createTiddlerToolbar(title,true);
// Get the body of the tiddler
var tiddlerText = getTiddlerText(title);
var tiddlerExists = (tiddlerText != null);
if(!tiddlerExists)
tiddlerText = "Type the text for '" + title + "' here.";
// Create the editor div
var theEditor = createTiddlyElement(place,"div","editor",null);
theEditor.setAttribute("id","editor" + title);
// Create the title editor
var theTitle = createTiddlyElement(theEditor,"div",null,null);
var theTitleBox = createTiddlyElement(theTitle,"input",null,null);
theTitleBox.setAttribute("id","editorTitle" + title);
theTitleBox.setAttribute("type","text");
theTitleBox.value = title;
theTitleBox.setAttribute("size","40");
// Do the body
var theBody = createTiddlyElement(theEditor,"div",null,null);
var theBodyBox = createTiddlyElement(theBody,"textarea",null,null);
theBodyBox.value = tiddlerText;
theBodyBox.setAttribute("id","editorBody" + title);
theBodyBox.setAttribute("rows","10");
theBodyBox.setAttribute("cols","50");
}
// Create child text nodes and link elements to represent a wiki-fied version of some text
function wikify(text,parent,highlightText,highlightCaseSensitive)
{
// Link patterns
var upperLetter = "[A-Z]";
var lowerLetter = "[a-z]";
var anyLetter = "[A-Za-z_0-9]";
var linkPattern = "(" + upperLetter + "+" + lowerLetter + "+" + upperLetter + anyLetter + "*)";
var urlPattern = "|((?:http|https|mailto|ftp):\\S*)";
var breakPattern = "|(\\n)";
// Create the RegExp object for matching formatting
var formatRegExp = new RegExp(linkPattern + urlPattern + breakPattern,"mg");
// The start of the fragment of the text being considered
var nextPos = 0;
// Prepare the regexp for the highlighted selection
if(highlightText == "")
highlightText = null;
var highlightRegExp,highlightMatch;
if(highlightText)
{
highlightRegExp = new RegExp(escapeRegExp(highlightText),highlightCaseSensitive ? "mg" : "img");
highlightMatch = highlightRegExp.exec(text);
}
// Loop through the bits of the body text
do {
// Get the next formatting match
var formatMatch = formatRegExp.exec(text);
var matchPos = formatMatch ? formatMatch.index : text.length;
// Subwikify the plain text before the match
if(nextPos < matchPos)
highlightMatch = subWikify(parent,text,nextPos,matchPos,highlightRegExp,highlightMatch);
// Dump out the formatted match
if(formatMatch)
{
// Dump out the link itself in the appropriate format
if(formatMatch[1])
{
var theLink = createTiddlyLink(parent,formatMatch[0],false);
highlightMatch = subWikify(theLink,text,matchPos,formatRegExp.lastIndex,highlightRegExp,highlightMatch);
}
else if(formatMatch[2])
{
var theLink = createExternalLink(parent,formatMatch[0]);
highlightMatch = subWikify(theLink,text,matchPos,formatRegExp.lastIndex,highlightRegExp,highlightMatch);
}
else if(formatMatch[3])
parent.appendChild(document.createElement("br"));
}
// Move the next position past the formatting match
nextPos = formatRegExp.lastIndex;
} while(formatMatch);
}
// Helper for wikify that handles highlights within runs of text
function subWikify(parent,text,startPos,endPos,highlightRegExp,highlightMatch)
{
// Check for highlights
while(highlightMatch && (!((highlightRegExp.lastIndex <= startPos) || (highlightMatch.index >= endPos))) && (startPos < endPos))
{
// Deal with the plain text before the highlight
if(highlightMatch.index > startPos)
{
parent.appendChild(document.createTextNode(text.substring(startPos,highlightMatch.index)));
startPos = highlightMatch.index;
}
// Deal with the highlight
var highlightEnd = Math.min(highlightRegExp.lastIndex,endPos);
var theHighlight = createTiddlyElement(parent,"span","highlight",text.substring(Math.max(startPos,highlightMatch.index),highlightEnd));
startPos = highlightEnd;
// Nudge along to the next highlight if we're done with this one
if(startPos >= highlightRegExp.lastIndex)
highlightMatch = highlightRegExp.exec(text);
}
// Do the unhighlighted text left over
if(startPos < endPos)
{
parent.appendChild(document.createTextNode(text.substring(startPos,endPos)));
startPos = endPos;
}
return(highlightMatch);
}
function saveTiddler(title)
{
// Get the title and body text
var theNewTitle = document.getElementById("editorTitle" + title).value;
var theNewBody = document.getElementById("editorBody" + title).value;
// Remove any existing entry from the store
var theExisting = document.getElementById("store" + title);
if(theExisting)
theExisting.parentNode.removeChild(theExisting);
if(title != theNewTitle)
{
theExisting = document.getElementById("store" + theNewTitle);
if(theExisting)
theExisting.parentNode.removeChild(theExisting);
}
// Create the new entry in the store
var place = document.getElementById("storeArea");
var storeItem = createTiddlyElement(place,"div",null,theNewBody);
storeItem.setAttribute("id","store" + theNewTitle);
var now = new Date();
storeItem.setAttribute("modified",ConvertToYYYYMMDDHHMM(now));
storeItem.setAttribute("modifier","JeremyRuston");
// Display the new tiddler read-only
displayTiddler(null,theNewTitle,1,null,null,null,false);
// Close the old tiddler if this is a rename
if(title != theNewTitle)
{
var oldTiddler = document.getElementById("tiddler" + title);
oldTiddler.parentNode.removeChild(oldTiddler);
}
// Refresh the menu and sidebars to take it into account
refreshAll();
}
function searchTiddlers(text,caseSensitive)
{
// If we're searching case insensitively, put the search text in lower case
if(!caseSensitive)
text = text.toLowerCase();
// Close any open tiddlers
closeAllTiddlers();
// If the search text is actually the full name of a tiddler, make sure that one is
// displayed first, and get a reference to it to add the other matches afterwards
if(document.getElementById("store" + text))
displayTiddler(null,text,1,text,caseSensitive,false);
var theTiddler = document.getElementById("tiddler" + text);
// Traverse through the store area looking for the text in the title or body
var store = document.getElementById("storeArea").childNodes;
var c = 0;
for(var t = 0; t < store.length; t++)
{
var e = store[t];
if(e.id)
if(e.id.substr(0,5) == "store")
{
if(caseSensitive)
{
var matchTitle = e.id.substr(5).indexOf(text);
var matchBody = e.firstChild.nodeValue.indexOf(text);
}
else
{
var matchTitle = e.id.substr(5).toLowerCase().indexOf(text);
var matchBody = e.firstChild.nodeValue.toLowerCase().indexOf(text);
}
if((matchTitle != -1) || (matchBody != -1))
{
// Display matching tiddlers
displayTiddler(null,e.id.substr(5),1,text,caseSensitive,false);
c++;
}
}
}
// Jam in a message
displayMessage(c + " tiddlers found matching '" + text + "'");
}
function selectTiddler(title)
{
// Make the toolbar visible
e = document.getElementById("toolbar" + title);
if(e != null)
e.style.visibility = "visible";
}
function deselectTiddler(title)
{
// Make the toolbar invisible
e = document.getElementById("toolbar" + title);
if(e != null)
e.style.visibility = "hidden";
}
function deleteTiddler(title)
{
// Remove the tiddler from the display
closeTiddler(title,false);
// Delete it from the store
var tiddler = document.getElementById("store" + title);
if(tiddler)
tiddler.parentNode.removeChild(tiddler);
// Refresh the menu and sidebars to take it into account
refreshAll();
}
function closeTiddler(title,slowly)
{
var tiddler = document.getElementById("tiddler" + title);
if(tiddler != null)
{
tiddler.id = "";
startCloser(tiddler,slowly);
}
}
function closeAllTiddlers()
{
// Delete all the elements in the displayArea
var e = document.getElementById("tiddlerDisplay");
while(e.firstChild != null)
e.removeChild(e.firstChild);
}
// ---------------------------------------------------------------------------------
// Tiddler-related utility functions
// ---------------------------------------------------------------------------------
function getTiddlerText(title)
{
// Attempt to retrieve it from the store
var tiddlerStore = document.getElementById("store" + title);
if(tiddlerStore != null)
return(tiddlerStore.firstChild.nodeValue);
else
return(null);
}
function getTiddlerSubtitle(title)
{
var tiddlerStore = document.getElementById("store" + title);
if(tiddlerStore != null)
{
var theModifier = tiddlerStore.getAttribute("modifier");
if(!theModifier)
theModifier = "(unknown)";
var theModified = tiddlerStore.getAttribute("modified");
if(theModified)
theModified = ConvertFromYYYYMMDDHHMM(theModified).toLocaleString();
else
theModified = "(unknown)";
return(theModifier + ", " + theModified);
}
else
return(null);
}
function createTiddlyElement(theParent,theElement,theClass,theText)
{
var e = document.createElement(theElement);
if(theClass != null)
e.className = theClass;
if(theText != null)
e.appendChild(document.createTextNode(theText));
if(theParent != null)
theParent.appendChild(e);
return(e);
}
function createTiddlyButton(theParent,theText,theTooltip,theAction)
{
var theButton = document.createElement("a");
if(theAction)
{
theButton.onclick = theAction;
theButton.setAttribute("href","JavaScript:;");
}
theButton.setAttribute("title",theTooltip);
if(theText)
{
theButton.appendChild(document.createTextNode(theText));
}
theParent.appendChild(theButton);
return(theButton);
}
function createTiddlyLink(place,title,includeText)
{
var btn;
var text = includeText ? title : null;
var subTitle = getTiddlerSubtitle(title);
var theClass = subTitle ? "tiddlyLinkExisting" : "tiddlyLinkNonExisting";
if(!subTitle)
subTitle = title + " doesn't yet exist";
var btn = createTiddlyButton(place,text,subTitle,onClickTiddlerLink);
btn.className = theClass;
btn.setAttribute("tiddlyLink",title);
return(btn);
}
// Create an external link
function createExternalLink(place,url)
{
var theLink = document.createElement("a");
theLink.href = url;
theLink.title = "External link to " + url;
theLink.target = "_blank";
place.appendChild(theLink);
return(theLink);
}
// Find the tiddler instance (if any) containing a specified element
function findContainingTiddler(e)
{
if(e == null)
return(null);
do {
if(e != document)
{
if(e.id)
if(e.id.substr(0,7) == "tiddler")
return(e);
}
e = e.parentNode;
} while(e != document);
return(null);
}
// Display some text in the message area
function displayMessage(text)
{
var msgArea = document.getElementById("messageArea");
var msg = document.createTextNode(text);
msgArea.replaceChild(msg,msgArea.firstChild);
msgArea.style.display = "block";
}
// Hide the message area and clear the search box
function hideMessage()
{
var msgArea = document.getElementById("messageArea");
msgArea.style.display = "none";
}
// ---------------------------------------------------------------------------------
// Menu and sidebar functions
// ---------------------------------------------------------------------------------
var currentTab; // The id of the currently selected tab
// Refresh everything
function refreshAll()
{
refreshHeader();
refreshMenu();
refreshSidebar();
}
// Refresh all parts of the header
function refreshHeader()
{
// Get the site title and subtitle
var theTitle = getTiddlerText("SiteTitle");
if(!theTitle) theTitle = "SiteTitle";
var theSubtitle = getTiddlerText("SiteSubtitle");
if(!theSubtitle) theSubtitle = "SiteSubtitle";
// Set the page title
document.title = theTitle + " - " + theSubtitle;
// Do the title
var place = document.getElementById("siteTitle");
while(place.firstChild != null)
place.removeChild(place.firstChild);
place.appendChild(document.createTextNode(theTitle));
// Do the subtitle
var place = document.getElementById("siteSubtitle");
while(place.firstChild != null)
place.removeChild(place.firstChild);
wikify(theSubtitle,place,null,null);
}
// Refresh all parts of the main menu
function refreshMenu()
{
var place = document.getElementById("mainMenu");
while(place.firstChild != null)
place.removeChild(place.firstChild);
var menu = getTiddlerText("MainMenu");
if(!menu) menu = "MainMenu";
wikify(menu,place,null,null);
}
// Refresh all parts of the sidebar
function refreshSidebar()
{
switch(currentTab)
{
case "tabTimeline":
refreshTabTimeline();
break;
case "tabAll":
refreshTabAll();
break;
case "tabTags":
refreshTabTags();
break;
default:
refreshTabTimeline();
break;
}
}
// Timeline tab
function refreshTabTimeline()
{
// Get names and dates of all tiddlers from the store
var allTiddlers = new Array(); // Will be an array of 2-entry arrays, where entry 0 = name, 1 = date
var storeNodes = document.getElementById("storeArea").childNodes;
for (var t = 0; t < storeNodes.length; t++)
{
var n = storeNodes[t];
if(n.id)
if(n.id.substr(0,5) == "store")
allTiddlers.push(new Array(n.id.substr(5),n.getAttribute("modified")));
}
// Sort the tiddlers by date
allTiddlers.sort(function (a,b) { if(a[1] == b[1]) return(1); else return (a[1] < b[1]) ? +1 : -1; });
// Delete any existing entries in the tab
var place = document.getElementById("sidebarContent");
while(place.firstChild != null)
place.removeChild(place.firstChild);
// Output the links
var lastDay = "";
for (t = 0; t < allTiddlers.length; t++)
{
var theDay = allTiddlers[t][1].substr(0,8);
if(theDay != lastDay)
{
var theDateElement = document.createElement("span");
var theDateCaption = ConvertFromYYYYMMDDHHMM(allTiddlers[t][1]).toLocaleDateString();
theDateElement.appendChild(document.createTextNode(theDateCaption));
theDateElement.className = "sidebarSubHeading";
place.appendChild(theDateElement);
place.appendChild(document.createElement("br"));
lastDay = theDay;
}
place.appendChild(document.createTextNode(String.fromCharCode(160)));
place.appendChild(document.createTextNode(String.fromCharCode(160)));
createTiddlyLink(place,allTiddlers[t][0],true);
place.appendChild(document.createElement("br"));
}
}
// All tab
function refreshTabAll()
{
// Get names and dates of all tiddlers from the store
var allTiddlers = new Array(); // Will be an array of 2-entry arrays, where entry 0 = name, 1 = date
var storeNodes = document.getElementById("storeArea").childNodes;
for (var t = 0; t < storeNodes.length; t++)
{
var n = storeNodes[t];
if(n.id)
if(n.id.substr(0,5) == "store")
allTiddlers.push(new Array(n.id.substr(5),n.getAttribute("modified")));
}
// Sort the tiddlers by name
allTiddlers.sort(function (a,b) { if(a[0] == b[0]) return(0); else return (a[0] > b[0]) ? +1 : -1; });
// Delete any existing entries in the 'all' list
var place = document.getElementById("sidebarContent");
while(place.firstChild != null)
place.removeChild(place.firstChild);
// Output the links
for (t = 0; t < allTiddlers.length; t++)
{
createTiddlyLink(place,allTiddlers[t][0],true);
place.appendChild(document.createElement("br"));
}
}
// Tags tab
function refreshTabTags()
{
}
// ---------------------------------------------------------------------------------
// Quine (http://www.google.com/search?q=quine&ie=UTF-8&oe=UTF-8)
// ---------------------------------------------------------------------------------
// Get the text of the TiddlyWiki HTML file itself, incorporating new edits
function ShowSource()
{
// Create the popup window
var srcWindow = window.open("","sourceWindow","width=700,height=600");
var srcDocument = srcWindow.document;
// Jam in the text template
srcDocument.write("<html><head></head><body>" +
window.document.getElementById("saveMessage").innerHTML +
"</body></html>");
srcDocument.close();
// Get a reference to the text area
var theTextBox = srcDocument.getElementById("source");
// Jam in the current source
theTextBox.value = window.document.getElementById("storeArea").innerHTML;
// Select the text in the textbox
theTextBox.focus();
theTextBox.select();
;
}
// ---------------------------------------------------------------------------------
// Event handlers
// ---------------------------------------------------------------------------------
// Event handler for clicking on the logo
function onClickLogo(e)
{
restart();
}
// Event handler for clicking on a tiddly link
function onClickTiddlerLink(e)
{
if (!e) var e = window.event;
hideMessage();
// Get the text of the link
var title = this.getAttribute("tiddlyLink");
// Display that tiddler
if(title)
displayTiddler(this,title,0,null,null,e.shiftKey || e.altKey);
}
// Event handler for mouse over a tiddler
function onMouseOverTiddler(e)
{
// Get the name of this tiddler
var tiddler;
if(this.id.substr(0,7) == "tiddler")
tiddler = this.id.substr(7);
// Select that tiddler
if(tiddler)
selectTiddler(tiddler);
}
// Event handler for mouse out of a tiddler
function onMouseOutTiddler(e)
{
// Get the name of this tiddler
var tiddler;
if(this.id.substr(0,7) == "tiddler")
tiddler = this.id.substr(7);
// Deselect that tiddler
if(tiddler)
deselectTiddler(tiddler);
}
// Event handler for double click on a tiddler
function onDblClickTiddler(e)
{
hideMessage();
// Empty the current selection
if(document.selection)
document.selection.empty();
// Get the name of this tiddler
var tiddler;
if(this.id.substr(0,7) == "tiddler")
tiddler = this.id.substr(7);
// Deselect that tiddler
if(tiddler)
displayTiddler(null,tiddler,2,null,null,false);
}
// Event handler for clicking on toolbar close
function onClickToolbarClose(e)
{
if (!e) var e = window.event;
// Close that tiddler
hideMessage();
if(this.parentNode.id)
closeTiddler(this.parentNode.id.substr(7),e.shiftKey || e.altKey);
}
// Event handler for clicking on toolbar permalink
function onClickToolbarPermaLink(e)
{
if(this.parentNode.id)
window.location.hash = encodeURIComponent(this.parentNode.id.substr(7));
}
// Event handler for clicking on toolbar close
function onClickToolbarDelete(e)
{
hideMessage();
// Close that tiddler
if(this.parentNode.id)
deleteTiddler(this.parentNode.id.substr(7));
}
// Event handler for clicking on the toolbar backlink
function onClickToolbarBackLink(e)
{
hideMessage();
if(this.parentNode.id)
searchTiddlers(this.parentNode.id.substr(7),true);
}
// Event handler for clicking on toolbar close
function onClickToolbarEdit(e)
{
hideMessage();
// Edit that tiddler
if(this.parentNode.id)
displayTiddler(null,this.parentNode.id.substr(7),2,null,null,false);
}
// Event handler for clicking on toolbar save
function onClickToolbarSave(e)
{
// Save that tiddler
if(this.parentNode.id)
saveTiddler(this.parentNode.id.substr(7));
}
// Event handler for clicking on toolbar save
function onClickToolbarUndo(e)
{
// Redisplay that tiddler in read-only mode
if(this.parentNode.id)
displayTiddler(null,this.parentNode.id.substr(7),1,null,null,false);
}
// Event handler for clicking on toolbar close
function onClickTab(e)
{
if (!e) var e = window.event;
// Get the tab
var theTab;
if (e.target)
theTab = e.target;
else if (e.srcElement)
theTab = e.srcElement;
if (theTab.nodeType == 3) // defeat Safari bug
theTab = theTab.parentNode;
// Set the current tab
currentTab = theTab.id;
// Reset the classes of the tabs
var tabs = document.getElementById("sidebarTabs").childNodes;
for(var i=0;i < tabs.length;i++)
if(tabs[i].id)
{
if(tabs[i].id == currentTab)
tabs[i].className = "tabSelected";
else
tabs[i].className = "tabUnselected";
}
// Refresh the content
refreshSidebar();
}
// Event handler for typing into the search box. We need to detect when the text of the control actually changes, because we get keypresses
// for things like cursor keys that we don't want to trigger a search
var lastSearchText = "";
function onSearch(e)
{
// Do nothing if there's less than three characters or if it hasn't changed since last time
var text = document.getElementById("searchText").value;
if((text.length > 2) && (text != lastSearchText))
{
searchTiddlers(text,false);
lastSearchText = text;
}
}
function onClearSearch()
{
var text = document.getElementById("searchText");
text.value = "";
hideMessage();
}
// Eek... it's bad that this is done via a function rather than a normal, copy-able href
function onClickPermaView()
{
var tiddlerDisplay = document.getElementById("tiddlerDisplay");
var openTiddlers = "";
var separator = "";
for(var t=0;t<tiddlerDisplay.childNodes.length;t++)
{
openTiddlers = openTiddlers + separator + tiddlerDisplay.childNodes[t].id.substr(7);
separator = " ";
}
window.location.hash = encodeURIComponent(openTiddlers);
}
// ---------------------------------------------------------------------------------
// Animation engine
// ---------------------------------------------------------------------------------
// Animation housekeeping
var animating = 0; // Incremented at start of each animation, decremented afterwards. If zero, the interval timer is disabled
var animaterID; // ID of the timer used for animating
// 'zoomer' module of the animation engine smoothly moves an element from the position/size of the start element to the target element
var zoomerElement = null; // Element being shifted; null if none
var zoomerStart; // Where we're shifting from
var zoomerTarget; // Where we're shifting to
var zoomerStartScroll; // Where we're scrolling from
var zoomerTargetScroll; // Where we're scrolling to
var zoomerProgress; // 0..1 of how far we are
var zoomerStep; // 0..1 of how much to shift each step
// 'closer' module of the animation engine closes an element by smoothly reducing it's height to zero
var closerElement = null; // Element being closed; null if none