-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtwcore.js
8692 lines (7825 loc) · 281 KB
/
twcore.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
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
//
// Please note:
//
// * This code is designed to be readable but for compactness it only includes brief comments. You can see fuller comments
// in the project repository at https://github.com/TiddlyWiki/tiddlywiki
//
// * You should never need to modify this source code directly. TiddlyWiki is carefully designed to allow deep customisation
// without changing the core code. Please consult the development group at http://groups.google.com/group/TiddlyWikiDev
//
// JSLint directives
/*global jQuery:false, version:false */
/*jslint bitwise:true, browser:true, confusion:true, eqeq:true, evil:true, forin:true, maxerr:100, plusplus:true, regexp:true, sloppy:true, sub:true, undef:true, unparam:true, vars:true, white:true */
//--
//-- Global tw object (window.tw) exposing available methods and structures for developers
//--
window.tw = {
assets: {
icons: {}
},
io: {},
textUtils: {}
};
//--
//-- Configuration repository
//--
// Miscellaneous options
var config = {
numRssItems: 20, // Number of items in the RSS feed
animDuration: 400, // Duration of UI animations in milliseconds
cascadeFast: 20, // Speed for cascade animations (higher == slower)
cascadeSlow: 60, // Speed for EasterEgg cascade animations
cascadeDepth: 5, // Depth of cascade animation
locale: "en" // W3C language tag
};
// Hashmap of alternative parsers for the wikifier
config.parsers = {};
config.adaptors = {};
config.defaultAdaptor = null;
// defines the order of the backstage tasks
config.backstageTasks = ["save", "importTask", "tweak", "upgrade", "plugins"];
// map by names from config.backstageTasks, defines their content (see Lingo.js and Backstage.js)
config.tasks = {};
config.annotations = {};
// Custom fields to be automatically added to new tiddlers
config.defaultCustomFields = {};
config.messages = {
messageClose: {},
dates: {},
tiddlerPopup: {}
};
// Options that can be set in the options panel and/or cookies
config.options = {
chkAnimate: true,
chkAutoSave: false,
chkBackstage: false,
chkCaseSensitiveSearch: false,
chkConfirmDelete: true,
chkDisplayInstrumentation: false,
chkForceMinorUpdate: false,
chkGenerateAnRssFeed: false,
chkHttpReadOnly: true,
chkIncrementalSearch: true,
chkInsertTabs: false,
chkOpenInNewWindow: true,
chkPreventAsyncSaving: true,
chkRegExpSearch: false,
chkRemoveExtraMarkers: false, // #162
chkSaveBackups: true,
chkSaveEmptyTemplate: false,
chkSliderOptionsPanel: false,
chkToggleLinks: false,
chkUsePreForStorage: true, // Whether to use <pre> format for storage
txtBackupFolder: "",
txtEditorFocus: "text",
txtFileSystemCharSet: "UTF-8",
txtMainTab: "tabTimeline",
txtMaxEditRows: "30",
txtMoreTab: "moreTabAll",
txtTheme: "",
txtUpgradeCoreURI: ""
};
config.optionsDesc = {};
config.optionsSource = {};
// Default tiddler templates
var DEFAULT_VIEW_TEMPLATE = 1;
var DEFAULT_EDIT_TEMPLATE = 2;
config.tiddlerTemplates = {
1: "ViewTemplate",
2: "EditTemplate"
};
// More messages (rather a legacy layout that should not really be like this)
config.views = {
wikified: {
tag: {}
},
editor: {
tagChooser: {}
}
};
config.extensions = {};
// Macros; each has a 'handler' member that is inserted later
config.macros = {
today: {},
version: {},
search: { sizeTextbox: 15 },
tiddler: {},
tag: {},
tags: {},
tagging: {},
timeline: {},
allTags: {},
list: {
all: {},
missing: {},
orphans: {},
shadowed: {},
touched: {},
filter: {}
},
closeAll: {},
permaview: {},
saveChanges: {},
slider: {},
option: {},
options: {},
newTiddler: {},
newJournal: {},
tabs: {},
gradient: {},
message: {},
view: { defaultView: "text" },
edit: {},
tagChooser: {},
toolbar: {},
plugins: {},
refreshDisplay: {},
importTiddlers: {},
upgrade: {
source: "https://classic.tiddlywiki.com/upgrade/",
backupExtension: "pre.core.upgrade"
},
sync: {},
annotations: {}
};
// Commands supported by the toolbar macro
config.commands = {
closeTiddler: {},
closeOthers: {},
editTiddler: {},
saveTiddler: { hideReadOnly: true },
cancelTiddler: {},
deleteTiddler: { hideReadOnly: true },
permalink: {},
references: { type: "popup" },
jump: { type: "popup" },
syncing: { type: "popup" },
fields: { type: "popup" }
};
// Control of macro parameter evaluation
config.evaluateMacroParameters = "all";
// Basic regular expressions
var isBadSafari = !((new RegExp("[\u0150\u0170]", "g")).test("\u0150")); //# see 52678d4 and #22 ..remove at all?
config.textPrimitives = {
upperLetter: "[A-Z\u00c0-\u00de\u0150\u0170]",
lowerLetter: "[a-z0-9_\\-\u00df-\u00ff\u0151\u0171]",
anyLetter: "[A-Za-z0-9_\\-\u00c0-\u00de\u00df-\u00ff\u0150\u0170\u0151\u0171]",
anyLetterStrict: "[A-Za-z0-9\u00c0-\u00de\u00df-\u00ff\u0150\u0170\u0151\u0171]"
};
// Moved navigator dependent code out of Config.js into a separate module. Helps with https://github.com/TiddlyWiki/tiddlywiki/issues/22
if(isBadSafari) {
config.textPrimitives = {
upperLetter: "[A-Z\u00c0-\u00de]",
lowerLetter: "[a-z0-9_\\-\u00df-\u00ff]",
anyLetter: "[A-Za-z0-9_\\-\u00c0-\u00de\u00df-\u00ff]",
anyLetterStrict: "[A-Za-z0-9\u00c0-\u00de\u00df-\u00ff]"
};
}
config.textPrimitives.sliceSeparator = "::";
config.textPrimitives.sectionSeparator = "##";
config.textPrimitives.urlPattern =
"(?:file|http|https|mailto|ftp|irc|news|data):[^\\s'\"]+(?:/|\\b|\\[|\\])"; // #132
config.textPrimitives.unWikiLink = "~";
config.textPrimitives.wikiLink = "(?:(?:" + config.textPrimitives.upperLetter + "+" +
config.textPrimitives.lowerLetter + "+" +
config.textPrimitives.upperLetter +
config.textPrimitives.anyLetter + "*)|(?:" +
config.textPrimitives.upperLetter + "{2,}" +
config.textPrimitives.lowerLetter + "+))";
config.textPrimitives.cssLookahead = "(?:(" + config.textPrimitives.anyLetter +
"+)\\(([^\\)\\|\\n]+)(?:\\):))|(?:(" + config.textPrimitives.anyLetter + "+):([^;\\|\\n]+);)";
config.textPrimitives.cssLookaheadRegExp = new RegExp(config.textPrimitives.cssLookahead, "mg");
config.textPrimitives.brackettedLink = "\\[\\[([^\\]]+)\\]\\]";
config.textPrimitives.titledBrackettedLink = "\\[\\[([^\\[\\]\\|]+)\\|([^\\[\\]\\|]+)\\]\\]";
config.textPrimitives.tiddlerForcedLinkRegExp =
new RegExp("(?:" + config.textPrimitives.titledBrackettedLink + ")|(?:" +
config.textPrimitives.brackettedLink + ")|(?:" +
config.textPrimitives.urlPattern + ")", "mg");
config.textPrimitives.tiddlerAnyLinkRegExp =
new RegExp("(" + config.textPrimitives.wikiLink + ")|(?:" +
config.textPrimitives.titledBrackettedLink + ")|(?:" +
config.textPrimitives.brackettedLink + ")|(?:" +
config.textPrimitives.urlPattern + ")", "mg");
config.glyphs = {
currBrowser: null,
browsers: [],
codes: {}
};
//--
//-- Shadow tiddlers
//--
config.shadowTiddlers = {
StyleSheet: "",
MarkupPreHead: "",
MarkupPostHead: "",
MarkupPreBody: "",
MarkupPostBody: "",
TabTimeline: '<<timeline>>',
TabAll: '<<list all>>',
TabTags: '<<allTags excludeLists>>',
TabMoreMissing: '<<list missing>>',
TabMoreOrphans: '<<list orphans>>',
TabMoreShadowed: '<<list shadowed>>',
AdvancedOptions: '<<options>>',
PluginManager: '<<plugins>>',
SystemSettings: '',
ToolbarCommands: '|~ViewToolbar|closeTiddler closeOthers +editTiddler > fields permalink references jump|\n' +
'|~EditToolbar|+saveTiddler -cancelTiddler deleteTiddler|', // #160
WindowTitle: '<<tiddler SiteTitle>> - <<tiddler SiteSubtitle>>'
};
// Browser detection... In a very few places, there's nothing else for it but to know what browser we're using.
config.userAgent = navigator.userAgent.toLowerCase();
config.browser = {
isIE: config.userAgent.indexOf("msie") != -1 && config.userAgent.indexOf("opera") == -1,
isGecko: navigator.product == "Gecko" && config.userAgent.indexOf("WebKit") == -1,
// config.browser.ieVersion[1], if it exists, will be the IE version string, eg "6.0"
ieVersion: /MSIE (\d{1,2}.\d)/i.exec(config.userAgent),
isSafari: config.userAgent.indexOf("applewebkit") != -1,
isBadSafari: !((new RegExp("[\u0150\u0170]", "g")).test("\u0150")),
// config.browser.firefoxDate[1], if it exists, will be Firefox release date as "YYYYMMDD"
firefoxDate: /gecko\/(\d{8})/i.exec(config.userAgent),
isOpera: config.userAgent.indexOf("opera") != -1,
isChrome: config.userAgent.indexOf('chrome') > -1,
isLinux: config.userAgent.indexOf("linux") != -1,
isUnix: config.userAgent.indexOf("x11") != -1,
isMac: config.userAgent.indexOf("mac") != -1,
isWindows: config.userAgent.indexOf("win") != -1
};
merge(config.glyphs, {
browsers: [
function() { return config.browser.isIE },
function() { return true }
],
codes: {
downTriangle: ["\u25BC", "\u25BE"],
downArrow: ["\u2193", "\u2193"],
bentArrowLeft: ["\u2190", "\u21A9"],
bentArrowRight: ["\u2192", "\u21AA"]
}
});
//--
//-- Translateable strings
//--
// Strings in "double quotes" should be translated; strings in 'single quotes' should be left alone
merge(config.options, {
txtUserName: "YourName"
});
merge(config.tasks, {
save: { text: "save", tooltip: "Save your changes to this TiddlyWiki" },
importTask: { text: "import", tooltip: "Import tiddlers and plugins " +
"from other TiddlyWiki files and servers", content: '<<importTiddlers>>' },
tweak: { text: "tweak", tooltip: "Tweak the appearance and behaviour of TiddlyWiki", content: '<<options>>' },
upgrade: { text: "upgrade", tooltip: "Upgrade TiddlyWiki core", content: '<<upgrade>>' },
plugins: { text: "plugins", tooltip: "Manage installed plugins", content: '<<plugins>>' }
});
// Options that can be set in the options panel and/or cookies
merge(config.optionsDesc, {
chkAnimate: "Enable animations",
chkAutoSave: "Automatically save changes",
chkCaseSensitiveSearch: "Case-sensitive searching",
chkConfirmDelete: "Require confirmation before deleting tiddlers",
chkIncrementalSearch: "Incremental key-by-key searching",
chkInsertTabs: "Use the tab key to insert tab characters instead of moving between fields",
chkForceMinorUpdate: "Don't update modifier username and date when editing tiddlers",
chkGenerateAnRssFeed: "Generate an RSS feed when saving changes",
chkHttpReadOnly: "Hide editing features when viewed over HTTP",
chkOpenInNewWindow: "Open external links in a new window",
chkPreventAsyncSaving: "Disable attempting async saving (may be needed by old plugins)",
chkRegExpSearch: "Enable regular expressions for searches",
chkSaveBackups: "Keep backup file when saving changes",
chkSaveEmptyTemplate: "Generate an empty template when saving changes",
chkToggleLinks: "Clicking on links to open tiddlers causes them to close",
txtBackupFolder: "Name of folder to use for backups",
txtFileSystemCharSet: "Default character set for saving changes (Firefox/Mozilla only)",
txtMaxEditRows: "Maximum number of rows in edit boxes",
chkRemoveExtraMarkers: "Replace unused transclusion markers with blanks", // #162
txtTheme: "Name of the theme to use",
txtUpgradeCoreURI: "Custom URI to download TiddlyWiki core from (when upgrading)",
txtUserName: "Username for signing your edits"
});
merge(config.messages, {
customConfigError: "Problems were encountered loading plugins. See PluginManager for details",
pluginError: "Error: %0",
pluginDisabled: "Not executed because disabled via 'systemConfigDisable' tag",
pluginForced: "Executed because forced via 'systemConfigForce' tag",
pluginVersionError: "Not executed because this plugin needs a newer version of TiddlyWiki",
nothingSelected: "Nothing is selected. You must select one or more items first",
savedSnapshotError: "It appears that this TiddlyWiki has been incorrectly saved. Please see https://classic.tiddlywiki.com/#SaveUnpredictabilities for details",
subtitleUnknown: "(unknown)",
undefinedTiddlerToolTip: "The tiddler '%0' doesn't yet exist",
shadowedTiddlerToolTip: "The tiddler '%0' doesn't yet exist, but has a pre-defined shadow value",
tiddlerLinkTooltip: "%0 - %1, %2",
externalLinkTooltip: "External link to %0",
noTags: "There are no tagged tiddlers",
notFileUrlError: "You need to save this TiddlyWiki to a file before you can save changes",
cantSaveError: "It's not possible to save changes. Possible reasons include:\n- your browser doesn't support saving (Firefox, Internet Explorer, Safari and Opera all work if properly configured)\n- the pathname to your TiddlyWiki file contains illegal characters\n- the TiddlyWiki HTML file has been moved or renamed",
invalidFileError: "The original file '%0' does not appear to be a valid TiddlyWiki",
backupSaved: "Backup saved",
backupFailed: "Failed to save backup file",
rssSaved: "RSS feed saved",
rssFailed: "Failed to save RSS feed file",
emptySaved: "Empty template saved",
emptyFailed: "Failed to save empty template file",
mainSaved: "TiddlyWiki saved",
mainDownload: "Downloading/saving main TiddlyWiki file",
mainDownloadManual: "RIGHT CLICK HERE to download/save main TiddlyWiki file",
mainFailed: "Failed to save main TiddlyWiki file. Your changes have not been saved",
macroError: "Error in macro <<%0>>",
macroErrorDetails: "Error while executing macro <<%0>>:\n%1",
missingMacro: "No such macro",
overwriteWarning: "A tiddler named '%0' already exists. Choose OK to overwrite it",
unsavedChangesWarning: "WARNING! There are unsaved changes in TiddlyWiki\n\nChoose OK to save\nChoose CANCEL to discard",
confirmExit: "--------------------------------\n\nThere are unsaved changes in TiddlyWiki. If you continue you will lose those changes\n\n--------------------------------",
saveInstructions: "SaveChanges",
unsupportedTWFormat: "Unsupported TiddlyWiki format '%0'",
tiddlerSaveError: "Error when saving tiddler '%0'",
tiddlerLoadError: "Error when loading tiddler '%0'",
wrongSaveFormat: "Cannot save with storage format '%0'. Using standard format for save.",
invalidFieldName: "Invalid field name %0",
fieldCannotBeChanged: "Field '%0' cannot be changed",
loadingMissingTiddler: "Attempting to retrieve the tiddler '%0' from the '%1' server at:\n\n'%2' in the workspace '%3'",
upgradeDone: "The upgrade to version %0 is now complete\n\nClick 'OK' to reload the newly upgraded TiddlyWiki",
invalidCookie: "Invalid cookie '%0'"
});
merge(config.messages.messageClose, {
text: "close",
tooltip: "close this message area"
});
config.messages.backstage = {
open: { text: "backstage", tooltip: "Open the backstage area to perform authoring and editing tasks" },
close: { text: "close", tooltip: "Close the backstage area" },
prompt: "backstage: ",
decal: {
edit: { text: "edit", tooltip: "Edit the tiddler '%0'" }
}
};
config.messages.listView = {
tiddlerTooltip: "Click for the full text of this tiddler",
previewUnavailable: "(preview not available)"
};
config.messages.dates.months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
config.messages.dates.days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
config.messages.dates.shortMonths = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
config.messages.dates.shortDays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
// suffixes for dates, eg "1st","2nd","3rd"..."30th","31st"
config.messages.dates.daySuffixes = [
"st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th",
"th", "th", "th", "th", "th", "th", "th", "th", "th", "th",
"st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th",
"st"
];
config.messages.dates.am = "am";
config.messages.dates.pm = "pm";
merge(config.messages.tiddlerPopup, {});
merge(config.views.wikified.tag, {
labelNoTags: "no tags",
labelTags: "tags: ",
openTag: "Open tag '%0'",
tooltip: "Show tiddlers tagged with '%0'",
openAllText: "Open all",
openAllTooltip: "Open all of these tiddlers",
popupNone: "No other tiddlers tagged with '%0'"
});
merge(config.views.wikified, {
defaultText: "The tiddler '%0' doesn't yet exist. Double-click to create it",
defaultModifier: "(missing)",
shadowModifier: "(built-in shadow tiddler)",
dateFormat: "DD MMM YYYY",
createdPrompt: "created"
});
merge(config.views.editor, {
tagPrompt: "Type tags separated with spaces, [[use double square brackets]] if necessary, or add existing",
defaultText: "Type the text for '%0'"
});
merge(config.views.editor.tagChooser, {
text: "tags",
tooltip: "Choose existing tags to add to this tiddler",
popupNone: "There are no tags defined",
tagTooltip: "Add the tag '%0'"
});
merge(config.messages, {
sizeTemplates: [
{ unit: 1024 * 1024 * 1024, template: "%0\u00a0GB" },
{ unit: 1024 * 1024, template: "%0\u00a0MB" },
{ unit: 1024, template: "%0\u00a0KB" },
{ unit: 1, template: "%0\u00a0B" }
]
});
merge(config.macros.search, {
label: "search",
prompt: "Search this TiddlyWiki",
placeholder: "",
accessKey: "F",
successMsg: "%0 tiddlers found matching %1",
failureMsg: "No tiddlers found matching %0"
});
merge(config.macros.tagging, {
label: "tagging: ",
labelNotTag: "not tagging",
tooltip: "List of tiddlers tagged with '%0'"
});
merge(config.macros.timeline, {
dateFormat: "DD MMM YYYY"
});
merge(config.macros.allTags, {
tooltip: "Show tiddlers tagged with '%0'",
noTags: "There are no tagged tiddlers"
});
config.macros.list.all.prompt = "All tiddlers in alphabetical order";
config.macros.list.missing.prompt = "Tiddlers that have links to them but are not defined";
config.macros.list.orphans.prompt = "Tiddlers that are not linked to from any other tiddlers";
config.macros.list.shadowed.prompt = "Tiddlers shadowed with default contents";
config.macros.list.touched.prompt = "Tiddlers that have been modified locally";
merge(config.macros.closeAll, {
label: "close all",
prompt: "Close all displayed tiddlers (except any that are being edited)"
});
merge(config.macros.permaview, {
label: "permaview",
prompt: "Link to an URL that retrieves all the currently displayed tiddlers"
});
merge(config.macros.saveChanges, {
label: "save changes",
prompt: "Save all tiddlers to create a new TiddlyWiki",
accessKey: "S"
});
merge(config.macros.newTiddler, {
label: "new tiddler",
prompt: "Create a new tiddler",
title: "New Tiddler",
accessKey: "N"
});
merge(config.macros.newJournal, {
label: "new journal",
prompt: "Create a new tiddler from the current date and time",
accessKey: "J"
});
merge(config.macros.options, {
wizardTitle: "Tweak advanced options",
step1Title: "These options are saved in cookies in your browser",
step1Html: "<input type='hidden' name='markList'></input><br>" +
"<label><input type='checkbox' checked='false' name='chkUnknown'>Show unknown options</label>",
unknownDescription: "//(unknown)//",
listViewTemplate: {
columns: [
{ name: 'Option', field: 'option', title: "Option", type: 'String' },
{ name: 'Description', field: 'description', title: "Description", type: 'WikiText' },
{ name: 'Name', field: 'name', title: "Name", type: 'String' }
],
rowClasses: [
{ className: 'lowlight', field: 'lowlight' }
]
}
});
merge(config.macros.plugins, {
wizardTitle: "Manage plugins",
step1Title: "Currently loaded plugins",
step1Html: "<input type='hidden' name='markList'></input>", // DO NOT TRANSLATE
skippedText: "(This plugin has not been executed because it was added since startup)",
noPluginText: "There are no plugins installed",
confirmDeleteText: "Are you sure you want to delete these plugins:\n\n%0",
removeLabel: "remove systemConfig tag",
removePrompt: "Remove systemConfig tag",
deleteLabel: "delete",
deletePrompt: "Delete these tiddlers forever",
listViewTemplate: {
columns: [
{ name: 'Selected', field: 'Selected', rowName: 'title', type: 'Selector' },
{ name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler' },
{ name: 'Description', field: 'Description', title: "Description", type: 'String' },
{ name: 'Version', field: 'Version', title: "Version", type: 'String' },
{ name: 'Size', field: 'size', tiddlerLink: 'size', title: "Size", type: 'Size' },
{ name: 'Forced', field: 'forced', title: "Forced", tag: 'systemConfigForce', type: 'TagCheckbox' },
{ name: 'Disabled', field: 'disabled', title: "Disabled", tag: 'systemConfigDisable', type: 'TagCheckbox' },
{ name: 'Executed', field: 'executed', title: "Loaded", type: 'Boolean', trueText: "Yes", falseText: "No" },
{ name: 'Startup Time', field: 'startupTime', title: "Startup Time", type: 'String' },
{ name: 'Error', field: 'error', title: "Status", type: 'Boolean', trueText: "Error", falseText: "OK" },
{ name: 'Log', field: 'log', title: "Log", type: 'StringList' }
],
rowClasses: [
{ className: 'error', field: 'error' },
{ className: 'warning', field: 'warning' }
]
},
listViewTemplateReadOnly: {
columns: [
{ name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler' },
{ name: 'Description', field: 'Description', title: "Description", type: 'String' },
{ name: 'Version', field: 'Version', title: "Version", type: 'String' },
{ name: 'Size', field: 'size', tiddlerLink: 'size', title: "Size", type: 'Size' },
{ name: 'Executed', field: 'executed', title: "Loaded", type: 'Boolean', trueText: "Yes", falseText: "No" },
{ name: 'Startup Time', field: 'startupTime', title: "Startup Time", type: 'String' },
{ name: 'Error', field: 'error', title: "Status", type: 'Boolean', trueText: "Error", falseText: "OK" },
{ name: 'Log', field: 'log', title: "Log", type: 'StringList' }
],
rowClasses: [
{ className: 'error', field: 'error' },
{ className: 'warning', field: 'warning' }
]
}
});
merge(config.macros.toolbar, {
moreLabel: "more",
morePrompt: "Show additional commands",
lessLabel: "less",
lessPrompt: "Hide additional commands",
separator: "|"
});
merge(config.macros.refreshDisplay, {
label: "refresh",
prompt: "Redraw the entire TiddlyWiki display"
});
merge(config.macros.importTiddlers, {
readOnlyWarning: "You cannot import into a read-only TiddlyWiki file. Try opening it from a file:// URL",
wizardTitle: "Import tiddlers from another file or server",
step1Title: "Step 1: Locate the server or TiddlyWiki file",
step1Html: "Specify the type of the server: <select name='selTypes'><option value=''>Choose...</option></select><br>" +
"Enter the URL or pathname here: <input type='text' size=50 name='txtPath'><br>" +
"...or browse for a file: <input type='file' size=50 name='txtBrowse'><br><hr>" +
"...or select a pre-defined feed: <select name='selFeeds'><option value=''>Choose...</option></select>",
openLabel: "open",
openPrompt: "Open the connection to this file or server",
statusOpenHost: "Opening the host",
statusGetWorkspaceList: "Getting the list of available workspaces",
step2Title: "Step 2: Choose the workspace",
step2Html: "Enter a workspace name: <input type='text' size=50 name='txtWorkspace'><br>...or select a workspace: " +
"<select name='selWorkspace'><option value=''>Choose...</option></select>",
cancelLabel: "cancel",
cancelPrompt: "Cancel this import",
statusOpenWorkspace: "Opening the workspace",
statusGetTiddlerList: "Getting the list of available tiddlers",
errorGettingTiddlerList: "Error getting list of tiddlers, click Cancel to try again",
errorGettingTiddlerListHttp404: "Error retrieving tiddlers from url, please ensure the url exists. Click Cancel to try again.",
errorGettingTiddlerListHttp: "Error retrieving tiddlers from url, please " +
"ensure this url exists and is <a href='http://enable-cors.org/'>CORS</a> enabled",
errorGettingTiddlerListFile: "Error retrieving tiddlers from local file, " +
"please make sure the file is in the same directory as your TiddlyWiki. Click Cancel to try again.",
step3Title: "Step 3: Choose the tiddlers to import",
step3Html: "<input type='hidden' name='markList'></input><br><input type='checkbox' checked='true' name='chkSync'>" +
"Keep these tiddlers linked to this server so that you can synchronise subsequent changes</input><br>" +
"<input type='checkbox' name='chkSave'>Save the details of this server in a 'systemServer' tiddler called:</input> <input type='text' size=25 name='txtSaveTiddler'>",
importLabel: "import",
importPrompt: "Import these tiddlers",
confirmOverwriteText: "Are you sure you want to overwrite these tiddlers:\n\n%0",
step4Title: "Step 4: Importing %0 tiddler(s)",
step4Html: "<input type='hidden' name='markReport'></input>", // DO NOT TRANSLATE
doneLabel: "done",
donePrompt: "Close this wizard",
statusDoingImport: "Importing tiddlers",
statusDoneImport: "All tiddlers imported",
systemServerNamePattern: "%2 on %1",
systemServerNamePatternNoWorkspace: "%1",
confirmOverwriteSaveTiddler: "The tiddler '%0' already exists. Click 'OK' " +
"to overwrite it with the details of this server, or 'Cancel' to leave it unchanged",
serverSaveTemplate: "|''Type:''|%0|\n|''URL:''|%1|\n|''Workspace:''|%2|\n\n" +
"This tiddler was automatically created to record the details of this server",
serverSaveModifier: "(System)",
listViewTemplate: {
columns: [
{ name: 'Selected', field: 'Selected', rowName: 'title', type: 'Selector' },
{ name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler' },
{ name: 'Size', field: 'size', tiddlerLink: 'size', title: "Size", type: 'Size' },
{ name: 'Tags', field: 'tags', title: "Tags", type: 'Tags' }
],
rowClasses: []
}
});
merge(config.macros.upgrade, {
wizardTitle: "Upgrade TiddlyWiki",
step1Title: "Update or repair TiddlyWiki core to the latest release",
step1Html: "You are about to upgrade TiddlyWiki core to the latest release " +
"(from <a href='%0' class='externalLink' target='_blank'>%1</a>). " +
"Your content will be preserved across the upgrade.<br><br>" +
"Note that core upgrades have been known to interfere with older plugins. " +
"If you run into problems with upgrading, read how to handle them " +
"<a href='%2' class='externalLink' target='_blank'>here</a>.",
errorCantUpgrade: "Unable to upgrade this TiddlyWiki. You can only perform upgrades on TiddlyWiki files stored locally",
errorNotSaved: "You must save changes before you can perform an upgrade",
step2Title: "Confirm the upgrade details",
step2Html_downgrade: "You are about to downgrade to TiddlyWiki version %0 from %1.<br><br>Downgrading to an earlier version of the core code is not recommended",
step2Html_restore: "This TiddlyWiki appears to be already using the latest version of the core code (%0).<br><br>" +
"You can continue to upgrade anyway to ensure that the core code hasn't been corrupted or damaged",
step2Html_upgrade: "You are about to upgrade to TiddlyWiki version %0 from %1",
upgradeLabel: "upgrade",
upgradePrompt: "Prepare for the upgrade process",
statusPreparingBackup: "Preparing backup",
statusSavingBackup: "Saving backup file",
errorSavingBackup: "There was a problem saving the backup file",
errorVerifyingBackup: "Failed to verify the backup was saved. " +
"This is either because it wasn't saved to the moment of the check or " +
"loading file doesn't work with your saver (and it is needed for " +
"the next step of upgrading). To upgrade your TiddlyWiki, you can use " +
"other methods listed at <a href='%0' class='externalLink' target='_blank'>%0</a>",
statusLoadingCore: "Loading core code",
errorLoadingCore: "Error loading the core code",
errorCoreFormat: "Error with the new core code",
statusSavingCore: "Saving the new core code",
statusReloadingCore: "Reloading the new core code",
startLabel: "start",
startPrompt: "Start the upgrade process",
cancelLabel: "cancel",
cancelPrompt: "Cancel the upgrade process",
step3Title: "Upgrade cancelled",
step3Html: "You have cancelled the upgrade process"
});
merge(config.macros.annotations, {});
merge(config.commands.closeTiddler, {
text: "close",
tooltip: "Close this tiddler"
});
merge(config.commands.closeOthers, {
text: "close others",
tooltip: "Close all other tiddlers"
});
merge(config.commands.editTiddler, {
text: "edit",
tooltip: "Edit this tiddler",
readOnlyText: "view",
readOnlyTooltip: "View the source of this tiddler"
});
merge(config.commands.saveTiddler, {
text: "done",
tooltip: "Save changes to this tiddler"
});
merge(config.commands.cancelTiddler, {
text: "cancel",
tooltip: "Undo changes to this tiddler",
warning: "Are you sure you want to abandon your changes to '%0'?",
readOnlyText: "done",
readOnlyTooltip: "View this tiddler normally"
});
merge(config.commands.deleteTiddler, {
text: "delete",
tooltip: "Delete this tiddler",
warning: "Are you sure you want to delete '%0'?"
});
merge(config.commands.permalink, {
text: "permalink",
tooltip: "Permalink for this tiddler"
});
merge(config.commands.references, {
text: "references",
tooltip: "Show tiddlers that link to this one",
popupNone: "No references"
});
merge(config.commands.jump, {
text: "jump",
tooltip: "Jump to another open tiddler"
});
merge(config.commands.fields, {
text: "fields",
tooltip: "Show the extended fields of this tiddler",
emptyText: "There are no extended fields for this tiddler",
listViewTemplate: {
columns: [
{ name: 'Field', field: 'field', title: "Field", type: 'String' },
{ name: 'Value', field: 'value', title: "Value", type: 'String' }
],
rowClasses: [],
buttons: []
}
});
merge(config.shadowTiddlers, {
DefaultTiddlers: "[[GettingStarted]]",
MainMenu: "[[GettingStarted]]",
SiteTitle: "My TiddlyWiki",
SiteSubtitle: "a reusable non-linear personal web notebook",
SiteUrl: "",
SideBarOptions: '<<search>><<closeAll>><<permaview>><<newTiddler>><<newJournal "DD MMM YYYY" "journal">>' +
'<<saveChanges>><<slider chkSliderOptionsPanel OptionsPanel "options \u00bb" "Change TiddlyWiki advanced options">>',
SideBarTabs: '<<tabs txtMainTab "Timeline" "Timeline" TabTimeline "All" "All tiddlers" TabAll "Tags" "All tags" TabTags "More" "More lists" TabMore>>',
TabMore: '<<tabs txtMoreTab "Missing" "Missing tiddlers" TabMoreMissing "Orphans" "Orphaned tiddlers" TabMoreOrphans "Shadowed" "Shadowed tiddlers" TabMoreShadowed>>'
});
merge(config.annotations, {
AdvancedOptions: "This shadow tiddler provides access to several advanced options",
ColorPalette: "These values in this shadow tiddler determine the colour scheme of the ~TiddlyWiki user interface",
DefaultTiddlers: "The tiddlers listed in this shadow tiddler will be automatically displayed when ~TiddlyWiki starts up",
EditTemplate: "The HTML template in this shadow tiddler determines how tiddlers look while they are being edited",
GettingStarted: "This shadow tiddler provides basic usage instructions",
ImportTiddlers: "This shadow tiddler provides access to importing tiddlers",
MainMenu: "This shadow tiddler is used as the contents of the main menu in the left-hand column of the screen",
MarkupPreHead: "This tiddler is inserted at the top of the <head> section of the TiddlyWiki HTML file",
MarkupPostHead: "This tiddler is inserted at the bottom of the <head> section of the TiddlyWiki HTML file",
MarkupPreBody: "This tiddler is inserted at the top of the <body> section of the TiddlyWiki HTML file",
MarkupPostBody: "This tiddler is inserted at the end of the <body> section of the TiddlyWiki HTML file immediately after the script block",
OptionsPanel: "This shadow tiddler is used as the contents of the options panel slider in the right-hand sidebar",
PageTemplate: "The HTML template in this shadow tiddler determines the overall ~TiddlyWiki layout",
PluginManager: "This shadow tiddler provides access to the plugin manager",
SideBarOptions: "This shadow tiddler is used as the contents of the option panel in the right-hand sidebar",
SideBarTabs: "This shadow tiddler is used as the contents of the tabs panel in the right-hand sidebar",
SiteSubtitle: "This shadow tiddler is used as the second part of the page title",
SiteTitle: "This shadow tiddler is used as the first part of the page title",
SiteUrl: "This shadow tiddler should be set to the full target URL for publication",
StyleSheetColors: "This shadow tiddler contains CSS definitions related to the color of page elements. " +
"''DO NOT EDIT THIS TIDDLER'', instead make your changes in the StyleSheet shadow tiddler",
StyleSheet: "This tiddler can contain custom CSS definitions",
StyleSheetLayout: "This shadow tiddler contains CSS definitions related to the layout of page elements. " +
"''DO NOT EDIT THIS TIDDLER'', instead make your changes in the StyleSheet shadow tiddler",
StyleSheetLocale: "This shadow tiddler contains CSS definitions related to the translation locale",
StyleSheetPrint: "This shadow tiddler contains CSS definitions for printing",
SystemSettings: "Options may be stored here using the slice notation (like {{{chkAutoSave: true}}} or {{{|txtUserName|The great inventor|}}})",
TabAll: "This shadow tiddler contains the contents of the 'All' tab in the right-hand sidebar",
TabMore: "This shadow tiddler contains the contents of the 'More' tab in the right-hand sidebar",
TabMoreMissing: "This shadow tiddler contains the contents of the 'Missing' tab in the right-hand sidebar",
TabMoreOrphans: "This shadow tiddler contains the contents of the 'Orphans' tab in the right-hand sidebar",
TabMoreShadowed: "This shadow tiddler contains the contents of the 'Shadowed' tab in the right-hand sidebar",
TabTags: "This shadow tiddler contains the contents of the 'Tags' tab in the right-hand sidebar",
TabTimeline: "This shadow tiddler contains the contents of the 'Timeline' tab in the right-hand sidebar",
ToolbarCommands: "This shadow tiddler determines which commands are shown in tiddler toolbars",
ViewTemplate: "The HTML template in this shadow tiddler determines how tiddlers look"
});
//--
//-- Main
//--
var params = null; // Command line parameters
var store = null; // TiddlyWiki storage
var story = null; // Main story
var formatter = null; // Default formatters for the wikifier
var anim = typeof Animator == "function" ? new Animator() : null; // Animation engine
var readOnly = false; // Whether we're in readonly mode
var highlightHack = null; // Embarrassing hack department...
var hadConfirmExit = false; // Don't warn more than once
var safeMode = false; // Disable all plugins and cookies
var showBackstage; // Whether to include the backstage area
var installedPlugins = []; // Information filled in when plugins are executed
var startingUp = false; // Whether we're in the process of starting up
var pluginInfo, tiddler; // Used to pass information to plugins in loadPlugins()
// Whether this file can be saved back to the same location [Preemption]
window.allowSave = window.allowSave || function(l) {
return true;
};
// Whether this file is being viewed locally
window.isLocal = function() {
return (document.location.protocol == "file:");
};
var useJavaSaver = false;
// Allow preemption code a chance to tweak config and useJavaSaver [Preemption]
if (window.tweakConfig) window.tweakConfig();
if(!window || !window.console) {
console = { tiddlywiki: true, log: function(message) { displayMessage(message) } };
}
// Starting up
function main() {
window.originalHTML = recreateOriginal();
var t10, t9, t8, t7, t6, t5, t4, t3, t2, t1, t0 = new Date();
startingUp = true;
var doc = jQuery(document);
jQuery.noConflict();
window.onbeforeunload = function(e) { if(window.confirmExit) return confirmExit(); };
params = getParameters();
if(params) params = params.parseParams("open", null, false);
store = new TiddlyWiki({ config: config });
invokeParamifier(params, "oninit");
story = new Story("tiddlerDisplay", "tiddler");
addEvent(document, "click", Popup.onDocumentClick);
saveTest();
for(var i = 0; i < config.notifyTiddlers.length; i++)
store.addNotification(config.notifyTiddlers[i].name, config.notifyTiddlers[i].notify);
t1 = new Date();
loadShadowTiddlers();
doc.trigger("loadShadows");
t2 = new Date();
store.loadFromDiv("storeArea", "store", true);
doc.trigger("loadTiddlers");
loadOptions();
t3 = new Date();
invokeParamifier(params, "onload");
t4 = new Date();
readOnly = window.isLocal() ? false : config.options.chkHttpReadOnly;
var pluginProblem = loadPlugins("systemConfig");
doc.trigger("loadPlugins");
t5 = new Date();
formatter = new Formatter(config.formatters);
invokeParamifier(params, "onconfig");
story.switchTheme(config.options.txtTheme);
showBackstage = showBackstage !== undefined ? showBackstage : !readOnly;
t6 = new Date();
for(var name in config.macros) {
if(config.macros[name].init)
config.macros[name].init();
}
t7 = new Date();
store.notifyAll();
t8 = new Date();
restart();
refreshDisplay();
t9 = new Date();
if(pluginProblem) {
story.displayTiddler(null, "PluginManager");
displayMessage(config.messages.customConfigError);
}
if(showBackstage)
backstage.init();
t10 = new Date();
if(config.options.chkDisplayInstrumentation) {
displayMessage("LoadShadows " + (t2 - t1) + " ms");
displayMessage("LoadFromDiv " + (t3 - t2) + " ms");
displayMessage("LoadPlugins " + (t5 - t4) + " ms");
displayMessage("Macro init " + (t7 - t6) + " ms");
displayMessage("Notify " + (t8 - t7) + " ms");
displayMessage("Restart " + (t9 - t8) + " ms");
displayMessage("Total: " + (t10 - t0) + " ms");
}
startingUp = false;
doc.trigger("startup");
}
// Called on unload. Functions may get unloaded too, so they are called conditionally.
function unload() {
if(window.checkUnsavedChanges) checkUnsavedChanges();
if(window.scrubNodes) scrubNodes(document.body);
}
// Restarting
function restart() {
invokeParamifier(params, "onstart");
if(story.isEmpty()) {
story.displayDefaultTiddlers();
}
window.scrollTo(0, 0);
}
function saveTest() {
var s = document.getElementById("saveTest");
if(s.hasChildNodes())
alert(config.messages.savedSnapshotError);
s.appendChild(document.createTextNode("savetest"));
}
function loadShadowTiddlers() {
var shadows = new TiddlyWiki();
shadows.loadFromDiv("shadowArea", "shadows", true);
shadows.forEachTiddler(function(title, tiddler) { config.shadowTiddlers[title] = tiddler.text });
}
function loadPlugins(tag) {
if(safeMode) return false;
var tiddlers = store.getTaggedTiddlers(tag);
tiddlers.sort(function(a, b) { return a.title < b.title ? -1 : (a.title == b.title ? 0 : 1) });
var toLoad = [];
var nLoaded = 0;
var map = {};
var nPlugins = tiddlers.length;
installedPlugins = [];
for(var i = 0; i < nPlugins; i++) {
var p = getPluginInfo(tiddlers[i]);
installedPlugins[i] = p;
var n = p.Name || p.title;
if(n) map[n] = p;
n = p.Source;
if(n) map[n] = p;
}
var visit = function(p) {
if(!p || p.done) return;
p.done = 1;
var reqs = p.Requires;
if(reqs) {
reqs = reqs.readBracketedList();
for(var i = 0; i < reqs.length; i++)
visit(map[reqs[i]]);
}
toLoad.push(p);
};
for(i = 0; i < nPlugins; i++)
visit(installedPlugins[i]);
for(i = 0; i < toLoad.length; i++) {
p = toLoad[i];
pluginInfo = p;
tiddler = p.tiddler;
if(isPluginExecutable(p)) {
if(isPluginEnabled(p)) {
p.executed = true;
var startTime = new Date();
try {
if(tiddler.text) window.eval(tiddler.text);
nLoaded++;
} catch(ex) {
p.log.push(config.messages.pluginError.format([exceptionText(ex)]));
p.error = true;
if(!console.tiddlywiki) {
console.log("error evaluating " + tiddler.title, ex);
}
}
pluginInfo.startupTime = String((new Date()) - startTime) + "ms";
} else {
nPlugins--;
}
} else {
p.warning = true;
}
}
return nLoaded != nPlugins;
}
function getPluginInfo(tiddler) {
var p = store.getTiddlerSlices(tiddler.title, ["Name", "Description", "Version",
"Requires", "CoreVersion", "Date", "Source", "Author", "License", "Browsers"]);
p.tiddler = tiddler;
p.title = tiddler.title;
p.log = [];