mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-01-24 20:04:40 +00:00
Compare commits
511 Commits
v5.1.17
...
wikitext-v
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b799d924f0 | ||
|
|
1c436cbbf3 | ||
|
|
94607aa9cd | ||
|
|
62477c9fbb | ||
|
|
b1edcdb757 | ||
|
|
d38b42f7c7 | ||
|
|
fffd0ee9e1 | ||
|
|
9f0d726f7d | ||
|
|
7709192cc8 | ||
|
|
02ae8969b2 | ||
|
|
a01dc6cb3d | ||
|
|
f99fb4f9f5 | ||
|
|
e52a616891 | ||
|
|
a89991cc46 | ||
|
|
f4fe254038 | ||
|
|
9f630b5829 | ||
|
|
c904aeb05f | ||
|
|
efd7aa3a53 | ||
|
|
a4b24670f6 | ||
|
|
2e0b2c8045 | ||
|
|
d068cb3625 | ||
|
|
0d8c749f37 | ||
|
|
0303b7871b | ||
|
|
44d1a00bb0 | ||
|
|
784db30614 | ||
|
|
26c6d6035e | ||
|
|
b82cf3d070 | ||
|
|
f07ffb2b41 | ||
|
|
c9b16d88f3 | ||
|
|
256321cd42 | ||
|
|
71aed78e2e | ||
|
|
0ab29e2c09 | ||
|
|
648c7ccd1f | ||
|
|
2dc70682cd | ||
|
|
441011885c | ||
|
|
449fd02cda | ||
|
|
a7dc8b5583 | ||
|
|
7478ba9165 | ||
|
|
12630d4a91 | ||
|
|
07635d7b3e | ||
|
|
e61c71961b | ||
|
|
f047e7cbf5 | ||
|
|
2c2d03f7a7 | ||
|
|
c036c22826 | ||
|
|
6de13e2f60 | ||
|
|
0c2689dd78 | ||
|
|
a9e595c3f6 | ||
|
|
348a0bc8bc | ||
|
|
477c41f843 | ||
|
|
0b1ce30a04 | ||
|
|
e8b50df4a6 | ||
|
|
2104017249 | ||
|
|
148c1a0355 | ||
|
|
dd4305d520 | ||
|
|
638eb53429 | ||
|
|
b6e2985ac6 | ||
|
|
87eab62b7e | ||
|
|
fb0713ae78 | ||
|
|
16bb474fef | ||
|
|
77e6f5c0e3 | ||
|
|
41e338dc41 | ||
|
|
a6875df7ef | ||
|
|
655fc31cee | ||
|
|
18c00c2ef0 | ||
|
|
b862348b06 | ||
|
|
36e76429b1 | ||
|
|
181897514f | ||
|
|
810033bd71 | ||
|
|
6aab4d5524 | ||
|
|
72f2a94251 | ||
|
|
6dedcd958d | ||
|
|
f97d18bb6e | ||
|
|
9d7d3fefa0 | ||
|
|
6ff7a7d261 | ||
|
|
2710fae71d | ||
|
|
0e6855eba8 | ||
|
|
8b04cfd4d5 | ||
|
|
2c37c25c28 | ||
|
|
adb07ccba0 | ||
|
|
b64216cfa7 | ||
|
|
9601e570af | ||
|
|
5c5628e10b | ||
|
|
cdeabbaf56 | ||
|
|
5577f7a4fe | ||
|
|
51b4f63c5c | ||
|
|
7df58a6813 | ||
|
|
158f96a207 | ||
|
|
dc29acd656 | ||
|
|
af40485e37 | ||
|
|
9b2d52716a | ||
|
|
64b665e706 | ||
|
|
f709641967 | ||
|
|
94f143bf64 | ||
|
|
22fe4451c8 | ||
|
|
1c982fba2d | ||
|
|
0ea00b59b0 | ||
|
|
5e9fc661a9 | ||
|
|
e5f3301c1c | ||
|
|
b08a7e3f04 | ||
|
|
44c66b98a9 | ||
|
|
ce256102a7 | ||
|
|
6f5f9ca2fb | ||
|
|
e31c5563ff | ||
|
|
70f5dff81e | ||
|
|
689e172e79 | ||
|
|
5ffcd7e5da | ||
|
|
5a37a84a54 | ||
|
|
4228c3f9cc | ||
|
|
a4eb139f99 | ||
|
|
7bc1458749 | ||
|
|
92b8368115 | ||
|
|
c4bb2110e3 | ||
|
|
f7d938e4bc | ||
|
|
8defe41458 | ||
|
|
6753a1485a | ||
|
|
7f97e3080c | ||
|
|
b6d901f888 | ||
|
|
90b7961629 | ||
|
|
c5aa855ce6 | ||
|
|
036ea400c5 | ||
|
|
049244e8a8 | ||
|
|
95aca11719 | ||
|
|
02fbae4200 | ||
|
|
fc3227831f | ||
|
|
72ec4d05e4 | ||
|
|
07aeaaa1a4 | ||
|
|
790d606885 | ||
|
|
c6f1fb7627 | ||
|
|
44816ea0da | ||
|
|
ca7b62a5f6 | ||
|
|
353821f442 | ||
|
|
4c1e3aa8d6 | ||
|
|
952826e0fa | ||
|
|
e6aaafbc8d | ||
|
|
79eb6a5ec1 | ||
|
|
7c0528340d | ||
|
|
273768da1d | ||
|
|
52a30be7c6 | ||
|
|
479726c46e | ||
|
|
3afb251b3a | ||
|
|
1f829dd5a8 | ||
|
|
95dbdff08a | ||
|
|
bfd09133de | ||
|
|
dc74fc4306 | ||
|
|
557053ab35 | ||
|
|
317d75171c | ||
|
|
0e568fe69a | ||
|
|
e2fe40a282 | ||
|
|
193fb32423 | ||
|
|
e14e69bedc | ||
|
|
af9f90e8cd | ||
|
|
b899563971 | ||
|
|
d0afbe50a1 | ||
|
|
0aac98f361 | ||
|
|
fa638b8b5b | ||
|
|
4d5a79acb8 | ||
|
|
fcfdb0632b | ||
|
|
d14d7f0168 | ||
|
|
83bea2a270 | ||
|
|
2b8efdc3ea | ||
|
|
27d0b2b491 | ||
|
|
824930682a | ||
|
|
d8104e2c41 | ||
|
|
06f1f1a532 | ||
|
|
6121c0b5a7 | ||
|
|
2c5b1c4a8c | ||
|
|
3d687a7935 | ||
|
|
5d20a54713 | ||
|
|
14623d33d2 | ||
|
|
37b335a136 | ||
|
|
d5a25c9a96 | ||
|
|
6c48c24332 | ||
|
|
86e27d64f2 | ||
|
|
decbe33f1f | ||
|
|
8205893af9 | ||
|
|
75158c0366 | ||
|
|
a2d4239db0 | ||
|
|
1d9c932e16 | ||
|
|
58f7e7bd85 | ||
|
|
8f54231d62 | ||
|
|
97f7f8f111 | ||
|
|
4e0b03b19f | ||
|
|
097b0e2d4a | ||
|
|
87f077314b | ||
|
|
7a07c84eac | ||
|
|
512d5662cc | ||
|
|
32974eebdb | ||
|
|
eca5df9f01 | ||
|
|
c42eba3308 | ||
|
|
77d286213f | ||
|
|
da864e23d6 | ||
|
|
d58bc33df4 | ||
|
|
c97c3cea74 | ||
|
|
e9f2a24f30 | ||
|
|
0b7f72ce5c | ||
|
|
52d328ee1b | ||
|
|
ddf22ec2a4 | ||
|
|
6b4294923f | ||
|
|
2dd76007d3 | ||
|
|
31470f676c | ||
|
|
d6bffad8ab | ||
|
|
6195069c5e | ||
|
|
8e3f9d6aba | ||
|
|
1793dc5e34 | ||
|
|
21f4d05ca0 | ||
|
|
653604ae86 | ||
|
|
1aea7b075d | ||
|
|
1dce674e51 | ||
|
|
5b6a468757 | ||
|
|
4f71c9072f | ||
|
|
04ba91ce2f | ||
|
|
9acff8f21c | ||
|
|
ed714ab731 | ||
|
|
f3e17c365a | ||
|
|
98a395095b | ||
|
|
5f1e8acbc0 | ||
|
|
3827feee3f | ||
|
|
172751605e | ||
|
|
d8b291bc04 | ||
|
|
d5618ca60a | ||
|
|
500fd8c062 | ||
|
|
d5ac2ee49e | ||
|
|
a4937224b7 | ||
|
|
42cf077639 | ||
|
|
f71a3b72d7 | ||
|
|
eea036f803 | ||
|
|
2cfdf59b77 | ||
|
|
a8b8fb3b6f | ||
|
|
aa1c6a9872 | ||
|
|
a7cdb94957 | ||
|
|
f6b1e27281 | ||
|
|
de808ac66d | ||
|
|
18ed2faf82 | ||
|
|
38b088eabf | ||
|
|
c4b39af052 | ||
|
|
1c73783ea4 | ||
|
|
c065dfa4bb | ||
|
|
a36d8471a8 | ||
|
|
e3c0616326 | ||
|
|
d00d46a772 | ||
|
|
40eeba20ef | ||
|
|
f163a1f12c | ||
|
|
018f7628f5 | ||
|
|
bc124c0645 | ||
|
|
d4716a6f2b | ||
|
|
ad799dbb61 | ||
|
|
31e88dd2c6 | ||
|
|
e509291b18 | ||
|
|
70500140b9 | ||
|
|
87b3e470c2 | ||
|
|
e466f62e7e | ||
|
|
e17456e3bc | ||
|
|
c058378da0 | ||
|
|
b9df224f99 | ||
|
|
0f3912ba95 | ||
|
|
11f02dc362 | ||
|
|
d711ef25ed | ||
|
|
419ea9a243 | ||
|
|
288d25e733 | ||
|
|
0ecc7c6071 | ||
|
|
80f44e880c | ||
|
|
4a9e2696d6 | ||
|
|
6e59d2597a | ||
|
|
7502ef875e | ||
|
|
8c367cdb21 | ||
|
|
63031bb3fc | ||
|
|
2bf6203cf5 | ||
|
|
6e674fe9db | ||
|
|
a82800050d | ||
|
|
9cd58caafc | ||
|
|
ea91ab1632 | ||
|
|
17232cfe91 | ||
|
|
603c564872 | ||
|
|
b18c85b85c | ||
|
|
62cbbf1db4 | ||
|
|
0396af849a | ||
|
|
907d498baf | ||
|
|
ea76a868bf | ||
|
|
addc7c0176 | ||
|
|
9268a8c3ca | ||
|
|
fe52d5462f | ||
|
|
5b14a97e0f | ||
|
|
545c508138 | ||
|
|
42f7c03824 | ||
|
|
9232279a79 | ||
|
|
ee8821a5b4 | ||
|
|
e0126b2f77 | ||
|
|
19c49ae18a | ||
|
|
ad4107a94b | ||
|
|
8542ebaecb | ||
|
|
cd0ce0cde5 | ||
|
|
01407fa8f9 | ||
|
|
09ea59240a | ||
|
|
2e7faf3439 | ||
|
|
1700eb4ba7 | ||
|
|
536ab10790 | ||
|
|
f6334723f6 | ||
|
|
a83cd3f984 | ||
|
|
078df9c157 | ||
|
|
dc972237a2 | ||
|
|
32c8ef1d62 | ||
|
|
3f91d5b3a1 | ||
|
|
f32cb52ba6 | ||
|
|
0622d03beb | ||
|
|
9d0083d8dc | ||
|
|
8134f8de28 | ||
|
|
2541b9b090 | ||
|
|
d55a498fca | ||
|
|
ce7becd64f | ||
|
|
09330968cc | ||
|
|
02f26d94a1 | ||
|
|
7729649f0e | ||
|
|
430be4ec30 | ||
|
|
b009a60b69 | ||
|
|
8832409666 | ||
|
|
6d67dc8eb8 | ||
|
|
f4ca295086 | ||
|
|
b629b1412d | ||
|
|
eea034c32d | ||
|
|
f373d8f2bf | ||
|
|
4f78d3d81b | ||
|
|
72679d2041 | ||
|
|
33ba69e852 | ||
|
|
3aae643e14 | ||
|
|
e983936c30 | ||
|
|
849844be12 | ||
|
|
2b6514ddc2 | ||
|
|
ddc76622f2 | ||
|
|
882cad1a0d | ||
|
|
33dd367a65 | ||
|
|
db3f41db29 | ||
|
|
d317bdf3da | ||
|
|
9752531b61 | ||
|
|
43c8a0f485 | ||
|
|
4f7297645d | ||
|
|
c5d4990cc5 | ||
|
|
1f296951d4 | ||
|
|
88664f0286 | ||
|
|
0ff96f9caf | ||
|
|
c82edbe6bc | ||
|
|
55b5b6dd56 | ||
|
|
8ae62c90df | ||
|
|
277bc92f92 | ||
|
|
196992167f | ||
|
|
cb74536b3c | ||
|
|
22caef9e34 | ||
|
|
d64fc5d8cd | ||
|
|
9f8a74c6d9 | ||
|
|
6c9dfd7f62 | ||
|
|
4f8e32a647 | ||
|
|
4d1127ed5b | ||
|
|
16eb5e1e32 | ||
|
|
abda6dd078 | ||
|
|
729c1e1030 | ||
|
|
88c47d9df4 | ||
|
|
899fe7608b | ||
|
|
7cd1c48643 | ||
|
|
d7914e3f3e | ||
|
|
698224556e | ||
|
|
aeaf5ee5b6 | ||
|
|
97b098b059 | ||
|
|
457f03798c | ||
|
|
3592333cb8 | ||
|
|
b584295831 | ||
|
|
dff5315afe | ||
|
|
6dcdc2049a | ||
|
|
d6a0b06f02 | ||
|
|
a75434a347 | ||
|
|
78f5465a47 | ||
|
|
baddd89abb | ||
|
|
c0c1b557eb | ||
|
|
b95f6b523b | ||
|
|
6b03ba9876 | ||
|
|
d50e2df57b | ||
|
|
9c849eb10a | ||
|
|
d8007386cf | ||
|
|
5dcdff4b37 | ||
|
|
240bd7bec4 | ||
|
|
eeb453d471 | ||
|
|
f0c6a09ea7 | ||
|
|
c208c55a22 | ||
|
|
83a245ed21 | ||
|
|
107b0c17c0 | ||
|
|
f162f4bc7b | ||
|
|
a9dd8c2f52 | ||
|
|
d5da7fd57c | ||
|
|
7022a98d5a | ||
|
|
fe85845c3c | ||
|
|
f61a61c060 | ||
|
|
86f2de0dda | ||
|
|
cfb2d7c9c8 | ||
|
|
806df86434 | ||
|
|
7282bf4721 | ||
|
|
287a83c1cc | ||
|
|
b776f9fe90 | ||
|
|
7368cc74e1 | ||
|
|
f98b4d5956 | ||
|
|
e4e7a0912d | ||
|
|
d650784dd6 | ||
|
|
b76c5011cf | ||
|
|
e5550b91e6 | ||
|
|
587fe9d10e | ||
|
|
874318091e | ||
|
|
f9eed0dc87 | ||
|
|
f2a38960fc | ||
|
|
3d10a35fb7 | ||
|
|
8321d2e6fc | ||
|
|
4f39e69e9d | ||
|
|
d7b8c1c298 | ||
|
|
19f7287a53 | ||
|
|
65af4e7748 | ||
|
|
25727df649 | ||
|
|
4ec8881c2b | ||
|
|
4b630de4bd | ||
|
|
e237d8fa97 | ||
|
|
0f7ce7b67f | ||
|
|
3bfa9c6f10 | ||
|
|
63ad284784 | ||
|
|
7dbe117bc5 | ||
|
|
72e2238dc9 | ||
|
|
7a6213dcbf | ||
|
|
03602215c4 | ||
|
|
0151d8e564 | ||
|
|
b7558f98f4 | ||
|
|
09112ed455 | ||
|
|
5756f30edd | ||
|
|
59b6cc134f | ||
|
|
ee28f66b0a | ||
|
|
9a2e2cd385 | ||
|
|
d96c844264 | ||
|
|
11529ab399 | ||
|
|
fbaceaa8bd | ||
|
|
0c965175aa | ||
|
|
e92eb6a945 | ||
|
|
dce564c238 | ||
|
|
68b063ab24 | ||
|
|
fe527b7eaf | ||
|
|
e72c72f04c | ||
|
|
f218c946f1 | ||
|
|
b1f9ff3f6c | ||
|
|
7d0b255a2a | ||
|
|
5a2e87eb09 | ||
|
|
b55a3102be | ||
|
|
8a38685de9 | ||
|
|
f210b75a30 | ||
|
|
763f8afaf2 | ||
|
|
3140ff9e49 | ||
|
|
b89e8d1635 | ||
|
|
c48aff2c87 | ||
|
|
7b9dc7557c | ||
|
|
c87c18be96 | ||
|
|
bb9e2de861 | ||
|
|
0a5633dd4a | ||
|
|
fcc5a6e796 | ||
|
|
ec18a55033 | ||
|
|
097c87fa7b | ||
|
|
2d231a2e07 | ||
|
|
0285eb600e | ||
|
|
4b9bc1b766 | ||
|
|
a3a4c28143 | ||
|
|
6cfd973fbd | ||
|
|
794be7ffd7 | ||
|
|
49e9789d9c | ||
|
|
8520c9d8fd | ||
|
|
be58de8409 | ||
|
|
34e04b7ca6 | ||
|
|
aa8b2e11bb | ||
|
|
8b787cd806 | ||
|
|
1317e13974 | ||
|
|
e554561f95 | ||
|
|
57d6215fda | ||
|
|
fcccc85994 | ||
|
|
e0be9a3d09 | ||
|
|
d7001c6f6b | ||
|
|
c05c0d3df6 | ||
|
|
9735e13dea | ||
|
|
c72e4f01f1 | ||
|
|
19b54fe905 | ||
|
|
2f425c303f | ||
|
|
bef3242075 | ||
|
|
f54a0a11bc | ||
|
|
929b0c9833 | ||
|
|
acaa07a964 | ||
|
|
23797b05a1 | ||
|
|
1ce9973bed | ||
|
|
c29f5a1b61 | ||
|
|
2a3f1b4403 | ||
|
|
7557b8b5b7 | ||
|
|
35cbb127a3 | ||
|
|
aba9c94f5a | ||
|
|
bacf500d50 | ||
|
|
2e51f08bef | ||
|
|
29606c6d24 | ||
|
|
17e73befde | ||
|
|
89f99151b3 | ||
|
|
d2682b71ff | ||
|
|
121e868ca4 | ||
|
|
4b42173962 | ||
|
|
01bdaff005 | ||
|
|
edcf1b1d41 | ||
|
|
05af050cbf | ||
|
|
6b14969cf6 | ||
|
|
f0b7c9a3d5 | ||
|
|
33453039fc | ||
|
|
33e636cbe7 | ||
|
|
760c80c655 | ||
|
|
1436196758 | ||
|
|
c252d7c945 | ||
|
|
4fd980debe | ||
|
|
38b24906c1 | ||
|
|
9e8a0653b0 |
34
.travis.yml
Normal file
34
.travis.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
language: node_js
|
||||
- "node"
|
||||
|
||||
stages:
|
||||
- name: test
|
||||
- name: build-prerelease
|
||||
if: branch = "master"
|
||||
- name: build-tiddlywiki-com
|
||||
if: branch = "tiddlywiki-com"
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: test
|
||||
script: ./bin/test.sh
|
||||
- stage: build-prerelease
|
||||
script:
|
||||
- ./bin/travis-pre-build.sh
|
||||
- export TW5_BUILD_TIDDLYWIKI='./tiddlywiki.js'
|
||||
- export TW5_BUILD_VERSION=$(./bin/get-plugin-library-version-number)
|
||||
- export TW5_BUILD_DETAILS="Prerelease built from branch '$TRAVIS_BRANCH' at commit $(git rev-parse HEAD) of $(git remote get-url origin) at $(date +'%F %T %Z')"
|
||||
- export TW5_BUILD_MAIN_EDITION='./editions/prerelease'
|
||||
- export TW5_BUILD_OUTPUT='./output/prerelease'
|
||||
- ./bin/build-site.sh
|
||||
- ./bin/travis-push.sh
|
||||
- stage: build-tiddlywiki-com
|
||||
script:
|
||||
- ./bin/travis-pre-build.sh
|
||||
- export TW5_BUILD_TIDDLYWIKI='./node_modules/tiddlywiki/tiddlywiki.js'
|
||||
- export TW5_BUILD_VERSION=$(./bin/get-plugin-library-version-number)
|
||||
- export TW5_BUILD_DETAILS="Built from branch '$TRAVIS_BRANCH' at commit $(git rev-parse HEAD) of $(git remote get-url origin) at $(date +'%F %T %Z')"
|
||||
- export TW5_BUILD_MAIN_EDITION='./editions/tw5.com'
|
||||
- export TW5_BUILD_OUTPUT='./output'
|
||||
- ./bin/build-site.sh
|
||||
- ./bin/travis-push.sh
|
||||
15
bin/2bld.cmd
15
bin/2bld.cmd
@@ -1,15 +0,0 @@
|
||||
@echo off
|
||||
|
||||
rem build TiddlyWiki 2.x
|
||||
|
||||
rem cook the TiddlyWiki 2.x.x index file
|
||||
|
||||
node .\tiddlywiki.js ^
|
||||
editions\tw2 ^
|
||||
--verbose ^
|
||||
--output tmp\tw2 ^
|
||||
--load editions\tw2\source\tiddlywiki.com\index.html.recipe ^
|
||||
--rendertiddler $:/core/templates/tiddlywiki2.template.html index.html text/plain ^
|
||||
|| exit 1
|
||||
|
||||
fc tmp\tw2\index.html editions\tw2\target\prebuilt.html
|
||||
15
bin/2bld.sh
15
bin/2bld.sh
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# build TiddlyWiki 2.x
|
||||
|
||||
# cook the TiddlyWiki 2.x.x index file
|
||||
|
||||
node ./tiddlywiki.js \
|
||||
editions/tw2 \
|
||||
--verbose \
|
||||
--output tmp/tw2 \
|
||||
--load editions/tw2/source/tiddlywiki.com/index.html.recipe \
|
||||
--rendertiddler $:/core/templates/tiddlywiki2.template.html index.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
diff -q tmp/tw2/index.html editions/tw2/target/prebuilt.html
|
||||
443
bin/build-site.sh
Executable file
443
bin/build-site.sh
Executable file
@@ -0,0 +1,443 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Build all tiddlywiki.com assets.
|
||||
|
||||
# Default to the current version number for building the plugin library
|
||||
|
||||
if [ -z "$TW5_BUILD_VERSION" ]; then
|
||||
TW5_BUILD_VERSION=v5.1.19
|
||||
fi
|
||||
|
||||
echo "Using TW5_BUILD_VERSION as [$TW5_BUILD_VERSION]"
|
||||
|
||||
# Default to using tw5.com as the main edition for /index.html
|
||||
|
||||
if [ -z "$TW5_BUILD_MAIN_EDITION" ]; then
|
||||
TW5_BUILD_MAIN_EDITION=./editions/tw5.com
|
||||
fi
|
||||
|
||||
echo "Using TW5_BUILD_MAIN_EDITION as [$TW5_BUILD_MAIN_EDITION]"
|
||||
|
||||
# Default to the version of TiddlyWiki installed in this repo
|
||||
|
||||
if [ -z "$TW5_BUILD_TIDDLYWIKI" ]; then
|
||||
TW5_BUILD_TIDDLYWIKI=./tiddlywiki.js
|
||||
fi
|
||||
|
||||
echo "Using TW5_BUILD_TIDDLYWIKI as [$TW5_BUILD_TIDDLYWIKI]"
|
||||
|
||||
# Set up the build details
|
||||
|
||||
if [ -z "$TW5_BUILD_DETAILS" ]; then
|
||||
TW5_BUILD_DETAILS="$(git symbolic-ref --short HEAD)-$(git rev-parse HEAD) from $(git remote get-url origin)"
|
||||
fi
|
||||
|
||||
echo "Using TW5_BUILD_DETAILS as [$TW5_BUILD_DETAILS]"
|
||||
|
||||
# Set up the build output directory
|
||||
|
||||
if [ -z "$TW5_BUILD_OUTPUT" ]; then
|
||||
TW5_BUILD_OUTPUT=./output
|
||||
fi
|
||||
|
||||
mkdir -p $TW5_BUILD_OUTPUT
|
||||
|
||||
if [ ! -d "$TW5_BUILD_OUTPUT" ]; then
|
||||
echo 'A valid TW5_BUILD_OUTPUT environment variable must be set'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Using TW5_BUILD_OUTPUT as [$TW5_BUILD_OUTPUT]"
|
||||
|
||||
echo "Build details: $TW5_BUILD_DETAILS"
|
||||
|
||||
# Make the CNAME file that GitHub Pages requires
|
||||
|
||||
echo "tiddlywiki.com" > $TW5_BUILD_OUTPUT/CNAME
|
||||
|
||||
# Delete any existing static content
|
||||
|
||||
mkdir -p $TW5_BUILD_OUTPUT/static
|
||||
mkdir -p $TW5_BUILD_OUTPUT/dev
|
||||
mkdir -p $TW5_BUILD_OUTPUT/dev/static
|
||||
rm $TW5_BUILD_OUTPUT/static/*
|
||||
rm $TW5_BUILD_OUTPUT/dev/static/*
|
||||
|
||||
# Redirects
|
||||
|
||||
echo "<a href='./plugins/tiddlywiki/tw2parser/index.html'>Moved to http://tiddlywiki.com/plugins/tiddlywiki/tw2parser/index.html</a>" > $TW5_BUILD_OUTPUT/classicparserdemo.html
|
||||
echo "<a href='./plugins/tiddlywiki/codemirror/index.html'>Moved to http://tiddlywiki.com/plugins/tiddlywiki/codemirror/index.html</a>" > $TW5_BUILD_OUTPUT/codemirrordemo.html
|
||||
echo "<a href='./plugins/tiddlywiki/d3/index.html'>Moved to http://tiddlywiki.com/plugins/tiddlywiki/d3/index.html</a>" > $TW5_BUILD_OUTPUT/d3demo.html
|
||||
echo "<a href='./plugins/tiddlywiki/highlight/index.html'>Moved to http://tiddlywiki.com/plugins/tiddlywiki/highlight/index.html</a>" > $TW5_BUILD_OUTPUT/highlightdemo.html
|
||||
echo "<a href='./plugins/tiddlywiki/markdown/index.html'>Moved to http://tiddlywiki.com/plugins/tiddlywiki/markdown/index.html</a>" > $TW5_BUILD_OUTPUT/markdowndemo.html
|
||||
echo "<a href='./plugins/tiddlywiki/tahoelafs/index.html'>Moved to http://tiddlywiki.com/plugins/tiddlywiki/tahoelafs/index.html</a>" > $TW5_BUILD_OUTPUT/tahoelafs.html
|
||||
|
||||
# Put the build details into a .tid file so that it can be included in each build (deleted at the end of this script)
|
||||
|
||||
echo -e -n "title: $:/build\n\n$TW5_BUILD_DETAILS\n" > $TW5_BUILD_OUTPUT/build.tid
|
||||
|
||||
######################################################
|
||||
#
|
||||
# Core distribution
|
||||
#
|
||||
######################################################
|
||||
|
||||
# /index.html Main site
|
||||
# /favicon.ico Favicon for main site
|
||||
# /static.html Static rendering of default tiddlers
|
||||
# /alltiddlers.html Static rendering of all tiddlers
|
||||
# /static/* Static single tiddlers
|
||||
# /static/static.css Static stylesheet
|
||||
# /static/favicon.ico Favicon for static pages
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
$TW5_BUILD_MAIN_EDITION \
|
||||
--verbose \
|
||||
--version \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--build favicon static index \
|
||||
|| exit 1
|
||||
|
||||
# /empty.html Empty
|
||||
# /empty.hta For Internet Explorer
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/empty \
|
||||
--verbose \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--build empty \
|
||||
|| exit 1
|
||||
|
||||
|
||||
# /test.html Test edition
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/test \
|
||||
--verbose \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--rendertiddler $:/core/save/all test.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
# /dev/index.html Developer docs
|
||||
# /dev/favicon.ico Favicon for dev site
|
||||
# /dev/static.html Static rendering of default tiddlers
|
||||
# /dev/alltiddlers.html Static rendering of all tiddlers
|
||||
# /dev/static/* Static single tiddlers
|
||||
# /dev/static/static.css Static stylesheet
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/dev \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/dev \
|
||||
--build index favicon static \
|
||||
|| exit 1
|
||||
|
||||
# /upgrade.html Custom edition for performing upgrades
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/upgrade \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--build upgrade \
|
||||
|| exit 1
|
||||
|
||||
# /encrypted.html Copy of the main file encrypted with the password "password"
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
$TW5_BUILD_MAIN_EDITION \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--build encrypted \
|
||||
|| exit 1
|
||||
|
||||
|
||||
######################################################
|
||||
#
|
||||
# Editions
|
||||
#
|
||||
######################################################
|
||||
|
||||
# /editions/xlsx-utils/index.html xlsx-utils edition
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/xlsx-utils \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/editions/xlsx-utils/ \
|
||||
--build index \
|
||||
|| exit 1
|
||||
|
||||
# /editions/resumebuilder/index.html Resume builder edition
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/resumebuilder \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/editions/resumebuilder/ \
|
||||
--build index \
|
||||
|| exit 1
|
||||
|
||||
# /editions/text-slicer/index.html Text slicer edition
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/text-slicer \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/editions/text-slicer/ \
|
||||
--build index \
|
||||
|| exit 1
|
||||
|
||||
# /editions/translators/index.html Translators edition
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/translators \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/editions/translators/ \
|
||||
--build index \
|
||||
|| exit 1
|
||||
|
||||
# /editions/introduction/index.html Introduction edition
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/introduction \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/editions/introduction/ \
|
||||
--build index \
|
||||
|| exit 1
|
||||
|
||||
# /editions/full/index.html Full edition
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/full \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/editions/full/ \
|
||||
--build index \
|
||||
|| exit 1
|
||||
|
||||
# /editions/tw5.com-docs/index.html tiddlywiki.com docs edition
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/tw5.com-docs \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/editions/tw5.com-docs/ \
|
||||
--build index \
|
||||
|| exit 1
|
||||
|
||||
######################################################
|
||||
#
|
||||
# Plugin demos
|
||||
#
|
||||
######################################################
|
||||
|
||||
# /plugins/tiddlywiki/innerwiki/index.html Demo wiki with Innerwiki plugin
|
||||
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/innerwikidemo \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--rendertiddler $:/core/save/all plugins/tiddlywiki/innerwiki/index.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
# /plugins/tiddlywiki/dynaview/index.html Demo wiki with DynaView plugin
|
||||
# /plugins/tiddlywiki/dynaview/empty.html Empty wiki with DynaView plugin
|
||||
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/dynaviewdemo \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--rendertiddler $:/core/save/all plugins/tiddlywiki/dynaview/index.html text/plain \
|
||||
--rendertiddler $:/core/save/empty plugins/tiddlywiki/dynaview/empty.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
# /plugins/tiddlywiki/katex/index.html Demo wiki with KaTeX plugin
|
||||
# /plugins/tiddlywiki/katex/empty.html Empty wiki with KaTeX plugin
|
||||
|
||||
# TODO: Build the static file with the release of 5.1.3
|
||||
# --rendertiddler $:/core/templates/static.template.html plugins/tiddlywiki/katex/static.html text/plain \
|
||||
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/katexdemo \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--rendertiddler $:/core/save/all plugins/tiddlywiki/katex/index.html text/plain \
|
||||
--rendertiddler $:/core/save/empty plugins/tiddlywiki/katex/empty.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
# /plugins/tiddlywiki/tahoelafs/index.html Demo wiki with Tahoe-LAFS plugin
|
||||
# /plugins/tiddlywiki/tahoelafs/empty.html Empty wiki with Tahoe-LAFS plugin
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/tahoelafs \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--rendertiddler $:/core/save/all plugins/tiddlywiki/tahoelafs/index.html text/plain \
|
||||
--rendertiddler $:/core/save/empty plugins/tiddlywiki/tahoelafs/empty.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
# /plugins/tiddlywiki/d3/index.html Demo wiki with D3 plugin
|
||||
# /plugins/tiddlywiki/d3/empty.html Empty wiki with D3 plugin
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/d3demo \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--rendertiddler $:/core/save/all plugins/tiddlywiki/d3/index.html text/plain \
|
||||
--rendertiddler $:/core/save/empty plugins/tiddlywiki/d3/empty.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
# /plugins/tiddlywiki/codemirror/index.html Demo wiki with codemirror plugin
|
||||
# /plugins/tiddlywiki/codemirror/empty.html Empty wiki with codemirror plugin
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/codemirrordemo \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--rendertiddler $:/core/save/all plugins/tiddlywiki/codemirror/index.html text/plain \
|
||||
--rendertiddler $:/core/save/empty plugins/tiddlywiki/codemirror/empty.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
# /plugins/tiddlywiki/markdown/index.html Demo wiki with Markdown plugin
|
||||
# /plugins/tiddlywiki/markdown/empty.html Empty wiki with Markdown plugin
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/markdowndemo \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--rendertiddler $:/core/save/all plugins/tiddlywiki/markdown/index.html text/plain \
|
||||
--rendertiddler $:/core/save/empty plugins/tiddlywiki/markdown/empty.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
# /plugins/tiddlywiki/tw2parser/index.html Demo wiki with tw2parser plugin
|
||||
# /plugins/tiddlywiki/tw2parser/empty.html Empty wiki with tw2parser plugin
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/classicparserdemo \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--rendertiddler $:/core/save/all plugins/tiddlywiki/tw2parser/index.html text/plain \
|
||||
--rendertiddler $:/core/save/empty plugins/tiddlywiki/tw2parser/empty.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
# /plugins/tiddlywiki/highlight/index.html Demo wiki with highlight plugin
|
||||
# /plugins/tiddlywiki/highlight/empty.html Empty wiki with highlight plugin
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/highlightdemo \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT \
|
||||
--rendertiddler $:/core/save/all plugins/tiddlywiki/highlight/index.html text/plain \
|
||||
--rendertiddler $:/core/save/empty plugins/tiddlywiki/highlight/empty.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
######################################################
|
||||
#
|
||||
# Language editions
|
||||
#
|
||||
######################################################
|
||||
|
||||
# Delete any existing static content
|
||||
|
||||
rm $TW5_BUILD_OUTPUT/languages/de-AT/static/*
|
||||
rm $TW5_BUILD_OUTPUT/languages/de-DE/static/*
|
||||
rm $TW5_BUILD_OUTPUT/languages/es-ES/static/*
|
||||
rm $TW5_BUILD_OUTPUT/languages/fr-FR/static/*
|
||||
rm $TW5_BUILD_OUTPUT/languages/ja-JP/static/*
|
||||
rm $TW5_BUILD_OUTPUT/languages/ko-KR/static/*
|
||||
rm $TW5_BUILD_OUTPUT/languages/zh-Hans/static/*
|
||||
rm $TW5_BUILD_OUTPUT/languages/zh-Hant/static/*
|
||||
|
||||
# /languages/de-AT/index.html Demo wiki with de-AT language
|
||||
# /languages/de-AT/empty.html Empty wiki with de-AT language
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/de-AT \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/languages/de-AT \
|
||||
--build favicon empty static index \
|
||||
|| exit 1
|
||||
|
||||
# /languages/de-DE/index.html Demo wiki with de-DE language
|
||||
# /languages/de-DE/empty.html Empty wiki with de-DE language
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/de-DE \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/languages/de-DE \
|
||||
--build favicon empty static index \
|
||||
|| exit 1
|
||||
|
||||
# /languages/es-ES/index.html Demo wiki with es-ES language
|
||||
# /languages/es-ES/empty.html Empty wiki with es-ES language
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/es-ES \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/languages/es-ES \
|
||||
--build favicon empty static index \
|
||||
|| exit 1
|
||||
|
||||
# /languages/fr-FR/index.html Demo wiki with fr-FR language
|
||||
# /languages/fr-FR/empty.html Empty wiki with fr-FR language
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/fr-FR \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/languages/fr-FR \
|
||||
--build favicon empty static index \
|
||||
|| exit 1
|
||||
|
||||
# /languages/ja-JP/index.html Demo wiki with ja-JP language
|
||||
# /languages/ja-JP/empty.html Empty wiki with ja-JP language
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/ja-JP \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/languages/ja-JP \
|
||||
--build empty index \
|
||||
|| exit 1
|
||||
|
||||
# /languages/ko-KR/index.html Demo wiki with ko-KR language
|
||||
# /languages/ko-KR/empty.html Empty wiki with ko-KR language
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/ko-KR \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/languages/ko-KR \
|
||||
--build favicon empty static index \
|
||||
|| exit 1
|
||||
|
||||
# /languages/zh-Hans/index.html Demo wiki with zh-Hans language
|
||||
# /languages/zh-Hans/empty.html Empty wiki with zh-Hans language
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/zh-Hans \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/languages/zh-Hans \
|
||||
--build empty index \
|
||||
|| exit 1
|
||||
|
||||
# /languages/zh-Hant/index.html Demo wiki with zh-Hant language
|
||||
# /languages/zh-Hant/empty.html Empty wiki with zh-Hant language
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/zh-Hant \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/languages/zh-Hant \
|
||||
--build empty index \
|
||||
|| exit 1
|
||||
|
||||
######################################################
|
||||
#
|
||||
# Plugin library
|
||||
#
|
||||
######################################################
|
||||
|
||||
node $TW5_BUILD_TIDDLYWIKI \
|
||||
./editions/pluginlibrary \
|
||||
--verbose \
|
||||
--load $TW5_BUILD_OUTPUT/build.tid \
|
||||
--output $TW5_BUILD_OUTPUT/library/$TW5_BUILD_VERSION \
|
||||
--build \
|
||||
|| exit 1
|
||||
|
||||
# Delete the temporary build tiddler
|
||||
|
||||
rm $TW5_BUILD_OUTPUT/build.tid || exit 1
|
||||
19
bin/get-plugin-library-version-number
Executable file
19
bin/get-plugin-library-version-number
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Extract raw version number from package.json (without the optional "-prerelease" suffix)
|
||||
|
||||
if(!process.env["TW5_BUILD_TIDDLYWIKI"]) {
|
||||
throw "TW5_BUILD_TIDDLYWIKI environment variable not set";
|
||||
}
|
||||
|
||||
var fs = require("fs"),
|
||||
path = require("path");
|
||||
|
||||
var filename = path.resolve(path.dirname(process.env["TW5_BUILD_TIDDLYWIKI"]),"./package.json"),
|
||||
json = JSON.parse(fs.readFileSync(filename,"utf8"));
|
||||
|
||||
if(!json.version) {
|
||||
throw "Missing version number in package.json";
|
||||
}
|
||||
|
||||
process.stdout.write("v" + json.version.split("-")[0]);
|
||||
@@ -7,6 +7,7 @@
|
||||
node ./tiddlywiki.js \
|
||||
./editions/test \
|
||||
--verbose \
|
||||
--version \
|
||||
--rendertiddler $:/core/save/all test.html text/plain \
|
||||
|| exit 1
|
||||
|
||||
|
||||
10
bin/travis-pre-build.sh
Executable file
10
bin/travis-pre-build.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Install latest current release from npm
|
||||
# (we need to force because otherwise npm will refuse to install a module of the same name)
|
||||
|
||||
npm --force install tiddlywiki || exit 1
|
||||
|
||||
# Pull existing GitHub pages content
|
||||
|
||||
git clone --depth=1 --branch=master "https://github.com/Jermolene/jermolene.github.io.git" output
|
||||
20
bin/travis-push.sh
Executable file
20
bin/travis-push.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Push output back to GitHub
|
||||
|
||||
|
||||
cd output || exit 1
|
||||
|
||||
git config --global user.email "travis@travis-ci.org" || exit 1
|
||||
|
||||
git config --global user.name "Travis CI" || exit 1
|
||||
|
||||
git add -A . || exit 1
|
||||
|
||||
git commit --message "Travis build: $TRAVIS_BUILD_NUMBER of $TRAVIS_BRANCH ($(date +'%F %T %Z'))" || exit 1
|
||||
|
||||
git remote add deploy "https://$GH_TOKEN@github.com/Jermolene/jermolene.github.io.git" &>/dev/null || exit 1
|
||||
|
||||
git push deploy master &>/dev/null || exit 1
|
||||
|
||||
cd .. || exit 1
|
||||
130
boot/boot.js
130
boot/boot.js
@@ -51,6 +51,63 @@ $tw.utils.isArray = function(value) {
|
||||
return Object.prototype.toString.call(value) == "[object Array]";
|
||||
};
|
||||
|
||||
/*
|
||||
Check if an array is equal by value and by reference.
|
||||
*/
|
||||
$tw.utils.isArrayEqual = function(array1,array2) {
|
||||
if(array1 === array2) {
|
||||
return true;
|
||||
}
|
||||
array1 = array1 || [];
|
||||
array2 = array2 || [];
|
||||
if(array1.length !== array2.length) {
|
||||
return false;
|
||||
}
|
||||
return array1.every(function(value,index) {
|
||||
return value === array2[index];
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Push entries onto an array, removing them first if they already exist in the array
|
||||
array: array to modify (assumed to be free of duplicates)
|
||||
value: a single value to push or an array of values to push
|
||||
*/
|
||||
$tw.utils.pushTop = function(array,value) {
|
||||
var t,p;
|
||||
if($tw.utils.isArray(value)) {
|
||||
// Remove any array entries that are duplicated in the new values
|
||||
if(value.length !== 0) {
|
||||
if(array.length !== 0) {
|
||||
if(value.length < array.length) {
|
||||
for(t=0; t<value.length; t++) {
|
||||
p = array.indexOf(value[t]);
|
||||
if(p !== -1) {
|
||||
array.splice(p,1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(t=array.length-1; t>=0; t--) {
|
||||
p = value.indexOf(array[t]);
|
||||
if(p !== -1) {
|
||||
array.splice(t,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Push the values on top of the main array
|
||||
array.push.apply(array,value);
|
||||
}
|
||||
} else {
|
||||
p = array.indexOf(value);
|
||||
if(p !== -1) {
|
||||
array.splice(p,1);
|
||||
}
|
||||
array.push(value);
|
||||
}
|
||||
return array;
|
||||
};
|
||||
|
||||
/*
|
||||
Determine if a value is a date
|
||||
*/
|
||||
@@ -89,7 +146,9 @@ Helper for making DOM elements
|
||||
tag: tag name
|
||||
options: see below
|
||||
Options include:
|
||||
namespace: defaults to http://www.w3.org/1999/xhtml
|
||||
attributes: hashmap of attribute values
|
||||
style: hashmap of styles
|
||||
text: text to add as a child node
|
||||
children: array of further child nodes
|
||||
innerHTML: optional HTML for element
|
||||
@@ -99,7 +158,7 @@ eventListeners: array of event listeners (this option won't work until $tw.utils
|
||||
*/
|
||||
$tw.utils.domMaker = function(tag,options) {
|
||||
var doc = options.document || document;
|
||||
var element = doc.createElement(tag);
|
||||
var element = doc.createElementNS(options.namespace || "http://www.w3.org/1999/xhtml",tag);
|
||||
if(options["class"]) {
|
||||
element.className = options["class"];
|
||||
}
|
||||
@@ -115,6 +174,9 @@ $tw.utils.domMaker = function(tag,options) {
|
||||
$tw.utils.each(options.attributes,function(attribute,name) {
|
||||
element.setAttribute(name,attribute);
|
||||
});
|
||||
$tw.utils.each(options.style,function(value,name) {
|
||||
element.style[name] = value;
|
||||
});
|
||||
if(options.eventListeners) {
|
||||
$tw.utils.addEventListeners(element,options.eventListeners);
|
||||
}
|
||||
@@ -268,7 +330,7 @@ $tw.utils.stringifyList = function(value) {
|
||||
};
|
||||
|
||||
// Parse a string array from a bracketted list. For example "OneTiddler [[Another Tiddler]] LastOne"
|
||||
$tw.utils.parseStringArray = function(value) {
|
||||
$tw.utils.parseStringArray = function(value, allowDuplicate) {
|
||||
if(typeof value === "string") {
|
||||
var memberRegExp = /(?:^|[^\S\xA0])(?:\[\[(.*?)\]\])(?=[^\S\xA0]|$)|([\S\xA0]+)/mg,
|
||||
results = [], names = {},
|
||||
@@ -277,7 +339,7 @@ $tw.utils.parseStringArray = function(value) {
|
||||
match = memberRegExp.exec(value);
|
||||
if(match) {
|
||||
var item = match[1] || match[2];
|
||||
if(item !== undefined && !$tw.utils.hop(names,item)) {
|
||||
if(item !== undefined && (!$tw.utils.hop(names,item) || allowDuplicate)) {
|
||||
results.push(item);
|
||||
names[item] = true;
|
||||
}
|
||||
@@ -862,6 +924,61 @@ $tw.Tiddler.prototype.hasField = function(field) {
|
||||
return $tw.utils.hop(this.fields,field);
|
||||
};
|
||||
|
||||
/*
|
||||
Compare two tiddlers for equality
|
||||
tiddler: the tiddler to compare
|
||||
excludeFields: array of field names to exclude from the comparison
|
||||
*/
|
||||
$tw.Tiddler.prototype.isEqual = function(tiddler,excludeFields) {
|
||||
if(!(tiddler instanceof $tw.Tiddler)) {
|
||||
return false;
|
||||
}
|
||||
excludeFields = excludeFields || [];
|
||||
var self = this,
|
||||
differences = []; // Fields that have differences
|
||||
// Add to the differences array
|
||||
function addDifference(fieldName) {
|
||||
// Check for this field being excluded
|
||||
if(excludeFields.indexOf(fieldName) === -1) {
|
||||
// Save the field as a difference
|
||||
$tw.utils.pushTop(differences,fieldName);
|
||||
}
|
||||
}
|
||||
// Returns true if the two values of this field are equal
|
||||
function isFieldValueEqual(fieldName) {
|
||||
var valueA = self.fields[fieldName],
|
||||
valueB = tiddler.fields[fieldName];
|
||||
// Check for identical string values
|
||||
if(typeof(valueA) === "string" && typeof(valueB) === "string" && valueA === valueB) {
|
||||
return true;
|
||||
}
|
||||
// Check for identical array values
|
||||
if($tw.utils.isArray(valueA) && $tw.utils.isArray(valueB) && $tw.utils.isArrayEqual(valueA,valueB)) {
|
||||
return true;
|
||||
}
|
||||
// Check for identical date values
|
||||
if($tw.utils.isDate(valueA) && $tw.utils.isDate(valueB) && valueA.getTime() === valueB.getTime()) {
|
||||
return true;
|
||||
}
|
||||
// Otherwise the fields must be different
|
||||
return false;
|
||||
}
|
||||
// Compare our fields
|
||||
for(var fieldName in this.fields) {
|
||||
if(!isFieldValueEqual(fieldName)) {
|
||||
addDifference(fieldName);
|
||||
}
|
||||
}
|
||||
// There's a difference for every field in the other tiddler that we don't have
|
||||
for(fieldName in tiddler.fields) {
|
||||
if(!(fieldName in this.fields)) {
|
||||
addDifference(fieldName);
|
||||
}
|
||||
}
|
||||
// Return whether there were any differences
|
||||
return differences.length === 0;
|
||||
};
|
||||
|
||||
/*
|
||||
Register and install the built in tiddler field modules
|
||||
*/
|
||||
@@ -1985,6 +2102,9 @@ $tw.boot.startup = function(options) {
|
||||
$tw.utils.registerFileType("image/jpeg","base64",[".jpg",".jpeg"],{flags:["image"]});
|
||||
$tw.utils.registerFileType("image/png","base64",".png",{flags:["image"]});
|
||||
$tw.utils.registerFileType("image/gif","base64",".gif",{flags:["image"]});
|
||||
$tw.utils.registerFileType("image/webp","base64",".webp",{flags:["image"]});
|
||||
$tw.utils.registerFileType("image/heic","base64",".heic",{flags:["image"]});
|
||||
$tw.utils.registerFileType("image/heif","base64",".heif",{flags:["image"]});
|
||||
$tw.utils.registerFileType("image/svg+xml","utf8",".svg",{flags:["image"]});
|
||||
$tw.utils.registerFileType("image/x-icon","base64",".ico",{flags:["image"]});
|
||||
$tw.utils.registerFileType("application/font-woff","base64",".woff");
|
||||
@@ -1999,8 +2119,10 @@ $tw.boot.startup = function(options) {
|
||||
$tw.utils.registerFileType("application/vnd.openxmlformats-officedocument.wordprocessingml.document","base64",".docx");
|
||||
$tw.utils.registerFileType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","base64",".xlsx");
|
||||
$tw.utils.registerFileType("application/vnd.openxmlformats-officedocument.presentationml.presentation","base64",".pptx");
|
||||
$tw.utils.registerFileType("text/x-bibtex","utf8",".bib",{deserializerType:"application/x-bibtex"});
|
||||
$tw.utils.registerFileType("application/x-bibtex","utf8",".bib");
|
||||
$tw.utils.registerFileType("application/epub+zip","base64",".epub");
|
||||
$tw.utils.registerFileType("application/octet-stream","base64",".octet-stream");
|
||||
// Create the wiki store for the app
|
||||
$tw.wiki = new $tw.Wiki();
|
||||
// Install built in tiddler fields modules
|
||||
@@ -2032,6 +2154,8 @@ $tw.boot.startup = function(options) {
|
||||
if($tw.preloadTiddlers) {
|
||||
$tw.wiki.addTiddlers($tw.preloadTiddlers);
|
||||
}
|
||||
// Give hooks a chance to modify the store
|
||||
$tw.hooks.invokeHook("th-boot-tiddlers-loaded");
|
||||
// Unpack plugin tiddlers
|
||||
$tw.wiki.readPluginInfo();
|
||||
$tw.wiki.registerPluginTiddlers("plugin",$tw.safeMode ? ["$:/core"] : undefined);
|
||||
|
||||
4
core/images/add-comment.tid
Normal file
4
core/images/add-comment.tid
Normal file
@@ -0,0 +1,4 @@
|
||||
title: $:/core/images/add-comment
|
||||
tags: $:/tags/Image
|
||||
|
||||
<svg class="tc-image-add-comment tc-image-button" width="22pt" height="22pt" viewBox="0 0 128 128"><path d="M56 56H36a8 8 0 1 0 0 16h20v20a8 8 0 1 0 16 0V72h20a8 8 0 1 0 0-16H72V36a8 8 0 1 0-16 0v20zm-12.595 58.362c-6.683 7.659-20.297 12.903-36.006 12.903-2.196 0-4.35-.102-6.451-.3 9.652-3.836 17.356-12.24 21.01-22.874C8.516 94.28 0 79.734 0 63.5 0 33.953 28.206 10 63 10s63 23.953 63 53.5S97.794 117 63 117c-6.841 0-13.428-.926-19.595-2.638z" fill-rule="evenodd"/></svg>
|
||||
9
core/images/gitter.tid
Normal file
9
core/images/gitter.tid
Normal file
@@ -0,0 +1,9 @@
|
||||
title: $:/core/images/gitter
|
||||
tags: $:/tags/Image
|
||||
|
||||
<svg class="tc-image-gitter tc-image-button" width="22pt" height="22pt" viewBox="0 0 18 25">
|
||||
<rect x="15" y="5" width="2" height="10"></rect>
|
||||
<rect x="10" y="5" width="2" height="20"></rect>
|
||||
<rect x="5" y="5" width="2" height="20"></rect>
|
||||
<rect width="2" height="15"></rect>
|
||||
</svg>
|
||||
@@ -126,6 +126,10 @@ Settings/NavigationHistory/Caption: Navigation History
|
||||
Settings/NavigationHistory/Hint: Update browser history when navigating to a tiddler:
|
||||
Settings/NavigationHistory/No/Description: Do not update history
|
||||
Settings/NavigationHistory/Yes/Description: Update history
|
||||
Settings/NavigationPermalinkviewMode/Caption: Permalink/permaview Mode
|
||||
Settings/NavigationPermalinkviewMode/Hint: Choose how permalink/permaview is handled:
|
||||
Settings/NavigationPermalinkviewMode/CopyToClipboard/Description: Copy permalink/permaview URL to clipboard
|
||||
Settings/NavigationPermalinkviewMode/UpdateAddressBar/Description: Update address bar with permalink/permaview URL
|
||||
Settings/PerformanceInstrumentation/Caption: Performance Instrumentation
|
||||
Settings/PerformanceInstrumentation/Hint: Displays performance statistics in the browser developer console. Requires reload to take effect
|
||||
Settings/PerformanceInstrumentation/Description: Enable performance instrumentation
|
||||
|
||||
@@ -2,6 +2,7 @@ title: $:/language/Docs/ModuleTypes/
|
||||
|
||||
allfilteroperator: A sub-operator for the ''all'' filter operator.
|
||||
animation: Animations that may be used with the RevealWidget.
|
||||
authenticator: Defines how requests are authenticated by the built-in HTTP server.
|
||||
bitmapeditoroperation: A bitmap editor toolbar operation.
|
||||
command: Commands that can be executed under Node.js.
|
||||
config: Data to be inserted into `$tw.config`.
|
||||
@@ -12,6 +13,7 @@ isfilteroperator: Operands for the ''is'' filter operator.
|
||||
library: Generic module type for general purpose JavaScript modules.
|
||||
macro: JavaScript macro definitions.
|
||||
parser: Parsers for different content types.
|
||||
route: Defines how individual URL patterns are handled by the built-in HTTP server.
|
||||
saver: Savers handle different methods for saving files from the browser.
|
||||
startup: Startup functions.
|
||||
storyview: Story views customise the animation and behaviour of list widgets.
|
||||
|
||||
@@ -45,6 +45,8 @@ page-background: Page background
|
||||
pre-background: Preformatted code background
|
||||
pre-border: Preformatted code border
|
||||
primary: General primary
|
||||
select-tag-background: `<select>` element background
|
||||
select-tag-foreground: `<select>` element text
|
||||
sidebar-button-foreground: Sidebar button foreground
|
||||
sidebar-controls-foreground-hover: Sidebar controls foreground hover
|
||||
sidebar-controls-foreground: Sidebar controls foreground
|
||||
|
||||
@@ -22,6 +22,7 @@ Tags/Dropdown/Hint: Show tag list
|
||||
Title/BadCharacterWarning: Warning: avoid using any of the characters <<bad-chars>> in tiddler titles
|
||||
Title/Exists/Prompt: Target tiddler already exists
|
||||
Title/Relink/Prompt: Update ''<$text text=<<fromTitle>>/>'' to ''<$text text=<<toTitle>>/>'' in the //tags// and //list// fields of other tiddlers
|
||||
Title/References/Prompt: The following references to this tiddler will not be automatically updated:
|
||||
Type/Dropdown/Caption: content type list
|
||||
Type/Dropdown/Hint: Show content type list
|
||||
Type/Delete/Caption: delete content type
|
||||
|
||||
@@ -14,8 +14,9 @@ draft.of: For draft tiddlers, contains the title of the tiddler of which this is
|
||||
draft.title: For draft tiddlers, contains the proposed new title of the tiddler
|
||||
footer: The footer text for a wizard
|
||||
hack-to-give-us-something-to-compare-against: A temporary storage field used in [[$:/core/templates/static.content]]
|
||||
hide-body: The view template will hide bodies of tiddlers if set to: ''yes''
|
||||
icon: The title of the tiddler containing the icon associated with a tiddler
|
||||
library: If set to "yes" indicates that a tiddler should be saved as a JavaScript library
|
||||
library: Indicates that a tiddler should be saved as a JavaScript library if set to: ''yes''
|
||||
list: An ordered list of tiddler titles associated with a tiddler
|
||||
list-before: If set, the title of a tiddler before which this tiddler should be added to the ordered list of tiddler titles, or at the start of the list if this field is present but empty
|
||||
list-after: If set, the title of the tiddler after which this tiddler should be added to the ordered list of tiddler titles, or at the end of the list if this field is present but empty
|
||||
@@ -31,5 +32,6 @@ subtitle: The subtitle text for a wizard
|
||||
tags: A list of tags associated with a tiddler
|
||||
text: The body text of a tiddler
|
||||
title: The unique name of a tiddler
|
||||
toc-link: Suppresses the tiddler's link in a Table of Contents tree if set to: ''no''
|
||||
type: The content type of a tiddler
|
||||
version: Version information for a plugin
|
||||
|
||||
@@ -10,6 +10,7 @@ Orphans: Orphan tiddlers
|
||||
SystemTiddlers: System tiddlers
|
||||
ShadowTiddlers: Shadow tiddlers
|
||||
OverriddenShadowTiddlers: Overridden shadow tiddlers
|
||||
SessionTiddlers: Tiddlers modified since the wiki was loaded
|
||||
SystemTags: System tags
|
||||
StoryList: Tiddlers in the story river, excluding <$text text="$:/AdvancedSearch"/>
|
||||
TypedTiddlers: Non wiki-text tiddlers
|
||||
34
core/language/en-GB/Help/listen.tid
Normal file
34
core/language/en-GB/Help/listen.tid
Normal file
@@ -0,0 +1,34 @@
|
||||
title: $:/language/Help/listen
|
||||
description: Provides an HTTP server interface to TiddlyWiki
|
||||
|
||||
Serves a wiki over HTTP.
|
||||
|
||||
The listen command uses NamedCommandParameters:
|
||||
|
||||
```
|
||||
--listen [<name>=<value>]...
|
||||
```
|
||||
|
||||
All parameters are optional with safe defaults, and can be specified in any order. The recognised parameters are:
|
||||
|
||||
* ''host'' - optional hostname to serve from (defaults to "127.0.0.1" aka "localhost")
|
||||
* ''path-prefix'' - optional prefix for paths
|
||||
* ''port'' - port number on which to listen; non-numeric values are interpreted as a system environment variable from which the port number is extracted (defaults to "8080")
|
||||
* ''credentials'' - pathname of credentials CSV file (relative to wiki folder)
|
||||
* ''anon-username'' - the username for signing edits for anonymous users
|
||||
* ''username'' - optional username for basic authentication
|
||||
* ''password'' - optional password for basic authentication
|
||||
* ''authenticated-user-header'' - optional name of header to be used for trusted authentication
|
||||
* ''readers'' - comma separated list of principals allowed to read from this wiki
|
||||
* ''writers'' - comma separated list of principals allowed to write to this wiki
|
||||
* ''csrf-disable'' - set to "yes" to disable CSRF checks (defaults to "no")
|
||||
* ''root-tiddler'' - the tiddler to serve at the root (defaults to "$:/core/save/all")
|
||||
* ''root-render-type'' - the content type to which the root tiddler should be rendered (defaults to "text/plain")
|
||||
* ''root-serve-type'' - the content type with which the root tiddler should be served (defaults to "text/html")
|
||||
* ''tls-cert'' - pathname of TLS certificate file (relative to wiki folder)
|
||||
* ''tls-key'' - pathname of TLS key file (relative to wiki folder)
|
||||
* ''debug-level'' - optional debug level; set to "debug" to view request details (defaults to "none")
|
||||
* ''gzip'' - set to "yes" to enable gzip compression for some http endpoints (defaults to "no")
|
||||
|
||||
For information on opening up your instance to the entire local network, and possible security concerns, see the WebServer tiddler at TiddlyWiki.com.
|
||||
|
||||
@@ -4,10 +4,12 @@ description: Load tiddlers from a file
|
||||
Load tiddlers from TiddlyWiki (`.html`), `.tiddler`, `.tid`, `.json` or other local files. The processing applied to incoming files is determined by the file extension. Use the alternative `import` command if you need to specify the deserializer and encoding explicitly.
|
||||
|
||||
```
|
||||
--load <filepath>
|
||||
--load <dirpath>
|
||||
--load <filepath> [noerror]
|
||||
--load <dirpath> [noerror]
|
||||
```
|
||||
|
||||
By default, the load command raises an error if no tiddlers are found. The error can be suppressed by providing the optional "noerror" parameter.
|
||||
|
||||
To load tiddlers from an encrypted TiddlyWiki file you should first specify the password with the PasswordCommand. For example:
|
||||
|
||||
```
|
||||
|
||||
@@ -13,8 +13,8 @@ A name and value for an additional variable may optionally also be specified.
|
||||
|
||||
* ''tiddler-filter'': A filter identifying the tiddler(s) to be rendered
|
||||
* ''filename-filter'': Optional filter transforming tiddler titles into pathnames. If omitted, defaults to `[is[tiddler]addsuffix[.html]]`, which uses the unchanged tiddler title as the filename
|
||||
* ''template'': Optional template through which each tiddler is rendered
|
||||
* ''render-type'': Optional render type: `text/html` (the default) returns the full HTML text and `text/plain` just returns the text content (ie it ignores HTML tags and other unprintable material)
|
||||
* ''template'': Optional template through which each tiddler is rendered
|
||||
* ''name'': Name of optional variable
|
||||
* ''value'': Value of optional variable
|
||||
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
title: $:/language/Help/server
|
||||
description: Provides an HTTP server interface to TiddlyWiki
|
||||
description: Provides an HTTP server interface to TiddlyWiki (deprecated in favour of the new listen command)
|
||||
|
||||
The server built in to TiddlyWiki5 is very simple. Although compatible with TiddlyWeb it doesn't support many of the features needed for robust Internet-facing usage.
|
||||
|
||||
At the root, it serves a rendering of a specified tiddler. Away from the root, it serves individual tiddlers encoded in JSON, and supports the basic HTTP operations for `GET`, `PUT` and `DELETE`.
|
||||
Legacy command to serve a wiki over HTTP.
|
||||
|
||||
```
|
||||
--server <port> <roottiddler> <rendertype> <servetype> <username> <password> <host> <pathprefix>
|
||||
--server <port> <root-tiddler> <root-render-type> <root-serve-type> <username> <password> <host> <path-prefix> <debug-level>
|
||||
```
|
||||
|
||||
The parameters are:
|
||||
|
||||
* ''port'' - port number on which to listen; non-numeric values are interpreted as a system environment variable from which the port number is extracted (defaults to "8080")
|
||||
* ''roottiddler'' - the tiddler to serve at the root (defaults to "$:/core/save/all")
|
||||
* ''rendertype'' - the content type to which the root tiddler should be rendered (defaults to "text/plain")
|
||||
* ''servetype'' - the content type with which the root tiddler should be served (defaults to "text/html")
|
||||
* ''root-tiddler'' - the tiddler to serve at the root (defaults to "$:/core/save/all")
|
||||
* ''root-render-type'' - the content type to which the root tiddler should be rendered (defaults to "text/plain")
|
||||
* ''root-serve-type'' - the content type with which the root tiddler should be served (defaults to "text/html")
|
||||
* ''username'' - the default username for signing edits
|
||||
* ''password'' - optional password for basic authentication
|
||||
* ''host'' - optional hostname to serve from (defaults to "127.0.0.1" aka "localhost")
|
||||
* ''pathprefix'' - optional prefix for paths
|
||||
* ''path-prefix'' - optional prefix for paths
|
||||
* ''debug-level'' - optional debug level; set to "debug" to view request details (defaults to "none")
|
||||
|
||||
If the password parameter is specified then the browser will prompt the user for the username and password. Note that the password is transmitted in plain text so this implementation isn't suitable for general use.
|
||||
If the password parameter is specified then the browser will prompt the user for the username and password. Note that the password is transmitted in plain text so this implementation should only be used on a trusted network or over HTTPS.
|
||||
|
||||
For example:
|
||||
|
||||
@@ -28,14 +27,16 @@ For example:
|
||||
--server 8080 $:/core/save/all text/plain text/html MyUserName passw0rd
|
||||
```
|
||||
|
||||
The username and password can be specified as empty strings if you need to set the hostname or pathprefix and don't want to require a password:
|
||||
The username and password can be specified as empty strings if you need to set the hostname or pathprefix and don't want to require a password.
|
||||
|
||||
|
||||
```
|
||||
--server 8080 $:/core/save/all text/plain text/html "" "" 192.168.0.245
|
||||
```
|
||||
|
||||
To run multiple TiddlyWiki servers at the same time you'll need to put each one on a different port. It can be useful to use an environment variable to pass the port number to the Node.js process. This example references an environment variable called "MY_PORT_NUMBER":
|
||||
Using an address like this exposes your system to the local network. For information on opening up your instance to the entire local network, and possible security concerns, see the WebServer tiddler at TiddlyWiki.com.
|
||||
|
||||
To run multiple TiddlyWiki servers at the same time you'll need to put each one on a different port. It can be useful to use an environment variable to pass the port number to the Node.js process. This example references an environment variable called "MY_PORT_NUMBER":
|
||||
|
||||
```
|
||||
--server MY_PORT_NUMBER $:/core/save/all text/plain text/html MyUserName passw0rd
|
||||
|
||||
@@ -18,4 +18,6 @@ Upgrader/Plugins/Suppressed/Version: Blocked plugin (due to incoming <<incoming>
|
||||
Upgrader/Plugins/Upgraded: Upgraded plugin from <<incoming>> to <<upgraded>>
|
||||
Upgrader/State/Suppressed: Blocked temporary state tiddler
|
||||
Upgrader/System/Suppressed: Blocked system tiddler
|
||||
Upgrader/System/Warning: Core module tiddler
|
||||
Upgrader/System/Alert: You are about to import a tiddler that will overwrite a core module tiddler. This is not recommended as it may make the system unstable
|
||||
Upgrader/ThemeTweaks/Created: Migrated theme tweak from <$text text=<<from>>/>
|
||||
|
||||
@@ -2,5 +2,5 @@ title: $:/language/Notifications/
|
||||
|
||||
Save/Done: Saved wiki
|
||||
Save/Starting: Starting to save wiki
|
||||
CopiedToClipboard/Succeeded: Copied!
|
||||
CopiedToClipboard/Succeeded: Copied to clipboard!
|
||||
CopiedToClipboard/Failed: Failed to copy to clipboard!
|
||||
|
||||
@@ -94,6 +94,13 @@ Commander.prototype.executeNextCommand = function() {
|
||||
if(this.verbose) {
|
||||
this.streams.output.write("Executing command: " + commandName + " " + params.join(" ") + "\n");
|
||||
}
|
||||
// Parse named parameters if required
|
||||
if(command.info.namedParameterMode) {
|
||||
params = this.extractNamedParameters(params,command.info.mandatoryParameters);
|
||||
if(typeof params === "string") {
|
||||
return this.callback(params);
|
||||
}
|
||||
}
|
||||
if(command.info.synchronous) {
|
||||
// Synchronous command
|
||||
c = new command.Command(params,this);
|
||||
@@ -122,6 +129,35 @@ Commander.prototype.executeNextCommand = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Given an array of parameter strings `params` in name:value format, and an array of mandatory parameter names in `mandatoryParameters`, returns a hashmap of values or a string if error
|
||||
*/
|
||||
Commander.prototype.extractNamedParameters = function(params,mandatoryParameters) {
|
||||
mandatoryParameters = mandatoryParameters || [];
|
||||
var errors = [],
|
||||
paramsByName = Object.create(null);
|
||||
// Extract the parameters
|
||||
$tw.utils.each(params,function(param) {
|
||||
var index = param.indexOf("=");
|
||||
if(index < 1) {
|
||||
errors.push("malformed named parameter: '" + param + "'");
|
||||
}
|
||||
paramsByName[param.slice(0,index)] = $tw.utils.trim(param.slice(index+1));
|
||||
});
|
||||
// Check the mandatory parameters are present
|
||||
$tw.utils.each(mandatoryParameters,function(mandatoryParameter) {
|
||||
if(!$tw.utils.hop(paramsByName,mandatoryParameter)) {
|
||||
errors.push("missing mandatory parameter: '" + mandatoryParameter + "'");
|
||||
}
|
||||
});
|
||||
// Return any errors
|
||||
if(errors.length > 0) {
|
||||
return errors.join(" and\n");
|
||||
} else {
|
||||
return paramsByName;
|
||||
}
|
||||
};
|
||||
|
||||
Commander.initCommands = function(moduleType) {
|
||||
moduleType = moduleType || "command";
|
||||
$tw.commands = {};
|
||||
|
||||
48
core/modules/commands/listen.js
Normal file
48
core/modules/commands/listen.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/*\
|
||||
title: $:/core/modules/commands/listen.js
|
||||
type: application/javascript
|
||||
module-type: command
|
||||
|
||||
Listen for HTTP requests and serve tiddlers
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var Server = require("$:/core/modules/server/server.js").Server;
|
||||
|
||||
exports.info = {
|
||||
name: "listen",
|
||||
synchronous: true,
|
||||
namedParameterMode: true,
|
||||
mandatoryParameters: [],
|
||||
};
|
||||
|
||||
var Command = function(params,commander,callback) {
|
||||
var self = this;
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
this.callback = callback;
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
var self = this;
|
||||
if(!$tw.boot.wikiTiddlersPath) {
|
||||
$tw.utils.warning("Warning: Wiki folder '" + $tw.boot.wikiPath + "' does not exist or is missing a tiddlywiki.info file");
|
||||
}
|
||||
// Set up server
|
||||
this.server = new Server({
|
||||
wiki: this.commander.wiki,
|
||||
variables: self.params
|
||||
});
|
||||
var nodeServer = this.server.listen();
|
||||
$tw.hooks.invokeHook("th-server-command-post-start",this.server,nodeServer,"tiddlywiki");
|
||||
return null;
|
||||
};
|
||||
|
||||
exports.Command = Command;
|
||||
|
||||
})();
|
||||
@@ -38,7 +38,7 @@ Command.prototype.execute = function() {
|
||||
count++;
|
||||
});
|
||||
});
|
||||
if(!count) {
|
||||
if(!count && self.params[1] !== "noerror") {
|
||||
self.callback("No tiddlers found in file \"" + self.params[0] + "\"");
|
||||
} else {
|
||||
self.callback(null);
|
||||
|
||||
@@ -3,7 +3,7 @@ title: $:/core/modules/commands/server.js
|
||||
type: application/javascript
|
||||
module-type: command
|
||||
|
||||
Serve tiddlers over http
|
||||
Deprecated legacy command for serving tiddlers
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
@@ -12,304 +12,41 @@ Serve tiddlers over http
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
if($tw.node) {
|
||||
var util = require("util"),
|
||||
fs = require("fs"),
|
||||
url = require("url"),
|
||||
path = require("path"),
|
||||
http = require("http");
|
||||
}
|
||||
var Server = require("$:/core/modules/server/server.js").Server;
|
||||
|
||||
exports.info = {
|
||||
name: "server",
|
||||
synchronous: true
|
||||
};
|
||||
|
||||
/*
|
||||
A simple HTTP server with regexp-based routes
|
||||
*/
|
||||
function SimpleServer(options) {
|
||||
this.routes = options.routes || [];
|
||||
this.wiki = options.wiki;
|
||||
this.variables = options.variables || {};
|
||||
}
|
||||
|
||||
SimpleServer.prototype.set = function(obj) {
|
||||
var self = this;
|
||||
$tw.utils.each(obj,function(value,name) {
|
||||
self.variables[name] = value;
|
||||
});
|
||||
};
|
||||
|
||||
SimpleServer.prototype.get = function(name) {
|
||||
return this.variables[name];
|
||||
};
|
||||
|
||||
SimpleServer.prototype.addRoute = function(route) {
|
||||
this.routes.push(route);
|
||||
};
|
||||
|
||||
SimpleServer.prototype.findMatchingRoute = function(request,state) {
|
||||
var pathprefix = this.get("pathprefix") || "";
|
||||
for(var t=0; t<this.routes.length; t++) {
|
||||
var potentialRoute = this.routes[t],
|
||||
pathRegExp = potentialRoute.path,
|
||||
pathname = state.urlInfo.pathname,
|
||||
match;
|
||||
if(pathprefix) {
|
||||
if(pathname.substr(0,pathprefix.length) === pathprefix) {
|
||||
pathname = pathname.substr(pathprefix.length);
|
||||
match = potentialRoute.path.exec(pathname);
|
||||
} else {
|
||||
match = false;
|
||||
}
|
||||
} else {
|
||||
match = potentialRoute.path.exec(pathname);
|
||||
}
|
||||
if(match && request.method === potentialRoute.method) {
|
||||
state.params = [];
|
||||
for(var p=1; p<match.length; p++) {
|
||||
state.params.push(match[p]);
|
||||
}
|
||||
return potentialRoute;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
SimpleServer.prototype.checkCredentials = function(request,incomingUsername,incomingPassword) {
|
||||
var header = request.headers.authorization || "",
|
||||
token = header.split(/\s+/).pop() || "",
|
||||
auth = $tw.utils.base64Decode(token),
|
||||
parts = auth.split(/:/),
|
||||
username = parts[0],
|
||||
password = parts[1];
|
||||
if(incomingUsername === username && incomingPassword === password) {
|
||||
return "ALLOWED";
|
||||
} else {
|
||||
return "DENIED";
|
||||
}
|
||||
};
|
||||
|
||||
SimpleServer.prototype.requestHandler = function(request,response) {
|
||||
// Compose the state object
|
||||
var self = this;
|
||||
var state = {};
|
||||
state.wiki = self.wiki;
|
||||
state.server = self;
|
||||
state.urlInfo = url.parse(request.url);
|
||||
// Find the route that matches this path
|
||||
var route = self.findMatchingRoute(request,state);
|
||||
// Check for the username and password if we've got one
|
||||
var username = self.get("username"),
|
||||
password = self.get("password");
|
||||
if(username && password) {
|
||||
// Check they match
|
||||
if(self.checkCredentials(request,username,password) !== "ALLOWED") {
|
||||
var servername = state.wiki.getTiddlerText("$:/SiteTitle") || "TiddlyWiki5";
|
||||
response.writeHead(401,"Authentication required",{
|
||||
"WWW-Authenticate": 'Basic realm="Please provide your username and password to login to ' + servername + '"'
|
||||
});
|
||||
response.end();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Return a 404 if we didn't find a route
|
||||
if(!route) {
|
||||
response.writeHead(404);
|
||||
response.end();
|
||||
return;
|
||||
}
|
||||
// Set the encoding for the incoming request
|
||||
// TODO: Presumably this would need tweaking if we supported PUTting binary tiddlers
|
||||
request.setEncoding("utf8");
|
||||
// Dispatch the appropriate method
|
||||
switch(request.method) {
|
||||
case "GET": // Intentional fall-through
|
||||
case "DELETE":
|
||||
route.handler(request,response,state);
|
||||
break;
|
||||
case "PUT":
|
||||
var data = "";
|
||||
request.on("data",function(chunk) {
|
||||
data += chunk.toString();
|
||||
});
|
||||
request.on("end",function() {
|
||||
state.data = data;
|
||||
route.handler(request,response,state);
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
SimpleServer.prototype.listen = function(port,host) {
|
||||
return http.createServer(this.requestHandler.bind(this)).listen(port,host);
|
||||
};
|
||||
|
||||
var Command = function(params,commander,callback) {
|
||||
var self = this;
|
||||
this.params = params;
|
||||
this.commander = commander;
|
||||
this.callback = callback;
|
||||
// Set up server
|
||||
this.server = new SimpleServer({
|
||||
wiki: this.commander.wiki
|
||||
});
|
||||
// Add route handlers
|
||||
this.server.addRoute({
|
||||
method: "PUT",
|
||||
path: /^\/recipes\/default\/tiddlers\/(.+)$/,
|
||||
handler: function(request,response,state) {
|
||||
var title = decodeURIComponent(state.params[0]),
|
||||
fields = JSON.parse(state.data);
|
||||
// Pull up any subfields in the `fields` object
|
||||
if(fields.fields) {
|
||||
$tw.utils.each(fields.fields,function(field,name) {
|
||||
fields[name] = field;
|
||||
});
|
||||
delete fields.fields;
|
||||
}
|
||||
// Remove any revision field
|
||||
if(fields.revision) {
|
||||
delete fields.revision;
|
||||
}
|
||||
state.wiki.addTiddler(new $tw.Tiddler(state.wiki.getCreationFields(),fields,{title: title},state.wiki.getModificationFields()));
|
||||
var changeCount = state.wiki.getChangeCount(title).toString();
|
||||
response.writeHead(204, "OK",{
|
||||
Etag: "\"default/" + encodeURIComponent(title) + "/" + changeCount + ":\"",
|
||||
"Content-Type": "text/plain"
|
||||
});
|
||||
response.end();
|
||||
}
|
||||
});
|
||||
this.server.addRoute({
|
||||
method: "DELETE",
|
||||
path: /^\/bags\/default\/tiddlers\/(.+)$/,
|
||||
handler: function(request,response,state) {
|
||||
var title = decodeURIComponent(state.params[0]);
|
||||
state.wiki.deleteTiddler(title);
|
||||
response.writeHead(204, "OK", {
|
||||
"Content-Type": "text/plain"
|
||||
});
|
||||
response.end();
|
||||
}
|
||||
});
|
||||
this.server.addRoute({
|
||||
method: "GET",
|
||||
path: /^\/$/,
|
||||
handler: function(request,response,state) {
|
||||
response.writeHead(200, {"Content-Type": state.server.get("serveType")});
|
||||
var text = state.wiki.renderTiddler(state.server.get("renderType"),state.server.get("rootTiddler"));
|
||||
response.end(text,"utf8");
|
||||
}
|
||||
});
|
||||
this.server.addRoute({
|
||||
method: "GET",
|
||||
path: /^\/status$/,
|
||||
handler: function(request,response,state) {
|
||||
response.writeHead(200, {"Content-Type": "application/json"});
|
||||
var text = JSON.stringify({
|
||||
username: state.server.get("username"),
|
||||
space: {
|
||||
recipe: "default"
|
||||
},
|
||||
tiddlywiki_version: $tw.version
|
||||
});
|
||||
response.end(text,"utf8");
|
||||
}
|
||||
});
|
||||
this.server.addRoute({
|
||||
method: "GET",
|
||||
path: /^\/favicon.ico$/,
|
||||
handler: function(request,response,state) {
|
||||
response.writeHead(200, {"Content-Type": "image/x-icon"});
|
||||
var buffer = state.wiki.getTiddlerText("$:/favicon.ico","");
|
||||
response.end(buffer,"base64");
|
||||
}
|
||||
});
|
||||
this.server.addRoute({
|
||||
method: "GET",
|
||||
path: /^\/recipes\/default\/tiddlers.json$/,
|
||||
handler: function(request,response,state) {
|
||||
response.writeHead(200, {"Content-Type": "application/json"});
|
||||
var tiddlers = [];
|
||||
state.wiki.forEachTiddler({sortField: "title"},function(title,tiddler) {
|
||||
var tiddlerFields = {};
|
||||
$tw.utils.each(tiddler.fields,function(field,name) {
|
||||
if(name !== "text") {
|
||||
tiddlerFields[name] = tiddler.getFieldString(name);
|
||||
}
|
||||
});
|
||||
tiddlerFields.revision = state.wiki.getChangeCount(title);
|
||||
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
||||
tiddlers.push(tiddlerFields);
|
||||
});
|
||||
var text = JSON.stringify(tiddlers);
|
||||
response.end(text,"utf8");
|
||||
}
|
||||
});
|
||||
this.server.addRoute({
|
||||
method: "GET",
|
||||
path: /^\/recipes\/default\/tiddlers\/(.+)$/,
|
||||
handler: function(request,response,state) {
|
||||
var title = decodeURIComponent(state.params[0]),
|
||||
tiddler = state.wiki.getTiddler(title),
|
||||
tiddlerFields = {},
|
||||
knownFields = [
|
||||
"bag", "created", "creator", "modified", "modifier", "permissions", "recipe", "revision", "tags", "text", "title", "type", "uri"
|
||||
];
|
||||
if(tiddler) {
|
||||
$tw.utils.each(tiddler.fields,function(field,name) {
|
||||
var value = tiddler.getFieldString(name);
|
||||
if(knownFields.indexOf(name) !== -1) {
|
||||
tiddlerFields[name] = value;
|
||||
} else {
|
||||
tiddlerFields.fields = tiddlerFields.fields || {};
|
||||
tiddlerFields.fields[name] = value;
|
||||
}
|
||||
});
|
||||
tiddlerFields.revision = state.wiki.getChangeCount(title);
|
||||
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
||||
response.writeHead(200, {"Content-Type": "application/json"});
|
||||
response.end(JSON.stringify(tiddlerFields),"utf8");
|
||||
} else {
|
||||
response.writeHead(404);
|
||||
response.end();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Command.prototype.execute = function() {
|
||||
if(!$tw.boot.wikiTiddlersPath) {
|
||||
$tw.utils.warning("Warning: Wiki folder '" + $tw.boot.wikiPath + "' does not exist or is missing a tiddlywiki.info file");
|
||||
}
|
||||
var port = this.params[0] || "8080",
|
||||
rootTiddler = this.params[1] || "$:/core/save/all",
|
||||
renderType = this.params[2] || "text/plain",
|
||||
serveType = this.params[3] || "text/html",
|
||||
username = this.params[4],
|
||||
password = this.params[5],
|
||||
host = this.params[6] || "127.0.0.1",
|
||||
pathprefix = this.params[7];
|
||||
if(parseInt(port,10).toString() !== port) {
|
||||
port = process.env[port] || 8080;
|
||||
}
|
||||
this.server.set({
|
||||
rootTiddler: rootTiddler,
|
||||
renderType: renderType,
|
||||
serveType: serveType,
|
||||
username: username,
|
||||
password: password,
|
||||
pathprefix: pathprefix
|
||||
// Set up server
|
||||
this.server = new Server({
|
||||
wiki: this.commander.wiki,
|
||||
variables: {
|
||||
port: this.params[0],
|
||||
host: this.params[6],
|
||||
"root-tiddler": this.params[1],
|
||||
"root-render-type": this.params[2],
|
||||
"root-serve-type": this.params[3],
|
||||
username: this.params[4],
|
||||
password: this.params[5],
|
||||
"path-prefix": this.params[7],
|
||||
"debug-level": this.params[8]
|
||||
}
|
||||
});
|
||||
var nodeServer = this.server.listen(port,host);
|
||||
$tw.utils.log("Serving on " + host + ":" + port,"brown/orange");
|
||||
$tw.utils.log("(press ctrl-C to exit)","red");
|
||||
// Warn if required plugins are missing
|
||||
if(!$tw.wiki.getTiddler("$:/plugins/tiddlywiki/tiddlyweb") || !$tw.wiki.getTiddler("$:/plugins/tiddlywiki/filesystem")) {
|
||||
$tw.utils.warning("Warning: Plugins required for client-server operation (\"tiddlywiki/filesystem\" and \"tiddlywiki/tiddlyweb\") are missing from tiddlywiki.info file");
|
||||
}
|
||||
$tw.hooks.invokeHook('th-server-command-post-start', this.server, nodeServer);
|
||||
var nodeServer = this.server.listen();
|
||||
$tw.hooks.invokeHook("th-server-command-post-start",this.server,nodeServer,"tiddlywiki");
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
@@ -70,6 +70,9 @@ function FramedEngine(options) {
|
||||
if(this.widget.editRows) {
|
||||
this.domNode.setAttribute("rows",this.widget.editRows);
|
||||
}
|
||||
if(this.widget.editTabIndex) {
|
||||
this.iframeNode.setAttribute("tabindex",this.widget.editTabIndex);
|
||||
}
|
||||
// Copy the styles from the dummy textarea
|
||||
this.copyStyles();
|
||||
// Add event listeners
|
||||
|
||||
@@ -49,6 +49,9 @@ function SimpleEngine(options) {
|
||||
if(this.widget.editClass) {
|
||||
this.domNode.className = this.widget.editClass;
|
||||
}
|
||||
if(this.widget.editTabIndex) {
|
||||
this.domNode.setAttribute("tabindex",this.widget.editTabIndex);
|
||||
}
|
||||
// Add an input event handler
|
||||
$tw.utils.addEventListeners(this.domNode,[
|
||||
{name: "focus", handlerObject: this, handlerMethod: "handleFocusEvent"},
|
||||
|
||||
@@ -176,6 +176,7 @@ function editTextWidgetFactory(toolbarEngine,nonToolbarEngine) {
|
||||
this.editMinHeight = this.getAttribute("minHeight",DEFAULT_MIN_TEXT_AREA_HEIGHT);
|
||||
this.editFocusPopup = this.getAttribute("focusPopup");
|
||||
this.editFocus = this.getAttribute("focus");
|
||||
this.editTabIndex = this.getAttribute("tabindex");
|
||||
// Get the default editor element tag and type
|
||||
var tag,type;
|
||||
if(this.editField === "text") {
|
||||
@@ -207,7 +208,7 @@ function editTextWidgetFactory(toolbarEngine,nonToolbarEngine) {
|
||||
EditTextWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
// Completely rerender if any of our attributes have changed
|
||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes["default"] || changedAttributes["class"] || changedAttributes.placeholder || changedAttributes.size || changedAttributes.autoHeight || changedAttributes.minHeight || changedAttributes.focusPopup || changedAttributes.rows || changedTiddlers[HEIGHT_MODE_TITLE] || changedTiddlers[ENABLE_TOOLBAR_TITLE]) {
|
||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes["default"] || changedAttributes["class"] || changedAttributes.placeholder || changedAttributes.size || changedAttributes.autoHeight || changedAttributes.minHeight || changedAttributes.focusPopup || changedAttributes.rows || changedAttributes.tabindex || changedTiddlers[HEIGHT_MODE_TITLE] || changedTiddlers[ENABLE_TOOLBAR_TITLE]) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
} else if(changedTiddlers[this.editTitle]) {
|
||||
@@ -216,7 +217,7 @@ function editTextWidgetFactory(toolbarEngine,nonToolbarEngine) {
|
||||
}
|
||||
this.engine.fixHeight();
|
||||
if(this.editShowToolbar) {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -266,7 +267,7 @@ function editTextWidgetFactory(toolbarEngine,nonToolbarEngine) {
|
||||
el.dispatchEvent(clickEvent);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
23
core/modules/editor/operations/text/save-selection.js
Normal file
23
core/modules/editor/operations/text/save-selection.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/*\
|
||||
title: $:/core/modules/editor/operations/text/save-selection.js
|
||||
type: application/javascript
|
||||
module-type: texteditoroperation
|
||||
|
||||
Text editor operation to save the current selection in a specified tiddler
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports["save-selection"] = function(event,operation) {
|
||||
var tiddler = event.paramObject.tiddler,
|
||||
field = event.paramObject.field || "text";
|
||||
if(tiddler && field) {
|
||||
this.wiki.setText(tiddler,field,null,operation.text.substring(operation.selStart,operation.selEnd));
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -16,14 +16,12 @@ exports["wrap-selection"] = function(event,operation) {
|
||||
if(operation.selStart === operation.selEnd) {
|
||||
// No selection; check if we're within the prefix/suffix
|
||||
if(operation.text.substring(operation.selStart - event.paramObject.prefix.length,operation.selStart + event.paramObject.suffix.length) === event.paramObject.prefix + event.paramObject.suffix) {
|
||||
// Remove the prefix and suffix unless they comprise the entire text
|
||||
if(operation.selStart > event.paramObject.prefix.length || (operation.selEnd + event.paramObject.suffix.length) < operation.text.length ) {
|
||||
operation.cutStart = operation.selStart - event.paramObject.prefix.length;
|
||||
operation.cutEnd = operation.selEnd + event.paramObject.suffix.length;
|
||||
operation.replacement = "";
|
||||
operation.newSelStart = operation.cutStart;
|
||||
operation.newSelEnd = operation.newSelStart;
|
||||
}
|
||||
// Remove the prefix and suffix
|
||||
operation.cutStart = operation.selStart - event.paramObject.prefix.length;
|
||||
operation.cutEnd = operation.selEnd + event.paramObject.suffix.length;
|
||||
operation.replacement = "";
|
||||
operation.newSelStart = operation.cutStart;
|
||||
operation.newSelEnd = operation.newSelStart;
|
||||
} else {
|
||||
// Wrap the cursor instead
|
||||
operation.cutStart = operation.selStart;
|
||||
|
||||
@@ -40,12 +40,23 @@ function parseFilterOperation(operators,filterString,p) {
|
||||
nextBracketPos += p;
|
||||
var bracket = filterString.charAt(nextBracketPos);
|
||||
operator.operator = filterString.substring(p,nextBracketPos);
|
||||
|
||||
// Any suffix?
|
||||
var colon = operator.operator.indexOf(':');
|
||||
if(colon > -1) {
|
||||
// The raw suffix for older filters
|
||||
operator.suffix = operator.operator.substring(colon + 1);
|
||||
operator.operator = operator.operator.substring(0,colon) || "field";
|
||||
// The processed suffix for newer filters
|
||||
operator.suffixes = [];
|
||||
$tw.utils.each(operator.suffix.split(":"),function(subsuffix) {
|
||||
operator.suffixes.push([]);
|
||||
$tw.utils.each(subsuffix.split(","),function(entry) {
|
||||
entry = $tw.utils.trim(entry);
|
||||
if(entry) {
|
||||
operator.suffixes[operator.suffixes.length - 1].push(entry);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// Empty operator means: title
|
||||
else if(operator.operator === "") {
|
||||
@@ -108,7 +119,7 @@ exports.parseFilter = function(filterString) {
|
||||
p = 0, // Current position in the filter string
|
||||
match;
|
||||
var whitespaceRegExp = /(\s+)/mg,
|
||||
operandRegExp = /((?:\+|\-)?)(?:(\[)|(?:"([^"]*)")|(?:'([^']*)')|([^\s\[\]]+))/mg;
|
||||
operandRegExp = /((?:\+|\-|~)?)(?:(\[)|(?:"([^"]*)")|(?:'([^']*)')|([^\s\[\]]+))/mg;
|
||||
while(p < filterString.length) {
|
||||
// Skip any whitespace
|
||||
whitespaceRegExp.lastIndex = p;
|
||||
@@ -208,6 +219,7 @@ exports.compileFilter = function(filterString) {
|
||||
operand: operand,
|
||||
prefix: operator.prefix,
|
||||
suffix: operator.suffix,
|
||||
suffixes: operator.suffixes,
|
||||
regexp: operator.regexp
|
||||
},{
|
||||
wiki: self,
|
||||
@@ -247,6 +259,13 @@ exports.compileFilter = function(filterString) {
|
||||
results.splice(0,results.length);
|
||||
$tw.utils.pushTop(results,operationSubFunction(source,widget));
|
||||
};
|
||||
case "~": // This operation is unioned into the result only if the main result so far is empty
|
||||
return function(results,source,widget) {
|
||||
if(results.length === 0) {
|
||||
// Main result so far is empty
|
||||
$tw.utils.pushTop(results,operationSubFunction(source,widget));
|
||||
}
|
||||
};
|
||||
}
|
||||
})());
|
||||
});
|
||||
|
||||
45
core/modules/filters/contains.js
Normal file
45
core/modules/filters/contains.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/contains.js
|
||||
type: application/javascript
|
||||
module-type: filteroperator
|
||||
|
||||
Filter operator for finding values in array fields
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Export our filter function
|
||||
*/
|
||||
exports.contains = function(source,operator,options) {
|
||||
var results = [],
|
||||
fieldname = (operator.suffix || "list").toLowerCase();
|
||||
if(operator.prefix === "!") {
|
||||
source(function(tiddler,title) {
|
||||
if(tiddler) {
|
||||
var list = tiddler.getFieldList(fieldname);
|
||||
if(list.indexOf(operator.operand) === -1) {
|
||||
results.push(title);
|
||||
}
|
||||
} else {
|
||||
results.push(title);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
source(function(tiddler,title) {
|
||||
if(tiddler) {
|
||||
var list = tiddler.getFieldList(fieldname);
|
||||
if(list.indexOf(operator.operand) !== -1) {
|
||||
results.push(title);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -19,7 +19,12 @@ Export our filter functions
|
||||
exports.decodeuricomponent = function(source,operator,options) {
|
||||
var results = [];
|
||||
source(function(tiddler,title) {
|
||||
results.push(decodeURIComponent(title));
|
||||
var value = title;
|
||||
try {
|
||||
value = decodeURIComponent(title);
|
||||
} catch(e) {
|
||||
}
|
||||
results.push(value);
|
||||
});
|
||||
return results;
|
||||
};
|
||||
@@ -35,7 +40,12 @@ exports.encodeuricomponent = function(source,operator,options) {
|
||||
exports.decodeuri = function(source,operator,options) {
|
||||
var results = [];
|
||||
source(function(tiddler,title) {
|
||||
results.push(decodeURI(title));
|
||||
var value = title;
|
||||
try {
|
||||
value = decodeURI(title);
|
||||
} catch(e) {
|
||||
}
|
||||
results.push(value);
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
||||
36
core/modules/filters/is/variable.js
Normal file
36
core/modules/filters/is/variable.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/is/variable.js
|
||||
type: application/javascript
|
||||
module-type: isfilteroperator
|
||||
|
||||
Filter function for [is[variable]]
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Export our filter function
|
||||
*/
|
||||
exports.variable = function(source,prefix,options) {
|
||||
var results = [];
|
||||
if(prefix === "!") {
|
||||
source(function(tiddler,title) {
|
||||
if(!(title in options.widget.variables)) {
|
||||
results.push(title);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
source(function(tiddler,title) {
|
||||
if(title in options.widget.variables) {
|
||||
results.push(title);
|
||||
}
|
||||
});
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
})();
|
||||
142
core/modules/filters/math.js
Normal file
142
core/modules/filters/math.js
Normal file
@@ -0,0 +1,142 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/math.js
|
||||
type: application/javascript
|
||||
module-type: filteroperator
|
||||
|
||||
Filter operators for math. Unary/binary operators work on each item in turn, and return a new item list.
|
||||
|
||||
Sum/product/maxall/minall operate on the entire list, returning a single item.
|
||||
|
||||
Note that strings are converted to numbers automatically. Trailing non-digits are ignored.
|
||||
|
||||
* "" converts to 0
|
||||
* "12kk" converts to 12
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.negate = makeNumericBinaryOperator(
|
||||
function(a) {return -a}
|
||||
);
|
||||
|
||||
exports.abs = makeNumericBinaryOperator(
|
||||
function(a) {return Math.abs(a)}
|
||||
);
|
||||
|
||||
exports.ceil = makeNumericBinaryOperator(
|
||||
function(a) {return Math.ceil(a)}
|
||||
);
|
||||
|
||||
exports.floor = makeNumericBinaryOperator(
|
||||
function(a) {return Math.floor(a)}
|
||||
);
|
||||
|
||||
exports.round = makeNumericBinaryOperator(
|
||||
function(a) {return Math.round(a)}
|
||||
);
|
||||
|
||||
exports.trunc = makeNumericBinaryOperator(
|
||||
function(a) {return Math.trunc(a)}
|
||||
);
|
||||
|
||||
exports.sign = makeNumericBinaryOperator(
|
||||
function(a) {return Math.sign(a)}
|
||||
);
|
||||
|
||||
exports.add = makeNumericBinaryOperator(
|
||||
function(a,b) {return a + b;}
|
||||
);
|
||||
|
||||
exports.subtract = makeNumericBinaryOperator(
|
||||
function(a,b) {return a - b;}
|
||||
);
|
||||
|
||||
exports.multiply = makeNumericBinaryOperator(
|
||||
function(a,b) {return a * b;}
|
||||
);
|
||||
|
||||
exports.divide = makeNumericBinaryOperator(
|
||||
function(a,b) {return a / b;}
|
||||
);
|
||||
|
||||
exports.remainder = makeNumericBinaryOperator(
|
||||
function(a,b) {return a % b;}
|
||||
);
|
||||
|
||||
exports.max = makeNumericBinaryOperator(
|
||||
function(a,b) {return Math.max(a,b);}
|
||||
);
|
||||
|
||||
exports.min = makeNumericBinaryOperator(
|
||||
function(a,b) {return Math.min(a,b);}
|
||||
);
|
||||
|
||||
exports.fixed = makeNumericBinaryOperator(
|
||||
function(a,b) {return Number.prototype.toFixed.call(a,b);}
|
||||
);
|
||||
|
||||
exports.precision = makeNumericBinaryOperator(
|
||||
function(a,b) {return Number.prototype.toPrecision.call(a,b);}
|
||||
);
|
||||
|
||||
exports.exponential = makeNumericBinaryOperator(
|
||||
function(a,b) {return Number.prototype.toExponential.call(a,b);}
|
||||
);
|
||||
|
||||
exports.sum = makeNumericArrayOperator(
|
||||
function(accumulator,value) {return accumulator + value},
|
||||
0 // Initial value
|
||||
);
|
||||
|
||||
exports.product = makeNumericArrayOperator(
|
||||
function(accumulator,value) {return accumulator * value},
|
||||
1 // Initial value
|
||||
);
|
||||
|
||||
exports.maxall = makeNumericArrayOperator(
|
||||
function(accumulator,value) {return Math.max(accumulator,value)},
|
||||
-Infinity // Initial value
|
||||
);
|
||||
|
||||
exports.minall = makeNumericArrayOperator(
|
||||
function(accumulator,value) {return Math.min(accumulator,value)},
|
||||
Infinity // Initial value
|
||||
);
|
||||
|
||||
function makeNumericBinaryOperator(fnCalc) {
|
||||
return function(source,operator,options) {
|
||||
var result = [],
|
||||
numOperand = parseNumber(operator.operand);
|
||||
source(function(tiddler,title) {
|
||||
result.push(stringifyNumber(fnCalc(parseNumber(title),numOperand)));
|
||||
});
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
function makeNumericArrayOperator(fnCalc,initialValue) {
|
||||
initialValue = initialValue || 0;
|
||||
return function(source,operator,options) {
|
||||
var result = [];
|
||||
source(function(tiddler,title) {
|
||||
result.push(title);
|
||||
});
|
||||
return [stringifyNumber(result.reduce(function(accumulator,currentValue) {
|
||||
return fnCalc(accumulator,parseNumber(currentValue));
|
||||
},initialValue))];
|
||||
};
|
||||
}
|
||||
|
||||
function parseNumber(str) {
|
||||
return parseFloat(str) || 0;
|
||||
}
|
||||
|
||||
function stringifyNumber(num) {
|
||||
return num + "";
|
||||
}
|
||||
|
||||
})();
|
||||
99
core/modules/filters/range.js
Normal file
99
core/modules/filters/range.js
Normal file
@@ -0,0 +1,99 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/range.js
|
||||
type: application/javascript
|
||||
module-type: filteroperator
|
||||
|
||||
Filter operator for generating a numeric range.
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Export our filter function
|
||||
*/
|
||||
exports.range = function(source,operator,options) {
|
||||
var results = [];
|
||||
// Split the operand into numbers delimited by these symbols
|
||||
var parts = operator.operand.split(/[,:;]/g),
|
||||
beg, end, inc, i, fixed = 0;
|
||||
for (i=0; i<parts.length; i++) {
|
||||
// Validate real number
|
||||
if(!/^\s*[+-]?((\d+(\.\d*)?)|(\.\d+))\s*$/.test(parts[i])) {
|
||||
return ["range: bad number \"" + parts[i] + "\""];
|
||||
}
|
||||
// Count digits; the most precise number determines decimal places in output.
|
||||
var frac = /\.\d+/.exec(parts[i]);
|
||||
if(frac) {
|
||||
fixed = Math.max(fixed,frac[0].length-1);
|
||||
}
|
||||
parts[i] = parseFloat(parts[i]);
|
||||
}
|
||||
switch(parts.length) {
|
||||
case 1:
|
||||
end = parts[0];
|
||||
if (end >= 1) {
|
||||
beg = 1;
|
||||
}
|
||||
else if (end <= -1) {
|
||||
beg = -1;
|
||||
}
|
||||
else {
|
||||
return [];
|
||||
}
|
||||
inc = 1;
|
||||
break;
|
||||
case 2:
|
||||
beg = parts[0];
|
||||
end = parts[1];
|
||||
inc = 1;
|
||||
break;
|
||||
case 3:
|
||||
beg = parts[0];
|
||||
end = parts[1];
|
||||
inc = Math.abs(parts[2]);
|
||||
break;
|
||||
}
|
||||
if(inc === 0) {
|
||||
return ["range: increment 0 causes infinite loop"];
|
||||
}
|
||||
// May need to count backwards
|
||||
var direction = ((end < beg) ? -1 : 1);
|
||||
inc *= direction;
|
||||
// Estimate number of resulting elements
|
||||
if((end - beg) / inc > 10000) {
|
||||
return ["range: too many steps (over 10K)"];
|
||||
}
|
||||
// Avoid rounding error on last step
|
||||
end += direction * 0.5 * Math.pow(0.1,fixed);
|
||||
var safety = 10010;
|
||||
// Enumerate the range
|
||||
if (end<beg) {
|
||||
for(i=beg; i>end; i+=inc) {
|
||||
results.push(i.toFixed(fixed));
|
||||
if(--safety<0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(i=beg; i<end; i+=inc) {
|
||||
results.push(i.toFixed(fixed));
|
||||
if(--safety<0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(safety<0) {
|
||||
return ["range: unexpectedly large output"];
|
||||
}
|
||||
// Reverse?
|
||||
if(operator.prefix === "!") {
|
||||
results.reverse();
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -18,7 +18,7 @@ Export our filter function
|
||||
exports.removesuffix = function(source,operator,options) {
|
||||
var results = [];
|
||||
source(function(tiddler,title) {
|
||||
if(title.substr(-operator.operand.length) === operator.operand) {
|
||||
if(title && title.substr(-operator.operand.length) === operator.operand) {
|
||||
results.push(title.substr(0,title.length - operator.operand.length));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -17,11 +17,34 @@ Export our filter function
|
||||
*/
|
||||
exports.search = function(source,operator,options) {
|
||||
var invert = operator.prefix === "!";
|
||||
if(operator.suffix) {
|
||||
if(operator.suffixes) {
|
||||
var hasFlag = function(flag) {
|
||||
return (operator.suffixes[1] || []).indexOf(flag) !== -1;
|
||||
},
|
||||
excludeFields = false,
|
||||
fieldList = operator.suffixes[0] || [],
|
||||
firstField = fieldList[0] || "",
|
||||
firstChar = firstField.charAt(0),
|
||||
fields;
|
||||
if(firstChar === "-") {
|
||||
fields = [firstField.slice(1)].concat(fieldList.slice(1));
|
||||
excludeFields = true;
|
||||
} else if(fieldList[0] === "*"){
|
||||
fields = [];
|
||||
excludeFields = true;
|
||||
} else {
|
||||
fields = fieldList.slice(0);
|
||||
}
|
||||
return options.wiki.search(operator.operand,{
|
||||
source: source,
|
||||
invert: invert,
|
||||
field: operator.suffix
|
||||
field: fields,
|
||||
excludeField: excludeFields,
|
||||
caseSensitive: hasFlag("casesensitive"),
|
||||
literal: hasFlag("literal"),
|
||||
whitespace: hasFlag("whitespace"),
|
||||
regexp: hasFlag("regexp"),
|
||||
words: hasFlag("words")
|
||||
});
|
||||
} else {
|
||||
return options.wiki.search(operator.operand,{
|
||||
|
||||
70
core/modules/filters/strings.js
Normal file
70
core/modules/filters/strings.js
Normal file
@@ -0,0 +1,70 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/strings.js
|
||||
type: application/javascript
|
||||
module-type: filteroperator
|
||||
|
||||
Filter operators for strings. Unary/binary operators work on each item in turn, and return a new item list.
|
||||
|
||||
Sum/product/maxall/minall operate on the entire list, returning a single item.
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.length = makeStringBinaryOperator(
|
||||
function(a) {return ["" + ("" + a).length];}
|
||||
);
|
||||
|
||||
exports.uppercase = makeStringBinaryOperator(
|
||||
function(a) {return [("" + a).toUpperCase()];}
|
||||
);
|
||||
|
||||
exports.lowercase = makeStringBinaryOperator(
|
||||
function(a) {return [("" + a).toLowerCase()];}
|
||||
);
|
||||
|
||||
exports.trim = makeStringBinaryOperator(
|
||||
function(a) {return [$tw.utils.trim(a)];}
|
||||
);
|
||||
|
||||
exports.concat = makeStringBinaryOperator(
|
||||
function(a,b) {return ["" + a + b];}
|
||||
);
|
||||
|
||||
exports.split = makeStringBinaryOperator(
|
||||
function(a,b) {return ("" + a).split(b).filter(function(str) {return !!str;});}
|
||||
);
|
||||
|
||||
exports.join = makeStringArrayOperator(
|
||||
function(accumulator,value,operand) {
|
||||
return "" + (accumulator ? accumulator + (operand || "") + value : value);
|
||||
}
|
||||
);
|
||||
|
||||
function makeStringBinaryOperator(fnCalc) {
|
||||
return function(source,operator,options) {
|
||||
var result = [];
|
||||
source(function(tiddler,title) {
|
||||
Array.prototype.push.apply(result,fnCalc(title,operator.operand || ""));
|
||||
});
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
function makeStringArrayOperator(fnCalc,initialValue) {
|
||||
initialValue = initialValue || "";
|
||||
return function(source,operator,options) {
|
||||
var result = [];
|
||||
source(function(tiddler,title) {
|
||||
result.push(title);
|
||||
});
|
||||
return [result.reduce(function(accumulator,currentValue) {
|
||||
return fnCalc(accumulator,currentValue,operator.operand || "");
|
||||
},initialValue)];
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
||||
33
core/modules/filters/subfilter.js
Normal file
33
core/modules/filters/subfilter.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/subfilter.js
|
||||
type: application/javascript
|
||||
module-type: filteroperator
|
||||
|
||||
Filter operator returning its operand evaluated as a filter
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Export our filter function
|
||||
*/
|
||||
exports.subfilter = function(source,operator,options) {
|
||||
var list = options.wiki.filterTiddlers(operator.operand,options.widget,source);
|
||||
if(operator.prefix === "!") {
|
||||
var results = [];
|
||||
source(function(tiddler,title) {
|
||||
if(list.indexOf(title) === -1) {
|
||||
results.push(title);
|
||||
}
|
||||
});
|
||||
return results;
|
||||
} else {
|
||||
return list;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -35,6 +35,8 @@ exports.getInfoTiddlerFields = function() {
|
||||
// Screen size
|
||||
infoTiddlerFields.push({title: "$:/info/browser/screen/width", text: window.screen.width.toString()});
|
||||
infoTiddlerFields.push({title: "$:/info/browser/screen/height", text: window.screen.height.toString()});
|
||||
// Language
|
||||
infoTiddlerFields.push({title: "$:/info/browser/language", text: navigator.language || ""});
|
||||
}
|
||||
return infoTiddlerFields;
|
||||
};
|
||||
|
||||
@@ -138,6 +138,17 @@ function KeyboardManager(options) {
|
||||
});
|
||||
// Save the platform-specific name of the "meta" key
|
||||
this.metaKeyName = $tw.platform.isMac ? "cmd-" : "win-";
|
||||
this.shortcutKeysList = [], // Stores the shortcut-key descriptors
|
||||
this.shortcutActionList = [], // Stores the corresponding action strings
|
||||
this.shortcutParsedList = []; // Stores the parsed key descriptors
|
||||
this.lookupNames = ["shortcuts"];
|
||||
this.lookupNames.push($tw.platform.isMac ? "shortcuts-mac" : "shortcuts-not-mac")
|
||||
this.lookupNames.push($tw.platform.isWindows ? "shortcuts-windows" : "shortcuts-not-windows");
|
||||
this.lookupNames.push($tw.platform.isLinux ? "shortcuts-linux" : "shortcuts-not-linux");
|
||||
this.updateShortcutLists(this.getShortcutTiddlerList());
|
||||
$tw.wiki.addEventListener("change",function(changes) {
|
||||
self.handleShortcutChanges(changes);
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -229,10 +240,9 @@ KeyboardManager.prototype.parseKeyDescriptors = function(keyDescriptors,options)
|
||||
result.push.apply(result,self.parseKeyDescriptors(keyDescriptors,options));
|
||||
}
|
||||
};
|
||||
lookupName("shortcuts");
|
||||
lookupName($tw.platform.isMac ? "shortcuts-mac" : "shortcuts-not-mac");
|
||||
lookupName($tw.platform.isWindows ? "shortcuts-windows" : "shortcuts-not-windows");
|
||||
lookupName($tw.platform.isLinux ? "shortcuts-linux" : "shortcuts-not-linux");
|
||||
$tw.utils.each(self.lookupNames,function(platformDescriptor) {
|
||||
lookupName(platformDescriptor);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
result.push(self.parseKeyDescriptor(keyDescriptor));
|
||||
@@ -274,6 +284,70 @@ KeyboardManager.prototype.checkKeyDescriptors = function(event,keyInfoArray) {
|
||||
return false;
|
||||
};
|
||||
|
||||
KeyboardManager.prototype.getShortcutTiddlerList = function() {
|
||||
return $tw.wiki.getTiddlersWithTag("$:/tags/KeyboardShortcut");
|
||||
};
|
||||
|
||||
KeyboardManager.prototype.updateShortcutLists = function(tiddlerList) {
|
||||
this.shortcutTiddlers = tiddlerList;
|
||||
for(var i=0; i<tiddlerList.length; i++) {
|
||||
var title = tiddlerList[i],
|
||||
tiddlerFields = $tw.wiki.getTiddler(title).fields;
|
||||
this.shortcutKeysList[i] = tiddlerFields.key !== undefined ? tiddlerFields.key : undefined;
|
||||
this.shortcutActionList[i] = tiddlerFields.text;
|
||||
this.shortcutParsedList[i] = this.shortcutKeysList[i] !== undefined ? this.parseKeyDescriptors(this.shortcutKeysList[i]) : undefined;
|
||||
}
|
||||
};
|
||||
|
||||
KeyboardManager.prototype.handleKeydownEvent = function(event) {
|
||||
var key, action;
|
||||
for(var i=0; i<this.shortcutTiddlers.length; i++) {
|
||||
if(this.shortcutParsedList[i] !== undefined && this.checkKeyDescriptors(event,this.shortcutParsedList[i])) {
|
||||
key = this.shortcutParsedList[i];
|
||||
action = this.shortcutActionList[i];
|
||||
}
|
||||
}
|
||||
if(key !== undefined) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
$tw.rootWidget.invokeActionString(action,$tw.rootWidget);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
KeyboardManager.prototype.detectNewShortcuts = function(changedTiddlers) {
|
||||
var shortcutConfigTiddlers = [],
|
||||
handled = false;
|
||||
$tw.utils.each(this.lookupNames,function(platformDescriptor) {
|
||||
var descriptorString = "$:/config/" + platformDescriptor + "/";
|
||||
Object.keys(changedTiddlers).forEach(function(configTiddler) {
|
||||
var configString = configTiddler.substr(0, configTiddler.lastIndexOf("/") + 1);
|
||||
if(configString === descriptorString) {
|
||||
shortcutConfigTiddlers.push(configTiddler);
|
||||
handled = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
if(handled) {
|
||||
return $tw.utils.hopArray(changedTiddlers,shortcutConfigTiddlers);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
KeyboardManager.prototype.handleShortcutChanges = function(changedTiddlers) {
|
||||
var newList = this.getShortcutTiddlerList();
|
||||
var hasChanged = $tw.utils.hopArray(changedTiddlers,this.shortcutTiddlers) ? true :
|
||||
($tw.utils.hopArray(changedTiddlers,newList) ? true :
|
||||
(this.detectNewShortcuts(changedTiddlers))
|
||||
);
|
||||
// Re-cache shortcuts if something changed
|
||||
if(hasChanged) {
|
||||
this.updateShortcutLists(newList);
|
||||
}
|
||||
};
|
||||
|
||||
exports.KeyboardManager = KeyboardManager;
|
||||
|
||||
})();
|
||||
|
||||
@@ -26,19 +26,7 @@ exports.params = [
|
||||
Run the macro
|
||||
*/
|
||||
exports.run = function(filter) {
|
||||
var tiddlers = this.wiki.filterTiddlers(filter),
|
||||
data = [];
|
||||
for(var t=0;t<tiddlers.length; t++) {
|
||||
var tiddler = this.wiki.getTiddler(tiddlers[t]);
|
||||
if(tiddler) {
|
||||
var fields = new Object();
|
||||
for(var field in tiddler.fields) {
|
||||
fields[field] = tiddler.getFieldString(field);
|
||||
}
|
||||
data.push(fields);
|
||||
}
|
||||
}
|
||||
return JSON.stringify(data,null,$tw.config.preferences.jsonSpaces);
|
||||
return this.wiki.getTiddlersAsJson(filter);
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
34
core/modules/macros/uniquetitle.js
Normal file
34
core/modules/macros/uniquetitle.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/*\
|
||||
title: $:/core/modules/macros/unusedtitle.js
|
||||
type: application/javascript
|
||||
module-type: macro
|
||||
Macro to return a new title that is unused in the wiki. It can be given a name as a base.
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Information about this macro
|
||||
*/
|
||||
|
||||
exports.name = "unusedtitle";
|
||||
|
||||
exports.params = [
|
||||
{name: "baseName"},
|
||||
{name: "options"}
|
||||
];
|
||||
|
||||
/*
|
||||
Run the macro
|
||||
*/
|
||||
exports.run = function(baseName, options) {
|
||||
if(!baseName) {
|
||||
baseName = $tw.language.getString("DefaultNewTiddlerTitle");
|
||||
}
|
||||
return this.wiki.generateNewTitle(baseName, options);
|
||||
};
|
||||
|
||||
})();
|
||||
29
core/modules/parsers/binaryparser.js
Normal file
29
core/modules/parsers/binaryparser.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/*\
|
||||
title: $:/core/modules/parsers/binaryparser.js
|
||||
type: application/javascript
|
||||
module-type: parser
|
||||
|
||||
The video parser parses a video tiddler into an embeddable HTML element
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var BINARY_WARNING_MESSAGE = "$:/core/ui/BinaryWarning";
|
||||
|
||||
var BinaryParser = function(type,text,options) {
|
||||
this.tree = [{
|
||||
type: "transclude",
|
||||
attributes: {
|
||||
tiddler: {type: "string", value: BINARY_WARNING_MESSAGE}
|
||||
}
|
||||
}];
|
||||
};
|
||||
|
||||
exports["application/octet-stream"] = BinaryParser;
|
||||
|
||||
})();
|
||||
|
||||
@@ -35,6 +35,9 @@ exports["image/jpg"] = ImageParser;
|
||||
exports["image/jpeg"] = ImageParser;
|
||||
exports["image/png"] = ImageParser;
|
||||
exports["image/gif"] = ImageParser;
|
||||
exports["image/webp"] = ImageParser;
|
||||
exports["image/heic"] = ImageParser;
|
||||
exports["image/heif"] = ImageParser;
|
||||
exports["image/x-icon"] = ImageParser;
|
||||
|
||||
})();
|
||||
|
||||
13
core/modules/parsers/wikiparser/macros/prettylink.tid
Normal file
13
core/modules/parsers/wikiparser/macros/prettylink.tid
Normal file
@@ -0,0 +1,13 @@
|
||||
title: $:/core/macros/shortcuts/prettylink
|
||||
tags: $:/tags/Macro
|
||||
|
||||
\define x-tm-prettylink-internal(to,text)
|
||||
<$link to=<<__to__>>><$text text=<<__text__>>/></$link>
|
||||
\end
|
||||
|
||||
\define tm-prettylink-internal(to,text)
|
||||
<$button>
|
||||
<$action-navigate $to=<<__to__>>/>
|
||||
<$text text=<<__text__>>/>
|
||||
</$button>
|
||||
\end
|
||||
53
core/modules/parsers/wikiparser/rules/import.js
Normal file
53
core/modules/parsers/wikiparser/rules/import.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/*\
|
||||
title: $:/core/modules/parsers/wikiparser/rules/import.js
|
||||
type: application/javascript
|
||||
module-type: wikirule
|
||||
|
||||
Wiki pragma rule for importing variable definitions
|
||||
|
||||
```
|
||||
\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]
|
||||
```
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.name = "import";
|
||||
exports.types = {pragma: true};
|
||||
|
||||
/*
|
||||
Instantiate parse rule
|
||||
*/
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /^\\import[^\S\n]/mg;
|
||||
};
|
||||
|
||||
/*
|
||||
Parse the most recent match
|
||||
*/
|
||||
exports.parse = function() {
|
||||
var self = this;
|
||||
// Move past the pragma invocation
|
||||
this.parser.pos = this.matchRegExp.lastIndex;
|
||||
// Parse the filter terminated by a line break
|
||||
var reMatch = /(.*)(\r?\n)|$/mg;
|
||||
reMatch.lastIndex = this.parser.pos;
|
||||
var match = reMatch.exec(this.parser.source);
|
||||
this.parser.pos = reMatch.lastIndex;
|
||||
// Parse tree nodes to return
|
||||
return [{
|
||||
type: "importvariables",
|
||||
attributes: {
|
||||
filter: {type: "string", value: match[1]}
|
||||
},
|
||||
children: []
|
||||
}];
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -84,7 +84,8 @@ exports.parse = function() {
|
||||
value: {type: "string", value: text}
|
||||
},
|
||||
children: [],
|
||||
params: params
|
||||
params: params,
|
||||
isMacroDefinition: true
|
||||
}];
|
||||
};
|
||||
|
||||
|
||||
@@ -49,13 +49,12 @@ exports.parse = function() {
|
||||
}];
|
||||
} else {
|
||||
return [{
|
||||
type: "link",
|
||||
attributes: {
|
||||
to: {type: "string", value: link}
|
||||
},
|
||||
children: [{
|
||||
type: "text", text: text
|
||||
}]
|
||||
type: "macrocall",
|
||||
name: "tm-prettylink-internal",
|
||||
params: [
|
||||
{name: "to", value: link},
|
||||
{name: "text", value: text}
|
||||
]
|
||||
}];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@ function SaverHandler(options) {
|
||||
var self = this;
|
||||
this.wiki = options.wiki;
|
||||
this.dirtyTracking = options.dirtyTracking;
|
||||
this.preloadDirty = options.preloadDirty || [];
|
||||
this.pendingAutoSave = false;
|
||||
// Make a logger
|
||||
this.logger = new $tw.utils.Logger("saver-handler");
|
||||
@@ -33,7 +34,13 @@ function SaverHandler(options) {
|
||||
// Compile the dirty tiddler filter
|
||||
this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter));
|
||||
// Count of changes that have not yet been saved
|
||||
this.numChanges = 0;
|
||||
var filteredChanges = self.filterFn.call(self.wiki,function(iterator) {
|
||||
$tw.utils.each(self.preloadDirty,function(title) {
|
||||
var tiddler = self.wiki.getTiddler(title);
|
||||
iterator(tiddler,title);
|
||||
});
|
||||
});
|
||||
this.numChanges = filteredChanges.length;
|
||||
// Listen out for changes to tiddlers
|
||||
this.wiki.addEventListener("change",function(changes) {
|
||||
// Filter the changes so that we only count changes to tiddlers that we care about
|
||||
@@ -144,8 +151,12 @@ Save the wiki contents. Options are:
|
||||
SaverHandler.prototype.saveWiki = function(options) {
|
||||
options = options || {};
|
||||
var self = this,
|
||||
method = options.method || "save",
|
||||
variables = options.variables || {},
|
||||
method = options.method || "save";
|
||||
// Ignore autosave if disabled
|
||||
if(method === "autosave" && this.wiki.getTiddlerText(this.titleAutoSave,"yes") !== "yes") {
|
||||
return false;
|
||||
}
|
||||
var variables = options.variables || {},
|
||||
template = options.template || "$:/core/save/all",
|
||||
downloadType = options.downloadType || "text/plain",
|
||||
text = this.wiki.renderTiddler(downloadType,template,options),
|
||||
@@ -164,10 +175,6 @@ SaverHandler.prototype.saveWiki = function(options) {
|
||||
}
|
||||
}
|
||||
};
|
||||
// Ignore autosave if disabled
|
||||
if(method === "autosave" && this.wiki.getTiddlerText(this.titleAutoSave,"yes") !== "yes") {
|
||||
return false;
|
||||
}
|
||||
// Call the highest priority saver that supports this method
|
||||
for(var t=this.savers.length-1; t>=0; t--) {
|
||||
var saver = this.savers[t];
|
||||
|
||||
@@ -18,16 +18,22 @@ to the current URL, such as a WebDAV server.
|
||||
/*
|
||||
Retrieve ETag if available
|
||||
*/
|
||||
var RetrieveETag = function(self) {
|
||||
var headers = { "Accept": "*/*;charset=UTF-8" };
|
||||
var retrieveETag = function(self) {
|
||||
var headers = {
|
||||
Accept: "*/*;charset=UTF-8"
|
||||
};
|
||||
$tw.utils.httpRequest({
|
||||
url: self.uri(),
|
||||
type: "HEAD",
|
||||
headers: headers,
|
||||
callback: function(err, data, xhr) {
|
||||
if(err) return;
|
||||
callback: function(err,data,xhr) {
|
||||
if(err) {
|
||||
return;
|
||||
}
|
||||
var etag = xhr.getResponseHeader("ETag");
|
||||
if(!etag) return;
|
||||
if(!etag) {
|
||||
return;
|
||||
}
|
||||
self.etag = etag.replace(/^W\//,"");
|
||||
}
|
||||
});
|
||||
@@ -46,14 +52,14 @@ var PutSaver = function(wiki) {
|
||||
$tw.utils.httpRequest({
|
||||
url: uri,
|
||||
type: "OPTIONS",
|
||||
callback: function(err, data, xhr) {
|
||||
callback: function(err,data,xhr) {
|
||||
// Check DAV header http://www.webdav.org/specs/rfc2518.html#rfc.section.9.1
|
||||
if(!err) {
|
||||
self.serverAcceptsPuts = xhr.status === 200 && !!xhr.getResponseHeader("dav");
|
||||
}
|
||||
}
|
||||
});
|
||||
RetrieveETag(this);
|
||||
retrieveETag(this);
|
||||
};
|
||||
|
||||
PutSaver.prototype.uri = function() {
|
||||
@@ -63,12 +69,14 @@ PutSaver.prototype.uri = function() {
|
||||
// TODO: in case of edit conflict
|
||||
// Prompt: Do you want to save over this? Y/N
|
||||
// Merging would be ideal, and may be possible using future generic merge flow
|
||||
PutSaver.prototype.save = function(text, method, callback) {
|
||||
PutSaver.prototype.save = function(text,method,callback) {
|
||||
if(!this.serverAcceptsPuts) {
|
||||
return false;
|
||||
}
|
||||
var self = this;
|
||||
var headers = { "Content-Type": "text/html;charset=UTF-8" };
|
||||
var headers = {
|
||||
"Content-Type": "text/html;charset=UTF-8"
|
||||
};
|
||||
if(this.etag) {
|
||||
headers["If-Match"] = this.etag;
|
||||
}
|
||||
@@ -77,10 +85,10 @@ PutSaver.prototype.save = function(text, method, callback) {
|
||||
type: "PUT",
|
||||
headers: headers,
|
||||
data: text,
|
||||
callback: function(err, data, xhr) {
|
||||
callback: function(err,data,xhr) {
|
||||
if(err) {
|
||||
// response is textual: "XMLHttpRequest error code: 412"
|
||||
const status = Number(err.substring(err.indexOf(':') + 2, err.length))
|
||||
var status = Number(err.substring(err.indexOf(':') + 2, err.length))
|
||||
if(status === 412) { // edit conflict
|
||||
var message = $tw.language.getString("Error/EditConflict");
|
||||
callback(message);
|
||||
@@ -89,8 +97,8 @@ PutSaver.prototype.save = function(text, method, callback) {
|
||||
}
|
||||
} else {
|
||||
self.etag = xhr.getResponseHeader("ETag");
|
||||
if (self.etag == null) {
|
||||
RetrieveETag(self);
|
||||
if(self.etag == null) {
|
||||
retrieveETag(self);
|
||||
}
|
||||
callback(null); // success
|
||||
}
|
||||
@@ -105,7 +113,7 @@ Information about this saver
|
||||
PutSaver.prototype.info = {
|
||||
name: "put",
|
||||
priority: 2000,
|
||||
capabilities: ["save", "autosave"]
|
||||
capabilities: ["save","autosave"]
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
94
core/modules/server/authenticators/basic.js
Normal file
94
core/modules/server/authenticators/basic.js
Normal file
@@ -0,0 +1,94 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/authenticators/basic.js
|
||||
type: application/javascript
|
||||
module-type: authenticator
|
||||
|
||||
Authenticator for WWW basic authentication
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
if($tw.node) {
|
||||
var util = require("util"),
|
||||
fs = require("fs"),
|
||||
url = require("url"),
|
||||
path = require("path");
|
||||
}
|
||||
|
||||
function BasicAuthenticator(server) {
|
||||
this.server = server;
|
||||
this.credentialsData = [];
|
||||
}
|
||||
|
||||
/*
|
||||
Returns true if the authenticator is active, false if it is inactive, or a string if there is an error
|
||||
*/
|
||||
BasicAuthenticator.prototype.init = function() {
|
||||
// Read the credentials data
|
||||
this.credentialsFilepath = this.server.get("credentials");
|
||||
if(this.credentialsFilepath) {
|
||||
var resolveCredentialsFilepath = path.resolve($tw.boot.wikiPath,this.credentialsFilepath);
|
||||
if(fs.existsSync(resolveCredentialsFilepath) && !fs.statSync(resolveCredentialsFilepath).isDirectory()) {
|
||||
var credentialsText = fs.readFileSync(resolveCredentialsFilepath,"utf8"),
|
||||
credentialsData = $tw.utils.parseCsvStringWithHeader(credentialsText);
|
||||
if(typeof credentialsData === "string") {
|
||||
return "Error: " + credentialsData + " reading credentials from '" + resolveCredentialsFilepath + "'";
|
||||
} else {
|
||||
this.credentialsData = credentialsData;
|
||||
}
|
||||
} else {
|
||||
return "Error: Unable to load user credentials from '" + credentialsFilepath + "'";
|
||||
}
|
||||
}
|
||||
// Add the hardcoded username and password if specified
|
||||
if(this.server.get("username") && this.server.get("password")) {
|
||||
this.credentialsData = this.credentialsData || [];
|
||||
this.credentialsData.push({
|
||||
username: this.server.get("username"),
|
||||
password: this.server.get("password")
|
||||
});
|
||||
}
|
||||
return this.credentialsData.length > 0;
|
||||
};
|
||||
|
||||
/*
|
||||
Returns true if the request is authenticated and assigns the "authenticatedUsername" state variable.
|
||||
Returns false if the request couldn't be authenticated having sent an appropriate response to the browser
|
||||
*/
|
||||
BasicAuthenticator.prototype.authenticateRequest = function(request,response,state) {
|
||||
// Extract the incoming username and password from the request
|
||||
var header = request.headers.authorization || "";
|
||||
if(!header && state.allowAnon) {
|
||||
// If there's no header and anonymous access is allowed then we don't set authenticatedUsername
|
||||
return true;
|
||||
}
|
||||
var token = header.split(/\s+/).pop() || "",
|
||||
auth = $tw.utils.base64Decode(token),
|
||||
parts = auth.split(/:/),
|
||||
incomingUsername = parts[0],
|
||||
incomingPassword = parts[1];
|
||||
// Check that at least one of the credentials matches
|
||||
var matchingCredentials = this.credentialsData.find(function(credential) {
|
||||
return credential.username === incomingUsername && credential.password === incomingPassword;
|
||||
});
|
||||
if(matchingCredentials) {
|
||||
// If so, add the authenticated username to the request state
|
||||
state.authenticatedUsername = incomingUsername;
|
||||
return true;
|
||||
} else {
|
||||
// If not, return an authentication challenge
|
||||
response.writeHead(401,"Authentication required",{
|
||||
"WWW-Authenticate": 'Basic realm="Please provide your username and password to login to ' + state.server.servername + '"'
|
||||
});
|
||||
response.end();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
exports.AuthenticatorClass = BasicAuthenticator;
|
||||
|
||||
})();
|
||||
47
core/modules/server/authenticators/header.js
Normal file
47
core/modules/server/authenticators/header.js
Normal file
@@ -0,0 +1,47 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/authenticators/header.js
|
||||
type: application/javascript
|
||||
module-type: authenticator
|
||||
|
||||
Authenticator for trusted header authentication
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
function HeaderAuthenticator(server) {
|
||||
this.server = server;
|
||||
this.header = server.get("authenticated-user-header");
|
||||
}
|
||||
|
||||
/*
|
||||
Returns true if the authenticator is active, false if it is inactive, or a string if there is an error
|
||||
*/
|
||||
HeaderAuthenticator.prototype.init = function() {
|
||||
return !!this.header;
|
||||
};
|
||||
|
||||
/*
|
||||
Returns true if the request is authenticated and assigns the "authenticatedUsername" state variable.
|
||||
Returns false if the request couldn't be authenticated having sent an appropriate response to the browser
|
||||
*/
|
||||
HeaderAuthenticator.prototype.authenticateRequest = function(request,response,state) {
|
||||
// Otherwise, authenticate as the username in the specified header
|
||||
var username = request.headers[this.header];
|
||||
if(!username && !state.allowAnon) {
|
||||
response.writeHead(401,"Authorization header required to login to '" + state.server.servername + "'");
|
||||
response.end();
|
||||
return false;
|
||||
} else {
|
||||
// authenticatedUsername will be undefined for anonymous users
|
||||
state.authenticatedUsername = username;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
exports.AuthenticatorClass = HeaderAuthenticator;
|
||||
|
||||
})();
|
||||
28
core/modules/server/routes/delete-tiddler.js
Normal file
28
core/modules/server/routes/delete-tiddler.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/routes/delete-tiddler.js
|
||||
type: application/javascript
|
||||
module-type: route
|
||||
|
||||
DELETE /recipes/default/tiddlers/:title
|
||||
|
||||
\*/
|
||||
(function() {
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.method = "DELETE";
|
||||
|
||||
exports.path = /^\/bags\/default\/tiddlers\/(.+)$/;
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
var title = decodeURIComponent(state.params[0]);
|
||||
state.wiki.deleteTiddler(title);
|
||||
response.writeHead(204, "OK", {
|
||||
"Content-Type": "text/plain"
|
||||
});
|
||||
response.end();
|
||||
};
|
||||
|
||||
}());
|
||||
25
core/modules/server/routes/get-favicon.js
Normal file
25
core/modules/server/routes/get-favicon.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/routes/get-favicon.js
|
||||
type: application/javascript
|
||||
module-type: route
|
||||
|
||||
GET /favicon.ico
|
||||
|
||||
\*/
|
||||
(function() {
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.method = "GET";
|
||||
|
||||
exports.path = /^\/favicon.ico$/;
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
response.writeHead(200, {"Content-Type": "image/x-icon"});
|
||||
var buffer = state.wiki.getTiddlerText("$:/favicon.ico","");
|
||||
response.end(buffer,"base64");
|
||||
};
|
||||
|
||||
}());
|
||||
50
core/modules/server/routes/get-file.js
Normal file
50
core/modules/server/routes/get-file.js
Normal file
@@ -0,0 +1,50 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/routes/get-file.js
|
||||
type: application/javascript
|
||||
module-type: route
|
||||
|
||||
GET /files/:filepath
|
||||
|
||||
\*/
|
||||
(function() {
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.method = "GET";
|
||||
|
||||
exports.path = /^\/files\/(.+)$/;
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
var path = require("path"),
|
||||
fs = require("fs"),
|
||||
util = require("util");
|
||||
var filename = path.resolve($tw.boot.wikiPath,"files",decodeURIComponent(state.params[0])),
|
||||
extension = path.extname(filename);
|
||||
fs.readFile(filename,function(err,content) {
|
||||
var status,content,type = "text/plain";
|
||||
if(err) {
|
||||
if(err.code === "ENOENT") {
|
||||
status = 404;
|
||||
content = "File '" + filename + "' not found";
|
||||
} else if(err.code === "EACCES") {
|
||||
status = 403;
|
||||
content = "You do not have permission to access the file '" + filename + "'";
|
||||
} else {
|
||||
status = 500;
|
||||
content = err.toString();
|
||||
}
|
||||
} else {
|
||||
status = 200;
|
||||
content = content;
|
||||
type = ($tw.config.fileExtensionInfo[extension] ? $tw.config.fileExtensionInfo[extension].type : "application/octet-stream");
|
||||
}
|
||||
response.writeHead(status,{
|
||||
"Content-Type": type
|
||||
});
|
||||
response.end(content);
|
||||
});
|
||||
};
|
||||
|
||||
}());
|
||||
51
core/modules/server/routes/get-index.js
Normal file
51
core/modules/server/routes/get-index.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/routes/get-index.js
|
||||
type: application/javascript
|
||||
module-type: route
|
||||
|
||||
GET /
|
||||
|
||||
\*/
|
||||
(function() {
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var zlib = require('zlib');
|
||||
|
||||
exports.method = "GET";
|
||||
|
||||
exports.path = /^\/$/;
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
var acceptEncoding = request.headers['accept-encoding'];
|
||||
if (!acceptEncoding) { acceptEncoding = ''; }
|
||||
|
||||
var text = state.wiki.renderTiddler(state.server.get("root-render-type"),state.server.get("root-tiddler"));
|
||||
|
||||
var responseHeaders = {
|
||||
"Content-Type": state.server.get("root-serve-type")
|
||||
};
|
||||
|
||||
/*
|
||||
If the gzip=yes flag for `listen` is set, check if the user agent permits
|
||||
compression. If so, compress our response. Note that we use the synchronous
|
||||
functions from zlib to stay in the imperative style. The current `Server`
|
||||
doesn't depend on this, and we may just as well use the async versions.
|
||||
*/
|
||||
if(state.server.enableGzip) {
|
||||
if (/\bdeflate\b/.test(acceptEncoding)) {
|
||||
responseHeaders['Content-Encoding'] = 'deflate';
|
||||
text = zlib.deflateSync(text);
|
||||
} else if (/\bgzip\b/.test(acceptEncoding)) {
|
||||
responseHeaders['Content-Encoding'] = 'gzip';
|
||||
text = zlib.gzipSync(text);
|
||||
}
|
||||
}
|
||||
|
||||
response.writeHead(200, responseHeaders);
|
||||
response.end(text);
|
||||
};
|
||||
|
||||
}());
|
||||
35
core/modules/server/routes/get-login-basic.js
Normal file
35
core/modules/server/routes/get-login-basic.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/routes/get-login-basic.js
|
||||
type: application/javascript
|
||||
module-type: route
|
||||
|
||||
GET /login-basic -- force a Basic Authentication challenge
|
||||
|
||||
\*/
|
||||
(function() {
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.method = "GET";
|
||||
|
||||
exports.path = /^\/login-basic$/;
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
if(!state.authenticatedUsername) {
|
||||
// Challenge if there's no username
|
||||
response.writeHead(401,{
|
||||
"WWW-Authenticate": 'Basic realm="Please provide your username and password to login to ' + state.server.servername + '"'
|
||||
});
|
||||
response.end();
|
||||
} else {
|
||||
// Redirect to the root wiki if login worked
|
||||
response.writeHead(302,{
|
||||
Location: "/"
|
||||
});
|
||||
response.end();
|
||||
}
|
||||
};
|
||||
|
||||
}());
|
||||
33
core/modules/server/routes/get-status.js
Normal file
33
core/modules/server/routes/get-status.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/routes/get-status.js
|
||||
type: application/javascript
|
||||
module-type: route
|
||||
|
||||
GET /status
|
||||
|
||||
\*/
|
||||
(function() {
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.method = "GET";
|
||||
|
||||
exports.path = /^\/status$/;
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
response.writeHead(200, {"Content-Type": "application/json"});
|
||||
var text = JSON.stringify({
|
||||
username: state.authenticatedUsername || state.server.get("anon-username") || "",
|
||||
anonymous: !state.authenticatedUsername,
|
||||
read_only: !state.server.isAuthorized("writers",state.authenticatedUsername),
|
||||
space: {
|
||||
recipe: "default"
|
||||
},
|
||||
tiddlywiki_version: $tw.version
|
||||
});
|
||||
response.end(text,"utf8");
|
||||
};
|
||||
|
||||
}());
|
||||
44
core/modules/server/routes/get-tiddler-html.js
Normal file
44
core/modules/server/routes/get-tiddler-html.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/routes/get-tiddler-html.js
|
||||
type: application/javascript
|
||||
module-type: route
|
||||
|
||||
GET /:title
|
||||
|
||||
\*/
|
||||
(function() {
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.method = "GET";
|
||||
|
||||
exports.path = /^\/([^\/]+)$/;
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
var title = decodeURIComponent(state.params[0]),
|
||||
tiddler = state.wiki.getTiddler(title);
|
||||
if(tiddler) {
|
||||
var renderType = tiddler.getFieldString("_render_type"),
|
||||
renderTemplate = tiddler.getFieldString("_render_template");
|
||||
// Tiddler fields '_render_type' and '_render_template' overwrite
|
||||
// system wide settings for render type and template
|
||||
if(state.wiki.isSystemTiddler(title)) {
|
||||
renderType = renderType || state.server.get("system-tiddler-render-type");
|
||||
renderTemplate = renderTemplate || state.server.get("system-tiddler-render-template");
|
||||
} else {
|
||||
renderType = renderType || state.server.get("tiddler-render-type");
|
||||
renderTemplate = renderTemplate || state.server.get("tiddler-render-template");
|
||||
}
|
||||
var text = state.wiki.renderTiddler(renderType,renderTemplate,{parseAsInline: true, variables: {currentTiddler: title}});
|
||||
// Naughty not to set a content-type, but it's the easiest way to ensure the browser will see HTML pages as HTML, and accept plain text tiddlers as CSS or JS
|
||||
response.writeHead(200);
|
||||
response.end(text,"utf8");
|
||||
} else {
|
||||
response.writeHead(404);
|
||||
response.end();
|
||||
}
|
||||
};
|
||||
|
||||
}());
|
||||
46
core/modules/server/routes/get-tiddler.js
Normal file
46
core/modules/server/routes/get-tiddler.js
Normal file
@@ -0,0 +1,46 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/routes/get-tiddler.js
|
||||
type: application/javascript
|
||||
module-type: route
|
||||
|
||||
GET /recipes/default/tiddlers/:title
|
||||
|
||||
\*/
|
||||
(function() {
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.method = "GET";
|
||||
|
||||
exports.path = /^\/recipes\/default\/tiddlers\/(.+)$/;
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
var title = decodeURIComponent(state.params[0]),
|
||||
tiddler = state.wiki.getTiddler(title),
|
||||
tiddlerFields = {},
|
||||
knownFields = [
|
||||
"bag", "created", "creator", "modified", "modifier", "permissions", "recipe", "revision", "tags", "text", "title", "type", "uri"
|
||||
];
|
||||
if(tiddler) {
|
||||
$tw.utils.each(tiddler.fields,function(field,name) {
|
||||
var value = tiddler.getFieldString(name);
|
||||
if(knownFields.indexOf(name) !== -1) {
|
||||
tiddlerFields[name] = value;
|
||||
} else {
|
||||
tiddlerFields.fields = tiddlerFields.fields || {};
|
||||
tiddlerFields.fields[name] = value;
|
||||
}
|
||||
});
|
||||
tiddlerFields.revision = state.wiki.getChangeCount(title);
|
||||
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
||||
response.writeHead(200, {"Content-Type": "application/json"});
|
||||
response.end(JSON.stringify(tiddlerFields),"utf8");
|
||||
} else {
|
||||
response.writeHead(404);
|
||||
response.end();
|
||||
}
|
||||
};
|
||||
|
||||
}());
|
||||
37
core/modules/server/routes/get-tiddlers-json.js
Normal file
37
core/modules/server/routes/get-tiddlers-json.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/routes/get-tiddlers-json.js
|
||||
type: application/javascript
|
||||
module-type: route
|
||||
|
||||
GET /recipes/default/tiddlers/tiddlers.json
|
||||
|
||||
\*/
|
||||
(function() {
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.method = "GET";
|
||||
|
||||
exports.path = /^\/recipes\/default\/tiddlers.json$/;
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
response.writeHead(200, {"Content-Type": "application/json"});
|
||||
var tiddlers = [];
|
||||
state.wiki.forEachTiddler({sortField: "title"},function(title,tiddler) {
|
||||
var tiddlerFields = {};
|
||||
$tw.utils.each(tiddler.fields,function(field,name) {
|
||||
if(name !== "text") {
|
||||
tiddlerFields[name] = tiddler.getFieldString(name);
|
||||
}
|
||||
});
|
||||
tiddlerFields.revision = state.wiki.getChangeCount(title);
|
||||
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
||||
tiddlers.push(tiddlerFields);
|
||||
});
|
||||
var text = JSON.stringify(tiddlers);
|
||||
response.end(text,"utf8");
|
||||
};
|
||||
|
||||
}());
|
||||
42
core/modules/server/routes/put-tiddler.js
Normal file
42
core/modules/server/routes/put-tiddler.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/routes/put-tiddler.js
|
||||
type: application/javascript
|
||||
module-type: route
|
||||
|
||||
PUT /recipes/default/tiddlers/:title
|
||||
|
||||
\*/
|
||||
(function() {
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.method = "PUT";
|
||||
|
||||
exports.path = /^\/recipes\/default\/tiddlers\/(.+)$/;
|
||||
|
||||
exports.handler = function(request,response,state) {
|
||||
var title = decodeURIComponent(state.params[0]),
|
||||
fields = JSON.parse(state.data);
|
||||
// Pull up any subfields in the `fields` object
|
||||
if(fields.fields) {
|
||||
$tw.utils.each(fields.fields,function(field,name) {
|
||||
fields[name] = field;
|
||||
});
|
||||
delete fields.fields;
|
||||
}
|
||||
// Remove any revision field
|
||||
if(fields.revision) {
|
||||
delete fields.revision;
|
||||
}
|
||||
state.wiki.addTiddler(new $tw.Tiddler(state.wiki.getCreationFields(),fields,{title: title},state.wiki.getModificationFields()));
|
||||
var changeCount = state.wiki.getChangeCount(title).toString();
|
||||
response.writeHead(204, "OK",{
|
||||
Etag: "\"default/" + encodeURIComponent(title) + "/" + changeCount + ":\"",
|
||||
"Content-Type": "text/plain"
|
||||
});
|
||||
response.end();
|
||||
};
|
||||
|
||||
}());
|
||||
265
core/modules/server/server.js
Normal file
265
core/modules/server/server.js
Normal file
@@ -0,0 +1,265 @@
|
||||
/*\
|
||||
title: $:/core/modules/server/server.js
|
||||
type: application/javascript
|
||||
module-type: library
|
||||
|
||||
Serve tiddlers over http
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
if($tw.node) {
|
||||
var util = require("util"),
|
||||
fs = require("fs"),
|
||||
url = require("url"),
|
||||
path = require("path");
|
||||
}
|
||||
|
||||
/*
|
||||
A simple HTTP server with regexp-based routes
|
||||
options: variables - optional hashmap of variables to set (a misnomer - they are really constant parameters)
|
||||
routes - optional array of routes to use
|
||||
wiki - reference to wiki object
|
||||
*/
|
||||
function Server(options) {
|
||||
var self = this;
|
||||
this.routes = options.routes || [];
|
||||
this.authenticators = options.authenticators || [];
|
||||
this.wiki = options.wiki;
|
||||
this.servername = $tw.utils.transliterateToSafeASCII(this.wiki.getTiddlerText("$:/SiteTitle") || "TiddlyWiki5");
|
||||
// Initialise the variables
|
||||
this.variables = $tw.utils.extend({},this.defaultVariables);
|
||||
if(options.variables) {
|
||||
for(var variable in options.variables) {
|
||||
if(options.variables[variable]) {
|
||||
this.variables[variable] = options.variables[variable];
|
||||
}
|
||||
}
|
||||
}
|
||||
$tw.utils.extend({},this.defaultVariables,options.variables);
|
||||
// Initialise CSRF
|
||||
this.csrfDisable = this.get("csrf-disable") === "yes";
|
||||
// Initialize Gzip compression
|
||||
this.enableGzip = this.get("gzip") === "yes";
|
||||
// Initialise authorization
|
||||
var authorizedUserName = (this.get("username") && this.get("password")) ? this.get("username") : "(anon)";
|
||||
this.authorizationPrincipals = {
|
||||
readers: (this.get("readers") || authorizedUserName).split(",").map($tw.utils.trim),
|
||||
writers: (this.get("writers") || authorizedUserName).split(",").map($tw.utils.trim)
|
||||
}
|
||||
// Load and initialise authenticators
|
||||
$tw.modules.forEachModuleOfType("authenticator", function(title,authenticatorDefinition) {
|
||||
// console.log("Loading server route " + title);
|
||||
self.addAuthenticator(authenticatorDefinition.AuthenticatorClass);
|
||||
});
|
||||
// Load route handlers
|
||||
$tw.modules.forEachModuleOfType("route", function(title,routeDefinition) {
|
||||
// console.log("Loading server route " + title);
|
||||
self.addRoute(routeDefinition);
|
||||
});
|
||||
// Initialise the http vs https
|
||||
this.listenOptions = null;
|
||||
this.protocol = "http";
|
||||
var tlsKeyFilepath = this.get("tls-key"),
|
||||
tlsCertFilepath = this.get("tls-cert");
|
||||
if(tlsCertFilepath && tlsKeyFilepath) {
|
||||
this.listenOptions = {
|
||||
key: fs.readFileSync(path.resolve($tw.boot.wikiPath,tlsKeyFilepath),"utf8"),
|
||||
cert: fs.readFileSync(path.resolve($tw.boot.wikiPath,tlsCertFilepath),"utf8")
|
||||
};
|
||||
this.protocol = "https";
|
||||
}
|
||||
this.transport = require(this.protocol);
|
||||
}
|
||||
|
||||
Server.prototype.defaultVariables = {
|
||||
port: "8080",
|
||||
host: "127.0.0.1",
|
||||
"root-tiddler": "$:/core/save/all",
|
||||
"root-render-type": "text/plain",
|
||||
"root-serve-type": "text/html",
|
||||
"tiddler-render-type": "text/html",
|
||||
"tiddler-render-template": "$:/core/templates/server/static.tiddler.html",
|
||||
"system-tiddler-render-type": "text/plain",
|
||||
"system-tiddler-render-template": "$:/core/templates/wikified-tiddler",
|
||||
"debug-level": "none",
|
||||
"gzip": "no"
|
||||
};
|
||||
|
||||
Server.prototype.get = function(name) {
|
||||
return this.variables[name];
|
||||
};
|
||||
|
||||
Server.prototype.addRoute = function(route) {
|
||||
this.routes.push(route);
|
||||
};
|
||||
|
||||
Server.prototype.addAuthenticator = function(AuthenticatorClass) {
|
||||
// Instantiate and initialise the authenticator
|
||||
var authenticator = new AuthenticatorClass(this),
|
||||
result = authenticator.init();
|
||||
if(typeof result === "string") {
|
||||
$tw.utils.error("Error: " + result);
|
||||
} else if(result) {
|
||||
// Only use the authenticator if it initialised successfully
|
||||
this.authenticators.push(authenticator);
|
||||
}
|
||||
};
|
||||
|
||||
Server.prototype.findMatchingRoute = function(request,state) {
|
||||
var pathprefix = this.get("path-prefix") || "";
|
||||
for(var t=0; t<this.routes.length; t++) {
|
||||
var potentialRoute = this.routes[t],
|
||||
pathRegExp = potentialRoute.path,
|
||||
pathname = state.urlInfo.pathname,
|
||||
match;
|
||||
if(pathprefix) {
|
||||
if(pathname.substr(0,pathprefix.length) === pathprefix) {
|
||||
pathname = pathname.substr(pathprefix.length) || "/";
|
||||
match = potentialRoute.path.exec(pathname);
|
||||
} else {
|
||||
match = false;
|
||||
}
|
||||
} else {
|
||||
match = potentialRoute.path.exec(pathname);
|
||||
}
|
||||
if(match && request.method === potentialRoute.method) {
|
||||
state.params = [];
|
||||
for(var p=1; p<match.length; p++) {
|
||||
state.params.push(match[p]);
|
||||
}
|
||||
return potentialRoute;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Server.prototype.methodMappings = {
|
||||
"GET": "readers",
|
||||
"OPTIONS": "readers",
|
||||
"HEAD": "readers",
|
||||
"PUT": "writers",
|
||||
"POST": "writers",
|
||||
"DELETE": "writers"
|
||||
};
|
||||
|
||||
/*
|
||||
Check whether a given user is authorized for the specified authorizationType ("readers" or "writers"). Pass null or undefined as the username to check for anonymous access
|
||||
*/
|
||||
Server.prototype.isAuthorized = function(authorizationType,username) {
|
||||
var principals = this.authorizationPrincipals[authorizationType] || [];
|
||||
return principals.indexOf("(anon)") !== -1 || (username && (principals.indexOf("(authenticated)") !== -1 || principals.indexOf(username) !== -1));
|
||||
}
|
||||
|
||||
Server.prototype.requestHandler = function(request,response) {
|
||||
// Compose the state object
|
||||
var self = this;
|
||||
var state = {};
|
||||
state.wiki = self.wiki;
|
||||
state.server = self;
|
||||
state.urlInfo = url.parse(request.url);
|
||||
// Get the principals authorized to access this resource
|
||||
var authorizationType = this.methodMappings[request.method] || "readers";
|
||||
// Check for the CSRF header if this is a write
|
||||
if(!this.csrfDisable && authorizationType === "writers" && request.headers["x-requested-with"] !== "TiddlyWiki") {
|
||||
response.writeHead(403,"'X-Requested-With' header required to login to '" + this.servername + "'");
|
||||
response.end();
|
||||
return;
|
||||
}
|
||||
// Check whether anonymous access is granted
|
||||
state.allowAnon = this.isAuthorized(authorizationType,null);
|
||||
// Authenticate with the first active authenticator
|
||||
if(this.authenticators.length > 0) {
|
||||
if(!this.authenticators[0].authenticateRequest(request,response,state)) {
|
||||
// Bail if we failed (the authenticator will have sent the response)
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Authorize with the authenticated username
|
||||
if(!this.isAuthorized(authorizationType,state.authenticatedUsername)) {
|
||||
response.writeHead(401,"'" + state.authenticatedUsername + "' is not authorized to access '" + this.servername + "'");
|
||||
response.end();
|
||||
return;
|
||||
}
|
||||
// Find the route that matches this path
|
||||
var route = self.findMatchingRoute(request,state);
|
||||
// Optionally output debug info
|
||||
if(self.get("debug-level") !== "none") {
|
||||
console.log("Request path:",JSON.stringify(state.urlInfo));
|
||||
console.log("Request headers:",JSON.stringify(request.headers));
|
||||
console.log("authenticatedUsername:",state.authenticatedUsername);
|
||||
}
|
||||
// Return a 404 if we didn't find a route
|
||||
if(!route) {
|
||||
response.writeHead(404);
|
||||
response.end();
|
||||
return;
|
||||
}
|
||||
// Receive the request body if necessary and hand off to the route handler
|
||||
if(route.bodyFormat === "stream" || request.method === "GET" || request.method === "HEAD") {
|
||||
// Let the route handle the request stream itself
|
||||
route.handler(request,response,state);
|
||||
} else if(route.bodyFormat === "string" || !route.bodyFormat) {
|
||||
// Set the encoding for the incoming request
|
||||
request.setEncoding("utf8");
|
||||
var data = "";
|
||||
request.on("data",function(chunk) {
|
||||
data += chunk.toString();
|
||||
});
|
||||
request.on("end",function() {
|
||||
state.data = data;
|
||||
route.handler(request,response,state);
|
||||
});
|
||||
} else if(route.bodyFormat === "buffer") {
|
||||
var data = [];
|
||||
request.on("data",function(chunk) {
|
||||
data.push(chunk);
|
||||
});
|
||||
request.on("end",function() {
|
||||
state.data = Buffer.concat(data);
|
||||
route.handler(request,response,state);
|
||||
})
|
||||
} else {
|
||||
response.writeHead(400,"Invalid bodyFormat " + route.bodyFormat + " in route " + route.method + " " + route.path.source);
|
||||
response.end();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Listen for requests
|
||||
port: optional port number (falls back to value of "port" variable)
|
||||
host: optional host address (falls back to value of "host" variable)
|
||||
prefix: optional prefix (falls back to value of "path-prefix" variable)
|
||||
*/
|
||||
Server.prototype.listen = function(port,host,prefix) {
|
||||
// Handle defaults for port and host
|
||||
port = port || this.get("port");
|
||||
host = host || this.get("host");
|
||||
prefix = prefix || this.get("path-prefix") || "";
|
||||
// Check for the port being a string and look it up as an environment variable
|
||||
if(parseInt(port,10).toString() !== port) {
|
||||
port = process.env[port] || 8080;
|
||||
}
|
||||
$tw.utils.log("Serving on " + this.protocol + "://" + host + ":" + port + prefix,"brown/orange");
|
||||
$tw.utils.log("(press ctrl-C to exit)","red");
|
||||
// Warn if required plugins are missing
|
||||
if(!$tw.wiki.getTiddler("$:/plugins/tiddlywiki/tiddlyweb") || !$tw.wiki.getTiddler("$:/plugins/tiddlywiki/filesystem")) {
|
||||
$tw.utils.warning("Warning: Plugins required for client-server operation (\"tiddlywiki/filesystem\" and \"tiddlywiki/tiddlyweb\") are missing from tiddlywiki.info file");
|
||||
}
|
||||
// Listen
|
||||
var server;
|
||||
if(this.listenOptions) {
|
||||
server = this.transport.createServer(this.listenOptions,this.requestHandler.bind(this));
|
||||
} else {
|
||||
server = this.transport.createServer(this.requestHandler.bind(this));
|
||||
}
|
||||
return server.listen(port,host);
|
||||
};
|
||||
|
||||
exports.Server = Server;
|
||||
|
||||
})();
|
||||
@@ -59,14 +59,22 @@ exports.startup = function() {
|
||||
$tw.pageWidgetNode.render($tw.pageContainer,null);
|
||||
$tw.hooks.invokeHook("th-page-refreshed");
|
||||
})();
|
||||
// Remove any splash screen elements
|
||||
var removeList = document.querySelectorAll(".tc-remove-when-wiki-loaded");
|
||||
$tw.utils.each(removeList,function(removeItem) {
|
||||
if(removeItem.parentNode) {
|
||||
removeItem.parentNode.removeChild(removeItem);
|
||||
}
|
||||
});
|
||||
// Prepare refresh mechanism
|
||||
var deferredChanges = Object.create(null),
|
||||
timerId;
|
||||
function refresh() {
|
||||
// Process the refresh
|
||||
$tw.hooks.invokeHook("th-page-refreshing");
|
||||
$tw.pageWidgetNode.refresh(deferredChanges);
|
||||
deferredChanges = Object.create(null);
|
||||
$tw.hooks.invokeHook("th-page-refreshed");
|
||||
$tw.hooks.invokeHook("th-page-refreshed");
|
||||
}
|
||||
// Add the change event handler
|
||||
$tw.wiki.addEventListener("change",$tw.perf.report("mainRefresh",function(changes) {
|
||||
|
||||
@@ -23,7 +23,7 @@ exports.startup = function() {
|
||||
// Install the modal message mechanism
|
||||
$tw.modal = new $tw.utils.Modal($tw.wiki);
|
||||
$tw.rootWidget.addEventListener("tm-modal",function(event) {
|
||||
$tw.modal.display(event.param,{variables: event.paramObject});
|
||||
$tw.modal.display(event.param,{variables: event.paramObject, event: event});
|
||||
});
|
||||
// Install the notification mechanism
|
||||
$tw.notifier = new $tw.utils.Notifier($tw.wiki);
|
||||
@@ -42,10 +42,17 @@ exports.startup = function() {
|
||||
var fullscreen = $tw.utils.getFullScreenApis();
|
||||
if(fullscreen) {
|
||||
$tw.rootWidget.addEventListener("tm-full-screen",function(event) {
|
||||
if(document[fullscreen._fullscreenElement]) {
|
||||
document[fullscreen._exitFullscreen]();
|
||||
var fullScreenDocument = event.event ? event.event.target.ownerDocument : document;
|
||||
if(event.param === "enter") {
|
||||
fullScreenDocument.documentElement[fullscreen._requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
|
||||
} else if(event.param === "exit") {
|
||||
fullScreenDocument[fullscreen._exitFullscreen]();
|
||||
} else {
|
||||
document.documentElement[fullscreen._requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
|
||||
if(fullScreenDocument[fullscreen._fullscreenElement]) {
|
||||
fullScreenDocument[fullscreen._exitFullscreen]();
|
||||
} else {
|
||||
fullScreenDocument.documentElement[fullscreen._requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ exports.startup = function() {
|
||||
if($tw.browser) {
|
||||
$tw.platform.isMac = /Mac/.test(navigator.platform);
|
||||
$tw.platform.isWindows = /win/i.test(navigator.platform);
|
||||
$tw.platform.isLinux = /Linux/i.test(navigator.appVersion);
|
||||
$tw.platform.isLinux = /Linux/i.test(navigator.platform);
|
||||
} else {
|
||||
switch(require("os").platform()) {
|
||||
case "darwin":
|
||||
@@ -55,6 +55,27 @@ exports.startup = function() {
|
||||
$tw.version = $tw.utils.extractVersionInfo();
|
||||
// Set up the performance framework
|
||||
$tw.perf = new $tw.Performance($tw.wiki.getTiddlerText(PERFORMANCE_INSTRUMENTATION_CONFIG_TITLE,"no") === "yes");
|
||||
// Create a root widget for attaching event handlers. By using it as the parentWidget for another widget tree, one can reuse the event handlers
|
||||
$tw.rootWidget = new widget.widget({
|
||||
type: "widget",
|
||||
children: []
|
||||
},{
|
||||
wiki: $tw.wiki,
|
||||
document: $tw.browser ? document : $tw.fakeDocument
|
||||
});
|
||||
// Execute any startup actions
|
||||
var executeStartupTiddlers = function(tag) {
|
||||
$tw.utils.each($tw.wiki.filterTiddlers("[all[shadows+tiddlers]tag[" + tag + "]!has[draft.of]]"),function(title) {
|
||||
$tw.rootWidget.invokeActionString($tw.wiki.getTiddlerText(title),$tw.rootWidget);
|
||||
});
|
||||
};
|
||||
executeStartupTiddlers("$:/tags/StartupAction");
|
||||
if($tw.browser) {
|
||||
executeStartupTiddlers("$:/tags/StartupAction/Browser");
|
||||
}
|
||||
if($tw.node) {
|
||||
executeStartupTiddlers("$:/tags/StartupAction/Node");
|
||||
}
|
||||
// Kick off the language manager and switcher
|
||||
$tw.language = new $tw.Language();
|
||||
$tw.languageSwitcher = new $tw.PluginSwitcher({
|
||||
@@ -62,7 +83,7 @@ exports.startup = function() {
|
||||
pluginType: "language",
|
||||
controllerTitle: "$:/language",
|
||||
defaultPlugins: [
|
||||
"$:/languages/en-US"
|
||||
"$:/languages/en-GB"
|
||||
],
|
||||
onSwitch: function(plugins) {
|
||||
if($tw.browser) {
|
||||
@@ -87,26 +108,13 @@ exports.startup = function() {
|
||||
});
|
||||
// Kick off the keyboard manager
|
||||
$tw.keyboardManager = new $tw.KeyboardManager();
|
||||
// Create a root widget for attaching event handlers. By using it as the parentWidget for another widget tree, one can reuse the event handlers
|
||||
$tw.rootWidget = new widget.widget({
|
||||
type: "widget",
|
||||
children: []
|
||||
},{
|
||||
wiki: $tw.wiki,
|
||||
document: $tw.browser ? document : $tw.fakeDocument
|
||||
});
|
||||
// Execute any startup actions
|
||||
var executeStartupTiddlers = function(tag) {
|
||||
$tw.utils.each($tw.wiki.filterTiddlers("[all[shadows+tiddlers]tag[" + tag + "]!has[draft.of]]"),function(title) {
|
||||
$tw.rootWidget.invokeActionString($tw.wiki.getTiddlerText(title),$tw.rootWidget);
|
||||
});
|
||||
};
|
||||
executeStartupTiddlers("$:/tags/StartupAction");
|
||||
// Listen for shortcuts
|
||||
if($tw.browser) {
|
||||
executeStartupTiddlers("$:/tags/StartupAction/Browser");
|
||||
}
|
||||
if($tw.node) {
|
||||
executeStartupTiddlers("$:/tags/StartupAction/Node");
|
||||
$tw.utils.addEventListeners(document,[{
|
||||
name: "keydown",
|
||||
handlerObject: $tw.keyboardManager,
|
||||
handlerMethod: "handleKeydownEvent"
|
||||
}]);
|
||||
}
|
||||
// Clear outstanding tiddler store change events to avoid an unnecessary refresh cycle at startup
|
||||
$tw.wiki.clearTiddlerEventQueue();
|
||||
@@ -122,7 +130,11 @@ exports.startup = function() {
|
||||
$tw.syncer = new $tw.Syncer({wiki: $tw.wiki, syncadaptor: $tw.syncadaptor});
|
||||
}
|
||||
// Setup the saver handler
|
||||
$tw.saverHandler = new $tw.SaverHandler({wiki: $tw.wiki, dirtyTracking: !$tw.syncadaptor});
|
||||
$tw.saverHandler = new $tw.SaverHandler({
|
||||
wiki: $tw.wiki,
|
||||
dirtyTracking: !$tw.syncadaptor,
|
||||
preloadDirty: $tw.boot.preloadDirty || []
|
||||
});
|
||||
// Host-specific startup
|
||||
if($tw.browser) {
|
||||
// Install the popup manager
|
||||
|
||||
@@ -27,10 +27,18 @@ var DEFAULT_TIDDLERS_TITLE = "$:/DefaultTiddlers";
|
||||
// Config
|
||||
var CONFIG_UPDATE_ADDRESS_BAR = "$:/config/Navigation/UpdateAddressBar"; // Can be "no", "permalink", "permaview"
|
||||
var CONFIG_UPDATE_HISTORY = "$:/config/Navigation/UpdateHistory"; // Can be "yes" or "no"
|
||||
var CONFIG_PERMALINKVIEW_COPY_TO_CLIPBOARD = "$:/config/Navigation/Permalinkview/CopyToClipboard"; // Can be "yes" (default) or "no"
|
||||
var CONFIG_PERMALINKVIEW_UPDATE_ADDRESS_BAR = "$:/config/Navigation/Permalinkview/UpdateAddressBar"; // Can be "yes" (default) or "no"
|
||||
|
||||
|
||||
// Links to help, if there is no param
|
||||
var HELP_OPEN_EXTERNAL_WINDOW = "http://tiddlywiki.com/#WidgetMessage%3A%20tm-open-external-window";
|
||||
|
||||
exports.startup = function() {
|
||||
// Open startup tiddlers
|
||||
openStartupTiddlers();
|
||||
openStartupTiddlers({
|
||||
disableHistory: $tw.boot.disableStartupNavigation
|
||||
});
|
||||
if($tw.browser) {
|
||||
// Set up location hash update
|
||||
$tw.wiki.addEventListener("change",function(changes) {
|
||||
@@ -53,6 +61,14 @@ exports.startup = function() {
|
||||
$tw.rootWidget.addEventListener("tm-browser-refresh",function(event) {
|
||||
window.location.reload(true);
|
||||
});
|
||||
// Listen for tm-open-external-window message
|
||||
$tw.rootWidget.addEventListener("tm-open-external-window",function(event) {
|
||||
var paramObject = event.paramObject || {},
|
||||
strUrl = event.param || HELP_OPEN_EXTERNAL_WINDOW,
|
||||
strWindowName = paramObject.windowName,
|
||||
strWindowFeatures = paramObject.windowFeatures;
|
||||
window.open(strUrl, strWindowName, strWindowFeatures);
|
||||
});
|
||||
// Listen for the tm-print message
|
||||
$tw.rootWidget.addEventListener("tm-print",function(event) {
|
||||
(event.event.view || window).print();
|
||||
@@ -66,30 +82,33 @@ exports.startup = function() {
|
||||
storyList = $tw.hooks.invokeHook("th-opening-default-tiddlers-list",storyList);
|
||||
$tw.wiki.addTiddler({title: DEFAULT_STORY_TITLE, text: "", list: storyList},$tw.wiki.getModificationFields());
|
||||
if(storyList[0]) {
|
||||
$tw.wiki.addToHistory(storyList[0]);
|
||||
$tw.wiki.addToHistory(storyList[0]);
|
||||
}
|
||||
});
|
||||
// Listen for the tm-permalink message
|
||||
$tw.rootWidget.addEventListener("tm-permalink",function(event) {
|
||||
updateLocationHash({
|
||||
updateAddressBar: "permalink",
|
||||
updateAddressBar: $tw.wiki.getTiddlerText(CONFIG_PERMALINKVIEW_UPDATE_ADDRESS_BAR,"yes").trim() === "yes" ? "permalink" : "none",
|
||||
updateHistory: $tw.wiki.getTiddlerText(CONFIG_UPDATE_HISTORY,"no").trim(),
|
||||
targetTiddler: event.param || event.tiddlerTitle
|
||||
targetTiddler: event.param || event.tiddlerTitle,
|
||||
copyToClipboard: $tw.wiki.getTiddlerText(CONFIG_PERMALINKVIEW_COPY_TO_CLIPBOARD,"yes").trim() === "yes" ? "permalink" : "none"
|
||||
});
|
||||
});
|
||||
// Listen for the tm-permaview message
|
||||
$tw.rootWidget.addEventListener("tm-permaview",function(event) {
|
||||
updateLocationHash({
|
||||
updateAddressBar: "permaview",
|
||||
updateAddressBar: $tw.wiki.getTiddlerText(CONFIG_PERMALINKVIEW_UPDATE_ADDRESS_BAR,"yes").trim() === "yes" ? "permaview" : "none",
|
||||
updateHistory: $tw.wiki.getTiddlerText(CONFIG_UPDATE_HISTORY,"no").trim(),
|
||||
targetTiddler: event.param || event.tiddlerTitle
|
||||
});
|
||||
targetTiddler: event.param || event.tiddlerTitle,
|
||||
copyToClipboard: $tw.wiki.getTiddlerText(CONFIG_PERMALINKVIEW_COPY_TO_CLIPBOARD,"yes").trim() === "yes" ? "permaview" : "none"
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Process the location hash to open the specified tiddlers. Options:
|
||||
disableHistory: if true $:/History is NOT updated
|
||||
defaultToCurrentStory: If true, the current story is retained as the default, instead of opening the default tiddlers
|
||||
*/
|
||||
function openStartupTiddlers(options) {
|
||||
@@ -130,15 +149,18 @@ function openStartupTiddlers(options) {
|
||||
}
|
||||
// Save the story list
|
||||
$tw.wiki.addTiddler({title: DEFAULT_STORY_TITLE, text: "", list: storyList},$tw.wiki.getModificationFields());
|
||||
// If a target tiddler was specified add it to the history stack
|
||||
if(target && target !== "") {
|
||||
// The target tiddler doesn't need double square brackets, but we'll silently remove them if they're present
|
||||
if(target.indexOf("[[") === 0 && target.substr(-2) === "]]") {
|
||||
target = target.substr(2,target.length - 4);
|
||||
}
|
||||
$tw.wiki.addToHistory(target);
|
||||
} else if(storyList.length > 0) {
|
||||
$tw.wiki.addToHistory(storyList[0]);
|
||||
// Update history
|
||||
if(!options.disableHistory) {
|
||||
// If a target tiddler was specified add it to the history stack
|
||||
if(target && target !== "") {
|
||||
// The target tiddler doesn't need double square brackets, but we'll silently remove them if they're present
|
||||
if(target.indexOf("[[") === 0 && target.substr(-2) === "]]") {
|
||||
target = target.substr(2,target.length - 4);
|
||||
}
|
||||
$tw.wiki.addToHistory(target);
|
||||
} else if(storyList.length > 0) {
|
||||
$tw.wiki.addToHistory(storyList[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,41 +168,52 @@ function openStartupTiddlers(options) {
|
||||
options: See below
|
||||
options.updateAddressBar: "permalink", "permaview" or "no" (defaults to "permaview")
|
||||
options.updateHistory: "yes" or "no" (defaults to "no")
|
||||
options.copyToClipboard: "permalink", "permaview" or "no" (defaults to "no")
|
||||
options.targetTiddler: optional title of target tiddler for permalink
|
||||
*/
|
||||
function updateLocationHash(options) {
|
||||
if(options.updateAddressBar !== "no") {
|
||||
// Get the story and the history stack
|
||||
var storyList = $tw.wiki.getTiddlerList(DEFAULT_STORY_TITLE),
|
||||
historyList = $tw.wiki.getTiddlerData(DEFAULT_HISTORY_TITLE,[]),
|
||||
// Get the story and the history stack
|
||||
var storyList = $tw.wiki.getTiddlerList(DEFAULT_STORY_TITLE),
|
||||
historyList = $tw.wiki.getTiddlerData(DEFAULT_HISTORY_TITLE,[]),
|
||||
targetTiddler = "";
|
||||
if(options.targetTiddler) {
|
||||
targetTiddler = options.targetTiddler;
|
||||
} else {
|
||||
// The target tiddler is the one at the top of the stack
|
||||
if(historyList.length > 0) {
|
||||
targetTiddler = historyList[historyList.length-1].title;
|
||||
}
|
||||
// Blank the target tiddler if it isn't present in the story
|
||||
if(storyList.indexOf(targetTiddler) === -1) {
|
||||
targetTiddler = "";
|
||||
if(options.targetTiddler) {
|
||||
targetTiddler = options.targetTiddler;
|
||||
} else {
|
||||
// The target tiddler is the one at the top of the stack
|
||||
if(historyList.length > 0) {
|
||||
targetTiddler = historyList[historyList.length-1].title;
|
||||
}
|
||||
// Blank the target tiddler if it isn't present in the story
|
||||
if(storyList.indexOf(targetTiddler) === -1) {
|
||||
targetTiddler = "";
|
||||
}
|
||||
}
|
||||
// Assemble the location hash
|
||||
if(options.updateAddressBar === "permalink") {
|
||||
}
|
||||
// Assemble the location hash
|
||||
switch(options.updateAddressBar) {
|
||||
case "permalink":
|
||||
$tw.locationHash = "#" + encodeURIComponent(targetTiddler);
|
||||
} else {
|
||||
break;
|
||||
case "permaview":
|
||||
$tw.locationHash = "#" + encodeURIComponent(targetTiddler) + ":" + encodeURIComponent($tw.utils.stringifyList(storyList));
|
||||
}
|
||||
// Only change the location hash if we must, thus avoiding unnecessary onhashchange events
|
||||
if($tw.utils.getLocationHash() !== $tw.locationHash) {
|
||||
if(options.updateHistory === "yes") {
|
||||
// Assign the location hash so that history is updated
|
||||
window.location.hash = $tw.locationHash;
|
||||
} else {
|
||||
// We use replace so that browser history isn't affected
|
||||
window.location.replace(window.location.toString().split("#")[0] + $tw.locationHash);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Copy URL to the clipboard
|
||||
switch(options.copyToClipboard) {
|
||||
case "permalink":
|
||||
$tw.utils.copyToClipboard($tw.utils.getLocationPath() + "#" + encodeURIComponent(targetTiddler));
|
||||
break;
|
||||
case "permaview":
|
||||
$tw.utils.copyToClipboard($tw.utils.getLocationPath() + "#" + encodeURIComponent(targetTiddler) + ":" + encodeURIComponent($tw.utils.stringifyList(storyList)));
|
||||
break;
|
||||
}
|
||||
// Only change the location hash if we must, thus avoiding unnecessary onhashchange events
|
||||
if($tw.utils.getLocationHash() !== $tw.locationHash) {
|
||||
if(options.updateHistory === "yes") {
|
||||
// Assign the location hash so that history is updated
|
||||
window.location.hash = $tw.locationHash;
|
||||
} else {
|
||||
// We use replace so that browser history isn't affected
|
||||
window.location.replace(window.location.toString().split("#")[0] + $tw.locationHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,16 @@ exports.startup = function() {
|
||||
height = paramObject.height || "600",
|
||||
variables = $tw.utils.extend({},paramObject,{currentTiddler: title});
|
||||
// Open the window
|
||||
var srcWindow = window.open("","external-" + title,"scrollbars,width=" + width + ",height=" + height),
|
||||
var srcWindow,
|
||||
srcDocument;
|
||||
// In case that popup blockers deny opening a new window
|
||||
try {
|
||||
srcWindow = window.open("","external-" + title,"scrollbars,width=" + width + ",height=" + height),
|
||||
srcDocument = srcWindow.document;
|
||||
}
|
||||
catch(e) {
|
||||
return;
|
||||
}
|
||||
windows[title] = srcWindow;
|
||||
// Check for reopening the same window
|
||||
if(srcWindow.haveInitialisedWindow) {
|
||||
@@ -70,6 +78,16 @@ exports.startup = function() {
|
||||
widgetNode.refresh(changes);
|
||||
};
|
||||
$tw.wiki.addEventListener("change",refreshHandler);
|
||||
// Listen for keyboard shortcuts
|
||||
$tw.utils.addEventListeners(srcDocument,[{
|
||||
name: "keydown",
|
||||
handlerObject: $tw.keyboardManager,
|
||||
handlerMethod: "handleKeydownEvent"
|
||||
},{
|
||||
name: "click",
|
||||
handlerObject: $tw.popup,
|
||||
handlerMethod: "handleEvent"
|
||||
}]);
|
||||
srcWindow.haveInitialisedWindow = true;
|
||||
});
|
||||
// Close open windows when unloading main window
|
||||
|
||||
@@ -16,8 +16,11 @@ The syncer tracks changes to the store. If a syncadaptor is used then individual
|
||||
Defaults
|
||||
*/
|
||||
Syncer.prototype.titleIsLoggedIn = "$:/status/IsLoggedIn";
|
||||
Syncer.prototype.titleIsAnonymous = "$:/status/IsAnonymous";
|
||||
Syncer.prototype.titleIsReadOnly = "$:/status/IsReadOnly";
|
||||
Syncer.prototype.titleUserName = "$:/status/UserName";
|
||||
Syncer.prototype.titleSyncFilter = "$:/config/SyncFilter";
|
||||
Syncer.prototype.titleSyncPollingInterval = "$:/config/SyncPollingInterval";
|
||||
Syncer.prototype.titleSavedNotification = "$:/language/Notifications/Save/Done";
|
||||
Syncer.prototype.taskTimerInterval = 1 * 1000; // Interval for sync timer
|
||||
Syncer.prototype.throttleInterval = 1 * 1000; // Defer saving tiddlers if they've changed in the last 1s...
|
||||
@@ -41,7 +44,7 @@ function Syncer(options) {
|
||||
this.taskTimerInterval = options.taskTimerInterval || this.taskTimerInterval;
|
||||
this.throttleInterval = options.throttleInterval || this.throttleInterval;
|
||||
this.fallbackInterval = options.fallbackInterval || this.fallbackInterval;
|
||||
this.pollTimerInterval = options.pollTimerInterval || this.pollTimerInterval;
|
||||
this.pollTimerInterval = options.pollTimerInterval || parseInt(this.wiki.getTiddlerText(this.titleSyncPollingInterval,""),10) || this.pollTimerInterval;
|
||||
this.logging = "logging" in options ? options.logging : true;
|
||||
// Make a logger
|
||||
this.logger = new $tw.utils.Logger("syncer" + ($tw.browser ? "-browser" : "") + ($tw.node ? "-server" : "") + (this.syncadaptor.name ? ("-" + this.syncadaptor.name) : ""),{
|
||||
@@ -151,7 +154,7 @@ Save an incoming tiddler in the store, and updates the associated tiddlerInfo
|
||||
*/
|
||||
Syncer.prototype.storeTiddler = function(tiddlerFields,hasBeenLazyLoaded) {
|
||||
// Save the tiddler
|
||||
var tiddler = new $tw.Tiddler(this.wiki.getTiddler(tiddlerFields.title),tiddlerFields);
|
||||
var tiddler = new $tw.Tiddler(tiddlerFields);
|
||||
this.wiki.addTiddler(tiddler);
|
||||
// Save the tiddler revision and changeCount details
|
||||
this.tiddlerInfo[tiddlerFields.title] = {
|
||||
@@ -169,12 +172,14 @@ Syncer.prototype.getStatus = function(callback) {
|
||||
// Mark us as not logged in
|
||||
this.wiki.addTiddler({title: this.titleIsLoggedIn,text: "no"});
|
||||
// Get login status
|
||||
this.syncadaptor.getStatus(function(err,isLoggedIn,username) {
|
||||
this.syncadaptor.getStatus(function(err,isLoggedIn,username,isReadOnly,isAnonymous) {
|
||||
if(err) {
|
||||
self.logger.alert(err);
|
||||
return;
|
||||
}
|
||||
// Set the various status tiddlers
|
||||
self.wiki.addTiddler({title: self.titleIsReadOnly,text: isReadOnly ? "yes" : "no"});
|
||||
self.wiki.addTiddler({title: self.titleIsAnonymous,text: isAnonymous ? "yes" : "no"});
|
||||
self.wiki.addTiddler({title: self.titleIsLoggedIn,text: isLoggedIn ? "yes" : "no"});
|
||||
if(isLoggedIn) {
|
||||
self.wiki.addTiddler({title: self.titleUserName,text: username || ""});
|
||||
|
||||
@@ -39,6 +39,18 @@ exports.getFieldString = function(field) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Get the value of a field as a list
|
||||
*/
|
||||
exports.getFieldList = function(field) {
|
||||
var value = this.fields[field];
|
||||
// Check for a missing field
|
||||
if(value === undefined || value === null) {
|
||||
return [];
|
||||
}
|
||||
return $tw.utils.parseStringArray(value);
|
||||
};
|
||||
|
||||
/*
|
||||
Get all the fields as a hashmap of strings. Options:
|
||||
exclude: an array of field names to exclude
|
||||
@@ -75,57 +87,6 @@ exports.getFieldStringBlock = function(options) {
|
||||
return fields.join("\n");
|
||||
};
|
||||
|
||||
/*
|
||||
Compare two tiddlers for equality
|
||||
tiddler: the tiddler to compare
|
||||
excludeFields: array of field names to exclude from the comparison
|
||||
*/
|
||||
exports.isEqual = function(tiddler,excludeFields) {
|
||||
if(!(tiddler instanceof $tw.Tiddler)) {
|
||||
return false;
|
||||
}
|
||||
excludeFields = excludeFields || [];
|
||||
var self = this,
|
||||
differences = []; // Fields that have differences
|
||||
// Add to the differences array
|
||||
function addDifference(fieldName) {
|
||||
// Check for this field being excluded
|
||||
if(excludeFields.indexOf(fieldName) === -1) {
|
||||
// Save the field as a difference
|
||||
$tw.utils.pushTop(differences,fieldName);
|
||||
}
|
||||
}
|
||||
// Returns true if the two values of this field are equal
|
||||
function isFieldValueEqual(fieldName) {
|
||||
var valueA = self.fields[fieldName],
|
||||
valueB = tiddler.fields[fieldName];
|
||||
// Check for identical string values
|
||||
if(typeof(valueA) === "string" && typeof(valueB) === "string" && valueA === valueB) {
|
||||
return true;
|
||||
}
|
||||
// Check for identical array values
|
||||
if($tw.utils.isArray(valueA) && $tw.utils.isArray(valueB) && $tw.utils.isArrayEqual(valueA,valueB)) {
|
||||
return true;
|
||||
}
|
||||
// Otherwise the fields must be different
|
||||
return false;
|
||||
}
|
||||
// Compare our fields
|
||||
for(var fieldName in this.fields) {
|
||||
if(!isFieldValueEqual(fieldName)) {
|
||||
addDifference(fieldName);
|
||||
}
|
||||
}
|
||||
// There's a difference for every field in the other tiddler that we don't have
|
||||
for(fieldName in tiddler.fields) {
|
||||
if(!(fieldName in this.fields)) {
|
||||
addDifference(fieldName);
|
||||
}
|
||||
}
|
||||
// Return whether there were any differences
|
||||
return differences.length === 0;
|
||||
};
|
||||
|
||||
exports.getFieldDay = function(field) {
|
||||
if(this.cache && this.cache.day && $tw.utils.hop(this.cache.day,field) ) {
|
||||
return this.cache.day[field];
|
||||
|
||||
@@ -13,11 +13,13 @@ Upgrader module that suppresses certain system tiddlers that shouldn't be import
|
||||
"use strict";
|
||||
|
||||
var DONT_IMPORT_LIST = ["$:/StoryList","$:/HistoryList"],
|
||||
DONT_IMPORT_PREFIX_LIST = ["$:/temp/","$:/state/"];
|
||||
DONT_IMPORT_PREFIX_LIST = ["$:/temp/","$:/state/","$:/Import"],
|
||||
WARN_IMPORT_PREFIX_LIST = ["$:/core/modules/"];
|
||||
|
||||
exports.upgrade = function(wiki,titles,tiddlers) {
|
||||
var self = this,
|
||||
messages = {};
|
||||
messages = {},
|
||||
showAlert = false;
|
||||
// Check for tiddlers on our list
|
||||
$tw.utils.each(titles,function(title) {
|
||||
if(DONT_IMPORT_LIST.indexOf(title) !== -1) {
|
||||
@@ -31,6 +33,17 @@ exports.upgrade = function(wiki,titles,tiddlers) {
|
||||
messages[title] = $tw.language.getString("Import/Upgrader/State/Suppressed");
|
||||
}
|
||||
}
|
||||
for(var t=0; t<WARN_IMPORT_PREFIX_LIST.length; t++) {
|
||||
var prefix = WARN_IMPORT_PREFIX_LIST[t];
|
||||
if(title.substr(0,prefix.length) === prefix) {
|
||||
showAlert = true;
|
||||
messages[title] = $tw.language.getString("Import/Upgrader/System/Warning");
|
||||
}
|
||||
}
|
||||
}
|
||||
if(showAlert) {
|
||||
var logger = new $tw.utils.Logger("import");
|
||||
logger.alert($tw.language.getString("Import/Upgrader/System/Alert"));
|
||||
}
|
||||
});
|
||||
return messages;
|
||||
|
||||
46
core/modules/utils/csv.js
Normal file
46
core/modules/utils/csv.js
Normal file
@@ -0,0 +1,46 @@
|
||||
/*\
|
||||
title: $:/core/modules/utils/csv.js
|
||||
type: application/javascript
|
||||
module-type: utils
|
||||
|
||||
A barebones CSV parser
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Parse a CSV string with a header row and return an array of hashmaps.
|
||||
*/
|
||||
exports.parseCsvStringWithHeader = function(text,options) {
|
||||
options = options || {};
|
||||
var separator = options.separator || ",",
|
||||
rows = text.split(/\r?\n/mg).map(function(row) {
|
||||
return $tw.utils.trim(row);
|
||||
}).filter(function(row) {
|
||||
return row !== "";
|
||||
});
|
||||
if(rows.length < 1) {
|
||||
return "Missing header row";
|
||||
}
|
||||
var headings = rows[0].split(separator),
|
||||
results = [];
|
||||
for(var row=1; row<rows.length; row++) {
|
||||
var columns = rows[row].split(separator),
|
||||
columnResult = Object.create(null);
|
||||
if(columns.length !== headings.length) {
|
||||
return "Malformed CSV row '" + rows[row] + "'";
|
||||
}
|
||||
for(var column=0; column<columns.length; column++) {
|
||||
var columnName = headings[column];
|
||||
columnResult[columnName] = $tw.utils.trim(columns[column] || "");
|
||||
}
|
||||
results.push(columnResult);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -82,11 +82,12 @@ Returns:
|
||||
y: vertical scroll position in pixels
|
||||
}
|
||||
*/
|
||||
exports.getScrollPosition = function() {
|
||||
if("scrollX" in window) {
|
||||
return {x: window.scrollX, y: window.scrollY};
|
||||
exports.getScrollPosition = function(srcWindow) {
|
||||
var scrollWindow = srcWindow || window;
|
||||
if("scrollX" in scrollWindow) {
|
||||
return {x: scrollWindow.scrollX, y: scrollWindow.scrollY};
|
||||
} else {
|
||||
return {x: document.documentElement.scrollLeft, y: document.documentElement.scrollTop};
|
||||
return {x: scrollWindow.document.documentElement.scrollLeft, y: scrollWindow.document.documentElement.scrollTop};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -119,7 +120,7 @@ exports.resizeTextAreaToFit = function(domNode,minHeight) {
|
||||
Gets the bounding rectangle of an element in absolute page coordinates
|
||||
*/
|
||||
exports.getBoundingPageRect = function(element) {
|
||||
var scrollPos = $tw.utils.getScrollPosition(),
|
||||
var scrollPos = $tw.utils.getScrollPosition(element.ownerDocument.defaultView),
|
||||
clientRect = element.getBoundingClientRect();
|
||||
return {
|
||||
left: clientRect.left + scrollPos.x,
|
||||
@@ -263,4 +264,9 @@ exports.copyToClipboard = function(text,options) {
|
||||
document.body.removeChild(textArea);
|
||||
};
|
||||
|
||||
exports.getLocationPath = function() {
|
||||
return window.location.toString().split("#")[0];
|
||||
};
|
||||
|
||||
|
||||
})();
|
||||
|
||||
@@ -134,6 +134,12 @@ exports.makeDraggable = function(options) {
|
||||
|
||||
exports.importDataTransfer = function(dataTransfer,fallbackTitle,callback) {
|
||||
// Try each provided data type in turn
|
||||
if($tw.log.IMPORT) {
|
||||
console.log("Available data types:");
|
||||
for(var type=0; type<dataTransfer.types.length; type++) {
|
||||
console.log("type",dataTransfer.types[type],dataTransfer.getData(dataTransfer.types[type]))
|
||||
}
|
||||
}
|
||||
for(var t=0; t<importDataTypes.length; t++) {
|
||||
if(!$tw.browser.isIE || importDataTypes[t].IECompatible) {
|
||||
// Get the data
|
||||
|
||||
@@ -15,6 +15,7 @@ Browser HTTP support
|
||||
/*
|
||||
A quick and dirty HTTP function; to be refactored later. Options are:
|
||||
url: URL to retrieve
|
||||
headers: hashmap of headers to send
|
||||
type: GET, PUT, POST etc
|
||||
callback: function invoked with (err,data)
|
||||
returnProp: string name of the property to return as first argument of callback
|
||||
@@ -60,6 +61,9 @@ exports.httpRequest = function(options) {
|
||||
if(data && !$tw.utils.hop(headers,"Content-type")) {
|
||||
request.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");
|
||||
}
|
||||
if(!$tw.utils.hop(headers,"X-Requested-With")) {
|
||||
request.setRequestHeader("X-Requested-With","TiddlyWiki");
|
||||
}
|
||||
try {
|
||||
request.send(data);
|
||||
} catch(e) {
|
||||
|
||||
@@ -28,6 +28,10 @@ Options include:
|
||||
*/
|
||||
Modal.prototype.display = function(title,options) {
|
||||
options = options || {};
|
||||
this.srcDocument = options.variables && (options.variables.rootwindow === "true" ||
|
||||
options.variables.rootwindow === "yes") ? document :
|
||||
(options.event.event && options.event.event.target ? options.event.event.target.ownerDocument : document);
|
||||
this.srcWindow = this.srcDocument.defaultView;
|
||||
var self = this,
|
||||
refreshHandler,
|
||||
duration = $tw.utils.getAnimationDuration(),
|
||||
@@ -39,16 +43,16 @@ Modal.prototype.display = function(title,options) {
|
||||
// Create the variables
|
||||
var variables = $tw.utils.extend({currentTiddler: title},options.variables);
|
||||
// Create the wrapper divs
|
||||
var wrapper = document.createElement("div"),
|
||||
modalBackdrop = document.createElement("div"),
|
||||
modalWrapper = document.createElement("div"),
|
||||
modalHeader = document.createElement("div"),
|
||||
headerTitle = document.createElement("h3"),
|
||||
modalBody = document.createElement("div"),
|
||||
modalLink = document.createElement("a"),
|
||||
modalFooter = document.createElement("div"),
|
||||
modalFooterHelp = document.createElement("span"),
|
||||
modalFooterButtons = document.createElement("span");
|
||||
var wrapper = this.srcDocument.createElement("div"),
|
||||
modalBackdrop = this.srcDocument.createElement("div"),
|
||||
modalWrapper = this.srcDocument.createElement("div"),
|
||||
modalHeader = this.srcDocument.createElement("div"),
|
||||
headerTitle = this.srcDocument.createElement("h3"),
|
||||
modalBody = this.srcDocument.createElement("div"),
|
||||
modalLink = this.srcDocument.createElement("a"),
|
||||
modalFooter = this.srcDocument.createElement("div"),
|
||||
modalFooterHelp = this.srcDocument.createElement("span"),
|
||||
modalFooterButtons = this.srcDocument.createElement("span");
|
||||
// Up the modal count and adjust the body class
|
||||
this.modalCount++;
|
||||
this.adjustPageClass();
|
||||
@@ -80,7 +84,7 @@ Modal.prototype.display = function(title,options) {
|
||||
value: title
|
||||
}}}],
|
||||
parentWidget: $tw.rootWidget,
|
||||
document: document,
|
||||
document: this.srcDocument,
|
||||
variables: variables,
|
||||
importPageMacros: true
|
||||
});
|
||||
@@ -88,7 +92,7 @@ Modal.prototype.display = function(title,options) {
|
||||
// Render the body of the message
|
||||
var bodyWidgetNode = this.wiki.makeTranscludeWidget(title,{
|
||||
parentWidget: $tw.rootWidget,
|
||||
document: document,
|
||||
document: this.srcDocument,
|
||||
variables: variables,
|
||||
importPageMacros: true
|
||||
});
|
||||
@@ -96,16 +100,16 @@ Modal.prototype.display = function(title,options) {
|
||||
// Setup the link if present
|
||||
if(options.downloadLink) {
|
||||
modalLink.href = options.downloadLink;
|
||||
modalLink.appendChild(document.createTextNode("Right-click to save changes"));
|
||||
modalLink.appendChild(this.srcDocument.createTextNode("Right-click to save changes"));
|
||||
modalBody.appendChild(modalLink);
|
||||
}
|
||||
// Render the footer of the message
|
||||
if(tiddler && tiddler.fields && tiddler.fields.help) {
|
||||
var link = document.createElement("a");
|
||||
var link = this.srcDocument.createElement("a");
|
||||
link.setAttribute("href",tiddler.fields.help);
|
||||
link.setAttribute("target","_blank");
|
||||
link.setAttribute("rel","noopener noreferrer");
|
||||
link.appendChild(document.createTextNode("Help"));
|
||||
link.appendChild(this.srcDocument.createTextNode("Help"));
|
||||
modalFooterHelp.appendChild(link);
|
||||
modalFooterHelp.style.float = "left";
|
||||
}
|
||||
@@ -129,7 +133,7 @@ Modal.prototype.display = function(title,options) {
|
||||
}}}
|
||||
]}],
|
||||
parentWidget: $tw.rootWidget,
|
||||
document: document,
|
||||
document: this.srcDocument,
|
||||
variables: variables,
|
||||
importPageMacros: true
|
||||
});
|
||||
@@ -155,13 +159,13 @@ Modal.prototype.display = function(title,options) {
|
||||
{opacity: "0"}
|
||||
]);
|
||||
$tw.utils.setStyle(modalWrapper,[
|
||||
{transform: "translateY(" + window.innerHeight + "px)"}
|
||||
{transform: "translateY(" + self.srcWindow.innerHeight + "px)"}
|
||||
]);
|
||||
// Set up an event for the transition end
|
||||
window.setTimeout(function() {
|
||||
self.srcWindow.setTimeout(function() {
|
||||
if(wrapper.parentNode) {
|
||||
// Remove the modal message from the DOM
|
||||
document.body.removeChild(wrapper);
|
||||
self.srcDocument.body.removeChild(wrapper);
|
||||
}
|
||||
},duration);
|
||||
// Don't let anyone else handle the tm-close-tiddler message
|
||||
@@ -176,10 +180,10 @@ Modal.prototype.display = function(title,options) {
|
||||
]);
|
||||
$tw.utils.setStyle(modalWrapper,[
|
||||
{transformOrigin: "0% 0%"},
|
||||
{transform: "translateY(" + (-window.innerHeight) + "px)"}
|
||||
{transform: "translateY(" + (-this.srcWindow.innerHeight) + "px)"}
|
||||
]);
|
||||
// Put the message into the document
|
||||
document.body.appendChild(wrapper);
|
||||
this.srcDocument.body.appendChild(wrapper);
|
||||
// Set up animation for the styles
|
||||
$tw.utils.setStyle(modalBackdrop,[
|
||||
{transition: "opacity " + duration + "ms ease-out"}
|
||||
@@ -200,8 +204,9 @@ Modal.prototype.display = function(title,options) {
|
||||
};
|
||||
|
||||
Modal.prototype.adjustPageClass = function() {
|
||||
if($tw.pageContainer) {
|
||||
$tw.utils.toggleClass($tw.pageContainer,"tc-modal-displayed",this.modalCount > 0);
|
||||
var windowContainer = $tw.pageContainer ? ($tw.pageContainer === this.srcDocument.body.firstChild ? $tw.pageContainer : this.srcDocument.body.firstChild) : null;
|
||||
if(windowContainer) {
|
||||
$tw.utils.toggleClass(windowContainer,"tc-modal-displayed",this.modalCount > 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -25,9 +25,11 @@ var Popup = function(options) {
|
||||
/*
|
||||
Trigger a popup open or closed. Parameters are in a hashmap:
|
||||
title: title of the tiddler where the popup details are stored
|
||||
domNode: dom node to which the popup will be positioned
|
||||
domNode: dom node to which the popup will be positioned (one of domNode or domNodeRect is required)
|
||||
domNodeRect: rectangle to which the popup will be positioned
|
||||
wiki: wiki
|
||||
force: if specified, forces the popup state to true or false (instead of toggling it)
|
||||
floating: if true, skips registering the popup, meaning that it will need manually clearing
|
||||
*/
|
||||
Popup.prototype.triggerPopup = function(options) {
|
||||
// Check if this popup is already active
|
||||
@@ -112,8 +114,9 @@ Popup.prototype.show = function(options) {
|
||||
var info = this.popupInfo(options.domNode);
|
||||
// Cancel any higher level popups
|
||||
this.cancel(info.popupLevel);
|
||||
|
||||
// Store the popup details if not already there
|
||||
if(this.findPopup(options.title) === -1) {
|
||||
if(!options.floating && this.findPopup(options.title) === -1) {
|
||||
this.popups.push({
|
||||
title: options.title,
|
||||
wiki: options.wiki,
|
||||
@@ -121,9 +124,24 @@ Popup.prototype.show = function(options) {
|
||||
});
|
||||
}
|
||||
// Set the state tiddler
|
||||
options.wiki.setTextReference(options.title,
|
||||
"(" + options.domNode.offsetLeft + "," + options.domNode.offsetTop + "," +
|
||||
options.domNode.offsetWidth + "," + options.domNode.offsetHeight + ")");
|
||||
var rect;
|
||||
if(options.domNodeRect) {
|
||||
rect = options.domNodeRect;
|
||||
} else {
|
||||
rect = {
|
||||
left: options.domNode.offsetLeft,
|
||||
top: options.domNode.offsetTop,
|
||||
width: options.domNode.offsetWidth,
|
||||
height: options.domNode.offsetHeight
|
||||
};
|
||||
}
|
||||
var popupRect = "(" + rect.left + "," + rect.top + "," +
|
||||
rect.width + "," + rect.height + ")";
|
||||
if(options.noStateReference) {
|
||||
options.wiki.setText(options.title,"text",undefined,popupRect);
|
||||
} else {
|
||||
options.wiki.setTextReference(options.title,popupRect);
|
||||
}
|
||||
// Add the click handler if we have any popups
|
||||
if(this.popups.length > 0) {
|
||||
this.rootElement.addEventListener("click",this,true);
|
||||
|
||||
@@ -33,9 +33,13 @@ var PageScroller = function() {
|
||||
};
|
||||
};
|
||||
|
||||
PageScroller.prototype.cancelScroll = function() {
|
||||
PageScroller.prototype.isScrolling = function() {
|
||||
return this.idRequestFrame !== null;
|
||||
}
|
||||
|
||||
PageScroller.prototype.cancelScroll = function(srcWindow) {
|
||||
if(this.idRequestFrame) {
|
||||
this.cancelAnimationFrame.call(window,this.idRequestFrame);
|
||||
this.cancelAnimationFrame.call(srcWindow,this.idRequestFrame);
|
||||
this.idRequestFrame = null;
|
||||
}
|
||||
};
|
||||
@@ -53,19 +57,26 @@ PageScroller.prototype.handleEvent = function(event) {
|
||||
/*
|
||||
Handle a scroll event hitting the page document
|
||||
*/
|
||||
PageScroller.prototype.scrollIntoView = function(element) {
|
||||
PageScroller.prototype.scrollIntoView = function(element,callback) {
|
||||
var self = this,
|
||||
duration = $tw.utils.getAnimationDuration();
|
||||
duration = $tw.utils.getAnimationDuration(),
|
||||
srcWindow = element ? element.ownerDocument.defaultView : window;
|
||||
// Now get ready to scroll the body
|
||||
this.cancelScroll();
|
||||
this.cancelScroll(srcWindow);
|
||||
this.startTime = Date.now();
|
||||
// Get the height of any position:fixed toolbars
|
||||
var toolbar = srcWindow.document.querySelector(".tc-adjust-top-of-scroll"),
|
||||
offset = 0;
|
||||
if(toolbar) {
|
||||
offset = toolbar.offsetHeight;
|
||||
}
|
||||
// Get the client bounds of the element and adjust by the scroll position
|
||||
var getBounds = function() {
|
||||
var clientBounds = element.getBoundingClientRect(),
|
||||
scrollPosition = $tw.utils.getScrollPosition();
|
||||
var clientBounds = typeof callback === 'function' ? callback() : element.getBoundingClientRect(),
|
||||
scrollPosition = $tw.utils.getScrollPosition(srcWindow);
|
||||
return {
|
||||
left: clientBounds.left + scrollPosition.x,
|
||||
top: clientBounds.top + scrollPosition.y,
|
||||
top: clientBounds.top + scrollPosition.y - offset,
|
||||
width: clientBounds.width,
|
||||
height: clientBounds.height
|
||||
};
|
||||
@@ -90,17 +101,17 @@ PageScroller.prototype.scrollIntoView = function(element) {
|
||||
t = ((Date.now()) - self.startTime) / duration;
|
||||
}
|
||||
if(t >= 1) {
|
||||
self.cancelScroll();
|
||||
self.cancelScroll(srcWindow);
|
||||
t = 1;
|
||||
}
|
||||
t = $tw.utils.slowInSlowOut(t);
|
||||
var scrollPosition = $tw.utils.getScrollPosition(),
|
||||
var scrollPosition = $tw.utils.getScrollPosition(srcWindow),
|
||||
bounds = getBounds(),
|
||||
endX = getEndPos(bounds.left,bounds.width,scrollPosition.x,window.innerWidth),
|
||||
endY = getEndPos(bounds.top,bounds.height,scrollPosition.y,window.innerHeight);
|
||||
window.scrollTo(scrollPosition.x + (endX - scrollPosition.x) * t,scrollPosition.y + (endY - scrollPosition.y) * t);
|
||||
endX = getEndPos(bounds.left,bounds.width,scrollPosition.x,srcWindow.innerWidth),
|
||||
endY = getEndPos(bounds.top,bounds.height,scrollPosition.y,srcWindow.innerHeight);
|
||||
srcWindow.scrollTo(scrollPosition.x + (endX - scrollPosition.x) * t,scrollPosition.y + (endY - scrollPosition.y) * t);
|
||||
if(t < 1) {
|
||||
self.idRequestFrame = self.requestAnimationFrame.call(window,drawFrame);
|
||||
self.idRequestFrame = self.requestAnimationFrame.call(srcWindow,drawFrame);
|
||||
}
|
||||
};
|
||||
drawFrame();
|
||||
|
||||
@@ -45,10 +45,28 @@ var TW_Element = function(tag,namespace) {
|
||||
this.attributes = {};
|
||||
this.isRaw = false;
|
||||
this.children = [];
|
||||
this.style = {};
|
||||
this._style = {};
|
||||
this.namespaceURI = namespace || "http://www.w3.org/1999/xhtml";
|
||||
};
|
||||
|
||||
Object.defineProperty(TW_Element.prototype, "style", {
|
||||
get: function() {
|
||||
return this._style;
|
||||
},
|
||||
set: function(str) {
|
||||
var self = this;
|
||||
str = str || "";
|
||||
$tw.utils.each(str.split(";"),function(declaration) {
|
||||
var parts = declaration.split(":"),
|
||||
name = $tw.utils.trim(parts[0]),
|
||||
value = $tw.utils.trim(parts[1]);
|
||||
if(name && value) {
|
||||
self._style[$tw.utils.convertStyleNameToPropertyName(name)] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(TW_Element.prototype, "nodeType", {
|
||||
get: function() {
|
||||
return 1;
|
||||
@@ -169,13 +187,13 @@ Object.defineProperty(TW_Element.prototype, "outerHTML", {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.style) {
|
||||
if(this._style) {
|
||||
var style = [];
|
||||
for(var s in this.style) {
|
||||
style.push(s + ":" + this.style[s] + ";");
|
||||
for(var s in this._style) {
|
||||
style.push($tw.utils.convertPropertyNameToStyleName(s) + ":" + this._style[s] + ";");
|
||||
}
|
||||
if(style.length > 0) {
|
||||
output.push(" style=\"",style.join(""),"\"")
|
||||
output.push(" style=\"",style.join(""),"\"");
|
||||
}
|
||||
}
|
||||
output.push(">");
|
||||
|
||||
@@ -57,7 +57,7 @@ var FILE_BUFFER_LENGTH = 64 * 1024,
|
||||
exports.copyFile = function(srcPath,dstPath) {
|
||||
// Create buffer if required
|
||||
if(!fileBuffer) {
|
||||
fileBuffer = new Buffer(FILE_BUFFER_LENGTH);
|
||||
fileBuffer = Buffer.alloc(FILE_BUFFER_LENGTH);
|
||||
}
|
||||
// Create any directories in the destination
|
||||
$tw.utils.createDirectory(path.dirname(dstPath));
|
||||
|
||||
@@ -916,4 +916,10 @@ exports.transliterate = function(str) {
|
||||
});
|
||||
};
|
||||
|
||||
exports.transliterateToSafeASCII = function(str) {
|
||||
return str.replace(/[^\x00-\x7F]/g,function(ch) {
|
||||
return exports.transliterationPairs[ch] || ""
|
||||
});
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
@@ -133,60 +133,15 @@ exports.count = function(object) {
|
||||
};
|
||||
|
||||
/*
|
||||
Check if an array is equal by value and by reference.
|
||||
Determine whether an array-item is an object-property
|
||||
*/
|
||||
exports.isArrayEqual = function(array1,array2) {
|
||||
if(array1 === array2) {
|
||||
return true;
|
||||
}
|
||||
array1 = array1 || [];
|
||||
array2 = array2 || [];
|
||||
if(array1.length !== array2.length) {
|
||||
return false;
|
||||
}
|
||||
return array1.every(function(value,index) {
|
||||
return value === array2[index];
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Push entries onto an array, removing them first if they already exist in the array
|
||||
array: array to modify (assumed to be free of duplicates)
|
||||
value: a single value to push or an array of values to push
|
||||
*/
|
||||
exports.pushTop = function(array,value) {
|
||||
var t,p;
|
||||
if($tw.utils.isArray(value)) {
|
||||
// Remove any array entries that are duplicated in the new values
|
||||
if(value.length !== 0) {
|
||||
if(array.length !== 0) {
|
||||
if(value.length < array.length) {
|
||||
for(t=0; t<value.length; t++) {
|
||||
p = array.indexOf(value[t]);
|
||||
if(p !== -1) {
|
||||
array.splice(p,1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(t=array.length-1; t>=0; t--) {
|
||||
p = value.indexOf(array[t]);
|
||||
if(p !== -1) {
|
||||
array.splice(t,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Push the values on top of the main array
|
||||
array.push.apply(array,value);
|
||||
exports.hopArray = function(object,array) {
|
||||
for(var i=0; i<array.length; i++) {
|
||||
if($tw.utils.hop(object,array[i])) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
p = array.indexOf(value);
|
||||
if(p !== -1) {
|
||||
array.splice(p,1);
|
||||
}
|
||||
array.push(value);
|
||||
}
|
||||
return array;
|
||||
return false;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -497,15 +452,21 @@ exports.htmlEncode = function(s) {
|
||||
// Converts all HTML entities to their character equivalents
|
||||
exports.entityDecode = function(s) {
|
||||
var converter = String.fromCodePoint || String.fromCharCode,
|
||||
e = s.substr(1,s.length-2); // Strip the & and the ;
|
||||
e = s.substr(1,s.length-2), // Strip the & and the ;
|
||||
c;
|
||||
if(e.charAt(0) === "#") {
|
||||
if(e.charAt(1) === "x" || e.charAt(1) === "X") {
|
||||
return converter(parseInt(e.substr(2),16));
|
||||
c = parseInt(e.substr(2),16);
|
||||
} else {
|
||||
return converter(parseInt(e.substr(1),10));
|
||||
c = parseInt(e.substr(1),10);
|
||||
}
|
||||
if(isNaN(c)) {
|
||||
return s;
|
||||
} else {
|
||||
return converter(c);
|
||||
}
|
||||
} else {
|
||||
var c = $tw.config.htmlEntities[e];
|
||||
c = $tw.config.htmlEntities[e];
|
||||
if(c) {
|
||||
return converter(c);
|
||||
} else {
|
||||
@@ -690,7 +651,7 @@ exports.extractVersionInfo = function() {
|
||||
Get the animation duration in ms
|
||||
*/
|
||||
exports.getAnimationDuration = function() {
|
||||
return parseInt($tw.wiki.getTiddlerText("$:/config/AnimationDuration","400"),10);
|
||||
return parseInt($tw.wiki.getTiddlerText("$:/config/AnimationDuration","400"),10) || 0;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -712,7 +673,7 @@ exports.base64Decode = function(string64) {
|
||||
// TODO
|
||||
throw "$tw.utils.base64Decode() doesn't work in the browser";
|
||||
} else {
|
||||
return (new Buffer(string64,"base64")).toString();
|
||||
return Buffer.from(string64,"base64").toString();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ NavigateWidget.prototype.refresh = function(changedTiddlers) {
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
NavigateWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
event = event || {};
|
||||
var bounds = triggeringWidget && triggeringWidget.getBoundingClientRect && triggeringWidget.getBoundingClientRect(),
|
||||
suppressNavigation = event.metaKey || event.ctrlKey || (event.button === 1);
|
||||
if(this.actionScroll === "yes") {
|
||||
|
||||
@@ -41,9 +41,9 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
|
||||
var domNode = this.document.createElement(tag);
|
||||
// Assign classes
|
||||
var classes = this["class"].split(" ") || [],
|
||||
isPoppedUp = this.popup && this.isPoppedUp();
|
||||
isPoppedUp = (this.popup || this.popupTitle) && this.isPoppedUp();
|
||||
if(this.selectedClass) {
|
||||
if(this.set && this.setTo && this.isSelected()) {
|
||||
if((this.set || this.setTitle) && this.setTo && this.isSelected()) {
|
||||
$tw.utils.pushTop(classes,this.selectedClass.split(" "));
|
||||
}
|
||||
if(isPoppedUp) {
|
||||
@@ -78,11 +78,11 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
|
||||
self.dispatchMessage(event);
|
||||
handled = true;
|
||||
}
|
||||
if(self.popup) {
|
||||
if(self.popup || self.popupTitle) {
|
||||
self.triggerPopup(event);
|
||||
handled = true;
|
||||
}
|
||||
if(self.set) {
|
||||
if(self.set || self.setTitle) {
|
||||
self.setTiddler();
|
||||
handled = true;
|
||||
}
|
||||
@@ -122,11 +122,14 @@ ButtonWidget.prototype.getBoundingClientRect = function() {
|
||||
};
|
||||
|
||||
ButtonWidget.prototype.isSelected = function() {
|
||||
return this.wiki.getTextReference(this.set,this.defaultSetValue,this.getVariable("currentTiddler")) === this.setTo;
|
||||
return this.setTitle ? (this.setField ? this.wiki.getTiddler(this.setTitle).getFieldString(this.setField) === this.setTo :
|
||||
(this.setIndex ? this.wiki.extractTiddlerDataItem(this.setTitle,this.setIndex) === this.setTo :
|
||||
this.wiki.getTiddlerText(this.setTitle))) || this.defaultSetValue || this.getVariable("currentTiddler") :
|
||||
this.wiki.getTextReference(this.set,this.defaultSetValue,this.getVariable("currentTiddler")) === this.setTo;
|
||||
};
|
||||
|
||||
ButtonWidget.prototype.isPoppedUp = function() {
|
||||
var tiddler = this.wiki.getTiddler(this.popup);
|
||||
var tiddler = this.popupTitle ? this.wiki.getTiddler(this.popupTitle) : this.wiki.getTiddler(this.popup);
|
||||
var result = tiddler && tiddler.fields.text ? $tw.popup.readPopupState(tiddler.fields.text) : false;
|
||||
return result;
|
||||
};
|
||||
@@ -150,15 +153,30 @@ ButtonWidget.prototype.dispatchMessage = function(event) {
|
||||
};
|
||||
|
||||
ButtonWidget.prototype.triggerPopup = function(event) {
|
||||
$tw.popup.triggerPopup({
|
||||
domNode: this.domNodes[0],
|
||||
title: this.popup,
|
||||
wiki: this.wiki
|
||||
});
|
||||
if(this.popupTitle) {
|
||||
$tw.popup.triggerPopup({
|
||||
domNode: this.domNodes[0],
|
||||
title: this.popupTitle,
|
||||
wiki: this.wiki,
|
||||
noStateReference: true
|
||||
});
|
||||
} else {
|
||||
$tw.popup.triggerPopup({
|
||||
domNode: this.domNodes[0],
|
||||
title: this.popup,
|
||||
wiki: this.wiki
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
ButtonWidget.prototype.setTiddler = function() {
|
||||
this.wiki.setTextReference(this.set,this.setTo,this.getVariable("currentTiddler"));
|
||||
if(this.setTitle) {
|
||||
this.setField ? this.wiki.setText(this.setTitle,this.setField,undefined,this.setTo) :
|
||||
(this.setIndex ? this.wiki.setText(this.setTitle,undefined,this.setIndex,this.setTo) :
|
||||
this.wiki.setText(this.setTitle,"text",undefined,this.setTo));
|
||||
} else {
|
||||
this.wiki.setTextReference(this.set,this.setTo,this.getVariable("currentTiddler"));
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -183,6 +201,10 @@ ButtonWidget.prototype.execute = function() {
|
||||
this.buttonTag = this.getAttribute("tag");
|
||||
this.dragTiddler = this.getAttribute("dragTiddler");
|
||||
this.dragFilter = this.getAttribute("dragFilter");
|
||||
this.setTitle = this.getAttribute("setTitle");
|
||||
this.setField = this.getAttribute("setField");
|
||||
this.setIndex = this.getAttribute("setIndex");
|
||||
this.popupTitle = this.getAttribute("popupTitle");
|
||||
// Make child widgets
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
@@ -192,7 +214,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
|
||||
*/
|
||||
ButtonWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.to || changedAttributes.message || changedAttributes.param || changedAttributes.set || changedAttributes.setTo || changedAttributes.popup || changedAttributes.hover || changedAttributes["class"] || changedAttributes.selectedClass || changedAttributes.style || changedAttributes.dragFilter || changedAttributes.dragTiddler || (this.set && changedTiddlers[this.set]) || (this.popup && changedTiddlers[this.popup])) {
|
||||
if(changedAttributes.to || changedAttributes.message || changedAttributes.param || changedAttributes.set || changedAttributes.setTo || changedAttributes.popup || changedAttributes.hover || changedAttributes["class"] || changedAttributes.selectedClass || changedAttributes.style || changedAttributes.dragFilter || changedAttributes.dragTiddler || (this.set && changedTiddlers[this.set]) || (this.popup && changedTiddlers[this.popup]) || (this.popupTitle && changedTiddlers[this.popupTitle]) || changedAttributes.setTitle || changedAttributes.setField || changedAttributes.setIndex || changedAttributes.popupTitle) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,8 @@ DropZoneWidget.prototype.render = function(parent,nextSibling) {
|
||||
{name: "dragover", handlerObject: this, handlerMethod: "handleDragOverEvent"},
|
||||
{name: "dragleave", handlerObject: this, handlerMethod: "handleDragLeaveEvent"},
|
||||
{name: "drop", handlerObject: this, handlerMethod: "handleDropEvent"},
|
||||
{name: "paste", handlerObject: this, handlerMethod: "handlePasteEvent"}
|
||||
{name: "paste", handlerObject: this, handlerMethod: "handlePasteEvent"},
|
||||
{name: "dragend", handlerObject: this, handlerMethod: "handleDragEndEvent"}
|
||||
]);
|
||||
domNode.addEventListener("click",function (event) {
|
||||
},false);
|
||||
@@ -103,6 +104,10 @@ DropZoneWidget.prototype.handleDragLeaveEvent = function(event) {
|
||||
this.leaveDrag(event);
|
||||
};
|
||||
|
||||
DropZoneWidget.prototype.handleDragEndEvent = function(event) {
|
||||
$tw.utils.removeClass(this.domNodes[0],"tc-dragover");
|
||||
};
|
||||
|
||||
DropZoneWidget.prototype.handleDropEvent = function(event) {
|
||||
var self = this,
|
||||
readFileCallback = function(tiddlerFieldsArray) {
|
||||
@@ -145,7 +150,7 @@ DropZoneWidget.prototype.handlePasteEvent = function(event) {
|
||||
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)});
|
||||
};
|
||||
// Let the browser handle it if we're in a textarea or input box
|
||||
if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) == -1) {
|
||||
if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) == -1 && !event.target.isContentEditable) {
|
||||
var self = this,
|
||||
items = event.clipboardData.items;
|
||||
// Enumerate the clipboard items
|
||||
|
||||
@@ -57,6 +57,10 @@ EditShortcutWidget.prototype.render = function(parent,nextSibling) {
|
||||
// Link into the DOM
|
||||
parent.insertBefore(this.inputNode,nextSibling);
|
||||
this.domNodes.push(this.inputNode);
|
||||
// Focus the input Node if focus === "yes" or focus === "true"
|
||||
if(this.shortcutFocus === "yes" || this.shortcutFocus === "true") {
|
||||
this.focus();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -72,6 +76,7 @@ EditShortcutWidget.prototype.execute = function() {
|
||||
this.shortcutStyle = this.getAttribute("style");
|
||||
this.shortcutTooltip = this.getAttribute("tooltip");
|
||||
this.shortcutAriaLabel = this.getAttribute("aria-label");
|
||||
this.shortcutFocus = this.getAttribute("focus");
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -118,12 +123,22 @@ EditShortcutWidget.prototype.handleKeydownEvent = function(event) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
focus the input node
|
||||
*/
|
||||
EditShortcutWidget.prototype.focus = function() {
|
||||
if(this.inputNode.focus && this.inputNode.select) {
|
||||
this.inputNode.focus();
|
||||
this.inputNode.select();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget needed re-rendering
|
||||
*/
|
||||
EditShortcutWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.placeholder || changedAttributes["default"] || changedAttributes["class"] || changedAttributes.style || changedAttributes.tooltip || changedAttributes["aria-label"]) {
|
||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.placeholder || changedAttributes["default"] || changedAttributes["class"] || changedAttributes.style || changedAttributes.tooltip || changedAttributes["aria-label"] || changedAttributes.focus) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
} else if(changedTiddlers[this.shortcutTiddler]) {
|
||||
|
||||
@@ -46,6 +46,7 @@ EditWidget.prototype.execute = function() {
|
||||
this.editIndex = this.getAttribute("index");
|
||||
this.editClass = this.getAttribute("class");
|
||||
this.editPlaceholder = this.getAttribute("placeholder");
|
||||
this.editTabIndex = this.getAttribute("tabindex");
|
||||
// Choose the appropriate edit widget
|
||||
this.editorType = this.getEditorType();
|
||||
// Make the child widgets
|
||||
@@ -56,7 +57,8 @@ EditWidget.prototype.execute = function() {
|
||||
field: {type: "string", value: this.editField},
|
||||
index: {type: "string", value: this.editIndex},
|
||||
"class": {type: "string", value: this.editClass},
|
||||
"placeholder": {type: "string", value: this.editPlaceholder}
|
||||
"placeholder": {type: "string", value: this.editPlaceholder},
|
||||
"tabindex": {type: "string", value: this.editTabIndex}
|
||||
},
|
||||
children: this.parseTreeNode.children
|
||||
}]);
|
||||
@@ -90,11 +92,11 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
|
||||
EditWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
// Refresh if an attribute has changed, or the type associated with the target tiddler has changed
|
||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || (changedTiddlers[this.editTitle] && this.getEditorType() !== this.editorType)) {
|
||||
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.tabindex || (changedTiddlers[this.editTitle] && this.getEditorType() !== this.editorType)) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
} else {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -35,6 +35,14 @@ ElementWidget.prototype.render = function(parent,nextSibling) {
|
||||
if($tw.config.htmlUnsafeElements.indexOf(tag) !== -1) {
|
||||
tag = "safe-" + tag;
|
||||
}
|
||||
// Adjust headings by the current base level
|
||||
var headingLevel = ["h1","h2","h3","h4","h5","h6"].indexOf(tag);
|
||||
if(headingLevel !== -1) {
|
||||
var baseLevel = parseInt(this.getVariable("tv-adjust-heading-level","0"),10) || 0;
|
||||
headingLevel = Math.min(Math.max(headingLevel + 1 + baseLevel,1),6);
|
||||
tag = "h" + headingLevel;
|
||||
}
|
||||
// Create the DOM node
|
||||
var domNode = this.document.createElementNS(this.namespace,tag);
|
||||
this.assignAttributes(domNode,{excludeEventAttributes: true});
|
||||
parent.insertBefore(domNode,nextSibling);
|
||||
|
||||
@@ -63,7 +63,8 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
||||
addWidgetNode({
|
||||
type: "set",
|
||||
attributes: parseTreeNode.attributes,
|
||||
params: parseTreeNode.params
|
||||
params: parseTreeNode.params,
|
||||
isMacroDefinition: parseTreeNode.isMacroDefinition
|
||||
});
|
||||
parseTreeNode = parseTreeNode.children[0];
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ KeyboardWidget.prototype.dispatchMessage = function(event) {
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
KeyboardWidget.prototype.execute = function() {
|
||||
var self = this;
|
||||
// Get attributes
|
||||
this.actions = this.getAttribute("actions");
|
||||
this.message = this.getAttribute("message");
|
||||
@@ -79,6 +80,13 @@ KeyboardWidget.prototype.execute = function() {
|
||||
this.tag = this.getAttribute("tag");
|
||||
this.keyInfoArray = $tw.keyboardManager.parseKeyDescriptors(this.key);
|
||||
this["class"] = this.getAttribute("class");
|
||||
if(this.key.substr(0,2) === "((" && this.key.substr(-2,2) === "))") {
|
||||
this.shortcutTiddlers = [];
|
||||
var name = this.key.substring(2,this.key.length -2);
|
||||
$tw.utils.each($tw.keyboardManager.lookupNames,function(platformDescriptor) {
|
||||
self.shortcutTiddlers.push("$:/config/" + platformDescriptor + "/" + name);
|
||||
});
|
||||
}
|
||||
// Make child widgets
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
@@ -92,6 +100,10 @@ KeyboardWidget.prototype.refresh = function(changedTiddlers) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
}
|
||||
// Update the keyInfoArray if one of its shortcut-config-tiddlers has changed
|
||||
if(this.shortcutTiddlers && $tw.utils.hopArray(changedTiddlers,this.shortcutTiddlers)) {
|
||||
this.keyInfoArray = $tw.keyboardManager.parseKeyDescriptors(this.key);
|
||||
}
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
};
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ Link widget
|
||||
"use strict";
|
||||
|
||||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
var MISSING_LINK_CONFIG_TITLE = "$:/config/MissingLinks";
|
||||
|
||||
var LinkWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
@@ -182,7 +181,7 @@ LinkWidget.prototype.execute = function() {
|
||||
// Determine the link characteristics
|
||||
this.isMissing = !this.wiki.tiddlerExists(this.to);
|
||||
this.isShadow = this.wiki.isShadowTiddler(this.to);
|
||||
this.hideMissingLinks = ($tw.wiki.getTiddlerText(MISSING_LINK_CONFIG_TITLE,"yes") === "no");
|
||||
this.hideMissingLinks = (this.getVariable("tv-show-missing-links") || "yes") === "no";
|
||||
// Make the child widgets
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
@@ -192,7 +191,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
|
||||
*/
|
||||
LinkWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.to || changedTiddlers[this.to] || changedAttributes["aria-label"] || changedAttributes.tooltip || changedTiddlers[MISSING_LINK_CONFIG_TITLE]) {
|
||||
if(changedAttributes.to || changedTiddlers[this.to] || changedAttributes["aria-label"] || changedAttributes.tooltip) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -116,51 +116,7 @@ NavigatorWidget.prototype.replaceFirstTitleInStory = function(storyList,oldTitle
|
||||
};
|
||||
|
||||
NavigatorWidget.prototype.addToStory = function(title,fromTitle) {
|
||||
var storyList = this.getStoryList();
|
||||
// Quit if we cannot get hold of the story list
|
||||
if(!storyList) {
|
||||
return;
|
||||
}
|
||||
// See if the tiddler is already there
|
||||
var slot = storyList.indexOf(title);
|
||||
// Quit if it already exists in the story river
|
||||
if(slot >= 0) {
|
||||
return;
|
||||
}
|
||||
// First we try to find the position of the story element we navigated from
|
||||
var fromIndex = storyList.indexOf(fromTitle);
|
||||
if(fromIndex >= 0) {
|
||||
// The tiddler is added from inside the river
|
||||
// Determine where to insert the tiddler; Fallback is "below"
|
||||
switch(this.getAttribute("openLinkFromInsideRiver","below")) {
|
||||
case "top":
|
||||
slot = 0;
|
||||
break;
|
||||
case "bottom":
|
||||
slot = storyList.length;
|
||||
break;
|
||||
case "above":
|
||||
slot = fromIndex;
|
||||
break;
|
||||
case "below": // Intentional fall-through
|
||||
default:
|
||||
slot = fromIndex + 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// The tiddler is opened from outside the river. Determine where to insert the tiddler; default is "top"
|
||||
if(this.getAttribute("openLinkFromOutsideRiver","top") === "bottom") {
|
||||
// Insert at bottom
|
||||
slot = storyList.length;
|
||||
} else {
|
||||
// Insert at top
|
||||
slot = 0;
|
||||
}
|
||||
}
|
||||
// Add the tiddler
|
||||
storyList.splice(slot,0,title);
|
||||
// Save the story
|
||||
this.saveStoryList(storyList);
|
||||
this.wiki.addToStory(title,fromTitle,this.storyTitle,{openLinkFromInsideRiver: this.getAttribute("openLinkFromInsideRiver","top"),openLinkFromOutsideRiver: this.getAttribute("openLinkFromOutsideRiver","top")});
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -324,9 +280,11 @@ Generate a title for the draft of a given tiddler
|
||||
*/
|
||||
NavigatorWidget.prototype.generateDraftTitle = function(title) {
|
||||
var c = 0,
|
||||
draftTitle;
|
||||
draftTitle,
|
||||
username = this.wiki.getTiddlerText("$:/status/UserName"),
|
||||
attribution = username ? " by " + username : "";
|
||||
do {
|
||||
draftTitle = "Draft " + (c ? (c + 1) + " " : "") + "of '" + title + "'";
|
||||
draftTitle = "Draft " + (c ? (c + 1) + " " : "") + "of '" + title + "'" + attribution;
|
||||
c++;
|
||||
} while(this.wiki.tiddlerExists(draftTitle));
|
||||
return draftTitle;
|
||||
@@ -498,9 +456,9 @@ NavigatorWidget.prototype.handleNewTiddlerEvent = function(event) {
|
||||
},
|
||||
templateTiddler,
|
||||
additionalFields,
|
||||
this.wiki.getCreationFields(),
|
||||
existingTiddler,
|
||||
filteredAdditionalFields,
|
||||
this.wiki.getCreationFields(),
|
||||
{
|
||||
title: draftTitle,
|
||||
"draft.of": title,
|
||||
@@ -510,6 +468,9 @@ NavigatorWidget.prototype.handleNewTiddlerEvent = function(event) {
|
||||
// Update the story to insert the new draft at the top and remove any existing tiddler
|
||||
if(storyList.indexOf(draftTitle) === -1) {
|
||||
var slot = storyList.indexOf(event.navigateFromTitle);
|
||||
if(slot === -1) {
|
||||
slot = this.getAttribute("openLinkFromOutsideRiver","top") === "bottom" ? storyList.length - 1 : slot;
|
||||
}
|
||||
storyList.splice(slot + 1,0,draftTitle);
|
||||
}
|
||||
if(storyList.indexOf(title) !== -1) {
|
||||
@@ -629,7 +590,7 @@ NavigatorWidget.prototype.handleFoldOtherTiddlersEvent = function(event) {
|
||||
NavigatorWidget.prototype.handleFoldAllTiddlersEvent = function(event) {
|
||||
var self = this,
|
||||
paramObject = event.paramObject || {},
|
||||
prefix = paramObject.foldedStatePrefix;
|
||||
prefix = paramObject.foldedStatePrefix || "$:/state/folded/";
|
||||
$tw.utils.each(this.getStoryList(),function(title) {
|
||||
self.wiki.setText(prefix + title,"text",null,"hide");
|
||||
});
|
||||
|
||||
66
core/modules/widgets/qualify.js
Normal file
66
core/modules/widgets/qualify.js
Normal file
@@ -0,0 +1,66 @@
|
||||
/*\
|
||||
title: $:/core/modules/widgets/qualify.js
|
||||
type: application/javascript
|
||||
module-type: widget
|
||||
|
||||
Qualify text to a variable
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var QualifyWidget = function(parseTreeNode,options) {
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
/*
|
||||
Inherit from the base widget class
|
||||
*/
|
||||
QualifyWidget.prototype = new Widget();
|
||||
|
||||
/*
|
||||
Render this widget into the DOM
|
||||
*/
|
||||
QualifyWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.parentDomNode = parent;
|
||||
this.computeAttributes();
|
||||
this.execute();
|
||||
this.renderChildren(parent,nextSibling);
|
||||
};
|
||||
|
||||
/*
|
||||
Compute the internal state of the widget
|
||||
*/
|
||||
QualifyWidget.prototype.execute = function() {
|
||||
// Get our parameters
|
||||
this.qualifyName = this.getAttribute("name");
|
||||
this.qualifyTitle = this.getAttribute("title");
|
||||
// Set context variable
|
||||
if(this.qualifyName) {
|
||||
this.setVariable(this.qualifyName,this.qualifyTitle + "-" + this.getStateQualifier());
|
||||
}
|
||||
// Construct the child widgets
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
/*
|
||||
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||
*/
|
||||
QualifyWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.name || changedAttributes.title) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
} else {
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
}
|
||||
};
|
||||
|
||||
exports.qualify = QualifyWidget;
|
||||
|
||||
})();
|
||||
@@ -58,23 +58,23 @@ RevealWidget.prototype.positionPopup = function(domNode) {
|
||||
domNode.style.zIndex = "1000";
|
||||
switch(this.position) {
|
||||
case "left":
|
||||
domNode.style.left = (this.popup.left - domNode.offsetWidth) + "px";
|
||||
domNode.style.left = Math.max(0, this.popup.left - domNode.offsetWidth) + "px";
|
||||
domNode.style.top = this.popup.top + "px";
|
||||
break;
|
||||
case "above":
|
||||
domNode.style.left = this.popup.left + "px";
|
||||
domNode.style.top = (this.popup.top - domNode.offsetHeight) + "px";
|
||||
domNode.style.top = Math.max(0, this.popup.top - domNode.offsetHeight) + "px";
|
||||
break;
|
||||
case "aboveright":
|
||||
domNode.style.left = (this.popup.left + this.popup.width) + "px";
|
||||
domNode.style.top = (this.popup.top + this.popup.height - domNode.offsetHeight) + "px";
|
||||
domNode.style.top = Math.max(0, this.popup.top + this.popup.height - domNode.offsetHeight) + "px";
|
||||
break;
|
||||
case "right":
|
||||
domNode.style.left = (this.popup.left + this.popup.width) + "px";
|
||||
domNode.style.top = this.popup.top + "px";
|
||||
break;
|
||||
case "belowleft":
|
||||
domNode.style.left = (this.popup.left + this.popup.width - domNode.offsetWidth) + "px";
|
||||
domNode.style.left = Math.max(0, this.popup.left + this.popup.width - domNode.offsetWidth) + "px";
|
||||
domNode.style.top = (this.popup.top + this.popup.height) + "px";
|
||||
break;
|
||||
default: // Below
|
||||
@@ -102,7 +102,10 @@ RevealWidget.prototype.execute = function() {
|
||||
this.openAnimation = this.animate === "no" ? undefined : "open";
|
||||
this.closeAnimation = this.animate === "no" ? undefined : "close";
|
||||
// Compute the title of the state tiddler and read it
|
||||
this.stateTitle = this.state;
|
||||
this.stateTiddlerTitle = this.state;
|
||||
this.stateTitle = this.getAttribute("stateTitle");
|
||||
this.stateField = this.getAttribute("stateField");
|
||||
this.stateIndex = this.getAttribute("stateIndex");
|
||||
this.readState();
|
||||
// Construct the child widgets
|
||||
var childNodes = this.isOpen ? this.parseTreeNode.children : [];
|
||||
@@ -115,7 +118,25 @@ Read the state tiddler
|
||||
*/
|
||||
RevealWidget.prototype.readState = function() {
|
||||
// Read the information from the state tiddler
|
||||
var state = this.stateTitle ? this.wiki.getTextReference(this.stateTitle,this["default"],this.getVariable("currentTiddler")) : this["default"];
|
||||
var state,
|
||||
defaultState = this["default"];
|
||||
if(this.stateTitle) {
|
||||
var stateTitleTiddler = this.wiki.getTiddler(this.stateTitle);
|
||||
if(this.stateField) {
|
||||
state = stateTitleTiddler ? stateTitleTiddler.getFieldString(this.stateField) || defaultState : defaultState;
|
||||
} else if(this.stateIndex) {
|
||||
state = stateTitleTiddler ? this.wiki.extractTiddlerDataItem(this.stateTitle,this.stateIndex) || defaultState : defaultState;
|
||||
} else if(stateTitleTiddler) {
|
||||
state = this.wiki.getTiddlerText(this.stateTitle) || defaultState;
|
||||
} else {
|
||||
state = defaultState;
|
||||
}
|
||||
} else {
|
||||
state = this.stateTiddlerTitle ? this.wiki.getTextReference(this.state,this["default"],this.getVariable("currentTiddler")) : this["default"];
|
||||
}
|
||||
if(state === null) {
|
||||
state = this["default"];
|
||||
}
|
||||
switch(this.type) {
|
||||
case "popup":
|
||||
this.readPopupState(state);
|
||||
@@ -170,22 +191,21 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
|
||||
*/
|
||||
RevealWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes.state || changedAttributes.type || changedAttributes.text || changedAttributes.position || changedAttributes["default"] || changedAttributes.animate) {
|
||||
if(changedAttributes.state || changedAttributes.type || changedAttributes.text || changedAttributes.position || changedAttributes["default"] || changedAttributes.animate || changedAttributes.stateTitle || changedAttributes.stateField || changedAttributes.stateIndex) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
} else {
|
||||
var refreshed = false,
|
||||
currentlyOpen = this.isOpen;
|
||||
var currentlyOpen = this.isOpen;
|
||||
this.readState();
|
||||
if(this.isOpen !== currentlyOpen) {
|
||||
if(this.isOpen !== currentlyOpen || (this.stateTiddlerTitle && changedTiddlers[this.stateTiddlerTitle])) {
|
||||
if(this.retain === "yes") {
|
||||
this.updateState();
|
||||
} else {
|
||||
this.refreshSelf();
|
||||
refreshed = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return this.refreshChildren(changedTiddlers) || refreshed;
|
||||
return this.refreshChildren(changedTiddlers);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -219,7 +239,7 @@ RevealWidget.prototype.updateState = function() {
|
||||
if(!self.isOpen) {
|
||||
domNode.setAttribute("hidden","true");
|
||||
}
|
||||
}});
|
||||
}});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -145,6 +145,7 @@ SelectWidget.prototype.execute = function() {
|
||||
this.selectDefault = this.getAttribute("default");
|
||||
this.selectMultiple = this.getAttribute("multiple", false);
|
||||
this.selectSize = this.getAttribute("size");
|
||||
this.selectTooltip = this.getAttribute("tooltip");
|
||||
// Make the child widgets
|
||||
var selectNode = {
|
||||
type: "element",
|
||||
@@ -160,6 +161,9 @@ SelectWidget.prototype.execute = function() {
|
||||
if(this.selectSize) {
|
||||
$tw.utils.addAttributeToParseTreeNode(selectNode,"size",this.selectSize);
|
||||
}
|
||||
if(this.selectTooltip) {
|
||||
$tw.utils.addAttributeToParseTreeNode(selectNode,"title",this.selectTooltip);
|
||||
}
|
||||
this.makeChildWidgets([selectNode]);
|
||||
};
|
||||
|
||||
@@ -169,7 +173,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
|
||||
SelectWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
// If we're using a different tiddler/field/index then completely refresh ourselves
|
||||
if(changedAttributes.selectTitle || changedAttributes.selectField || changedAttributes.selectIndex) {
|
||||
if(changedAttributes.selectTitle || changedAttributes.selectField || changedAttributes.selectIndex || changedAttributes.selectTooltip) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
// If the target tiddler value has changed, just update setting and refresh the children
|
||||
|
||||
@@ -48,7 +48,7 @@ SetWidget.prototype.execute = function() {
|
||||
this.setValue = this.getAttribute("value");
|
||||
this.setEmptyValue = this.getAttribute("emptyValue");
|
||||
// Set context variable
|
||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params);
|
||||
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,!!this.parseTreeNode.isMacroDefinition);
|
||||
// Construct the child widgets
|
||||
this.makeChildWidgets();
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user