PageRenderTime 102ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/Languages/Ruby/Docs/readme.htm

http://github.com/IronLanguages/main
HTML | 9785 lines | 8903 code | 838 blank | 44 comment | 0 complexity | 43f32b6db54dd4ef12902dcbeb434897 MD5 | raw file
Possible License(s): CPL-1.0, BSD-3-Clause, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  3. <head>
  4. <script type="text/javascript">
  5. //<![CDATA[
  6. var version = {title: "TiddlyWiki", major: 2, minor: 2, revision: 4, date: new Date("Jun 19, 2007"), extensions: {}};
  7. //]]>
  8. </script>
  9. <!--
  10. TiddlyWiki created by Jeremy Ruston, (jeremy [at] osmosoft [dot] com)
  11. Copyright (c) UnaMesa Association 2004-2007
  12. Redistribution and use in source and binary forms, with or without modification,
  13. are permitted provided that the following conditions are met:
  14. Redistributions of source code must retain the above copyright notice, this
  15. list of conditions and the following disclaimer.
  16. Redistributions in binary form must reproduce the above copyright notice, this
  17. list of conditions and the following disclaimer in the documentation and/or other
  18. materials provided with the distribution.
  19. Neither the name of the UnaMesa Association nor the names of its contributors may be
  20. used to endorse or promote products derived from this software without specific
  21. prior written permission.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  23. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  24. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  25. SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  27. TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  28. BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  30. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  31. DAMAGE.
  32. -->
  33. <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  34. <!--PRE-HEAD-START-->
  35. <!--{{{-->
  36. <link rel='alternate' type='application/rss+xml' title='RSS' href='index.xml'/>
  37. <!--}}}-->
  38. <!--PRE-HEAD-END-->
  39. <title> IronRuby Docs - Developer documentation for Microsoft IronRuby </title>
  40. <style type="text/css">
  41. #saveTest {display:none;}
  42. #messageArea {display:none;}
  43. #copyright {display:none;}
  44. #storeArea {display:none;}
  45. #storeArea div {padding:0.5em; margin:1em 0em 0em 0em; border-color:#fff #666 #444 #ddd; border-style:solid; border-width:2px; overflow:auto;}
  46. #shadowArea {display:none;}
  47. #javascriptWarning {width:100%; text-align:center; font-weight:bold; background-color:#dd1100; color:#fff; padding:1em 0em;}
  48. </style>
  49. <!--POST-HEAD-START-->
  50. <!--POST-HEAD-END-->
  51. </head>
  52. <body onload="main();" onunload="if(window.checkUnsavedChanges) checkUnsavedChanges(); if(window.scrubNodes) scrubNodes(document.body);">
  53. <!--PRE-BODY-START-->
  54. <!--PRE-BODY-END-->
  55. <div id="copyright">
  56. Welcome to TiddlyWiki created by Jeremy Ruston, Copyright &copy; 2007 UnaMesa Association
  57. </div>
  58. <noscript>
  59. <div id="javascriptWarning">This page requires JavaScript to function properly.<br /><br />If you are using Microsoft Internet Explorer you may need to click on the yellow bar above and select 'Allow Blocked Content'. You must then click 'Yes' on the following security warning.</div>
  60. </noscript>
  61. <div id="saveTest"></div>
  62. <div id="backstageCloak"></div>
  63. <div id="backstageButton"></div>
  64. <div id="backstageArea"><div id="backstageToolbar"></div></div>
  65. <div id="backstage">
  66. <div id="backstagePanel"></div>
  67. </div>
  68. <div id="contentWrapper"></div>
  69. <div id="contentStash"></div>
  70. <div id="shadowArea">
  71. <div title="ColorPalette">
  72. <pre>Background: #fff
  73. Foreground: #000
  74. PrimaryPale: #8cf
  75. PrimaryLight: #18f
  76. PrimaryMid: #04b
  77. PrimaryDark: #014
  78. SecondaryPale: #ffc
  79. SecondaryLight: #fe8
  80. SecondaryMid: #db4
  81. SecondaryDark: #841
  82. TertiaryPale: #eee
  83. TertiaryLight: #ccc
  84. TertiaryMid: #999
  85. TertiaryDark: #666
  86. Error: #f88</pre>
  87. </div>
  88. <div title="StyleSheetColors">
  89. <pre>/*{{{*/
  90. body {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}
  91. a {color:[[ColorPalette::PrimaryMid]];}
  92. a:hover {background-color:[[ColorPalette::PrimaryMid]]; color:[[ColorPalette::Background]];}
  93. a img {border:0;}
  94. h1,h2,h3,h4,h5,h6 {color:[[ColorPalette::SecondaryDark]]; background:transparent;}
  95. h1 {border-bottom:2px solid [[ColorPalette::TertiaryLight]];}
  96. h2,h3 {border-bottom:1px solid [[ColorPalette::TertiaryLight]];}
  97. .button {color:[[ColorPalette::PrimaryDark]]; border:1px solid [[ColorPalette::Background]];}
  98. .button:hover {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::SecondaryLight]]; border-color:[[ColorPalette::SecondaryMid]];}
  99. .button:active {color:[[ColorPalette::Background]]; background:[[ColorPalette::SecondaryMid]]; border:1px solid [[ColorPalette::SecondaryDark]];}
  100. .header {background:[[ColorPalette::PrimaryMid]];}
  101. .headerShadow {color:[[ColorPalette::Foreground]];}
  102. .headerShadow a {font-weight:normal; color:[[ColorPalette::Foreground]];}
  103. .headerForeground {color:[[ColorPalette::Background]];}
  104. .headerForeground a {font-weight:normal; color:[[ColorPalette::PrimaryPale]];}
  105. .tabSelected{color:[[ColorPalette::PrimaryDark]];
  106. background:[[ColorPalette::TertiaryPale]];
  107. border-left:1px solid [[ColorPalette::TertiaryLight]];
  108. border-top:1px solid [[ColorPalette::TertiaryLight]];
  109. border-right:1px solid [[ColorPalette::TertiaryLight]];
  110. }
  111. .tabUnselected {color:[[ColorPalette::Background]]; background:[[ColorPalette::TertiaryMid]];}
  112. .tabContents {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::TertiaryPale]]; border:1px solid [[ColorPalette::TertiaryLight]];}
  113. .tabContents .button {border:0;}
  114. #sidebar {}
  115. #sidebarOptions input {border:1px solid [[ColorPalette::PrimaryMid]];}
  116. #sidebarOptions .sliderPanel {background:[[ColorPalette::PrimaryPale]];}
  117. #sidebarOptions .sliderPanel a {border:none;color:[[ColorPalette::PrimaryMid]];}
  118. #sidebarOptions .sliderPanel a:hover {color:[[ColorPalette::Background]]; background:[[ColorPalette::PrimaryMid]];}
  119. #sidebarOptions .sliderPanel a:active {color:[[ColorPalette::PrimaryMid]]; background:[[ColorPalette::Background]];}
  120. .wizard {background:[[ColorPalette::PrimaryPale]]; border:1px solid [[ColorPalette::PrimaryMid]];}
  121. .wizard h1 {color:[[ColorPalette::PrimaryDark]]; border:none;}
  122. .wizard h2 {color:[[ColorPalette::Foreground]]; border:none;}
  123. .wizardStep {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];
  124. border:1px solid [[ColorPalette::PrimaryMid]];}
  125. .wizardStep.wizardStepDone {background::[[ColorPalette::TertiaryLight]];}
  126. .wizardFooter {background:[[ColorPalette::PrimaryPale]];}
  127. .wizardFooter .status {background:[[ColorPalette::PrimaryDark]]; color:[[ColorPalette::Background]];}
  128. .wizard .button {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::SecondaryLight]]; border: 1px solid;
  129. border-color:[[ColorPalette::SecondaryPale]] [[ColorPalette::SecondaryDark]] [[ColorPalette::SecondaryDark]] [[ColorPalette::SecondaryPale]];}
  130. .wizard .button:hover {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::Background]];}
  131. .wizard .button:active {color:[[ColorPalette::Background]]; background:[[ColorPalette::Foreground]]; border: 1px solid;
  132. border-color:[[ColorPalette::PrimaryDark]] [[ColorPalette::PrimaryPale]] [[ColorPalette::PrimaryPale]] [[ColorPalette::PrimaryDark]];}
  133. #messageArea {border:1px solid [[ColorPalette::SecondaryMid]]; background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]];}
  134. #messageArea .button {color:[[ColorPalette::PrimaryMid]]; background:[[ColorPalette::SecondaryPale]]; border:none;}
  135. .popupTiddler {background:[[ColorPalette::TertiaryPale]]; border:2px solid [[ColorPalette::TertiaryMid]];}
  136. .popup {background:[[ColorPalette::TertiaryPale]]; color:[[ColorPalette::TertiaryDark]]; border-left:1px solid [[ColorPalette::TertiaryMid]]; border-top:1px solid [[ColorPalette::TertiaryMid]]; border-right:2px solid [[ColorPalette::TertiaryDark]]; border-bottom:2px solid [[ColorPalette::TertiaryDark]];}
  137. .popup hr {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::PrimaryDark]]; border-bottom:1px;}
  138. .popup li.disabled {color:[[ColorPalette::TertiaryMid]];}
  139. .popup li a, .popup li a:visited {color:[[ColorPalette::Foreground]]; border: none;}
  140. .popup li a:hover {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; border: none;}
  141. .popup li a:active {background:[[ColorPalette::SecondaryPale]]; color:[[ColorPalette::Foreground]]; border: none;}
  142. .popupHighlight {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}
  143. .listBreak div {border-bottom:1px solid [[ColorPalette::TertiaryDark]];}
  144. .tiddler .defaultCommand {font-weight:bold;}
  145. .shadow .title {color:[[ColorPalette::TertiaryDark]];}
  146. .title {color:[[ColorPalette::SecondaryDark]];}
  147. .subtitle {color:[[ColorPalette::TertiaryDark]];}
  148. .toolbar {color:[[ColorPalette::PrimaryMid]];}
  149. .toolbar a {color:[[ColorPalette::TertiaryLight]];}
  150. .selected .toolbar a {color:[[ColorPalette::TertiaryMid]];}
  151. .selected .toolbar a:hover {color:[[ColorPalette::Foreground]];}
  152. .tagging, .tagged {border:1px solid [[ColorPalette::TertiaryPale]]; background-color:[[ColorPalette::TertiaryPale]];}
  153. .selected .tagging, .selected .tagged {background-color:[[ColorPalette::TertiaryLight]]; border:1px solid [[ColorPalette::TertiaryMid]];}
  154. .tagging .listTitle, .tagged .listTitle {color:[[ColorPalette::PrimaryDark]];}
  155. .tagging .button, .tagged .button {border:none;}
  156. .footer {color:[[ColorPalette::TertiaryLight]];}
  157. .selected .footer {color:[[ColorPalette::TertiaryMid]];}
  158. .sparkline {background:[[ColorPalette::PrimaryPale]]; border:0;}
  159. .sparktick {background:[[ColorPalette::PrimaryDark]];}
  160. .error, .errorButton {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::Error]];}
  161. .warning {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::SecondaryPale]];}
  162. .lowlight {background:[[ColorPalette::TertiaryLight]];}
  163. .zoomer {background:none; color:[[ColorPalette::TertiaryMid]]; border:3px solid [[ColorPalette::TertiaryMid]];}
  164. .imageLink, #displayArea .imageLink {background:transparent;}
  165. .annotation {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; border:2px solid [[ColorPalette::SecondaryMid]];}
  166. .viewer .listTitle {list-style-type:none; margin-left:-2em;}
  167. .viewer .button {border:1px solid [[ColorPalette::SecondaryMid]];}
  168. .viewer blockquote {border-left:3px solid [[ColorPalette::TertiaryDark]];}
  169. .viewer table, table.twtable {border:2px solid [[ColorPalette::TertiaryDark]];}
  170. .viewer th, .viewer thead td, .twtable th, .twtable thead td {background:[[ColorPalette::SecondaryMid]]; border:1px solid [[ColorPalette::TertiaryDark]]; color:[[ColorPalette::Background]];}
  171. .viewer td, .viewer tr, .twtable td, .twtable tr {border:1px solid [[ColorPalette::TertiaryDark]];}
  172. .viewer pre {border:1px solid [[ColorPalette::SecondaryLight]]; background:[[ColorPalette::SecondaryPale]];}
  173. .viewer code {color:[[ColorPalette::SecondaryDark]];}
  174. .viewer hr {border:0; border-top:dashed 1px [[ColorPalette::TertiaryDark]]; color:[[ColorPalette::TertiaryDark]];}
  175. .highlight, .marked {background:[[ColorPalette::SecondaryLight]];}
  176. .editor input {border:1px solid [[ColorPalette::PrimaryMid]];}
  177. .editor textarea {border:1px solid [[ColorPalette::PrimaryMid]]; width:100%;}
  178. .editorFooter {color:[[ColorPalette::TertiaryMid]];}
  179. #backstageArea {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::TertiaryMid]];}
  180. #backstageArea a {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::Background]]; border:none;}
  181. #backstageArea a:hover {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; }
  182. #backstageArea a.backstageSelTab {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}
  183. #backstageButton a {background:none; color:[[ColorPalette::Background]]; border:none;}
  184. #backstageButton a:hover {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::Background]]; border:none;}
  185. #backstagePanel {background:[[ColorPalette::Background]]; border-color: [[ColorPalette::Background]] [[ColorPalette::TertiaryDark]] [[ColorPalette::TertiaryDark]] [[ColorPalette::TertiaryDark]];}
  186. .backstagePanelFooter .button {border:none; color:[[ColorPalette::Background]];}
  187. .backstagePanelFooter .button:hover {color:[[ColorPalette::Foreground]];}
  188. #backstageCloak {background:[[ColorPalette::Foreground]]; opacity:0.6; filter:'alpha(opacity:60)';}
  189. /*}}}*/</pre>
  190. </div>
  191. <div title="StyleSheetLayout">
  192. <pre>/*{{{*/
  193. * html .tiddler {height:1%;}
  194. body {font-size:.75em; font-family:arial,helvetica; margin:0; padding:0;}
  195. h1,h2,h3,h4,h5,h6 {font-weight:bold; text-decoration:none;}
  196. h1,h2,h3 {padding-bottom:1px; margin-top:1.2em;margin-bottom:0.3em;}
  197. h4,h5,h6 {margin-top:1em;}
  198. h1 {font-size:1.35em;}
  199. h2 {font-size:1.25em;}
  200. h3 {font-size:1.1em;}
  201. h4 {font-size:1em;}
  202. h5 {font-size:.9em;}
  203. hr {height:1px;}
  204. a {text-decoration:none;}
  205. dt {font-weight:bold;}
  206. ol {list-style-type:decimal;}
  207. ol ol {list-style-type:lower-alpha;}
  208. ol ol ol {list-style-type:lower-roman;}
  209. ol ol ol ol {list-style-type:decimal;}
  210. ol ol ol ol ol {list-style-type:lower-alpha;}
  211. ol ol ol ol ol ol {list-style-type:lower-roman;}
  212. ol ol ol ol ol ol ol {list-style-type:decimal;}
  213. .txtOptionInput {width:11em;}
  214. #contentWrapper .chkOptionInput {border:0;}
  215. .externalLink {text-decoration:underline;}
  216. .indent {margin-left:3em;}
  217. .outdent {margin-left:3em; text-indent:-3em;}
  218. code.escaped {white-space:nowrap;}
  219. .tiddlyLinkExisting {font-weight:bold;}
  220. .tiddlyLinkNonExisting {font-style:italic;}
  221. /* the 'a' is required for IE, otherwise it renders the whole tiddler in bold */
  222. a.tiddlyLinkNonExisting.shadow {font-weight:bold;}
  223. #mainMenu .tiddlyLinkExisting,
  224. #mainMenu .tiddlyLinkNonExisting,
  225. #sidebarTabs .tiddlyLinkNonExisting {font-weight:normal; font-style:normal;}
  226. #sidebarTabs .tiddlyLinkExisting {font-weight:bold; font-style:normal;}
  227. .header {position:relative;}
  228. .header a:hover {background:transparent;}
  229. .headerShadow {position:relative; padding:4.5em 0em 1em 1em; left:-1px; top:-1px;}
  230. .headerForeground {position:absolute; padding:4.5em 0em 1em 1em; left:0px; top:0px;}
  231. .siteTitle {font-size:3em;}
  232. .siteSubtitle {font-size:1.2em;}
  233. #mainMenu {position:absolute; left:0; width:10em; text-align:right; line-height:1.6em; padding:1.5em 0.5em 0.5em 0.5em; font-size:1.1em;}
  234. #sidebar {position:absolute; right:3px; width:16em; font-size:.9em;}
  235. #sidebarOptions {padding-top:0.3em;}
  236. #sidebarOptions a {margin:0em 0.2em; padding:0.2em 0.3em; display:block;}
  237. #sidebarOptions input {margin:0.4em 0.5em;}
  238. #sidebarOptions .sliderPanel {margin-left:1em; padding:0.5em; font-size:.85em;}
  239. #sidebarOptions .sliderPanel a {font-weight:bold; display:inline; padding:0;}
  240. #sidebarOptions .sliderPanel input {margin:0 0 .3em 0;}
  241. #sidebarTabs .tabContents {width:15em; overflow:hidden;}
  242. .wizard {padding:0.1em 1em 0em 2em;}
  243. .wizard h1 {font-size:2em; font-weight:bold; background:none; padding:0em 0em 0em 0em; margin:0.4em 0em 0.2em 0em;}
  244. .wizard h2 {font-size:1.2em; font-weight:bold; background:none; padding:0em 0em 0em 0em; margin:0.4em 0em 0.2em 0em;}
  245. .wizardStep {padding:1em 1em 1em 1em;}
  246. .wizard .button {margin:0.5em 0em 0em 0em; font-size:1.2em;}
  247. .wizardFooter {padding:0.8em 0.4em 0.8em 0em;}
  248. .wizardFooter .status {padding:0em 0.4em 0em 0.4em; margin-left:1em;}
  249. .wizard .button {padding:0.1em 0.2em 0.1em 0.2em;}
  250. #messageArea {position:fixed; top:2em; right:0em; margin:0.5em; padding:0.5em; z-index:2000; _position:absolute;}
  251. .messageToolbar {display:block; text-align:right; padding:0.2em 0.2em 0.2em 0.2em;}
  252. #messageArea a {text-decoration:underline;}
  253. .tiddlerPopupButton {padding:0.2em 0.2em 0.2em 0.2em;}
  254. .popupTiddler {position: absolute; z-index:300; padding:1em 1em 1em 1em; margin:0;}
  255. .popup {position:absolute; z-index:300; font-size:.9em; padding:0; list-style:none; margin:0;}
  256. .popup .popupMessage {padding:0.4em;}
  257. .popup hr {display:block; height:1px; width:auto; padding:0; margin:0.2em 0em;}
  258. .popup li.disabled {padding:0.4em;}
  259. .popup li a {display:block; padding:0.4em; font-weight:normal; cursor:pointer;}
  260. .listBreak {font-size:1px; line-height:1px;}
  261. .listBreak div {margin:2px 0;}
  262. .tabset {padding:1em 0em 0em 0.5em;}
  263. .tab {margin:0em 0em 0em 0.25em; padding:2px;}
  264. .tabContents {padding:0.5em;}
  265. .tabContents ul, .tabContents ol {margin:0; padding:0;}
  266. .txtMainTab .tabContents li {list-style:none;}
  267. .tabContents li.listLink { margin-left:.75em;}
  268. #contentWrapper {display:block;}
  269. #splashScreen {display:none;}
  270. #displayArea {margin:1em 17em 0em 14em;}
  271. .toolbar {text-align:right; font-size:.9em;}
  272. .tiddler {padding:1em 1em 0em 1em;}
  273. .missing .viewer,.missing .title {font-style:italic;}
  274. .title {font-size:1.6em; font-weight:bold;}
  275. .missing .subtitle {display:none;}
  276. .subtitle {font-size:1.1em;}
  277. .tiddler .button {padding:0.2em 0.4em;}
  278. .tagging {margin:0.5em 0.5em 0.5em 0; float:left; display:none;}
  279. .isTag .tagging {display:block;}
  280. .tagged {margin:0.5em; float:right;}
  281. .tagging, .tagged {font-size:0.9em; padding:0.25em;}
  282. .tagging ul, .tagged ul {list-style:none; margin:0.25em; padding:0;}
  283. .tagClear {clear:both;}
  284. .footer {font-size:.9em;}
  285. .footer li {display:inline;}
  286. .annotation {padding:0.5em; margin:0.5em;}
  287. * html .viewer pre {width:99%; padding:0 0 1em 0;}
  288. .viewer {line-height:1.4em; padding-top:0.5em;}
  289. .viewer .button {margin:0em 0.25em; padding:0em 0.25em;}
  290. .viewer blockquote {line-height:1.5em; padding-left:0.8em;margin-left:2.5em;}
  291. .viewer ul, .viewer ol {margin-left:0.5em; padding-left:1.5em;}
  292. .viewer table, table.twtable {border-collapse:collapse; margin:0.8em 1.0em;}
  293. .viewer th, .viewer td, .viewer tr,.viewer caption,.twtable th, .twtable td, .twtable tr,.twtable caption {padding:3px;}
  294. table.listView {font-size:0.85em; margin:0.8em 1.0em;}
  295. table.listView th, table.listView td, table.listView tr {padding:0px 3px 0px 3px;}
  296. .viewer pre {padding:0.5em; margin-left:0.5em; font-size:1.2em; line-height:1.4em; overflow:auto;}
  297. .viewer code {font-size:1.2em; line-height:1.4em;}
  298. .editor {font-size:1.1em;}
  299. .editor input, .editor textarea {display:block; width:100%; font:inherit;}
  300. .editorFooter {padding:0.25em 0em; font-size:.9em;}
  301. .editorFooter .button {padding-top:0px; padding-bottom:0px;}
  302. .fieldsetFix {border:0; padding:0; margin:1px 0px 1px 0px;}
  303. .sparkline {line-height:1em;}
  304. .sparktick {outline:0;}
  305. .zoomer {font-size:1.1em; position:absolute; overflow:hidden;}
  306. .zoomer div {padding:1em;}
  307. * html #backstage {width:99%;}
  308. * html #backstageArea {width:99%;}
  309. #backstageArea {display:none; position:relative; overflow: hidden; z-index:150; padding:0.3em 0.5em 0.3em 0.5em;}
  310. #backstageToolbar {position:relative;}
  311. #backstageArea a {font-weight:bold; margin-left:0.5em; padding:0.3em 0.5em 0.3em 0.5em;}
  312. #backstageButton {display:none; position:absolute; z-index:175; top:0em; right:0em;}
  313. #backstageButton a {padding:0.1em 0.4em 0.1em 0.4em; margin:0.1em 0.1em 0.1em 0.1em;}
  314. #backstage {position:relative; width:100%; z-index:50;}
  315. #backstagePanel {display:none; z-index:100; position:absolute; margin:0em 3em 0em 3em; padding:1em 1em 1em 1em;}
  316. .backstagePanelFooter {padding-top:0.2em; float:right;}
  317. .backstagePanelFooter a {padding:0.2em 0.4em 0.2em 0.4em;}
  318. #backstageCloak {display:none; z-index:20; position:absolute; width:100%; height:100px;}
  319. .whenBackstage {display:none;}
  320. .backstageVisible .whenBackstage {display:block;}
  321. /*}}}*/</pre>
  322. </div>
  323. <div title="StyleSheetLocale">
  324. <pre>/***
  325. StyleSheet for use when a translation requires any css style changes.
  326. This StyleSheet can be used directly by languages such as Chinese, Japanese and Korean which use a logographic writing system and need larger font sizes.
  327. ***/
  328. /*{{{*/
  329. body {font-size:0.8em;}
  330. #sidebarOptions {font-size:1.05em;}
  331. #sidebarOptions a {font-style:normal;}
  332. #sidebarOptions .sliderPanel {font-size:0.95em;}
  333. .subtitle {font-size:0.8em;}
  334. .viewer table.listView {font-size:0.95em;}
  335. .htmlarea .toolbarHA table {border:1px solid ButtonFace; margin:0em 0em;}
  336. /*}}}*/</pre>
  337. </div>
  338. <div title="StyleSheetPrint">
  339. <pre>/*{{{*/
  340. @media print {
  341. #mainMenu, #sidebar, #messageArea, .toolbar, #backstageButton {display: none ! important;}
  342. #displayArea {margin: 1em 1em 0em 1em;}
  343. /* Fixes a feature in Firefox 1.5.0.2 where print preview displays the noscript content */
  344. noscript {display:none;}
  345. }
  346. /*}}}*/</pre>
  347. </div>
  348. <div title="PageTemplate">
  349. <pre>&lt;!--{{{--&gt;
  350. &lt;div class='header' macro='gradient vert [[ColorPalette::PrimaryLight]] [[ColorPalette::PrimaryMid]]'&gt;
  351. &lt;div class='headerShadow'&gt;
  352. &lt;span class='siteTitle' refresh='content' tiddler='SiteTitle'&gt;&lt;/span&gt;&amp;nbsp;
  353. &lt;span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'&gt;&lt;/span&gt;
  354. &lt;/div&gt;
  355. &lt;div class='headerForeground'&gt;
  356. &lt;span class='siteTitle' refresh='content' tiddler='SiteTitle'&gt;&lt;/span&gt;&amp;nbsp;
  357. &lt;span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'&gt;&lt;/span&gt;
  358. &lt;/div&gt;
  359. &lt;/div&gt;
  360. &lt;div id='mainMenu' refresh='content' tiddler='MainMenu'&gt;&lt;/div&gt;
  361. &lt;div id='sidebar'&gt;
  362. &lt;div id='sidebarOptions' refresh='content' tiddler='SideBarOptions'&gt;&lt;/div&gt;
  363. &lt;div id='sidebarTabs' refresh='content' force='true' tiddler='SideBarTabs'&gt;&lt;/div&gt;
  364. &lt;/div&gt;
  365. &lt;div id='displayArea'&gt;
  366. &lt;div id='messageArea'&gt;&lt;/div&gt;
  367. &lt;div id='tiddlerDisplay'&gt;&lt;/div&gt;
  368. &lt;/div&gt;
  369. &lt;!--}}}--&gt;</pre>
  370. </div>
  371. <div title="ViewTemplate">
  372. <pre>&lt;!--{{{--&gt;
  373. &lt;div class='toolbar' macro='toolbar closeTiddler closeOthers +editTiddler &gt; fields syncing permalink references jump'&gt;&lt;/div&gt;
  374. &lt;div class='title' macro='view title'&gt;&lt;/div&gt;
  375. &lt;div class='subtitle'&gt;&lt;span macro='view modifier link'&gt;&lt;/span&gt;, &lt;span macro='view modified date'&gt;&lt;/span&gt; (&lt;span macro='message views.wikified.createdPrompt'&gt;&lt;/span&gt; &lt;span macro='view created date'&gt;&lt;/span&gt;)&lt;/div&gt;
  376. &lt;div class='tagging' macro='tagging'&gt;&lt;/div&gt;
  377. &lt;div class='tagged' macro='tags'&gt;&lt;/div&gt;
  378. &lt;div class='viewer' macro='view text wikified'&gt;&lt;/div&gt;
  379. &lt;div class='tagClear'&gt;&lt;/div&gt;
  380. &lt;!--}}}--&gt;</pre>
  381. </div>
  382. <div title="EditTemplate">
  383. <pre>&lt;!--{{{--&gt;
  384. &lt;div class='toolbar' macro='toolbar +saveTiddler -cancelTiddler deleteTiddler'&gt;&lt;/div&gt;
  385. &lt;div class='title' macro='view title'&gt;&lt;/div&gt;
  386. &lt;div class='editor' macro='edit title'&gt;&lt;/div&gt;
  387. &lt;div macro='annotations'&gt;&lt;/div&gt;
  388. &lt;div class='editor' macro='edit text'&gt;&lt;/div&gt;
  389. &lt;div class='editor' macro='edit tags'&gt;&lt;/div&gt;&lt;div class='editorFooter'&gt;&lt;span macro='message views.editor.tagPrompt'&gt;&lt;/span&gt;&lt;span macro='tagChooser'&gt;&lt;/span&gt;&lt;/div&gt;
  390. &lt;!--}}}--&gt;</pre>
  391. </div>
  392. <div title="GettingStarted">
  393. <pre>To get started with this blank TiddlyWiki, you'll need to modify the following tiddlers:
  394. * SiteTitle &amp; SiteSubtitle: The title and subtitle of the site, as shown above (after saving, they will also appear in the browser title bar)
  395. * MainMenu: The menu (usually on the left)
  396. * DefaultTiddlers: Contains the names of the tiddlers that you want to appear when the TiddlyWiki is opened
  397. You'll also need to enter your username for signing your edits: &lt;&lt;option txtUserName&gt;&gt;</pre>
  398. </div>
  399. <div title="OptionsPanel">
  400. <pre>These InterfaceOptions for customising TiddlyWiki are saved in your browser
  401. Your username for signing your edits. Write it as a WikiWord (eg JoeBloggs)
  402. &lt;&lt;option txtUserName&gt;&gt;
  403. &lt;&lt;option chkSaveBackups&gt;&gt; SaveBackups
  404. &lt;&lt;option chkAutoSave&gt;&gt; AutoSave
  405. &lt;&lt;option chkRegExpSearch&gt;&gt; RegExpSearch
  406. &lt;&lt;option chkCaseSensitiveSearch&gt;&gt; CaseSensitiveSearch
  407. &lt;&lt;option chkAnimate&gt;&gt; EnableAnimations
  408. ----
  409. Also see AdvancedOptions</pre>
  410. </div>
  411. </div>
  412. <!--POST-SHADOWAREA-->
  413. <div id="storeArea">
  414. <div title="AddAMethod" modifier="JohnLam" modified="200707190023" created="200707182349" changecount="3">
  415. <pre>!Implementation
  416. Let's add a {{{downcase}}} method to the MutableString class. This is the simplest kind of method - it accepts no parameters and returns a MutableString.
  417. MutableString lives in Ruby\Builtins\MutableString.cs. Its unit tests live in Tests\Builtins\String\test_string.rb. Here's one possible implementation of this method:
  418. {{{
  419. [RubyMethodAttribute(&quot;downcase&quot;, RubyMethodAttributes.PublicInstance)]
  420. public static MutableString DownCase(MutableString str) {
  421. MutableString result = new MutableString(str);
  422. DownCaseMutableString(result);
  423. return result;
  424. }
  425. }}}
  426. Notice that the method is a _static_ method. DLR provides its own version of C#
  427. 3.0's ExtensionMethods. In library code, all methods are implemented as ''static''
  428. methods on the type, particularly if its on a type that we define (which is the case with MutableString).
  429. If it's a type that we don't define, such as Int32, we define our extension
  430. methods in a class that has the suffix &quot;Ops&quot; attached to the name. In the case
  431. of Int32, which is really a Ruby Fixnum type, our extension methods are
  432. implemented in a type called FixnumOps.
  433. Notice that we have attached a RubyMethodAttribute to this class. This attribute
  434. defines the Ruby-callable name of the method since Ruby supports method names
  435. that are illegal in C#, such as &quot;downcase!&quot;. The RubyMethodAttributes
  436. enumeration defines the instancing and visibility of the method; in this case we
  437. are defining a public instance method on the String type.
  438. !Unit Tests
  439. Next, we have to implement the unit tests. In this early implementation of
  440. IronRuby, we support a simple form of RSpec tests. The testing framework can be
  441. found in Ruby\Tests\Util\simple_test.rb. Here's an implementation of the tests:
  442. {{{
  443. describe &quot;String#downcase&quot; do
  444. it &quot;returns a copy of self with all uppercase letters downcased&quot; do
  445. &quot;hELLO&quot;.downcase.should == &quot;hello&quot;
  446. &quot;hello&quot;.downcase.should == &quot;hello&quot;
  447. end
  448. it &quot;is locale insensitive (only replacing A-Z)&quot; do
  449. &quot;ÃÃÃœ&quot;.downcase.should == &quot;ÃÃÃœ&quot;
  450. end
  451. end
  452. }}}
  453. Next up, lets define a method that AcceptsParameters.
  454. </pre>
  455. </div>
  456. <div title="CodingStandards" modifier="JohnLam" modified="200707192257" created="200707192056" changecount="8">
  457. <pre>IronRuby uses four-space indentation. Tabs must be expanded as spaces. No exceptions.
  458. Public names are subject to FxCop rules.
  459. !!Private class member variables start with underscore _:
  460. {{{
  461. class MyClass {
  462. private string _name;
  463. public MyClass(string name) {
  464. _name = name;
  465. }
  466. }
  467. }}}
  468. !!Static variable names start with underscore followed by upper case letter:
  469. {{{
  470. _StaticVar
  471. }}}
  472. !!Open brace on same line as code:
  473. {{{
  474. if (true) {
  475. DoSomething();
  476. }
  477. }}}
  478. !!Member variables should be declared at the top of a class declaration:
  479. {{{
  480. class MyClass {
  481. private string _name;
  482. public MyClass(string name) {
  483. _name = name;
  484. }
  485. // Additional Code Here
  486. public string Name {
  487. get { return _name; }
  488. set { _name = value; }
  489. }
  490. }
  491. }}}
  492. Not:
  493. {{{
  494. class MyClass {
  495. public MyClass(string name) {
  496. _name = name;
  497. }
  498. // Additional Code Here
  499. private string _name;
  500. public string Name {
  501. get { return _name; }
  502. set { _name = value; }
  503. }
  504. }
  505. }}}
  506. IronRuby uses uniform formatting of the C# code. Set your editor to use the IronRuby.vssettings file to set handling of tabs and formatting of the code. This file is located in the root directory of the IronRuby project.
  507. To use the team settings in Visual Studio, go to Tools-&gt;Options Expand the Environment node, select Import and Export Settings. Check the Use team settings file and browse to the &quot;IronRuby.vssettings file located in your workspace.</pre>
  508. </div>
  509. <div title="CompileSources" modifier="JohnLam" created="200707230557" changecount="1">
  510. <pre>You can compile IronRuby by running {{build.cmd}} from the root directory of your IronRuby source distribution. You must have the .NET 2.0 Framework redistributable installed, since the build scripts rely on MSBuild.
  511. This will generate a release mode build of IronRuby in the \bin\release directory of your source distribution.</pre>
  512. </div>
  513. <div title="DefaultTiddlers" modifier="JohnLam" created="200707191650" changecount="1">
  514. <pre>IronRuby</pre>
  515. </div>
  516. <div title="ExtensionMethods" modifier="JohnLam" modified="200707190026" created="200707190025" changecount="3">
  517. <pre>Extension methods let us add methods (instance and static) to types that we didn't define. The DLR method dispatch mechanism generates the correct code to call these methods.
  518. For more details on C# 3.0 extension methods, see &lt;&lt;some article&gt;&gt;</pre>
  519. </div>
  520. <div title="IronRuby" modifier="JohnLam" modified="200707230555" created="200707181616" changecount="8">
  521. <pre>Welcome to the IronRuby project!
  522. The current version of IronRuby is the 0.1 Pre-Alpha, released on July 23.
  523. IronRuby is licensed under the terms of the Apache License, Version 2.0.
  524. This release of IronRuby ships only in source form. You must CompileSources first.
  525. If you're new here, make sure you read the NewDev page first. We're currently looking for contributions in the StandardLibraries, which you can find under \ironruby\src\ironrubylibs\.
  526. </pre>
  527. </div>
  528. <div title="IronRubyLibraries" modifier="JohnLam" modified="200707191539" created="200707181722" changecount="3">
  529. <pre>We are dividing the IronRuby libraries into BuiltIns and StandardLibraries. This is the area of IronRuby where we need external help the most.
  530. Make sure that you follow the CodingConventions.
  531. If this is your first contribution, read the tutorial on how to AddAMethod to an existing type.
  532. </pre>
  533. </div>
  534. <div title="JohnLam" modifier="JohnLam" created="200707181617" changecount="1">
  535. <pre>John Lam is an IronRuby core team member, and a Program Manager on the DynamicLanguageRuntime team at Microsoft.
  536. John tracks the progress of the IronRuby project on his blog, http://www.iunknown.com
  537. </pre>
  538. </div>
  539. <div title="MSBuild" modifier="JohnLam" created="200707181702" changecount="1">
  540. <pre>It ships with the [[.NET 2.0 Framework redist|http://www.microsoft.com/downloads/details.aspx?FamilyID=0856EACB-4362-4B0D-8EDD-AAB15C5E04F5&amp;displaylang=en]]. We have build scripts to help you build the projects and run the unit tests.
  541. </pre>
  542. </div>
  543. <div title="MainMenu" modifier="JohnLam" created="200707191729" changecount="1">
  544. <pre>IronRuby</pre>
  545. </div>
  546. <div title="Apache" modifier="DinoViehland" modified="201007081732" created="200707181707" changecount="3"><pre>
  547. Apache License
  548. Version 2.0, January 2004
  549. http://www.apache.org/licenses/
  550. TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
  551. 1. Definitions.
  552. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
  553. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
  554. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
  555. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
  556. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
  557. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
  558. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
  559. "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
  560. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
  561. "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
  562. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
  563. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
  564. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
  565. You must give any other recipients of the Work or Derivative Works a copy of this License; and
  566. You must cause any modified files to carry prominent notices stating that You changed the files; and
  567. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
  568. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
  569. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
  570. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
  571. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
  572. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
  573. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
  574. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
  575. See FAQ for answers to frequently asked questions about this license.
  576. </pre>
  577. </div>
  578. <div title="MutableString" modifier="JohnLam" created="200707182351" changecount="1">
  579. <pre>MutableString is the CLR type that represents a Ruby String. It's currently based on the StringBuilder type, which is a very efficient implementation of a char[] buffer. The current plan of record is to use this type for the near future before we invest in converting this type to a byte[] which is the long term plan.</pre>
  580. </div>
  581. <div title="NewDev" modifier="JohnLam" modified="200707192306" created="200707181659" changecount="9">
  582. <pre>New to the project? There are a few things that you should know before you dive in.
  583. * We are currently only accepting contributions into the StandardLibraries.
  584. * Take some time to familiarize yourself with the SourceCodeLayout.
  585. * Make sure you understand how the UnitTests work.
  586. * Work through the RunningFirstTime tutorial.
  587. Contributing code
  588. * Read the CodingStandards
  589. * Read the tutorial on how to AddAMethod to the libraries
  590. * Build the solution using MSBuild and verify that the UnitTests pass</pre>
  591. </div>
  592. <div title="PageTemplate" modifier="YourName" modified="200701122313" created="200701122350" tags="LewcidOrangeBlogTheme" server.type="file" server.host="http://tiddlythemes.com/empties/LewcidOrangeBlog.html" server.page.revision="200701122313">
  593. <pre>&lt;!--{{{--&gt;
  594. &lt;div class='header'&gt;
  595. &lt;div class='gradient' macro='gradient vert #FF8614 #DA4A0D '&gt;
  596. &lt;div class='titleLine' &gt;
  597. &lt;span class='siteTitle' refresh='content' tiddler='SiteTitle'&gt;&lt;/span&gt;&amp;nbsp;
  598. &lt;span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'&gt;&lt;/span&gt;
  599. &lt;/div&gt;
  600. &lt;div id='topMenu' refresh='content' tiddler='MainMenu'&gt;&lt;/div&gt;
  601. &lt;/div&gt;
  602. &lt;/div&gt;
  603. &lt;div id='bodywrapper'&gt;
  604. &lt;div id='sidebar'&gt;
  605. &lt;div id='sidebarOptions' refresh='content' tiddler='SideBarOptions'&gt;&lt;/div&gt;
  606. &lt;div id='sidebarTabs' refresh='content' force='true' tiddler='SideBarTabs'&gt;&lt;/div&gt;
  607. &lt;/div&gt;
  608. &lt;div id='displayArea'&gt;
  609. &lt;div id='messageArea'&gt;&lt;/div&gt;
  610. &lt;div id='tiddlerDisplay'&gt;&lt;/div&gt;
  611. &lt;/div&gt;
  612. &lt;div id='contentFooter'&gt;TiddlyWiki&lt;/div&gt;
  613. &lt;/div&gt;
  614. &lt;!--}}}--&gt;</pre>
  615. </div>
  616. <div title="RunningFirstTime" modifier="JohnLam" modified="200707221829" created="200707221827" changecount="2">
  617. <pre>This topic will teach you the basics of how things run in IronRuby.
  618. First, we will step through the Ruby.Console application to see what happens when we run a simple program:
  619. {{{
  620. puts 'Hello, World!'
  621. }}}
  622. You will see a number of things when we step through this code:
  623. # The hosting interfaces
  624. # The Ruby parser
  625. # The Ruby AST
  626. # The transformation of the Ruby AST into the DLR AST
  627. # Some interesting execution paths
  628. </pre>
  629. </div>
  630. <div title="SideBarWG" modifier="YourName" modified="200701122313" created="200701122350" tags="LewcidOrangeBlogTheme" server.type="file" server.host="http://tiddlythemes.com/empties/LewcidOrangeBlog.html" server.page.revision="200701122313">
  631. <pre>/***
  632. This CSS by DaveBirss.
  633. ***/
  634. /*{{{*/
  635. .tabSelected {
  636. background: #fff;
  637. }
  638. .tabUnselected {
  639. background: #eee;
  640. }
  641. #sidebar {
  642. color: #000;
  643. background: transparent;
  644. }
  645. #sidebarOptions {
  646. background: #fff;
  647. }
  648. #sidebarOptions input {
  649. border: 1px solid #ccc;
  650. }
  651. #sidebarOptions input:hover, #sidebarOptions input:active, #sidebarOptions input:focus {
  652. border: 1px solid #000;
  653. }
  654. #sidebarOptions .button {
  655. color: #999;
  656. }
  657. #sidebarOptions .button:hover {
  658. color: #000;
  659. background: #fff;
  660. border-color:white;
  661. }
  662. #sidebarOptions .button:active {
  663. color: #000;
  664. background: #fff;
  665. }
  666. #sidebarOptions .sliderPanel {
  667. background: transparent;
  668. }
  669. #sidebarOptions .sliderPanel A {
  670. color: #999;
  671. }
  672. #sidebarOptions .sliderPanel A:hover {
  673. color: #000;
  674. background: #fff;
  675. }
  676. #sidebarOptions .sliderPanel A:active {
  677. color: #000;
  678. background: #fff;
  679. }
  680. .sidebarSubHeading {
  681. color: #000;
  682. }
  683. #sidebarTabs {`
  684. background: #fff
  685. }
  686. #sidebarTabs .tabSelected {
  687. color: #000;
  688. background: #fff;
  689. border-top: solid 1px #ccc;
  690. border-left: solid 1px #ccc;
  691. border-right: solid 1px #ccc;
  692. border-bottom: none;
  693. }
  694. #sidebarTabs .tabUnselected {
  695. color: #999;
  696. background: #eee;
  697. border-top: solid 1px #ccc;
  698. border-left: solid 1px #ccc;
  699. border-right: solid 1px #ccc;
  700. border-bottom: none;
  701. }
  702. #sidebarTabs .tabContents {
  703. background: #fff;
  704. }
  705. #sidebarTabs .txtMoreTab .tabSelected {
  706. background: #fff;
  707. }
  708. #sidebarTabs .txtMoreTab .tabUnselected {
  709. background: #eee;
  710. }
  711. #sidebarTabs .txtMoreTab .tabContents {
  712. background: #fff;
  713. }
  714. #sidebarTabs .tabContents .tiddlyLink {
  715. color: #999;
  716. border:none;
  717. }
  718. #sidebarTabs .tabContents .tiddlyLink:hover {
  719. background: #fff;
  720. color: #000;
  721. border:none;
  722. }
  723. #sidebarTabs .tabContents {
  724. color: #000;
  725. }
  726. #sidebarTabs .button {
  727. color: #666;
  728. }
  729. #sidebarTabs .tabContents .button:hover {
  730. color: #000;
  731. background: #fff;
  732. }
  733. #sidebar {color:#999;}
  734. /*}}}*/</pre>
  735. </div>
  736. <div title="SiteSubtitle" modifier="YourName" created="200707181614" changecount="1">
  737. <pre>Developer documentation for Microsoft IronRuby</pre>
  738. </div>
  739. <div title="SiteTitle" modifier="YourName" created="200707181614" changecount="1">
  740. <pre>IronRuby Docs</pre>
  741. </div>
  742. <div title="SourceCodeLayout" modifier="JohnLam" modified="200707191618" created="200707191555" changecount="2">
  743. <pre>The IronRuby source code has the following layout:
  744. {{{
  745. \ironruby
  746. src\
  747. ironruby\
  748. ironrubylibs\
  749. microsoft.scripting\
  750. tests\
  751. ironruby\
  752. microsoft.scripting\
  753. utils\
  754. IronRuby.Tests\
  755. ironruby.console\
  756. classinitgenerator\
  757. }}}
  758. The src\ironruby directory contains the code for the compiler and the BuiltIns. We are currently not AcceptingContributions into the core compiler.
  759. The src\ironrubylibs directory contains the code for the StandardLibraries. We are AcceptingContributions into this directory tree.
  760. The tests\ironruby directory contains the UnitTests for the compiler, BuiltIns, and StandardLibraries.
  761. The tests\microsoft.scripting directory contains the UnitTests for the DynamicLanguageRuntime.
  762. The utils\IronRuby.Tests directory contains a set of tests that are useful if you want to step into the core compiler using a debugger.
  763. The utils\ironruby.console directory contains a simple console-based host for the IronRuby compiler that supports REPL-style programming.
  764. The utils\classinitgenerator directory contains a utility that will generate code from class and method attributes used in the libraries. </pre>
  765. </div>
  766. <div title="StandardLibraries" modifier="JohnLam" modified="200707192244" created="200707191511" changecount="4">
  767. <pre>The StandardLibraries are the same list of libraries described in Chapter 28 of the PickAxe book. These libraries will be compiled into a separate assembly, IronRubyLibs.dll. The sources live in \ironruby\src\ironrubylibs\.
  768. Here's a complete list of the libraries that we are looking for contributions in:
  769. !Libraries to be ported to C#
  770. # [[strscan|http://ruby-doc.org/stdlib/libdoc/strscan/rdoc/classes/StringScanner.html]]: a high-speed string token scanner
  771. # syck: high-speed YAML parser
  772. # zlib: library for [de]compressing streams and working with gzip files
  773. # bigdecimal: variable precision floating point library (GPL)
  774. # readline: wrapper around GNU readline library
  775. # curses: wrapper around C-based curses library
  776. # enumerator: adds enumeration support to arbitrary objects and mixes in Enumerable
  777. # fcntl: symbolic names for fcntl constants based on underlying OS
  778. # iconv: translates string between different character encodings
  779. # io: adds IO#ready? and IO#wait methods to standard IO class
  780. # pty: pseudo-terminal interface
  781. # racc: runtime library for code produced by racc [Ruby yacc]
  782. # stringio: treat a string as if it were an I/O stream
  783. # thread: utility methods for multithreaded programming. Queue utility class is still used today by some libraries - most functionality superceded by Monitor
  784. !Libraries that should delegate functionality to existing .NET libraries
  785. # openssl: wrapper around OpenSSL library
  786. # digest: various hashing algorithms (md5, rmd160, sha1, sha2)
  787. # dl: access underlying platform's DLL infrastructure [similar to Win32API]
  788. # socket: interface with platform socket implementation (unknown license)
  789. # Win32API: allows access to arbitrary Win32 functions P/Invoke style wrapper
  790. # win32ole: library for manipulating COM objects (GPL or Artistic License)
  791. !Libraries that target non-Windows platforms
  792. # Dbm: wrapper around DBM databases which are persistent hash-like files
  793. # gdbm: Ruby wrapper around GNU database
  794. # nkf: wrapper around Network Kanji Filter library - guess character encodings
  795. # sdbm: key-value hashtable persistence library
  796. # etc: used to retrieve data under /etc directory on Unix systems
  797. # syslog: wrapper around Unix syslog library
  798. # tk: library for creating cross-platform UIs
  799. </pre>
  800. </div>
  801. <div title="StyleSheet" modifier="YourName" modified="200701122313" created="200701122350" tags="LewcidOrangeBlogTheme" server.type="file" server.host="http://tiddlythemes.com/empties/LewcidOrangeBlog.html" server.page.revision="200701122313">
  802. <pre>[[SideBarWG]]
  803. /***
  804. !Top Menu Styles
  805. ***/
  806. /*{{{*/
  807. #topMenu br {display:none; }
  808. #topMenu { background: #000 ; color:#fff;padding: 1em 1em;}
  809. /*}}}*/
  810. /***
  811. !General
  812. ***/
  813. /*{{{*/
  814. body {
  815. background: #444;
  816. margin: 0 auto;
  817. }
  818. #contentWrapper{
  819. background: #fff;
  820. border: 0;
  821. margin: 0 auto;
  822. width: 792px;
  823. padding:0;
  824. }
  825. /*}}}*/
  826. /***
  827. !Header rules
  828. ***/
  829. /*{{{*/
  830. .titleLine{
  831. margin: 80px auto 0em ;
  832. margin-left:1.7em;
  833. margin-bottom: 40px;
  834. padding: 0;
  835. text-align: left;
  836. color: #fff;
  837. }
  838. .siteTitle {
  839. font-size: 2em;
  840. font-weight: bold;
  841. }
  842. .siteSubtitle {
  843. font-size: 1.1em;
  844. display: block;
  845. margin: .5em auto 1em;
  846. }
  847. .gradient {margin: 0 auto;}
  848. .header {
  849. background: #fff;
  850. margin: 0 auto;
  851. padding:0 12px;
  852. width: 768px;
  853. }
  854. /*}}}*/
  855. /***
  856. !Display Area
  857. ***/
  858. /*{{{*/
  859. #bodywrapper {margin:0 12px; padding:0;background:#fff; height:1%}
  860. #displayArea{
  861. margin: 0em 16em 0em 1em;
  862. text-align: left;
  863. }
  864. .tiddler {
  865. padding: 1em 1em 0em 0em;
  866. }
  867. h1,h2,h3,h4,h5 { color: #000; background: transparent; padding-bottom:2px; border-bottom: 1px dotted #666; }
  868. .title {color:black; font-size:1.8em; border-bottom:1px solid #333; padding-bottom:0.3px;}
  869. .subtitle { font-size:90%; color:#ccc; padding-left:0.25em; margin-top:0.1em; }
  870. .shadow .title {
  871. color: #aaa;
  872. }
  873. .tagClear{
  874. clear: none;
  875. }
  876. * html .viewer pre {
  877. margin-left: 0em;
  878. }
  879. * html .editor textarea, * html .editor input {
  880. width: 98%;
  881. }
  882. .tiddler {margin-bottom:1em; padding-bottom:0em;}
  883. .toolbar .button {color:#bbb; border:none;}
  884. .toolbar .button:hover, .toolbar .highlight, .toolbar .marked, .toolbar a.button:active {background:transparent; color:#111; border:none; text-decoration:underline;}
  885. #sidebar .highlight, #sidebar .marked {background:transparent;}
  886. .tagging, .tagged {
  887. border: 1px solid #eee;
  888. background-color: #F7F7F7;
  889. }
  890. .selected .tagging, .selected .tagged {
  891. background-color: #eee;
  892. border: 1px solid #bbb;
  893. }
  894. .tagging .listTitle, .tagged .listTitle {
  895. color: #bbb;
  896. }
  897. .selected .tagging .listTitle, .selected .tagged .listTitle {
  898. color: #222;
  899. }
  900. .tagging .button:hover, .tagged .button:hover {
  901. border: none; background:transparent; text-decoration:underline; color:#000;
  902. }
  903. .tagging .button, .tagged .button {
  904. color:#aaa;
  905. }
  906. .selected .tagging .button, .selected .tagged .button {
  907. color:#000;
  908. }
  909. .viewer blockquote {
  910. border-left: 3px solid #000;
  911. }
  912. .viewer pre, .viewer code {
  913. border: 1px dashed #ccc;
  914. background: #eee;}
  915. .viewer hr {
  916. border: 0;
  917. border-top: solid 1px #333;
  918. margin: 0 8em;
  919. color: #333;
  920. }
  921. .highlight, .marked {background:transparent; color:#111; border:none; text-decoration:underline;}
  922. .viewer .highlight, .viewer .marked {text-decoration:none;}
  923. #sidebarTabs .highlight, #sidebarTabs .marked {color:#000; text-decoration:none;}
  924. .tabSelected {
  925. color: #000;
  926. background: #fff;
  927. border-top: solid 1px #ccc;
  928. border-left: solid 1px #ccc;
  929. border-right: solid 1px #ccc;
  930. border-bottom: none;
  931. }
  932. .viewer .tabSelected:hover{color:#000;}
  933. .viewer .tabSelected {font-weight:bold;}
  934. .tabUnselected {
  935. color: #999;
  936. background: #eee;
  937. border-top: solid 1px #ccc;
  938. border-left: solid 1px #ccc;
  939. border-right: solid 1px #ccc;
  940. border-bottom: solid 1px #ccc;
  941. padding-bottom:1px;
  942. }
  943. .tabContents {
  944. background: #fff;
  945. color: #000;
  946. }
  947. /*}}}*/
  948. /***
  949. !!!Tables
  950. ***/
  951. /*{{{*/
  952. .viewer table {
  953. border: 1px solid #000;
  954. }
  955. .viewer th, thead td {
  956. background: #000;
  957. border: 1px solid #000;
  958. color: #fff;
  959. }
  960. .viewer td, .viewer tr {
  961. border: 1px solid #111;
  962. }
  963. /*}}}*/
  964. /***
  965. !!!Editor area
  966. ***/
  967. /*{{{*/
  968. .editor input, .editor textarea {
  969. border: 1px solid #ccc;
  970. }
  971. .editor {padding-top:0.3em;}
  972. .editor textarea:focus, .editor input:focus {
  973. border: 1px solid #333;
  974. }
  975. /*}}}*/
  976. /***
  977. !Sidebar
  978. ***/
  979. /*{{{*/
  980. #sidebar{
  981. position:relative;
  982. float:right;
  983. margin-bottom:1em;
  984. display:inline;
  985. width: 16em;
  986. }
  987. #sidebarOptions .sliderPanel {
  988. background: #eee; border:1px solid #ccc;
  989. }
  990. /*}}}*/
  991. /***
  992. !Body Footer rules
  993. ***/
  994. /*{{{*/
  995. #contentFooter {
  996. text-align: left;
  997. clear: both;
  998. color:#fff;
  999. background: #000;
  1000. padding: 1em 2em;
  1001. font-weight:bold;
  1002. }
  1003. /*}}}*/
  1004. /***
  1005. !Link Styles
  1006. ***/
  1007. /*{{{*/
  1008. a{
  1009. color: #000;
  1010. }
  1011. a:hover{
  1012. color: #FF6600;
  1013. background:#fff;
  1014. }
  1015. .button {
  1016. color: #000;
  1017. border: 1px solid #fff;
  1018. }
  1019. .button:hover {
  1020. color: #fff;
  1021. background: #ff8614;
  1022. border-color: #000;
  1023. }
  1024. .button:active {
  1025. color: #fff;
  1026. background: #ff8614;
  1027. border: 1px solid #000;
  1028. }
  1029. .tiddlyLink {border-bottom: 1px dotted #000;}
  1030. .tiddlyLink:hover {border-bottom: 1px dotted #FF6600;}
  1031. .titleLine a {border-bottom: 1px dotted #FF9900;}
  1032. .titleLine a:hover {border-bottom: 1px dotted #fff;}
  1033. .siteTitle a, .siteSubtitle a{
  1034. color: #fff;
  1035. }
  1036. .viewer .button {border: 1px solid #ff8614; font-weight:bold;}
  1037. .viewer .button:hover, .viewer .marked, .viewer .highlight{background:#ff8614; color:#fff; font-weight:bold; border: 1px solid #000;}
  1038. #topMenu .button, #topMenu .tiddlyLink {
  1039. margin-left:0.5em; margin-right:0.5em;
  1040. padding-left:3px; padding-right:3px;
  1041. color:white;
  1042. }
  1043. #topMenu .button:hover, #topMenu .tiddlyLink:hover { background:#000; color:#FF8814}
  1044. #topMenu a{border:none;}
  1045. /*}}}*/
  1046. /***
  1047. !Message Area /%=================================================%/
  1048. ***/
  1049. /*{{{*/
  1050. #messageArea {
  1051. border: 4px dotted #ff8614;
  1052. background: #000;
  1053. color: #fff;
  1054. font-size:90%;
  1055. }
  1056. #messageArea .button {
  1057. padding: 0.2em;
  1058. color: #000;
  1059. background: #fff;
  1060. text-decoration:none;
  1061. font-weight:bold;
  1062. border:1px solid #000;
  1063. }
  1064. #messageArea a {color:#fff;}
  1065. #messageArea a:hover {color:#ff8614; background:transparent;}
  1066. #messageArea .button:hover {background: #FF8614; color:#fff; border:1px solid #fff; }
  1067. /*}}}*/
  1068. /***
  1069. !Popup /%=================================================%/
  1070. ***/
  1071. /*{{{*/
  1072. .popup {
  1073. background: #ff8814;
  1074. border: 1px solid #333;
  1075. }
  1076. .popup hr {
  1077. color: #333;
  1078. background: #333;
  1079. border-bottom: 1px;
  1080. }
  1081. .popup li.disabled {
  1082. color: #333;
  1083. }
  1084. .popup li a, .popup li a:visited {
  1085. color: #eee;
  1086. border: none;
  1087. }
  1088. .popup li a:hover {
  1089. background: #ff8614;
  1090. color: #fff;
  1091. border: none;
  1092. text-decoration:underline;
  1093. }
  1094. /*}}}*/
  1095. .blog h2, .blog h3, .blog h4{
  1096. margin:0;
  1097. padding:0;
  1098. border-bottom:none;
  1099. }
  1100. .blog {margin-left:1.5em;}
  1101. .blog .excerpt {
  1102. margin:0;
  1103. margin-top:0.3em;
  1104. padding: 0;
  1105. margin-left:1em;
  1106. padding-left:1em;
  1107. font-size:90%;
  1108. border-left:1px solid #ddd;
  1109. }
  1110. #tiddlerWhatsNew h1, #tiddlerWhatsNew h2 {border-bottom:none;}
  1111. div[tags~=&quot;RecentUpdates&quot;], div[tags~=&quot;lewcidExtension&quot;] {margin-bottom: 2em;}
  1112. #hoverMenu .button, #hoverMenu .tiddlyLink {border:none; font-weight:bold; background:#f37211; color:#fff; padding:0 5px; float:right; margin-bottom:4px;}
  1113. #hoverMenu .button:hover, #hoverMenu .tiddlyLink:hover {font-weight:bold; border:none; color:#f37211; background:#000; padding:0 5px; float:right; margin-bottom:4px;}
  1114. #topMenu .fontResizer {float:right;}
  1115. #topMenu .fontResizer .button{border:1px solid #000;}
  1116. #topMenu .fontResizer .button:hover {border:1px solid #f37211; color:#fff;}
  1117. #sidebarTabs .txtMainTab .tiddlyLinkExisting {
  1118. font-weight: normal;
  1119. font-style: normal;
  1120. }
  1121. #sidebarTabs .txtMoreTab .tiddlyLinkExisting {
  1122. font-weight: bold;
  1123. font-style: normal;
  1124. }
  1125. .blog h2, .blog h3, .blog h4{
  1126. margin:0;
  1127. padding:0;
  1128. border-bottom:none;
  1129. }
  1130. .blog {margin-left:1.5em;}
  1131. .blog .excerpt {
  1132. margin:0;
  1133. margin-top:0.3em;
  1134. padding: 0;
  1135. margin-left:1em;
  1136. padding-left:1em;
  1137. font-size:90%;
  1138. border-left:1px solid #ddd;
  1139. }
  1140. #tiddlerWhatsNew h1, #tiddlerWhatsNew h2 {border-bottom:none;}
  1141. div[tags~=&quot;RecentUpdates&quot;], div[tags~=&quot;lewcidExtension&quot;] {margin-bottom: 2em;}
  1142. #hoverMenu {background:transparent;}
  1143. #hoverMenu .button, #hoverMenu .tiddlyLink {border:none; font-weight:bold; background:#f37211; color:#fff; padding:0 5px; float:right; margin-bottom:4px;}
  1144. #hoverMenu .button:hover, #hoverMenu .tiddlyLink:hover {font-weight:bold; border:none; color:#f37211; background:#000; padding:0 5px; float:right; margin-bottom:4px;}
  1145. #topMenu .fontResizer {float:right;}
  1146. #topMenu .fontResizer .button{border:1px solid #000;}
  1147. #topMenu .fontResizer .button:hover {border:1px solid #f37211; color:#fff;}
  1148. #sidebarTabs .txtMainTab .tiddlyLinkExisting {
  1149. font-weight: normal;
  1150. font-style: normal;
  1151. }
  1152. #sidebarTabs .txtMoreTab .tiddlyLinkExisting {
  1153. font-weight: bold;
  1154. font-style: normal;
  1155. }
  1156. </pre>
  1157. </div>
  1158. <div title="UnitTests" modifier="JohnLam" modified="200707230554" created="200707192301" changecount="2">
  1159. <pre>There are several sets of UnitTests in IronRuby.
  1160. If you are contributing to the libraries, you will be interested in the tests under \tests\ruby\builtins. These tests use a minimalistic unit testing framework that can be found in \tests\ruby\util\simple_test.rb.
  1161. If you have added the \bin\release directory for IronRuby to your PATH, you can run the tests using:
  1162. {{{
  1163. rbx \tests\ruby\builtins\array\test_array.rb
  1164. }}}
  1165. </pre>
  1166. </div>
  1167. </div>
  1168. <!--POST-STOREAREA-->
  1169. <!--POST-BODY-START-->
  1170. <!--POST-BODY-END-->
  1171. <script type="text/javascript">
  1172. //<![CDATA[
  1173. //
  1174. // Please note:
  1175. //
  1176. // * This code is designed to be readable but for compactness it only includes brief comments. You can see fuller comments
  1177. // in the project Subversion repository at http://svn.tiddlywiki.org/Trunk/core/
  1178. //
  1179. // * You should never need to modify this source code directly. TiddlyWiki is carefully designed to allow deep customisation
  1180. // without changing the core code. Please consult the development group at http://groups.google.com/group/TiddlyWikiDev
  1181. //
  1182. //--
  1183. //-- Configuration repository
  1184. //--
  1185. // Miscellaneous options
  1186. var config = {
  1187. numRssItems: 20, // Number of items in the RSS feed
  1188. animDuration: 400, // Duration of UI animations in milliseconds
  1189. cascadeFast: 20, // Speed for cascade animations (higher == slower)
  1190. cascadeSlow: 60, // Speed for EasterEgg cascade animations
  1191. cascadeDepth: 5 // Depth of cascade animation
  1192. };
  1193. // Adaptors
  1194. config.adaptors = {};
  1195. // Backstage tasks
  1196. config.tasks = {};
  1197. // Annotations
  1198. config.annotations = {};
  1199. // Custom fields to be automatically added to new tiddlers
  1200. config.defaultCustomFields = {};
  1201. // Messages
  1202. config.messages = {
  1203. messageClose: {},
  1204. dates: {},
  1205. tiddlerPopup: {}
  1206. };
  1207. // Options that can be set in the options panel and/or cookies
  1208. config.options = {
  1209. chkRegExpSearch: false,
  1210. chkCaseSensitiveSearch: false,
  1211. chkAnimate: true,
  1212. chkSaveBackups: true,
  1213. chkAutoSave: false,
  1214. chkGenerateAnRssFeed: false,
  1215. chkSaveEmptyTemplate: false,
  1216. chkOpenInNewWindow: true,
  1217. chkToggleLinks: false,
  1218. chkHttpReadOnly: true,
  1219. chkForceMinorUpdate: false,
  1220. chkConfirmDelete: true,
  1221. chkInsertTabs: false,
  1222. chkUsePreForStorage: true, // Whether to use <pre> format for storage
  1223. chkDisplayStartupTime: false,
  1224. txtBackupFolder: "",
  1225. txtMainTab: "tabTimeline",
  1226. txtMoreTab: "moreTabAll",
  1227. txtMaxEditRows: "30",
  1228. txtFileSystemCharSet: "UTF-8"
  1229. };
  1230. config.optionsDesc = {};
  1231. // List of notification functions to be called when certain tiddlers are changed or deleted
  1232. config.notifyTiddlers = [
  1233. {name: "StyleSheetLayout", notify: refreshStyles},
  1234. {name: "StyleSheetColors", notify: refreshStyles},
  1235. {name: "StyleSheet", notify: refreshStyles},
  1236. {name: "StyleSheetPrint", notify: refreshStyles},
  1237. {name: "PageTemplate", notify: refreshPageTemplate},
  1238. {name: "SiteTitle", notify: refreshPageTitle},
  1239. {name: "SiteSubtitle", notify: refreshPageTitle},
  1240. {name: "ColorPalette", notify: refreshColorPalette},
  1241. {name: null, notify: refreshDisplay}
  1242. ];
  1243. // Default tiddler templates
  1244. var DEFAULT_VIEW_TEMPLATE = 1;
  1245. var DEFAULT_EDIT_TEMPLATE = 2;
  1246. config.tiddlerTemplates = {
  1247. 1: "ViewTemplate",
  1248. 2: "EditTemplate"
  1249. };
  1250. // More messages (rather a legacy layout that shouldn't really be like this)
  1251. config.views = {
  1252. wikified: {
  1253. tag: {}
  1254. },
  1255. editor: {
  1256. tagChooser: {}
  1257. }
  1258. };
  1259. // Backstage tasks
  1260. config.backstageTasks = ["save","sync","importTask","tweak","plugins"];
  1261. // Macros; each has a 'handler' member that is inserted later
  1262. config.macros = {
  1263. today: {},
  1264. version: {},
  1265. search: {sizeTextbox: 15},
  1266. tiddler: {},
  1267. tag: {},
  1268. tags: {},
  1269. tagging: {},
  1270. timeline: {},
  1271. allTags: {},
  1272. list: {
  1273. all: {},
  1274. missing: {},
  1275. orphans: {},
  1276. shadowed: {},
  1277. touched: {}
  1278. },
  1279. closeAll: {},
  1280. permaview: {},
  1281. saveChanges: {},
  1282. slider: {},
  1283. option: {},
  1284. options: {},
  1285. newTiddler: {},
  1286. newJournal: {},
  1287. sparkline: {},
  1288. tabs: {},
  1289. gradient: {},
  1290. message: {},
  1291. view: {},
  1292. edit: {},
  1293. tagChooser: {},
  1294. toolbar: {},
  1295. br: {},
  1296. plugins: {},
  1297. refreshDisplay: {},
  1298. importTiddlers: {},
  1299. sync: {},
  1300. annotations: {}
  1301. };
  1302. // Commands supported by the toolbar macro
  1303. config.commands = {
  1304. closeTiddler: {},
  1305. closeOthers: {},
  1306. editTiddler: {},
  1307. saveTiddler: {hideReadOnly: true},
  1308. cancelTiddler: {},
  1309. deleteTiddler: {hideReadOnly: true},
  1310. permalink: {},
  1311. references: {type: "popup"},
  1312. jump: {type: "popup"},
  1313. syncing: {type: "popup"},
  1314. fields: {type: "popup"}
  1315. };
  1316. // Browser detection... In a very few places, there's nothing else for it but to know what browser we're using.
  1317. config.userAgent = navigator.userAgent.toLowerCase();
  1318. config.browser = {
  1319. isIE: config.userAgent.indexOf("msie") != -1 && config.userAgent.indexOf("opera") == -1,
  1320. isGecko: config.userAgent.indexOf("gecko") != -1,
  1321. ieVersion: /MSIE (\d.\d)/i.exec(config.userAgent), // config.browser.ieVersion[1], if it exists, will be the IE version string, eg "6.0"
  1322. isSafari: config.userAgent.indexOf("applewebkit") != -1,
  1323. isBadSafari: !((new RegExp("[\u0150\u0170]","g")).test("\u0150")),
  1324. firefoxDate: /gecko\/(\d{8})/i.exec(config.userAgent), // config.browser.firefoxDate[1], if it exists, will be Firefox release date as "YYYYMMDD"
  1325. isOpera: config.userAgent.indexOf("opera") != -1,
  1326. isLinux: config.userAgent.indexOf("linux") != -1,
  1327. isUnix: config.userAgent.indexOf("x11") != -1,
  1328. isMac: config.userAgent.indexOf("mac") != -1,
  1329. isWindows: config.userAgent.indexOf("win") != -1
  1330. };
  1331. // Basic regular expressions
  1332. config.textPrimitives = {
  1333. upperLetter: "[A-Z\u00c0-\u00de\u0150\u0170]",
  1334. lowerLetter: "[a-z0-9_\\-\u00df-\u00ff\u0151\u0171]",
  1335. anyLetter: "[A-Za-z0-9_\\-\u00c0-\u00de\u00df-\u00ff\u0150\u0170\u0151\u0171]",
  1336. anyLetterStrict: "[A-Za-z0-9\u00c0-\u00de\u00df-\u00ff\u0150\u0170\u0151\u0171]"
  1337. };
  1338. if(config.browser.isBadSafari) {
  1339. config.textPrimitives = {
  1340. upperLetter: "[A-Z\u00c0-\u00de]",
  1341. lowerLetter: "[a-z0-9_\\-\u00df-\u00ff]",
  1342. anyLetter: "[A-Za-z0-9_\\-\u00c0-\u00de\u00df-\u00ff]",
  1343. anyLetterStrict: "[A-Za-z0-9\u00c0-\u00de\u00df-\u00ff]"
  1344. };
  1345. }
  1346. config.textPrimitives.sliceSeparator = "::";
  1347. config.textPrimitives.urlPattern = "[a-z]{3,8}:[^\\s:'\"][^\\s'\"]*(?:/|\\b)";
  1348. config.textPrimitives.unWikiLink = "~";
  1349. config.textPrimitives.wikiLink = "(?:(?:" + config.textPrimitives.upperLetter + "+" +
  1350. config.textPrimitives.lowerLetter + "+" +
  1351. config.textPrimitives.upperLetter +
  1352. config.textPrimitives.anyLetter + "*)|(?:" +
  1353. config.textPrimitives.upperLetter + "{2,}" +
  1354. config.textPrimitives.lowerLetter + "+))";
  1355. config.textPrimitives.cssLookahead = "(?:(" + config.textPrimitives.anyLetter + "+)\\(([^\\)\\|\\n]+)(?:\\):))|(?:(" + config.textPrimitives.anyLetter + "+):([^;\\|\\n]+);)";
  1356. config.textPrimitives.cssLookaheadRegExp = new RegExp(config.textPrimitives.cssLookahead,"mg");
  1357. config.textPrimitives.brackettedLink = "\\[\\[([^\\]]+)\\]\\]";
  1358. config.textPrimitives.titledBrackettedLink = "\\[\\[([^\\[\\]\\|]+)\\|([^\\[\\]\\|]+)\\]\\]";
  1359. config.textPrimitives.tiddlerForcedLinkRegExp = new RegExp("(?:" + config.textPrimitives.titledBrackettedLink + ")|(?:" +
  1360. config.textPrimitives.brackettedLink + ")|(?:" +
  1361. config.textPrimitives.urlPattern + ")","mg");
  1362. config.textPrimitives.tiddlerAnyLinkRegExp = new RegExp("("+ config.textPrimitives.wikiLink + ")|(?:" +
  1363. config.textPrimitives.titledBrackettedLink + ")|(?:" +
  1364. config.textPrimitives.brackettedLink + ")|(?:" +
  1365. config.textPrimitives.urlPattern + ")","mg");
  1366. config.glyphs = {
  1367. browsers: [
  1368. function() {return config.browser.isIE;},
  1369. function() {return true}
  1370. ],
  1371. currBrowser: null,
  1372. codes: {
  1373. downTriangle: ["\u25BC","\u25BE"],
  1374. downArrow: ["\u2193","\u2193"],
  1375. bentArrowLeft: ["\u2190","\u21A9"],
  1376. bentArrowRight: ["\u2192","\u21AA"]
  1377. }
  1378. };
  1379. //--
  1380. //-- Shadow tiddlers
  1381. //--
  1382. config.shadowTiddlers = {
  1383. StyleSheet: "",
  1384. MarkupPreHead: "<!--{{{-->\n<link rel='alternate' type='application/rss+xml' title='RSS' href='index.xml'/>\n<!--}}}-->",
  1385. MarkupPostHead: "",
  1386. MarkupPreBody: "",
  1387. MarkupPostBody: "",
  1388. TabTimeline: '<<timeline>>',
  1389. TabAll: '<<list all>>',
  1390. TabTags: '<<allTags excludeLists>>',
  1391. TabMoreMissing: '<<list missing>>',
  1392. TabMoreOrphans: '<<list orphans>>',
  1393. TabMoreShadowed: '<<list shadowed>>',
  1394. AdvancedOptions: '<<options>>',
  1395. PluginManager: '<<plugins>>',
  1396. ImportTiddlers: '<<importTiddlers>>'
  1397. };
  1398. //--
  1399. //-- Translateable strings
  1400. //--
  1401. // Strings in "double quotes" should be translated; strings in 'single quotes' should be left alone
  1402. merge(config.options,{
  1403. txtUserName: "YourName"});
  1404. merge(config.tasks,{
  1405. save: {text: "save", tooltip: "Save your changes to this TiddlyWiki", action: saveChanges},
  1406. sync: {text: "sync", tooltip: "Synchronise changes with other TiddlyWiki files and servers", content: '<<sync>>'},
  1407. importTask: {text: "import", tooltip: "Import tiddlers and plugins from other TiddlyWiki files and servers", content: '<<importTiddlers>>'},
  1408. tweak: {text: "tweak", tooltip: "Tweak the appearance and behaviour of TiddlyWiki", content: '<<options>>'},
  1409. plugins: {text: "plugins", tooltip: "Manage installed plugins", content: '<<plugins>>'}
  1410. });
  1411. // Options that can be set in the options panel and/or cookies
  1412. merge(config.optionsDesc,{
  1413. txtUserName: "Username for signing your edits",
  1414. chkRegExpSearch: "Enable regular expressions for searches",
  1415. chkCaseSensitiveSearch: "Case-sensitive searching",
  1416. chkAnimate: "Enable animations",
  1417. chkSaveBackups: "Keep backup file when saving changes",
  1418. chkAutoSave: "Automatically save changes",
  1419. chkGenerateAnRssFeed: "Generate an RSS feed when saving changes",
  1420. chkSaveEmptyTemplate: "Generate an empty template when saving changes",
  1421. chkOpenInNewWindow: "Open external links in a new window",
  1422. chkToggleLinks: "Clicking on links to open tiddlers causes them to close",
  1423. chkHttpReadOnly: "Hide editing features when viewed over HTTP",
  1424. chkForceMinorUpdate: "Don't update modifier username and date when editing tiddlers",
  1425. chkConfirmDelete: "Require confirmation before deleting tiddlers",
  1426. chkInsertTabs: "Use the tab key to insert tab characters instead of moving between fields",
  1427. txtBackupFolder: "Name of folder to use for backups",
  1428. txtMaxEditRows: "Maximum number of rows in edit boxes",
  1429. txtFileSystemCharSet: "Default character set for saving changes (Firefox/Mozilla only)"});
  1430. merge(config.messages,{
  1431. customConfigError: "Problems were encountered loading plugins. See PluginManager for details",
  1432. pluginError: "Error: %0",
  1433. pluginDisabled: "Not executed because disabled via 'systemConfigDisable' tag",
  1434. pluginForced: "Executed because forced via 'systemConfigForce' tag",
  1435. pluginVersionError: "Not executed because this plugin needs a newer version of TiddlyWiki",
  1436. nothingSelected: "Nothing is selected. You must select one or more items first",
  1437. savedSnapshotError: "It appears that this TiddlyWiki has been incorrectly saved. Please see http://www.tiddlywiki.com/#DownloadSoftware for details",
  1438. subtitleUnknown: "(unknown)",
  1439. undefinedTiddlerToolTip: "The tiddler '%0' doesn't yet exist",
  1440. shadowedTiddlerToolTip: "The tiddler '%0' doesn't yet exist, but has a pre-defined shadow value",
  1441. tiddlerLinkTooltip: "%0 - %1, %2",
  1442. externalLinkTooltip: "External link to %0",
  1443. noTags: "There are no tagged tiddlers",
  1444. notFileUrlError: "You need to save this TiddlyWiki to a file before you can save changes",
  1445. cantSaveError: "It's not possible to save changes. Possible reasons include:\n- your browser doesn't support saving (Firefox, Internet Explorer, Safari and Opera all work if properly configured)\n- the pathname to your TiddlyWiki file contains illegal characters\n- the TiddlyWiki HTML file has been moved or renamed",
  1446. invalidFileError: "The original file '%0' does not appear to be a valid TiddlyWiki",
  1447. backupSaved: "Backup saved",
  1448. backupFailed: "Failed to save backup file",
  1449. rssSaved: "RSS feed saved",
  1450. rssFailed: "Failed to save RSS feed file",
  1451. emptySaved: "Empty template saved",
  1452. emptyFailed: "Failed to save empty template file",
  1453. mainSaved: "Main TiddlyWiki file saved",
  1454. mainFailed: "Failed to save main TiddlyWiki file. Your changes have not been saved",
  1455. macroError: "Error in macro <<\%0>>",
  1456. macroErrorDetails: "Error while executing macro <<\%0>>:\n%1",
  1457. missingMacro: "No such macro",
  1458. overwriteWarning: "A tiddler named '%0' already exists. Choose OK to overwrite it",
  1459. unsavedChangesWarning: "WARNING! There are unsaved changes in TiddlyWiki\n\nChoose OK to save\nChoose CANCEL to discard",
  1460. confirmExit: "--------------------------------\n\nThere are unsaved changes in TiddlyWiki. If you continue you will lose those changes\n\n--------------------------------",
  1461. saveInstructions: "SaveChanges",
  1462. unsupportedTWFormat: "Unsupported TiddlyWiki format '%0'",
  1463. tiddlerSaveError: "Error when saving tiddler '%0'",
  1464. tiddlerLoadError: "Error when loading tiddler '%0'",
  1465. wrongSaveFormat: "Cannot save with storage format '%0'. Using standard format for save.",
  1466. invalidFieldName: "Invalid field name %0",
  1467. fieldCannotBeChanged: "Field '%0' cannot be changed",
  1468. loadingMissingTiddler: "Attempting to retrieve the tiddler '%0' from the '%1' server at:\n\n'%2' in the workspace '%3'"});
  1469. merge(config.messages.messageClose,{
  1470. text: "close",
  1471. tooltip: "close this message area"});
  1472. config.messages.backstage = {
  1473. open: {text: "backstage", tooltip: "Open the backstage area to perform authoring and editing tasks"},
  1474. close: {text: "close", tooltip: "Close the backstage area"},
  1475. prompt: "backstage: ",
  1476. decal: {
  1477. edit: {text: "edit", tooltip: "Edit the tiddler '%0'"}
  1478. }
  1479. };
  1480. config.messages.listView = {
  1481. tiddlerTooltip: "Click for the full text of this tiddler",
  1482. previewUnavailable: "(preview not available)"
  1483. };
  1484. config.messages.dates.months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November","December"];
  1485. config.messages.dates.days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  1486. config.messages.dates.shortMonths = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  1487. config.messages.dates.shortDays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
  1488. // suffixes for dates, eg "1st","2nd","3rd"..."30th","31st"
  1489. config.messages.dates.daySuffixes = ["st","nd","rd","th","th","th","th","th","th","th",
  1490. "th","th","th","th","th","th","th","th","th","th",
  1491. "st","nd","rd","th","th","th","th","th","th","th",
  1492. "st"];
  1493. config.messages.dates.am = "am";
  1494. config.messages.dates.pm = "pm";
  1495. merge(config.messages.tiddlerPopup,{
  1496. });
  1497. merge(config.views.wikified.tag,{
  1498. labelNoTags: "no tags",
  1499. labelTags: "tags: ",
  1500. openTag: "Open tag '%0'",
  1501. tooltip: "Show tiddlers tagged with '%0'",
  1502. openAllText: "Open all",
  1503. openAllTooltip: "Open all of these tiddlers",
  1504. popupNone: "No other tiddlers tagged with '%0'"});
  1505. merge(config.views.wikified,{
  1506. defaultText: "The tiddler '%0' doesn't yet exist. Double-click to create it",
  1507. defaultModifier: "(missing)",
  1508. shadowModifier: "(built-in shadow tiddler)",
  1509. dateFormat: "DD MMM YYYY",
  1510. createdPrompt: "created"});
  1511. merge(config.views.editor,{
  1512. tagPrompt: "Type tags separated with spaces, [[use double square brackets]] if necessary, or add existing",
  1513. defaultText: "Type the text for '%0'"});
  1514. merge(config.views.editor.tagChooser,{
  1515. text: "tags",
  1516. tooltip: "Choose existing tags to add to this tiddler",
  1517. popupNone: "There are no tags defined",
  1518. tagTooltip: "Add the tag '%0'"});
  1519. merge(config.messages,{
  1520. sizeTemplates:
  1521. [
  1522. {unit: 1024*1024*1024, template: "%0\u00a0GB"},
  1523. {unit: 1024*1024, template: "%0\u00a0MB"},
  1524. {unit: 1024, template: "%0\u00a0KB"},
  1525. {unit: 1, template: "%0\u00a0B"}
  1526. ]});
  1527. merge(config.macros.search,{
  1528. label: "search",
  1529. prompt: "Search this TiddlyWiki",
  1530. accessKey: "F",
  1531. successMsg: "%0 tiddlers found matching %1",
  1532. failureMsg: "No tiddlers found matching %0"});
  1533. merge(config.macros.tagging,{
  1534. label: "tagging: ",
  1535. labelNotTag: "not tagging",
  1536. tooltip: "List of tiddlers tagged with '%0'"});
  1537. merge(config.macros.timeline,{
  1538. dateFormat: "DD MMM YYYY"});
  1539. merge(config.macros.allTags,{
  1540. tooltip: "Show tiddlers tagged with '%0'",
  1541. noTags: "There are no tagged tiddlers"});
  1542. config.macros.list.all.prompt = "All tiddlers in alphabetical order";
  1543. config.macros.list.missing.prompt = "Tiddlers that have links to them but are not defined";
  1544. config.macros.list.orphans.prompt = "Tiddlers that are not linked to from any other tiddlers";
  1545. config.macros.list.shadowed.prompt = "Tiddlers shadowed with default contents";
  1546. config.macros.list.touched.prompt = "Tiddlers that have been modified locally";
  1547. merge(config.macros.closeAll,{
  1548. label: "close all",
  1549. prompt: "Close all displayed tiddlers (except any that are being edited)"});
  1550. merge(config.macros.permaview,{
  1551. label: "permaview",
  1552. prompt: "Link to an URL that retrieves all the currently displayed tiddlers"});
  1553. merge(config.macros.saveChanges,{
  1554. label: "save changes",
  1555. prompt: "Save all tiddlers to create a new TiddlyWiki",
  1556. accessKey: "S"});
  1557. merge(config.macros.newTiddler,{
  1558. label: "new tiddler",
  1559. prompt: "Create a new tiddler",
  1560. title: "New Tiddler",
  1561. accessKey: "N"});
  1562. merge(config.macros.newJournal,{
  1563. label: "new journal",
  1564. prompt: "Create a new tiddler from the current date and time",
  1565. accessKey: "J"});
  1566. merge(config.macros.options,{
  1567. wizardTitle: "Tweak advanced options",
  1568. step1Title: "These options are saved in cookies in your browser",
  1569. step1Html: "<input type='hidden' name='markList'></input><br><input type='checkbox' checked='false' name='chkUnknown'>Show unknown options</input>",
  1570. unknownDescription: "//(unknown)//",
  1571. listViewTemplate: {
  1572. columns: [
  1573. {name: 'Option', field: 'option', title: "Option", type: 'String'},
  1574. {name: 'Description', field: 'description', title: "Description", type: 'WikiText'},
  1575. {name: 'Name', field: 'name', title: "Name", type: 'String'}
  1576. ],
  1577. rowClasses: [
  1578. {className: 'lowlight', field: 'lowlight'}
  1579. ]}
  1580. });
  1581. merge(config.macros.plugins,{
  1582. wizardTitle: "Manage plugins",
  1583. step1Title: "Currently loaded plugins",
  1584. step1Html: "<input type='hidden' name='markList'></input>", // DO NOT TRANSLATE
  1585. skippedText: "(This plugin has not been executed because it was added since startup)",
  1586. noPluginText: "There are no plugins installed",
  1587. confirmDeleteText: "Are you sure you want to delete these plugins:\n\n%0",
  1588. removeLabel: "remove systemConfig tag",
  1589. removePrompt: "Remove systemConfig tag",
  1590. deleteLabel: "delete",
  1591. deletePrompt: "Delete these tiddlers forever",
  1592. listViewTemplate: {
  1593. columns: [
  1594. {name: 'Selected', field: 'Selected', rowName: 'title', type: 'Selector'},
  1595. {name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler'},
  1596. {name: 'Size', field: 'size', tiddlerLink: 'size', title: "Size", type: 'Size'},
  1597. {name: 'Forced', field: 'forced', title: "Forced", tag: 'systemConfigForce', type: 'TagCheckbox'},
  1598. {name: 'Disabled', field: 'disabled', title: "Disabled", tag: 'systemConfigDisable', type: 'TagCheckbox'},
  1599. {name: 'Executed', field: 'executed', title: "Loaded", type: 'Boolean', trueText: "Yes", falseText: "No"},
  1600. {name: 'Startup Time', field: 'startupTime', title: "Startup Time", type: 'String'},
  1601. {name: 'Error', field: 'error', title: "Status", type: 'Boolean', trueText: "Error", falseText: "OK"},
  1602. {name: 'Log', field: 'log', title: "Log", type: 'StringList'}
  1603. ],
  1604. rowClasses: [
  1605. {className: 'error', field: 'error'},
  1606. {className: 'warning', field: 'warning'}
  1607. ]}
  1608. });
  1609. merge(config.macros.toolbar,{
  1610. moreLabel: "more",
  1611. morePrompt: "Reveal further commands"
  1612. });
  1613. merge(config.macros.refreshDisplay,{
  1614. label: "refresh",
  1615. prompt: "Redraw the entire TiddlyWiki display"
  1616. });
  1617. merge(config.macros.importTiddlers,{
  1618. readOnlyWarning: "You cannot import into a read-only TiddlyWiki file. Try opening it from a file:// URL",
  1619. wizardTitle: "Import tiddlers from another file or server",
  1620. step1Title: "Step 1: Locate the server or TiddlyWiki file",
  1621. step1Html: "Specify the type of the server: <select name='selTypes'><option value=''>Choose...</option></select><br>Enter the URL or pathname here: <input type='text' size=50 name='txtPath'><br>...or browse for a file: <input type='file' size=50 name='txtBrowse'><br><hr>...or select a pre-defined feed: <select name='selFeeds'><option value=''>Choose...</option></select>",
  1622. openLabel: "open",
  1623. openPrompt: "Open the connection to this file or server",
  1624. openError: "There were problems fetching the tiddlywiki file",
  1625. statusOpenHost: "Opening the host",
  1626. statusGetWorkspaceList: "Getting the list of available workspaces",
  1627. step2Title: "Step 2: Choose the workspace",
  1628. step2Html: "Enter a workspace name: <input type='text' size=50 name='txtWorkspace'><br>...or select a workspace: <select name='selWorkspace'><option value=''>Choose...</option></select>",
  1629. cancelLabel: "cancel",
  1630. cancelPrompt: "Cancel this import",
  1631. statusOpenWorkspace: "Opening the workspace",
  1632. statusGetTiddlerList: "Getting the list of available tiddlers",
  1633. step3Title: "Step 3: Choose the tiddlers to import",
  1634. step3Html: "<input type='hidden' name='markList'></input><br><input type='checkbox' checked='true' name='chkSync'>Keep these tiddlers linked to this server so that you can synchronise subsequent changes</input><br><input type='checkbox' name='chkSave'>Save the details of this server in a 'systemServer' tiddler called:</input> <input type='text' size=25 name='txtSaveTiddler'>",
  1635. importLabel: "import",
  1636. importPrompt: "Import these tiddlers",
  1637. confirmOverwriteText: "Are you sure you want to overwrite these tiddlers:\n\n%0",
  1638. step4Title: "Step 4: Importing %0 tiddler(s)",
  1639. step4Html: "<input type='hidden' name='markReport'></input>", // DO NOT TRANSLATE
  1640. doneLabel: "done",
  1641. donePrompt: "Close this wizard",
  1642. statusDoingImport: "Importing tiddlers",
  1643. statusDoneImport: "All tiddlers imported",
  1644. systemServerNamePattern: "%2 on %1",
  1645. systemServerNamePatternNoWorkspace: "%1",
  1646. confirmOverwriteSaveTiddler: "The tiddler '%0' already exists. Click 'OK' to overwrite it with the details of this server, or 'Cancel' to leave it unchanged",
  1647. serverSaveTemplate: "|''Type:''|%0|\n|''URL:''|%1|\n|''Workspace:''|%2|\n\nThis tiddler was automatically created to record the details of this server",
  1648. serverSaveModifier: "(System)",
  1649. listViewTemplate: {
  1650. columns: [
  1651. {name: 'Selected', field: 'Selected', rowName: 'title', type: 'Selector'},
  1652. {name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler'},
  1653. {name: 'Size', field: 'size', tiddlerLink: 'size', title: "Size", type: 'Size'},
  1654. {name: 'Tags', field: 'tags', title: "Tags", type: 'Tags'}
  1655. ],
  1656. rowClasses: [
  1657. ]}
  1658. });
  1659. merge(config.macros.sync,{
  1660. listViewTemplate: {
  1661. columns: [
  1662. {name: 'Selected', field: 'selected', rowName: 'title', type: 'Selector'},
  1663. {name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler'},
  1664. {name: 'Server Type', field: 'serverType', title: "Server type", type: 'String'},
  1665. {name: 'Server Host', field: 'serverHost', title: "Server host", type: 'String'},
  1666. {name: 'Server Workspace', field: 'serverWorkspace', title: "Server workspace", type: 'String'},
  1667. {name: 'Status', field: 'status', title: "Synchronisation status", type: 'String'},
  1668. {name: 'Server URL', field: 'serverUrl', title: "Server URL", text: "View", type: 'Link'}
  1669. ],
  1670. rowClasses: [
  1671. ],
  1672. buttons: [
  1673. {caption: "Sync these tiddlers", name: 'sync'}
  1674. ]},
  1675. wizardTitle: "Synchronize with external servers and files",
  1676. step1Title: "Choose the tiddlers you want to synchronize",
  1677. step1Html: "<input type='hidden' name='markList'></input>", // DO NOT TRANSLATE
  1678. syncLabel: "sync",
  1679. syncPrompt: "Sync these tiddlers",
  1680. hasChanged: "Changed while unplugged",
  1681. hasNotChanged: "Unchanged while unplugged",
  1682. syncStatusList: {
  1683. none: {text: "...", color: "none"},
  1684. changedServer: {text: "Changed on server", color: '#80ff80'},
  1685. changedLocally: {text: "Changed while unplugged", color: '#80ff80'},
  1686. changedBoth: {text: "Changed while unplugged and on server", color: '#ff8080'},
  1687. notFound: {text: "Not found on server", color: '#ffff80'},
  1688. putToServer: {text: "Saved update on server", color: '#ff80ff'},
  1689. gotFromServer: {text: "Retrieved update from server", color: '#80ffff'}
  1690. }
  1691. });
  1692. merge(config.macros.annotations,{
  1693. });
  1694. merge(config.commands.closeTiddler,{
  1695. text: "close",
  1696. tooltip: "Close this tiddler"});
  1697. merge(config.commands.closeOthers,{
  1698. text: "close others",
  1699. tooltip: "Close all other tiddlers"});
  1700. merge(config.commands.editTiddler,{
  1701. text: "edit",
  1702. tooltip: "Edit this tiddler",
  1703. readOnlyText: "view",
  1704. readOnlyTooltip: "View the source of this tiddler"});
  1705. merge(config.commands.saveTiddler,{
  1706. text: "done",
  1707. tooltip: "Save changes to this tiddler"});
  1708. merge(config.commands.cancelTiddler,{
  1709. text: "cancel",
  1710. tooltip: "Undo changes to this tiddler",
  1711. warning: "Are you sure you want to abandon your changes to '%0'?",
  1712. readOnlyText: "done",
  1713. readOnlyTooltip: "View this tiddler normally"});
  1714. merge(config.commands.deleteTiddler,{
  1715. text: "delete",
  1716. tooltip: "Delete this tiddler",
  1717. warning: "Are you sure you want to delete '%0'?"});
  1718. merge(config.commands.permalink,{
  1719. text: "permalink",
  1720. tooltip: "Permalink for this tiddler"});
  1721. merge(config.commands.references,{
  1722. text: "references",
  1723. tooltip: "Show tiddlers that link to this one",
  1724. popupNone: "No references"});
  1725. merge(config.commands.jump,{
  1726. text: "jump",
  1727. tooltip: "Jump to another open tiddler"});
  1728. merge(config.commands.syncing,{
  1729. text: "syncing",
  1730. tooltip: "Control synchronisation of this tiddler with a server or external file",
  1731. currentlySyncing: "<div>Currently syncing via <span class='popupHighlight'>'%0'</span> to:</"+"div><div>host: <span class='popupHighlight'>%1</span></"+"div><div>workspace: <span class='popupHighlight'>%2</span></"+"div>", // Note escaping of closing <div> tag
  1732. notCurrentlySyncing: "Not currently syncing",
  1733. captionUnSync: "Stop synchronising this tiddler",
  1734. chooseServer: "Synchronise this tiddler with another server:",
  1735. currServerMarker: "\u25cf ",
  1736. notCurrServerMarker: " "});
  1737. merge(config.commands.fields,{
  1738. text: "fields",
  1739. tooltip: "Show the extended fields of this tiddler",
  1740. emptyText: "There are no extended fields for this tiddler",
  1741. listViewTemplate: {
  1742. columns: [
  1743. {name: 'Field', field: 'field', title: "Field", type: 'String'},
  1744. {name: 'Value', field: 'value', title: "Value", type: 'String'}
  1745. ],
  1746. rowClasses: [
  1747. ],
  1748. buttons: [
  1749. ]}});
  1750. merge(config.shadowTiddlers,{
  1751. DefaultTiddlers: "GettingStarted",
  1752. MainMenu: "GettingStarted",
  1753. SiteTitle: "My TiddlyWiki",
  1754. SiteSubtitle: "a reusable non-linear personal web notebook",
  1755. SiteUrl: "http://www.tiddlywiki.com/",
  1756. SideBarOptions: '<<search>><<closeAll>><<permaview>><<newTiddler>><<newJournal "DD MMM YYYY">><<saveChanges>><<slider chkSliderOptionsPanel OptionsPanel "options »" "Change TiddlyWiki advanced options">>',
  1757. SideBarTabs: '<<tabs txtMainTab "Timeline" "Timeline" TabTimeline "All" "All tiddlers" TabAll "Tags" "All tags" TabTags "More" "More lists" TabMore>>',
  1758. TabMore: '<<tabs txtMoreTab "Missing" "Missing tiddlers" TabMoreMissing "Orphans" "Orphaned tiddlers" TabMoreOrphans "Shadowed" "Shadowed tiddlers" TabMoreShadowed>>'});
  1759. merge(config.annotations,{
  1760. AdvancedOptions: "This shadow tiddler provides access to several advanced options",
  1761. ColorPalette: "These values in this shadow tiddler determine the colour scheme of the ~TiddlyWiki user interface",
  1762. DefaultTiddlers: "The tiddlers listed in this shadow tiddler will be automatically displayed when ~TiddlyWiki starts up",
  1763. EditTemplate: "The HTML template in this shadow tiddler determines how tiddlers look while they are being edited",
  1764. GettingStarted: "This shadow tiddler provides basic usage instructions",
  1765. ImportTiddlers: "This shadow tiddler provides access to importing tiddlers",
  1766. MainMenu: "This shadow tiddler is used as the contents of the main menu in the left-hand column of the screen",
  1767. MarkupPreHead: "This tiddler is inserted at the top of the <head> section of the TiddlyWiki HTML file",
  1768. MarkupPostHead: "This tiddler is inserted at the bottom of the <head> section of the TiddlyWiki HTML file",
  1769. MarkupPreBody: "This tiddler is inserted at the top of the <body> section of the TiddlyWiki HTML file",
  1770. MarkupPostBody: "This tiddler is inserted at the end of the <body> section of the TiddlyWiki HTML file immediately before the script block",
  1771. OptionsPanel: "This shadow tiddler is used as the contents of the options panel slider in the right-hand sidebar",
  1772. PageTemplate: "The HTML template in this shadow tiddler determines the overall ~TiddlyWiki layout",
  1773. PluginManager: "This shadow tiddler provides access to the plugin manager",
  1774. SideBarOptions: "This shadow tiddler is used as the contents of the option panel in the right-hand sidebar",
  1775. SideBarTabs: "This shadow tiddler is used as the contents of the tabs panel in the right-hand sidebar",
  1776. SiteSubtitle: "This shadow tiddler is used as the second part of the page title",
  1777. SiteTitle: "This shadow tiddler is used as the first part of the page title",
  1778. SiteUrl: "This shadow tiddler should be set to the full target URL for publication",
  1779. StyleSheetColours: "This shadow tiddler contains CSS definitions related to the color of page elements",
  1780. StyleSheet: "This tiddler can contain custom CSS definitions",
  1781. StyleSheetLayout: "This shadow tiddler contains CSS definitions related to the layout of page elements",
  1782. StyleSheetLocale: "This shadow tiddler contains CSS definitions related to the translation locale",
  1783. StyleSheetPrint: "This shadow tiddler contains CSS definitions for printing",
  1784. TabAll: "This shadow tiddler contains the contents of the 'All' tab in the right-hand sidebar",
  1785. TabMore: "This shadow tiddler contains the contents of the 'More' tab in the right-hand sidebar",
  1786. TabMoreMissing: "This shadow tiddler contains the contents of the 'Missing' tab in the right-hand sidebar",
  1787. TabMoreOrphans: "This shadow tiddler contains the contents of the 'Orphans' tab in the right-hand sidebar",
  1788. TabMoreShadowed: "This shadow tiddler contains the contents of the 'Shadowed' tab in the right-hand sidebar",
  1789. TabTags: "This shadow tiddler contains the contents of the 'Tags' tab in the right-hand sidebar",
  1790. TabTimeline: "This shadow tiddler contains the contents of the 'Timeline' tab in the right-hand sidebar",
  1791. ViewTemplate: "The HTML template in this shadow tiddler determines how tiddlers look"
  1792. });
  1793. //--
  1794. //-- Main
  1795. //--
  1796. var params = null; // Command line parameters
  1797. var store = null; // TiddlyWiki storage
  1798. var story = null; // Main story
  1799. var formatter = null; // Default formatters for the wikifier
  1800. config.parsers = {}; // Hashmap of alternative parsers for the wikifier
  1801. var anim = new Animator(); // Animation engine
  1802. var readOnly = false; // Whether we're in readonly mode
  1803. var highlightHack = null; // Embarrassing hack department...
  1804. var hadConfirmExit = false; // Don't warn more than once
  1805. var safeMode = false; // Disable all plugins and cookies
  1806. var installedPlugins = []; // Information filled in when plugins are executed
  1807. var startingUp = false; // Whether we're in the process of starting up
  1808. var pluginInfo,tiddler; // Used to pass information to plugins in loadPlugins()
  1809. // Whether to use the JavaSaver applet
  1810. var useJavaSaver = config.browser.isSafari || config.browser.isOpera;
  1811. // Starting up
  1812. function main()
  1813. {
  1814. var t9,t8,t7,t6,t5,t4,t3,t2,t1,t0 = new Date();
  1815. startingUp = true;
  1816. window.onbeforeunload = function(e) {if(window.confirmExit) return confirmExit();};
  1817. params = getParameters();
  1818. if(params)
  1819. params = params.parseParams("open",null,false);
  1820. store = new TiddlyWiki();
  1821. invokeParamifier(params,"oninit");
  1822. story = new Story("tiddlerDisplay","tiddler");
  1823. addEvent(document,"click",Popup.onDocumentClick);
  1824. saveTest();
  1825. loadOptionsCookie();
  1826. for(var s=0; s<config.notifyTiddlers.length; s++)
  1827. store.addNotification(config.notifyTiddlers[s].name,config.notifyTiddlers[s].notify);
  1828. t1 = new Date();
  1829. store.loadFromDiv("storeArea","store",true);
  1830. t2 = new Date();
  1831. loadShadowTiddlers();
  1832. t3 = new Date();
  1833. invokeParamifier(params,"onload");
  1834. t4 = new Date();
  1835. readOnly = (window.location.protocol == "file:") ? false : config.options.chkHttpReadOnly;
  1836. var pluginProblem = loadPlugins();
  1837. t5 = new Date();
  1838. formatter = new Formatter(config.formatters);
  1839. invokeParamifier(params,"onconfig");
  1840. t6 = new Date();
  1841. store.notifyAll();
  1842. t7 = new Date();
  1843. restart();
  1844. t8 = new Date();
  1845. if(pluginProblem) {
  1846. story.displayTiddler(null,"PluginManager");
  1847. displayMessage(config.messages.customConfigError);
  1848. }
  1849. for(var m in config.macros) {
  1850. if(config.macros[m].init)
  1851. config.macros[m].init();
  1852. }
  1853. if(!readOnly)
  1854. backstage.init();
  1855. t9 = new Date();
  1856. if(config.options.chkDisplayStartupTime) {
  1857. displayMessage("Load in " + (t2-t1) + " ms");
  1858. displayMessage("Loadshadows in " + (t3-t2) + " ms");
  1859. displayMessage("Loadplugins in " + (t5-t4) + " ms");
  1860. displayMessage("Notify in " + (t7-t6) + " ms");
  1861. displayMessage("Restart in " + (t8-t7) + " ms");
  1862. displayMessage("Total startup in " + (t9-t0) + " ms");
  1863. }
  1864. startingUp = false;
  1865. }
  1866. // Restarting
  1867. function restart()
  1868. {
  1869. invokeParamifier(params,"onstart");
  1870. if(story.isEmpty()) {
  1871. var defaultParams = store.getTiddlerText("DefaultTiddlers").parseParams("open",null,false);
  1872. invokeParamifier(defaultParams,"onstart");
  1873. }
  1874. window.scrollTo(0,0);
  1875. }
  1876. function saveTest()
  1877. {
  1878. var s = document.getElementById("saveTest");
  1879. if(s.hasChildNodes())
  1880. alert(config.messages.savedSnapshotError);
  1881. s.appendChild(document.createTextNode("savetest"));
  1882. }
  1883. function loadShadowTiddlers()
  1884. {
  1885. var shadows = new TiddlyWiki();
  1886. shadows.loadFromDiv("shadowArea","shadows",true);
  1887. shadows.forEachTiddler(function(title,tiddler){config.shadowTiddlers[title] = tiddler.text;});
  1888. delete shadows;
  1889. }
  1890. function loadPlugins()
  1891. {
  1892. if(safeMode)
  1893. return false;
  1894. var tiddlers = store.getTaggedTiddlers("systemConfig");
  1895. var toLoad = [];
  1896. var nLoaded = 0;
  1897. var map = {};
  1898. var nPlugins = tiddlers.length;
  1899. installedPlugins = [];
  1900. for(var i=0; i<nPlugins; i++) {
  1901. var p = getPluginInfo(tiddlers[i]);
  1902. installedPlugins[i] = p;
  1903. var n = p.Name;
  1904. if(n)
  1905. map[n] = p;
  1906. if(n = p.Source)
  1907. map[n] = p;
  1908. }
  1909. var visit = function(p) {
  1910. if(!p || p.done)
  1911. return;
  1912. p.done = 1;
  1913. var reqs = p.Requires;
  1914. if(reqs) {
  1915. reqs = reqs.readBracketedList();
  1916. for(var i=0; i<reqs.length; i++)
  1917. visit(map[reqs[i]]);
  1918. }
  1919. toLoad.push(p);
  1920. };
  1921. for(i=0; i<nPlugins; i++)
  1922. visit(installedPlugins[i]);
  1923. for(i=0; i<toLoad.length; i++) {
  1924. p = toLoad[i];
  1925. pluginInfo = p;
  1926. tiddler = p.tiddler;
  1927. if(isPluginExecutable(p)) {
  1928. if(isPluginEnabled(p)) {
  1929. p.executed = true;
  1930. var startTime = new Date();
  1931. try {
  1932. if(tiddler.text)
  1933. window.eval(tiddler.text);
  1934. nLoaded++;
  1935. } catch(ex) {
  1936. p.log.push(config.messages.pluginError.format([exceptionText(ex)]));
  1937. p.error = true;
  1938. }
  1939. pluginInfo.startupTime = String((new Date()) - startTime) + "ms";
  1940. } else {
  1941. nPlugins--;
  1942. }
  1943. } else {
  1944. p.warning = true;
  1945. }
  1946. }
  1947. return nLoaded != nPlugins;
  1948. }
  1949. function getPluginInfo(tiddler)
  1950. {
  1951. var p = store.getTiddlerSlices(tiddler.title,["Name","Description","Version","Requires","CoreVersion","Date","Source","Author","License","Browsers"]);
  1952. p.tiddler = tiddler;
  1953. p.title = tiddler.title;
  1954. p.log = [];
  1955. return p;
  1956. }
  1957. // Check that a particular plugin is valid for execution
  1958. function isPluginExecutable(plugin)
  1959. {
  1960. if(plugin.tiddler.isTagged("systemConfigForce"))
  1961. return verifyTail(plugin,true,config.messages.pluginForced);
  1962. if(plugin["CoreVersion"]) {
  1963. var coreVersion = plugin["CoreVersion"].split(".");
  1964. var w = parseInt(coreVersion[0]) - version.major;
  1965. if(w == 0 && coreVersion[1])
  1966. w = parseInt(coreVersion[1]) - version.minor;
  1967. if(w == 0 && coreVersion[2])
  1968. w = parseInt(coreVersion[2]) - version.revision;
  1969. if(w > 0)
  1970. return verifyTail(plugin,false,config.messages.pluginVersionError);
  1971. }
  1972. return true;
  1973. }
  1974. function isPluginEnabled(plugin)
  1975. {
  1976. if(plugin.tiddler.isTagged("systemConfigDisable"))
  1977. return verifyTail(plugin,false,config.messages.pluginDisabled);
  1978. return true;
  1979. }
  1980. function verifyTail(plugin,result,message)
  1981. {
  1982. plugin.log.push(message);
  1983. return result;
  1984. }
  1985. function invokeMacro(place,macro,params,wikifier,tiddler)
  1986. {
  1987. try {
  1988. var m = config.macros[macro];
  1989. if(m && m.handler)
  1990. m.handler(place,macro,params.readMacroParams(),wikifier,params,tiddler);
  1991. else
  1992. createTiddlyError(place,config.messages.macroError.format([macro]),config.messages.macroErrorDetails.format([macro,config.messages.missingMacro]));
  1993. } catch(ex) {
  1994. createTiddlyError(place,config.messages.macroError.format([macro]),config.messages.macroErrorDetails.format([macro,ex.toString()]));
  1995. }
  1996. }
  1997. //--
  1998. //-- Paramifiers
  1999. //--
  2000. function getParameters()
  2001. {
  2002. var p = null;
  2003. if(window.location.hash) {
  2004. p = decodeURI(window.location.hash.substr(1));
  2005. if(config.browser.firefoxDate != null && config.browser.firefoxDate[1] < "20051111")
  2006. p = convertUTF8ToUnicode(p);
  2007. }
  2008. return p;
  2009. }
  2010. function invokeParamifier(params,handler)
  2011. {
  2012. if(!params || params.length == undefined || params.length <= 1)
  2013. return;
  2014. for(var t=1; t<params.length; t++) {
  2015. var p = config.paramifiers[params[t].name];
  2016. if(p && p[handler] instanceof Function)
  2017. p[handler](params[t].value);
  2018. }
  2019. }
  2020. config.paramifiers = {};
  2021. config.paramifiers.start = {
  2022. oninit: function(v) {
  2023. safeMode = v.toLowerCase() == "safe";
  2024. }
  2025. };
  2026. config.paramifiers.open = {
  2027. onstart: function(v) {
  2028. story.displayTiddler("bottom",v,null,false,null);
  2029. }
  2030. };
  2031. config.paramifiers.story = {
  2032. onstart: function(v) {
  2033. var list = store.getTiddlerText(v,"").parseParams("open",null,false);
  2034. invokeParamifier(list,"onstart");
  2035. }
  2036. };
  2037. config.paramifiers.search = {
  2038. onstart: function(v) {
  2039. story.search(v,false,false);
  2040. }
  2041. };
  2042. config.paramifiers.searchRegExp = {
  2043. onstart: function(v) {
  2044. story.prototype.search(v,false,true);
  2045. }
  2046. };
  2047. config.paramifiers.tag = {
  2048. onstart: function(v) {
  2049. var tagged = store.getTaggedTiddlers(v,"title");
  2050. for(var t=0; t<tagged.length; t++)
  2051. story.displayTiddler("bottom",tagged[t].title,null,false,null);
  2052. }
  2053. };
  2054. config.paramifiers.newTiddler = {
  2055. onstart: function(v) {
  2056. if(!readOnly) {
  2057. story.displayTiddler(null,v,DEFAULT_EDIT_TEMPLATE);
  2058. story.focusTiddler(v,"text");
  2059. }
  2060. }
  2061. };
  2062. config.paramifiers.newJournal = {
  2063. onstart: function(v) {
  2064. if(!readOnly) {
  2065. var now = new Date();
  2066. var title = now.formatString(v.trim());
  2067. story.displayTiddler(null,title,DEFAULT_EDIT_TEMPLATE);
  2068. story.focusTiddler(title,"text");
  2069. }
  2070. }
  2071. };
  2072. config.paramifiers.readOnly = {
  2073. onconfig: function(v) {
  2074. var p = v.toLowerCase();
  2075. readOnly = p == "yes" ? true : (p == "no" ? false : readOnly);
  2076. }
  2077. };
  2078. //--
  2079. //-- Formatter helpers
  2080. //--
  2081. function Formatter(formatters)
  2082. {
  2083. this.formatters = [];
  2084. var pattern = [];
  2085. for(var n=0; n<formatters.length; n++) {
  2086. pattern.push("(" + formatters[n].match + ")");
  2087. this.formatters.push(formatters[n]);
  2088. }
  2089. this.formatterRegExp = new RegExp(pattern.join("|"),"mg");
  2090. }
  2091. config.formatterHelpers = {
  2092. createElementAndWikify: function(w)
  2093. {
  2094. w.subWikifyTerm(createTiddlyElement(w.output,this.element),this.termRegExp);
  2095. },
  2096. inlineCssHelper: function(w)
  2097. {
  2098. var styles = [];
  2099. config.textPrimitives.cssLookaheadRegExp.lastIndex = w.nextMatch;
  2100. var lookaheadMatch = config.textPrimitives.cssLookaheadRegExp.exec(w.source);
  2101. while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
  2102. var s,v;
  2103. if(lookaheadMatch[1]) {
  2104. s = lookaheadMatch[1].unDash();
  2105. v = lookaheadMatch[2];
  2106. } else {
  2107. s = lookaheadMatch[3].unDash();
  2108. v = lookaheadMatch[4];
  2109. }
  2110. if (s=="bgcolor")
  2111. s = "backgroundColor";
  2112. styles.push({style: s, value: v});
  2113. w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
  2114. config.textPrimitives.cssLookaheadRegExp.lastIndex = w.nextMatch;
  2115. lookaheadMatch = config.textPrimitives.cssLookaheadRegExp.exec(w.source);
  2116. }
  2117. return styles;
  2118. },
  2119. applyCssHelper: function(e,styles)
  2120. {
  2121. for(var t=0; t< styles.length; t++) {
  2122. try {
  2123. e.style[styles[t].style] = styles[t].value;
  2124. } catch (ex) {
  2125. }
  2126. }
  2127. },
  2128. enclosedTextHelper: function(w)
  2129. {
  2130. this.lookaheadRegExp.lastIndex = w.matchStart;
  2131. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2132. if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
  2133. var text = lookaheadMatch[1];
  2134. if(config.browser.isIE)
  2135. text = text.replace(/\n/g,"\r");
  2136. createTiddlyElement(w.output,this.element,null,null,text);
  2137. w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
  2138. }
  2139. },
  2140. isExternalLink: function(link)
  2141. {
  2142. if(store.tiddlerExists(link) || store.isShadowTiddler(link)) {
  2143. return false;
  2144. }
  2145. var urlRegExp = new RegExp(config.textPrimitives.urlPattern,"mg");
  2146. if(urlRegExp.exec(link)) {
  2147. return true;
  2148. }
  2149. if (link.indexOf(".")!=-1 || link.indexOf("\\")!=-1 || link.indexOf("/")!=-1){
  2150. return true;
  2151. }
  2152. return false;
  2153. }
  2154. };
  2155. //--
  2156. //-- Standard formatters
  2157. //--
  2158. config.formatters = [
  2159. {
  2160. name: "table",
  2161. match: "^\\|(?:[^\\n]*)\\|(?:[fhck]?)$",
  2162. lookaheadRegExp: /^\|([^\n]*)\|([fhck]?)$/mg,
  2163. rowTermRegExp: /(\|(?:[fhck]?)$\n?)/mg,
  2164. cellRegExp: /(?:\|([^\n\|]*)\|)|(\|[fhck]?$\n?)/mg,
  2165. cellTermRegExp: /((?:\x20*)\|)/mg,
  2166. rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"},
  2167. handler: function(w)
  2168. {
  2169. var table = createTiddlyElement(w.output,"table",null,"twtable");
  2170. var prevColumns = [];
  2171. var currRowType = null;
  2172. var rowContainer;
  2173. var rowCount = 0;
  2174. w.nextMatch = w.matchStart;
  2175. this.lookaheadRegExp.lastIndex = w.nextMatch;
  2176. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2177. while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
  2178. var nextRowType = lookaheadMatch[2];
  2179. if(nextRowType == "k") {
  2180. table.className = lookaheadMatch[1];
  2181. w.nextMatch += lookaheadMatch[0].length+1;
  2182. } else {
  2183. if(nextRowType != currRowType) {
  2184. rowContainer = createTiddlyElement(table,this.rowTypes[nextRowType]);
  2185. currRowType = nextRowType;
  2186. }
  2187. if(currRowType == "c") {
  2188. // Caption
  2189. w.nextMatch++;
  2190. if(rowContainer != table.firstChild)
  2191. table.insertBefore(rowContainer,table.firstChild);
  2192. rowContainer.setAttribute("align",rowCount == 0?"top":"bottom");
  2193. w.subWikifyTerm(rowContainer,this.rowTermRegExp);
  2194. } else {
  2195. this.rowHandler(w,createTiddlyElement(rowContainer,"tr",null,(rowCount&1)?"oddRow":"evenRow"),prevColumns);
  2196. rowCount++;
  2197. }
  2198. }
  2199. this.lookaheadRegExp.lastIndex = w.nextMatch;
  2200. lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2201. }
  2202. },
  2203. rowHandler: function(w,e,prevColumns)
  2204. {
  2205. var col = 0;
  2206. var colSpanCount = 1;
  2207. var prevCell = null;
  2208. this.cellRegExp.lastIndex = w.nextMatch;
  2209. var cellMatch = this.cellRegExp.exec(w.source);
  2210. while(cellMatch && cellMatch.index == w.nextMatch) {
  2211. if(cellMatch[1] == "~") {
  2212. // Rowspan
  2213. var last = prevColumns[col];
  2214. if(last) {
  2215. last.rowSpanCount++;
  2216. last.element.setAttribute("rowspan",last.rowSpanCount);
  2217. last.element.setAttribute("rowSpan",last.rowSpanCount); // Needed for IE
  2218. last.element.valign = "center";
  2219. }
  2220. w.nextMatch = this.cellRegExp.lastIndex-1;
  2221. } else if(cellMatch[1] == ">") {
  2222. // Colspan
  2223. colSpanCount++;
  2224. w.nextMatch = this.cellRegExp.lastIndex-1;
  2225. } else if(cellMatch[2]) {
  2226. // End of row
  2227. if(prevCell && colSpanCount > 1) {
  2228. prevCell.setAttribute("colspan",colSpanCount);
  2229. prevCell.setAttribute("colSpan",colSpanCount); // Needed for IE
  2230. }
  2231. w.nextMatch = this.cellRegExp.lastIndex;
  2232. break;
  2233. } else {
  2234. // Cell
  2235. w.nextMatch++;
  2236. var styles = config.formatterHelpers.inlineCssHelper(w);
  2237. var spaceLeft = false;
  2238. var chr = w.source.substr(w.nextMatch,1);
  2239. while(chr == " ") {
  2240. spaceLeft = true;
  2241. w.nextMatch++;
  2242. chr = w.source.substr(w.nextMatch,1);
  2243. }
  2244. var cell;
  2245. if(chr == "!") {
  2246. cell = createTiddlyElement(e,"th");
  2247. w.nextMatch++;
  2248. } else {
  2249. cell = createTiddlyElement(e,"td");
  2250. }
  2251. prevCell = cell;
  2252. prevColumns[col] = {rowSpanCount:1,element:cell};
  2253. if(colSpanCount > 1) {
  2254. cell.setAttribute("colspan",colSpanCount);
  2255. cell.setAttribute("colSpan",colSpanCount); // Needed for IE
  2256. colSpanCount = 1;
  2257. }
  2258. config.formatterHelpers.applyCssHelper(cell,styles);
  2259. w.subWikifyTerm(cell,this.cellTermRegExp);
  2260. if(w.matchText.substr(w.matchText.length-2,1) == " ") // spaceRight
  2261. cell.align = spaceLeft ? "center" : "left";
  2262. else if(spaceLeft)
  2263. cell.align = "right";
  2264. w.nextMatch--;
  2265. }
  2266. col++;
  2267. this.cellRegExp.lastIndex = w.nextMatch;
  2268. cellMatch = this.cellRegExp.exec(w.source);
  2269. }
  2270. }
  2271. },
  2272. {
  2273. name: "heading",
  2274. match: "^!{1,6}",
  2275. termRegExp: /(\n)/mg,
  2276. handler: function(w)
  2277. {
  2278. w.subWikifyTerm(createTiddlyElement(w.output,"h" + w.matchLength),this.termRegExp);
  2279. }
  2280. },
  2281. {
  2282. name: "list",
  2283. match: "^(?:[\\*#;:]+)",
  2284. lookaheadRegExp: /^(?:(?:(\*)|(#)|(;)|(:))+)/mg,
  2285. termRegExp: /(\n)/mg,
  2286. handler: function(w)
  2287. {
  2288. var stack = [w.output];
  2289. var currLevel = 0, currType = null;
  2290. var listLevel, listType, itemType;
  2291. w.nextMatch = w.matchStart;
  2292. this.lookaheadRegExp.lastIndex = w.nextMatch;
  2293. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2294. while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
  2295. if(lookaheadMatch[1]) {
  2296. listType = "ul";
  2297. itemType = "li";
  2298. } else if(lookaheadMatch[2]) {
  2299. listType = "ol";
  2300. itemType = "li";
  2301. } else if(lookaheadMatch[3]) {
  2302. listType = "dl";
  2303. itemType = "dt";
  2304. } else if(lookaheadMatch[4]) {
  2305. listType = "dl";
  2306. itemType = "dd";
  2307. }
  2308. listLevel = lookaheadMatch[0].length;
  2309. w.nextMatch += lookaheadMatch[0].length;
  2310. var t;
  2311. if(listLevel > currLevel) {
  2312. for(t=currLevel; t<listLevel; t++) {
  2313. var target = (currLevel == 0) ? stack[stack.length-1] : stack[stack.length-1].lastChild;
  2314. stack.push(createTiddlyElement(target,listType));
  2315. }
  2316. } else if(listLevel < currLevel) {
  2317. for(t=currLevel; t>listLevel; t--)
  2318. stack.pop();
  2319. } else if(listLevel == currLevel && listType != currType) {
  2320. stack.pop();
  2321. stack.push(createTiddlyElement(stack[stack.length-1].lastChild,listType));
  2322. }
  2323. currLevel = listLevel;
  2324. currType = listType;
  2325. var e = createTiddlyElement(stack[stack.length-1],itemType);
  2326. w.subWikifyTerm(e,this.termRegExp);
  2327. this.lookaheadRegExp.lastIndex = w.nextMatch;
  2328. lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2329. }
  2330. }
  2331. },
  2332. {
  2333. name: "quoteByBlock",
  2334. match: "^<<<\\n",
  2335. termRegExp: /(^<<<(\n|$))/mg,
  2336. element: "blockquote",
  2337. handler: config.formatterHelpers.createElementAndWikify
  2338. },
  2339. {
  2340. name: "quoteByLine",
  2341. match: "^>+",
  2342. lookaheadRegExp: /^>+/mg,
  2343. termRegExp: /(\n)/mg,
  2344. element: "blockquote",
  2345. handler: function(w)
  2346. {
  2347. var stack = [w.output];
  2348. var currLevel = 0;
  2349. var newLevel = w.matchLength;
  2350. var t;
  2351. do {
  2352. if(newLevel > currLevel) {
  2353. for(t=currLevel; t<newLevel; t++)
  2354. stack.push(createTiddlyElement(stack[stack.length-1],this.element));
  2355. } else if(newLevel < currLevel) {
  2356. for(t=currLevel; t>newLevel; t--)
  2357. stack.pop();
  2358. }
  2359. currLevel = newLevel;
  2360. w.subWikifyTerm(stack[stack.length-1],this.termRegExp);
  2361. createTiddlyElement(stack[stack.length-1],"br");
  2362. this.lookaheadRegExp.lastIndex = w.nextMatch;
  2363. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2364. var matched = lookaheadMatch && lookaheadMatch.index == w.nextMatch;
  2365. if(matched) {
  2366. newLevel = lookaheadMatch[0].length;
  2367. w.nextMatch += lookaheadMatch[0].length;
  2368. }
  2369. } while(matched);
  2370. }
  2371. },
  2372. {
  2373. name: "rule",
  2374. match: "^----+$\\n?",
  2375. handler: function(w)
  2376. {
  2377. createTiddlyElement(w.output,"hr");
  2378. }
  2379. },
  2380. {
  2381. name: "monospacedByLine",
  2382. match: "^\\{\\{\\{\\n",
  2383. lookaheadRegExp: /^\{\{\{\n((?:^[^\n]*\n)+?)(^\}\}\}$\n?)/mg,
  2384. element: "pre",
  2385. handler: config.formatterHelpers.enclosedTextHelper
  2386. },
  2387. {
  2388. name: "monospacedByLineForCSS",
  2389. match: "^/\\*\\{\\{\\{\\*/\\n",
  2390. lookaheadRegExp: /\/\*\{\{\{\*\/\n*((?:^[^\n]*\n)+?)(\n*^\/\*\}\}\}\*\/$\n?)/mg,
  2391. element: "pre",
  2392. handler: config.formatterHelpers.enclosedTextHelper
  2393. },
  2394. {
  2395. name: "monospacedByLineForPlugin",
  2396. match: "^//\\{\\{\\{\\n",
  2397. lookaheadRegExp: /^\/\/\{\{\{\n\n*((?:^[^\n]*\n)+?)(\n*^\/\/\}\}\}$\n?)/mg,
  2398. element: "pre",
  2399. handler: config.formatterHelpers.enclosedTextHelper
  2400. },
  2401. {
  2402. name: "monospacedByLineForTemplate",
  2403. match: "^<!--\\{\\{\\{-->\\n",
  2404. lookaheadRegExp: /<!--\{\{\{-->\n*((?:^[^\n]*\n)+?)(\n*^<!--\}\}\}-->$\n?)/mg,
  2405. element: "pre",
  2406. handler: config.formatterHelpers.enclosedTextHelper
  2407. },
  2408. {
  2409. name: "wikifyCommentForPlugin",
  2410. match: "^/\\*\\*\\*\\n",
  2411. termRegExp: /(^\*\*\*\/\n)/mg,
  2412. handler: function(w)
  2413. {
  2414. w.subWikifyTerm(w.output,this.termRegExp);
  2415. }
  2416. },
  2417. {
  2418. name: "wikifyCommentForTemplate",
  2419. match: "^<!---\\n",
  2420. termRegExp: /(^--->\n)/mg,
  2421. handler: function(w)
  2422. {
  2423. w.subWikifyTerm(w.output,this.termRegExp);
  2424. }
  2425. },
  2426. {
  2427. name: "macro",
  2428. match: "<<",
  2429. lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
  2430. handler: function(w)
  2431. {
  2432. this.lookaheadRegExp.lastIndex = w.matchStart;
  2433. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2434. if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
  2435. w.nextMatch = this.lookaheadRegExp.lastIndex;
  2436. invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
  2437. }
  2438. }
  2439. },
  2440. {
  2441. name: "prettyLink",
  2442. match: "\\[\\[",
  2443. lookaheadRegExp: /\[\[(.*?)(?:\|(~)?(.*?))?\]\]/mg,
  2444. handler: function(w)
  2445. {
  2446. this.lookaheadRegExp.lastIndex = w.matchStart;
  2447. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2448. if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
  2449. var e;
  2450. var text = lookaheadMatch[1];
  2451. if(lookaheadMatch[3]) {
  2452. // Pretty bracketted link
  2453. var link = lookaheadMatch[3];
  2454. e = (!lookaheadMatch[2] && config.formatterHelpers.isExternalLink(link)) ?
  2455. createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
  2456. } else {
  2457. // Simple bracketted link
  2458. e = createTiddlyLink(w.output,text,false,null,w.isStatic,w.tiddler);
  2459. }
  2460. createTiddlyText(e,text);
  2461. w.nextMatch = this.lookaheadRegExp.lastIndex;
  2462. }
  2463. }
  2464. },
  2465. {
  2466. name: "unWikiLink",
  2467. match: config.textPrimitives.unWikiLink+config.textPrimitives.wikiLink,
  2468. handler: function(w)
  2469. {
  2470. w.outputText(w.output,w.matchStart+1,w.nextMatch);
  2471. }
  2472. },
  2473. {
  2474. name: "wikiLink",
  2475. match: config.textPrimitives.wikiLink,
  2476. handler: function(w)
  2477. {
  2478. if(w.matchStart > 0) {
  2479. var preRegExp = new RegExp(config.textPrimitives.anyLetterStrict,"mg");
  2480. preRegExp.lastIndex = w.matchStart-1;
  2481. var preMatch = preRegExp.exec(w.source);
  2482. if(preMatch.index == w.matchStart-1) {
  2483. w.outputText(w.output,w.matchStart,w.nextMatch);
  2484. return;
  2485. }
  2486. }
  2487. if(w.autoLinkWikiWords == true || store.isShadowTiddler(w.matchText)) {
  2488. var link = createTiddlyLink(w.output,w.matchText,false,null,w.isStatic,w.tiddler);
  2489. w.outputText(link,w.matchStart,w.nextMatch);
  2490. } else {
  2491. w.outputText(w.output,w.matchStart,w.nextMatch);
  2492. }
  2493. }
  2494. },
  2495. {
  2496. name: "urlLink",
  2497. match: config.textPrimitives.urlPattern,
  2498. handler: function(w)
  2499. {
  2500. w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
  2501. }
  2502. },
  2503. {
  2504. name: "image",
  2505. match: "\\[[<>]?[Ii][Mm][Gg]\\[",
  2506. lookaheadRegExp: /\[([<]?)(>?)[Ii][Mm][Gg]\[(?:([^\|\]]+)\|)?([^\[\]\|]+)\](?:\[([^\]]*)\])?\]/mg,
  2507. handler: function(w)
  2508. {
  2509. this.lookaheadRegExp.lastIndex = w.matchStart;
  2510. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2511. if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
  2512. var e = w.output;
  2513. if(lookaheadMatch[5]) {
  2514. var link = lookaheadMatch[5];
  2515. e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
  2516. addClass(e,"imageLink");
  2517. }
  2518. var img = createTiddlyElement(e,"img");
  2519. if(lookaheadMatch[1])
  2520. img.align = "left";
  2521. else if(lookaheadMatch[2])
  2522. img.align = "right";
  2523. if(lookaheadMatch[3])
  2524. img.title = lookaheadMatch[3];
  2525. img.src = lookaheadMatch[4];
  2526. w.nextMatch = this.lookaheadRegExp.lastIndex;
  2527. }
  2528. }
  2529. },
  2530. {
  2531. name: "html",
  2532. match: "<[Hh][Tt][Mm][Ll]>",
  2533. lookaheadRegExp: /<[Hh][Tt][Mm][Ll]>((?:.|\n)*?)<\/[Hh][Tt][Mm][Ll]>/mg,
  2534. handler: function(w)
  2535. {
  2536. this.lookaheadRegExp.lastIndex = w.matchStart;
  2537. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2538. if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
  2539. createTiddlyElement(w.output,"span").innerHTML = lookaheadMatch[1];
  2540. w.nextMatch = this.lookaheadRegExp.lastIndex;
  2541. }
  2542. }
  2543. },
  2544. {
  2545. name: "commentByBlock",
  2546. match: "/%",
  2547. lookaheadRegExp: /\/%((?:.|\n)*?)%\//mg,
  2548. handler: function(w)
  2549. {
  2550. this.lookaheadRegExp.lastIndex = w.matchStart;
  2551. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2552. if(lookaheadMatch && lookaheadMatch.index == w.matchStart)
  2553. w.nextMatch = this.lookaheadRegExp.lastIndex;
  2554. }
  2555. },
  2556. {
  2557. name: "boldByChar",
  2558. match: "''",
  2559. termRegExp: /('')/mg,
  2560. element: "strong",
  2561. handler: config.formatterHelpers.createElementAndWikify
  2562. },
  2563. {
  2564. name: "italicByChar",
  2565. match: "//",
  2566. termRegExp: /(\/\/)/mg,
  2567. element: "em",
  2568. handler: config.formatterHelpers.createElementAndWikify
  2569. },
  2570. {
  2571. name: "underlineByChar",
  2572. match: "__",
  2573. termRegExp: /(__)/mg,
  2574. element: "u",
  2575. handler: config.formatterHelpers.createElementAndWikify
  2576. },
  2577. {
  2578. name: "strikeByChar",
  2579. match: "--(?!\\s|$)",
  2580. termRegExp: /((?!\s)--|(?=\n\n))/mg,
  2581. element: "strike",
  2582. handler: config.formatterHelpers.createElementAndWikify
  2583. },
  2584. {
  2585. name: "superscriptByChar",
  2586. match: "\\^\\^",
  2587. termRegExp: /(\^\^)/mg,
  2588. element: "sup",
  2589. handler: config.formatterHelpers.createElementAndWikify
  2590. },
  2591. {
  2592. name: "subscriptByChar",
  2593. match: "~~",
  2594. termRegExp: /(~~)/mg,
  2595. element: "sub",
  2596. handler: config.formatterHelpers.createElementAndWikify
  2597. },
  2598. {
  2599. name: "monospacedByChar",
  2600. match: "\\{\\{\\{",
  2601. lookaheadRegExp: /\{\{\{((?:.|\n)*?)\}\}\}/mg,
  2602. handler: function(w)
  2603. {
  2604. this.lookaheadRegExp.lastIndex = w.matchStart;
  2605. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2606. if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
  2607. createTiddlyElement(w.output,"code",null,null,lookaheadMatch[1]);
  2608. w.nextMatch = this.lookaheadRegExp.lastIndex;
  2609. }
  2610. }
  2611. },
  2612. {
  2613. name: "styleByChar",
  2614. match: "@@",
  2615. termRegExp: /(@@)/mg,
  2616. handler: function(w)
  2617. {
  2618. var e = createTiddlyElement(w.output,"span");
  2619. var styles = config.formatterHelpers.inlineCssHelper(w);
  2620. if(styles.length == 0)
  2621. e.className = "marked";
  2622. else
  2623. config.formatterHelpers.applyCssHelper(e,styles);
  2624. w.subWikifyTerm(e,this.termRegExp);
  2625. }
  2626. },
  2627. {
  2628. name: "lineBreak",
  2629. match: "\\n|<br ?/?>",
  2630. handler: function(w)
  2631. {
  2632. createTiddlyElement(w.output,"br");
  2633. }
  2634. },
  2635. {
  2636. name: "rawText",
  2637. match: "\\\"{3}|<nowiki>",
  2638. lookaheadRegExp: /(?:\"{3}|<nowiki>)((?:.|\n)*?)(?:\"{3}|<\/nowiki>)/mg,
  2639. handler: function(w)
  2640. {
  2641. this.lookaheadRegExp.lastIndex = w.matchStart;
  2642. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2643. if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
  2644. createTiddlyElement(w.output,"span",null,null,lookaheadMatch[1]);
  2645. w.nextMatch = this.lookaheadRegExp.lastIndex;
  2646. }
  2647. }
  2648. },
  2649. {
  2650. name: "mdash",
  2651. match: "--",
  2652. handler: function(w)
  2653. {
  2654. createTiddlyElement(w.output,"span").innerHTML = "&mdash;";
  2655. }
  2656. },
  2657. {
  2658. name: "htmlEntitiesEncoding",
  2659. match: "(?:(?:&#?[a-zA-Z0-9]{2,8};|.)(?:&#?(?:x0*(?:3[0-6][0-9a-fA-F]|1D[c-fC-F][0-9a-fA-F]|20[d-fD-F][0-9a-fA-F]|FE2[0-9a-fA-F])|0*(?:76[89]|7[7-9][0-9]|8[0-7][0-9]|761[6-9]|76[2-7][0-9]|84[0-3][0-9]|844[0-7]|6505[6-9]|6506[0-9]|6507[0-1]));)+|&#?[a-zA-Z0-9]{2,8};)",
  2660. handler: function(w)
  2661. {
  2662. createTiddlyElement(w.output,"span").innerHTML = w.matchText;
  2663. }
  2664. },
  2665. {
  2666. name: "customClasses",
  2667. match: "\\{\\{",
  2668. termRegExp: /(\}\}\})/mg,
  2669. lookaheadRegExp: /\{\{[\s]*([\w]+[\s\w]*)[\s]*\{(\n?)/mg,
  2670. handler: function(w)
  2671. {
  2672. this.lookaheadRegExp.lastIndex = w.matchStart;
  2673. var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
  2674. if(lookaheadMatch) {
  2675. var e = createTiddlyElement(w.output,lookaheadMatch[2] == "\n" ? "div" : "span",null,lookaheadMatch[1]);
  2676. w.nextMatch = this.lookaheadRegExp.lastIndex;
  2677. w.subWikifyTerm(e,this.termRegExp);
  2678. }
  2679. }
  2680. }
  2681. ];
  2682. //--
  2683. //-- Wikifier
  2684. //--
  2685. function getParser(tiddler,format)
  2686. {
  2687. if(tiddler) {
  2688. if(!format)
  2689. format = tiddler.fields["wikiformat"];
  2690. if(format) {
  2691. for(var i in config.parsers) {
  2692. if(format == config.parsers[i].format)
  2693. return config.parsers[i];
  2694. }
  2695. } else {
  2696. for(var i in config.parsers) {
  2697. if(tiddler.isTagged(config.parsers[i].formatTag))
  2698. return config.parsers[i];
  2699. }
  2700. }
  2701. }
  2702. return formatter;
  2703. }
  2704. function wikify(source,output,highlightRegExp,tiddler)
  2705. {
  2706. if(source && source != "") {
  2707. var wikifier = new Wikifier(source,getParser(tiddler),highlightRegExp,tiddler);
  2708. wikifier.subWikifyUnterm(output);
  2709. }
  2710. }
  2711. function wikifyStatic(source,highlightRegExp,tiddler,format)
  2712. {
  2713. var e = createTiddlyElement(document.body,"div");
  2714. e.style.display = "none";
  2715. var html = "";
  2716. if(source && source != "") {
  2717. var wikifier = new Wikifier(source,getParser(tiddler,format),highlightRegExp,tiddler);
  2718. wikifier.isStatic = true;
  2719. wikifier.subWikifyUnterm(e);
  2720. html = e.innerHTML;
  2721. removeNode(e);
  2722. }
  2723. return html;
  2724. }
  2725. function wikifyPlain(title,theStore,limit)
  2726. {
  2727. if(!theStore)
  2728. theStore = store;
  2729. if(theStore.tiddlerExists(title) || theStore.isShadowTiddler(title)) {
  2730. return wikifyPlainText(theStore.getTiddlerText(title),limit,tiddler);
  2731. } else {
  2732. return "";
  2733. }
  2734. }
  2735. function wikifyPlainText(text,limit,tiddler)
  2736. {
  2737. if(limit > 0)
  2738. text = text.substr(0,limit);
  2739. var wikifier = new Wikifier(text,formatter,null,tiddler);
  2740. return wikifier.wikifyPlain();
  2741. }
  2742. function highlightify(source,output,highlightRegExp,tiddler)
  2743. {
  2744. if(source && source != "") {
  2745. var wikifier = new Wikifier(source,formatter,highlightRegExp,tiddler);
  2746. wikifier.outputText(output,0,source.length);
  2747. }
  2748. }
  2749. function Wikifier(source,formatter,highlightRegExp,tiddler)
  2750. {
  2751. this.source = source;
  2752. this.output = null;
  2753. this.formatter = formatter;
  2754. this.nextMatch = 0;
  2755. this.autoLinkWikiWords = tiddler && tiddler.autoLinkWikiWords() == false ? false : true;
  2756. this.highlightRegExp = highlightRegExp;
  2757. this.highlightMatch = null;
  2758. this.isStatic = false;
  2759. if(highlightRegExp) {
  2760. highlightRegExp.lastIndex = 0;
  2761. this.highlightMatch = highlightRegExp.exec(source);
  2762. }
  2763. this.tiddler = tiddler;
  2764. }
  2765. Wikifier.prototype.wikifyPlain = function()
  2766. {
  2767. var e = createTiddlyElement(document.body,"div");
  2768. this.subWikify(e);
  2769. var text = getPlainText(e);
  2770. removeNode(e);
  2771. return text;
  2772. };
  2773. Wikifier.prototype.subWikify = function(output,terminator)
  2774. {
  2775. if(terminator)
  2776. this.subWikifyTerm(output,new RegExp("(" + terminator + ")","mg"));
  2777. else
  2778. this.subWikifyUnterm(output);
  2779. };
  2780. Wikifier.prototype.subWikifyUnterm = function(output)
  2781. {
  2782. // subWikify() can be indirectly recursive, so we need to save the old output pointer
  2783. var oldOutput = this.output;
  2784. this.output = output;
  2785. this.formatter.formatterRegExp.lastIndex = this.nextMatch;
  2786. var formatterMatch = this.formatter.formatterRegExp.exec(this.source);
  2787. while(formatterMatch) {
  2788. // Output any text before the match
  2789. if(formatterMatch.index > this.nextMatch)
  2790. this.outputText(this.output,this.nextMatch,formatterMatch.index);
  2791. // Set the match parameters for the handler
  2792. this.matchStart = formatterMatch.index;
  2793. this.matchLength = formatterMatch[0].length;
  2794. this.matchText = formatterMatch[0];
  2795. this.nextMatch = this.formatter.formatterRegExp.lastIndex;
  2796. for(var t=1; t<formatterMatch.length; t++) {
  2797. if(formatterMatch[t]) {
  2798. this.formatter.formatters[t-1].handler(this);
  2799. this.formatter.formatterRegExp.lastIndex = this.nextMatch;
  2800. break;
  2801. }
  2802. }
  2803. formatterMatch = this.formatter.formatterRegExp.exec(this.source);
  2804. }
  2805. if(this.nextMatch < this.source.length) {
  2806. this.outputText(this.output,this.nextMatch,this.source.length);
  2807. this.nextMatch = this.source.length;
  2808. }
  2809. this.output = oldOutput;
  2810. };
  2811. Wikifier.prototype.subWikifyTerm = function(output,terminatorRegExp)
  2812. {
  2813. // subWikify() can be indirectly recursive, so we need to save the old output pointer
  2814. var oldOutput = this.output;
  2815. this.output = output;
  2816. // Get the first matches for the formatter and terminator RegExps
  2817. terminatorRegExp.lastIndex = this.nextMatch;
  2818. var terminatorMatch = terminatorRegExp.exec(this.source);
  2819. this.formatter.formatterRegExp.lastIndex = this.nextMatch;
  2820. var formatterMatch = this.formatter.formatterRegExp.exec(terminatorMatch ? this.source.substr(0,terminatorMatch.index) : this.source);
  2821. while(terminatorMatch || formatterMatch) {
  2822. if(terminatorMatch && (!formatterMatch || terminatorMatch.index <= formatterMatch.index)) {
  2823. if(terminatorMatch.index > this.nextMatch)
  2824. this.outputText(this.output,this.nextMatch,terminatorMatch.index);
  2825. this.matchText = terminatorMatch[1];
  2826. this.matchLength = terminatorMatch[1].length;
  2827. this.matchStart = terminatorMatch.index;
  2828. this.nextMatch = this.matchStart + this.matchLength;
  2829. this.output = oldOutput;
  2830. return;
  2831. }
  2832. if(formatterMatch.index > this.nextMatch)
  2833. this.outputText(this.output,this.nextMatch,formatterMatch.index);
  2834. this.matchStart = formatterMatch.index;
  2835. this.matchLength = formatterMatch[0].length;
  2836. this.matchText = formatterMatch[0];
  2837. this.nextMatch = this.formatter.formatterRegExp.lastIndex;
  2838. for(var t=1; t<formatterMatch.length; t++) {
  2839. if(formatterMatch[t]) {
  2840. this.formatter.formatters[t-1].handler(this);
  2841. this.formatter.formatterRegExp.lastIndex = this.nextMatch;
  2842. break;
  2843. }
  2844. }
  2845. terminatorRegExp.lastIndex = this.nextMatch;
  2846. terminatorMatch = terminatorRegExp.exec(this.source);
  2847. formatterMatch = this.formatter.formatterRegExp.exec(terminatorMatch ? this.source.substr(0,terminatorMatch.index) : this.source);
  2848. }
  2849. if(this.nextMatch < this.source.length) {
  2850. this.outputText(this.output,this.nextMatch,this.source.length);
  2851. this.nextMatch = this.source.length;
  2852. }
  2853. this.output = oldOutput;
  2854. };
  2855. Wikifier.prototype.outputText = function(place,startPos,endPos)
  2856. {
  2857. while(this.highlightMatch && (this.highlightRegExp.lastIndex > startPos) && (this.highlightMatch.index < endPos) && (startPos < endPos)) {
  2858. if(this.highlightMatch.index > startPos) {
  2859. createTiddlyText(place,this.source.substring(startPos,this.highlightMatch.index));
  2860. startPos = this.highlightMatch.index;
  2861. }
  2862. var highlightEnd = Math.min(this.highlightRegExp.lastIndex,endPos);
  2863. var theHighlight = createTiddlyElement(place,"span",null,"highlight",this.source.substring(startPos,highlightEnd));
  2864. startPos = highlightEnd;
  2865. if(startPos >= this.highlightRegExp.lastIndex)
  2866. this.highlightMatch = this.highlightRegExp.exec(this.source);
  2867. }
  2868. if(startPos < endPos) {
  2869. createTiddlyText(place,this.source.substring(startPos,endPos));
  2870. }
  2871. };
  2872. //--
  2873. //-- Macro definitions
  2874. //--
  2875. config.macros.today.handler = function(place,macroName,params)
  2876. {
  2877. var now = new Date();
  2878. var text;
  2879. if(params[0])
  2880. text = now.formatString(params[0].trim());
  2881. else
  2882. text = now.toLocaleString();
  2883. createTiddlyElement(place,"span",null,null,text);
  2884. };
  2885. config.macros.version.handler = function(place)
  2886. {
  2887. createTiddlyElement(place,"span",null,null,version.major + "." + version.minor + "." + version.revision + (version.beta ? " (beta " + version.beta + ")" : ""));
  2888. };
  2889. config.macros.list.handler = function(place,macroName,params)
  2890. {
  2891. var type = params[0] ? params[0] : "all";
  2892. var list = document.createElement("ul");
  2893. place.appendChild(list);
  2894. if(this[type].prompt)
  2895. createTiddlyElement(list,"li",null,"listTitle",this[type].prompt);
  2896. var results;
  2897. if(this[type].handler)
  2898. results = this[type].handler(params);
  2899. for(var t = 0; t < results.length; t++) {
  2900. var li = document.createElement("li");
  2901. list.appendChild(li);
  2902. createTiddlyLink(li,typeof results[t] == "string" ? results[t] : results[t].title,true);
  2903. }
  2904. };
  2905. config.macros.list.all.handler = function(params)
  2906. {
  2907. return store.reverseLookup("tags","excludeLists",false,"title");
  2908. };
  2909. config.macros.list.missing.handler = function(params)
  2910. {
  2911. return store.getMissingLinks();
  2912. };
  2913. config.macros.list.orphans.handler = function(params)
  2914. {
  2915. return store.getOrphans();
  2916. };
  2917. config.macros.list.shadowed.handler = function(params)
  2918. {
  2919. return store.getShadowed();
  2920. };
  2921. config.macros.list.touched.handler = function(params)
  2922. {
  2923. return store.getTouched();
  2924. };
  2925. config.macros.allTags.handler = function(place,macroName,params)
  2926. {
  2927. var tags = store.getTags(params[0]);
  2928. var ul = createTiddlyElement(place,"ul");
  2929. if(tags.length == 0)
  2930. createTiddlyElement(ul,"li",null,"listTitle",this.noTags);
  2931. for(var t=0; t<tags.length; t++) {
  2932. var title = tags[t][0];
  2933. var info = getTiddlyLinkInfo(title);
  2934. var li =createTiddlyElement(ul,"li");
  2935. var btn = createTiddlyButton(li,title + " (" + tags[t][1] + ")",this.tooltip.format([title]),onClickTag,info.classes);
  2936. btn.setAttribute("tag",title);
  2937. btn.setAttribute("refresh","link");
  2938. btn.setAttribute("tiddlyLink",title);
  2939. }
  2940. };
  2941. config.macros.timeline.handler = function(place,macroName,params)
  2942. {
  2943. var field = params[0] ? params[0] : "modified";
  2944. var tiddlers = store.reverseLookup("tags","excludeLists",false,field);
  2945. var lastDay = "";
  2946. var last = params[1] ? tiddlers.length-Math.min(tiddlers.length,parseInt(params[1])) : 0;
  2947. for(var t=tiddlers.length-1; t>=last; t--) {
  2948. var tiddler = tiddlers[t];
  2949. var theDay = tiddler[field].convertToLocalYYYYMMDDHHMM().substr(0,8);
  2950. if(theDay != lastDay) {
  2951. var theDateList = document.createElement("ul");
  2952. place.appendChild(theDateList);
  2953. createTiddlyElement(theDateList,"li",null,"listTitle",tiddler[field].formatString(this.dateFormat));
  2954. lastDay = theDay;
  2955. }
  2956. var theDateListItem = createTiddlyElement(theDateList,"li",null,"listLink");
  2957. theDateListItem.appendChild(createTiddlyLink(place,tiddler.title,true));
  2958. }
  2959. };
  2960. config.macros.search.handler = function(place,macroName,params)
  2961. {
  2962. var searchTimeout = null;
  2963. var btn = createTiddlyButton(place,this.label,this.prompt,this.onClick);
  2964. var txt = createTiddlyElement(place,"input",null,"txtOptionInput");
  2965. if(params[0])
  2966. txt.value = params[0];
  2967. txt.onkeyup = this.onKeyPress;
  2968. txt.onfocus = this.onFocus;
  2969. txt.setAttribute("size",this.sizeTextbox);
  2970. txt.setAttribute("accessKey",this.accessKey);
  2971. txt.setAttribute("autocomplete","off");
  2972. txt.setAttribute("lastSearchText","");
  2973. if(config.browser.isSafari) {
  2974. txt.setAttribute("type","search");
  2975. txt.setAttribute("results","5");
  2976. } else {
  2977. txt.setAttribute("type","text");
  2978. }
  2979. };
  2980. // Global because there's only ever one outstanding incremental search timer
  2981. config.macros.search.timeout = null;
  2982. config.macros.search.doSearch = function(txt)
  2983. {
  2984. if(txt.value.length > 0) {
  2985. story.search(txt.value,config.options.chkCaseSensitiveSearch,config.options.chkRegExpSearch);
  2986. txt.setAttribute("lastSearchText",txt.value);
  2987. }
  2988. };
  2989. config.macros.search.onClick = function(e)
  2990. {
  2991. config.macros.search.doSearch(this.nextSibling);
  2992. return false;
  2993. };
  2994. config.macros.search.onKeyPress = function(e)
  2995. {
  2996. if(!e) var e = window.event;
  2997. switch(e.keyCode) {
  2998. case 13: // Ctrl-Enter
  2999. case 10: // Ctrl-Enter on IE PC
  3000. config.macros.search.doSearch(this);
  3001. break;
  3002. case 27: // Escape
  3003. this.value = "";
  3004. clearMessage();
  3005. break;
  3006. }
  3007. if(this.value.length > 2) {
  3008. if(this.value != this.getAttribute("lastSearchText")) {
  3009. if(config.macros.search.timeout)
  3010. clearTimeout(config.macros.search.timeout);
  3011. var txt = this;
  3012. config.macros.search.timeout = setTimeout(function() {config.macros.search.doSearch(txt);},500);
  3013. }
  3014. } else {
  3015. if(config.macros.search.timeout)
  3016. clearTimeout(config.macros.search.timeout);
  3017. }
  3018. };
  3019. config.macros.search.onFocus = function(e)
  3020. {
  3021. this.select();
  3022. };
  3023. config.macros.tiddler.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3024. {
  3025. params = paramString.parseParams("name",null,true,false,true);
  3026. var names = params[0]["name"];
  3027. var tiddlerName = names[0];
  3028. var className = names[1] ? names[1] : null;
  3029. var args = params[0]["with"];
  3030. var wrapper = createTiddlyElement(place,"span",null,className);
  3031. if(!args) {
  3032. wrapper.setAttribute("refresh","content");
  3033. wrapper.setAttribute("tiddler",tiddlerName);
  3034. }
  3035. var text = store.getTiddlerText(tiddlerName);
  3036. if(text) {
  3037. var stack = config.macros.tiddler.tiddlerStack;
  3038. if(stack.indexOf(tiddlerName) !== -1)
  3039. return;
  3040. stack.push(tiddlerName);
  3041. try {
  3042. var n = args ? Math.min(args.length,9) : 0;
  3043. for(var i=0; i<n; i++) {
  3044. var placeholderRE = new RegExp("\\$" + (i + 1),"mg");
  3045. text = text.replace(placeholderRE,args[i]);
  3046. }
  3047. config.macros.tiddler.renderText(wrapper,text,tiddlerName,params);
  3048. } finally {
  3049. stack.pop();
  3050. }
  3051. }
  3052. };
  3053. config.macros.tiddler.renderText = function(place,text,tiddlerName,params)
  3054. {
  3055. wikify(text,place,null,store.getTiddler(tiddlerName));
  3056. };
  3057. config.macros.tiddler.tiddlerStack = [];
  3058. config.macros.tag.handler = function(place,macroName,params)
  3059. {
  3060. createTagButton(place,params[0]);
  3061. };
  3062. config.macros.tags.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3063. {
  3064. params = paramString.parseParams("anon",null,true,false,false);
  3065. var theList = createTiddlyElement(place,"ul");
  3066. var title = getParam(params,"anon","");
  3067. if(title && store.tiddlerExists(title))
  3068. tiddler = store.getTiddler(title);
  3069. var sep = getParam(params,"sep"," ");
  3070. var lingo = config.views.wikified.tag;
  3071. var prompt = tiddler.tags.length == 0 ? lingo.labelNoTags : lingo.labelTags;
  3072. createTiddlyElement(theList,"li",null,"listTitle",prompt.format([tiddler.title]));
  3073. for(var t=0; t<tiddler.tags.length; t++) {
  3074. createTagButton(createTiddlyElement(theList,"li"),tiddler.tags[t],tiddler.title);
  3075. if(t<tiddler.tags.length-1)
  3076. createTiddlyText(theList,sep);
  3077. }
  3078. };
  3079. config.macros.tagging.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3080. {
  3081. params = paramString.parseParams("anon",null,true,false,false);
  3082. var theList = createTiddlyElement(place,"ul");
  3083. var title = getParam(params,"anon","");
  3084. if(title == "" && tiddler instanceof Tiddler)
  3085. title = tiddler.title;
  3086. var sep = getParam(params,"sep"," ");
  3087. theList.setAttribute("title",this.tooltip.format([title]));
  3088. var tagged = store.getTaggedTiddlers(title);
  3089. var prompt = tagged.length == 0 ? this.labelNotTag : this.label;
  3090. createTiddlyElement(theList,"li",null,"listTitle",prompt.format([title,tagged.length]));
  3091. for(var t=0; t<tagged.length; t++) {
  3092. createTiddlyLink(createTiddlyElement(theList,"li"),tagged[t].title,true);
  3093. if(t<tagged.length-1)
  3094. createTiddlyText(theList,sep);
  3095. }
  3096. };
  3097. config.macros.closeAll.handler = function(place)
  3098. {
  3099. createTiddlyButton(place,this.label,this.prompt,this.onClick);
  3100. };
  3101. config.macros.closeAll.onClick = function(e)
  3102. {
  3103. story.closeAllTiddlers();
  3104. return false;
  3105. };
  3106. config.macros.permaview.handler = function(place)
  3107. {
  3108. createTiddlyButton(place,this.label,this.prompt,this.onClick);
  3109. };
  3110. config.macros.permaview.onClick = function(e)
  3111. {
  3112. story.permaView();
  3113. return false;
  3114. };
  3115. config.macros.saveChanges.handler = function(place)
  3116. {
  3117. if(!readOnly)
  3118. createTiddlyButton(place,this.label,this.prompt,this.onClick,null,null,this.accessKey);
  3119. };
  3120. config.macros.saveChanges.onClick = function(e)
  3121. {
  3122. saveChanges();
  3123. return false;
  3124. };
  3125. config.macros.slider.onClickSlider = function(e)
  3126. {
  3127. if(!e) var e = window.event;
  3128. var n = this.nextSibling;
  3129. var cookie = n.getAttribute("cookie");
  3130. var isOpen = n.style.display != "none";
  3131. if(config.options.chkAnimate && anim && typeof Slider == "function")
  3132. anim.startAnimating(new Slider(n,!isOpen,null,"none"));
  3133. else
  3134. n.style.display = isOpen ? "none" : "block";
  3135. config.options[cookie] = !isOpen;
  3136. saveOptionCookie(cookie);
  3137. return false;
  3138. };
  3139. config.macros.slider.createSlider = function(place,cookie,title,tooltip)
  3140. {
  3141. var cookie = cookie ? cookie : "";
  3142. var btn = createTiddlyButton(place,title,tooltip,this.onClickSlider);
  3143. var panel = createTiddlyElement(null,"div",null,"sliderPanel");
  3144. panel.setAttribute("cookie",cookie);
  3145. panel.style.display = config.options[cookie] ? "block" : "none";
  3146. place.appendChild(panel);
  3147. return panel;
  3148. };
  3149. config.macros.slider.handler = function(place,macroName,params)
  3150. {
  3151. var panel = this.createSlider(place,params[0],params[2],params[3]);
  3152. var text = store.getTiddlerText(params[1]);
  3153. panel.setAttribute("refresh","content");
  3154. panel.setAttribute("tiddler",params[1]);
  3155. if(text)
  3156. wikify(text,panel,null,store.getTiddler(params[1]));
  3157. };
  3158. config.macros.option.genericCreate = function(place,type,opt,className,desc)
  3159. {
  3160. var typeInfo = config.macros.option.types[type];
  3161. var c = document.createElement(typeInfo.elementType);
  3162. if(typeInfo.typeValue)
  3163. c.setAttribute("type",typeInfo.typeValue);
  3164. c[typeInfo.eventName] = typeInfo.onChange;
  3165. c.setAttribute("option",opt);
  3166. if(className)
  3167. c.className = className;
  3168. else
  3169. c.className = typeInfo.className;
  3170. if(config.optionsDesc[opt])
  3171. c.setAttribute("title",config.optionsDesc[opt]);
  3172. place.appendChild(c);
  3173. if(desc != "no")
  3174. createTiddlyText(place,config.optionsDesc[opt] ? config.optionsDesc[opt] : opt);
  3175. c[typeInfo.valueField] = config.options[opt];
  3176. return c;
  3177. };
  3178. config.macros.option.genericOnChange = function(e)
  3179. {
  3180. var opt = this.getAttribute("option");
  3181. if(opt) {
  3182. var optType = opt.substr(0,3);
  3183. var handler = config.macros.option.types[optType];
  3184. if (handler.elementType && handler.valueField)
  3185. config.macros.option.propagateOption(opt,handler.valueField,this[handler.valueField],handler.elementType);
  3186. }
  3187. return true;
  3188. };
  3189. config.macros.option.types = {
  3190. 'txt': {
  3191. elementType: "input",
  3192. valueField: "value",
  3193. eventName: "onkeyup",
  3194. className: "txtOptionInput",
  3195. create: config.macros.option.genericCreate,
  3196. onChange: config.macros.option.genericOnChange
  3197. },
  3198. 'chk': {
  3199. elementType: "input",
  3200. valueField: "checked",
  3201. eventName: "onclick",
  3202. className: "chkOptionInput",
  3203. typeValue: "checkbox",
  3204. create: config.macros.option.genericCreate,
  3205. onChange: config.macros.option.genericOnChange
  3206. }
  3207. };
  3208. config.macros.option.propagateOption = function(opt,valueField,value,elementType)
  3209. {
  3210. config.options[opt] = value;
  3211. saveOptionCookie(opt);
  3212. var nodes = document.getElementsByTagName(elementType);
  3213. for(var t=0; t<nodes.length; t++) {
  3214. var optNode = nodes[t].getAttribute("option");
  3215. if(opt == optNode)
  3216. nodes[t][valueField] = value;
  3217. }
  3218. };
  3219. config.macros.option.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3220. {
  3221. params = paramString.parseParams("anon",null,true,false,false);
  3222. var opt = (params[1] && params[1].name == "anon") ? params[1].value : getParam(params,"name",null);
  3223. var className = (params[2] && params[2].name == "anon") ? params[2].value : getParam(params,"class",null);
  3224. var desc = getParam(params,"desc","no");
  3225. var type = opt.substr(0,3);
  3226. var h = config.macros.option.types[type];
  3227. if (h && h.create)
  3228. h.create(place,type,opt,className,desc);
  3229. };
  3230. config.macros.options.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3231. {
  3232. params = paramString.parseParams("anon",null,true,false,false);
  3233. var showUnknown = getParam(params,"showUnknown","no");
  3234. var wizard = new Wizard();
  3235. wizard.createWizard(place,this.wizardTitle);
  3236. wizard.addStep(this.step1Title,this.step1Html);
  3237. var markList = wizard.getElement("markList");
  3238. var chkUnknown = wizard.getElement("chkUnknown");
  3239. chkUnknown.checked = showUnknown == "yes";
  3240. chkUnknown.onchange = this.onChangeUnknown;
  3241. var listWrapper = document.createElement("div");
  3242. markList.parentNode.insertBefore(listWrapper,markList);
  3243. wizard.setValue("listWrapper",listWrapper);
  3244. this.refreshOptions(listWrapper,showUnknown == "yes");
  3245. };
  3246. config.macros.options.refreshOptions = function(listWrapper,showUnknown)
  3247. {
  3248. var opts = [];
  3249. for(var n in config.options) {
  3250. var opt = {};
  3251. opt.option = "";
  3252. opt.name = n;
  3253. opt.lowlight = !config.optionsDesc[n];
  3254. opt.description = opt.lowlight ? this.unknownDescription : config.optionsDesc[n];
  3255. if(!opt.lowlight || showUnknown)
  3256. opts.push(opt);
  3257. }
  3258. opts.sort(function(a,b) {return a.name.substr(3) < b.name.substr(3) ? -1 : (a.name.substr(3) == b.name.substr(3) ? 0 : +1);});
  3259. var listview = ListView.create(listWrapper,opts,this.listViewTemplate);
  3260. for(n=0; n<opts.length; n++) {
  3261. var type = opts[n].name.substr(0,3);
  3262. var h = config.macros.option.types[type];
  3263. if (h && h.create) {
  3264. h.create(opts[n].colElements['option'],type,opts[n].name,null,"no");
  3265. }
  3266. }
  3267. };
  3268. config.macros.options.onChangeUnknown = function(e)
  3269. {
  3270. var wizard = new Wizard(this);
  3271. var listWrapper = wizard.getValue("listWrapper");
  3272. removeChildren(listWrapper);
  3273. config.macros.options.refreshOptions(listWrapper,this.checked);
  3274. return false;
  3275. };
  3276. config.macros.newTiddler.createNewTiddlerButton = function(place,title,params,label,prompt,accessKey,newFocus,isJournal)
  3277. {
  3278. var tags = [];
  3279. for(var t=1; t<params.length; t++) {
  3280. if((params[t].name == "anon" && t != 1) || (params[t].name == "tag"))
  3281. tags.push(params[t].value);
  3282. }
  3283. label = getParam(params,"label",label);
  3284. prompt = getParam(params,"prompt",prompt);
  3285. accessKey = getParam(params,"accessKey",accessKey);
  3286. newFocus = getParam(params,"focus",newFocus);
  3287. var customFields = getParam(params,"fields","");
  3288. if(!customFields && !store.isShadowTiddler(title))
  3289. customFields = String.encodeHashMap(config.defaultCustomFields);
  3290. var btn = createTiddlyButton(place,label,prompt,this.onClickNewTiddler,null,null,accessKey);
  3291. btn.setAttribute("newTitle",title);
  3292. btn.setAttribute("isJournal",isJournal ? "true" : "false");
  3293. if(tags.length > 0)
  3294. btn.setAttribute("params",tags.join("|"));
  3295. btn.setAttribute("newFocus",newFocus);
  3296. btn.setAttribute("newTemplate",getParam(params,"template",DEFAULT_EDIT_TEMPLATE));
  3297. if(customFields !== "")
  3298. btn.setAttribute("customFields",customFields);
  3299. var text = getParam(params,"text");
  3300. if(text !== undefined)
  3301. btn.setAttribute("newText",text);
  3302. return btn;
  3303. };
  3304. config.macros.newTiddler.onClickNewTiddler = function()
  3305. {
  3306. var title = this.getAttribute("newTitle");
  3307. if(this.getAttribute("isJournal") == "true") {
  3308. var now = new Date();
  3309. title = now.formatString(title.trim());
  3310. }
  3311. var params = this.getAttribute("params");
  3312. var tags = params ? params.split("|") : [];
  3313. var focus = this.getAttribute("newFocus");
  3314. var template = this.getAttribute("newTemplate");
  3315. var customFields = this.getAttribute("customFields");
  3316. story.displayTiddler(null,title,template,false,null,null);
  3317. var tiddlerElem = document.getElementById(story.idPrefix + title);
  3318. if(customFields)
  3319. story.addCustomFields(tiddlerElem,customFields);
  3320. var text = this.getAttribute("newText");
  3321. if(typeof text == "string")
  3322. story.getTiddlerField(title,"text").value = text.format([title]);
  3323. for(var t=0;t<tags.length;t++)
  3324. story.setTiddlerTag(title,tags[t],+1);
  3325. story.focusTiddler(title,focus);
  3326. return false;
  3327. };
  3328. config.macros.newTiddler.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3329. {
  3330. if(!readOnly) {
  3331. params = paramString.parseParams("anon",null,true,false,false);
  3332. var title = params[1] && params[1].name == "anon" ? params[1].value : this.title;
  3333. title = getParam(params,"title",title);
  3334. this.createNewTiddlerButton(place,title,params,this.label,this.prompt,this.accessKey,"title",false);
  3335. }
  3336. };
  3337. config.macros.newJournal.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3338. {
  3339. if(!readOnly) {
  3340. params = paramString.parseParams("anon",null,true,false,false);
  3341. var title = params[1] && params[1].name == "anon" ? params[1].value : "";
  3342. title = getParam(params,"title",title);
  3343. config.macros.newTiddler.createNewTiddlerButton(place,title,params,this.label,this.prompt,this.accessKey,"text",true);
  3344. }
  3345. };
  3346. config.macros.sparkline.handler = function(place,macroName,params)
  3347. {
  3348. var data = [];
  3349. var min = 0;
  3350. var max = 0;
  3351. for(var t=0; t<params.length; t++) {
  3352. var v = parseInt(params[t]);
  3353. if(v < min)
  3354. min = v;
  3355. if(v > max)
  3356. max = v;
  3357. data.push(v);
  3358. }
  3359. if(data.length < 1)
  3360. return;
  3361. var box = createTiddlyElement(place,"span",null,"sparkline",String.fromCharCode(160));
  3362. box.title = data.join(",");
  3363. var w = box.offsetWidth;
  3364. var h = box.offsetHeight;
  3365. box.style.paddingRight = (data.length * 2 - w) + "px";
  3366. box.style.position = "relative";
  3367. for(var d=0; d<data.length; d++) {
  3368. var tick = document.createElement("img");
  3369. tick.border = 0;
  3370. tick.className = "sparktick";
  3371. tick.style.position = "absolute";
  3372. tick.src = "data:image/gif,GIF89a%01%00%01%00%91%FF%00%FF%FF%FF%00%00%00%C0%C0%C0%00%00%00!%F9%04%01%00%00%02%00%2C%00%00%00%00%01%00%01%00%40%02%02T%01%00%3B";
  3373. tick.style.left = d*2 + "px";
  3374. tick.style.width = "2px";
  3375. var v = Math.floor(((data[d] - min)/(max-min)) * h);
  3376. tick.style.top = (h-v) + "px";
  3377. tick.style.height = v + "px";
  3378. box.appendChild(tick);
  3379. }
  3380. };
  3381. config.macros.tabs.handler = function(place,macroName,params)
  3382. {
  3383. var cookie = params[0];
  3384. var numTabs = (params.length-1)/3;
  3385. var wrapper = createTiddlyElement(null,"div",null,cookie);
  3386. var tabset = createTiddlyElement(wrapper,"div",null,"tabset");
  3387. tabset.setAttribute("cookie",cookie);
  3388. var validTab = false;
  3389. for(var t=0; t<numTabs; t++) {
  3390. var label = params[t*3+1];
  3391. var prompt = params[t*3+2];
  3392. var content = params[t*3+3];
  3393. var tab = createTiddlyButton(tabset,label,prompt,this.onClickTab,"tab tabUnselected");
  3394. tab.setAttribute("tab",label);
  3395. tab.setAttribute("content",content);
  3396. tab.title = prompt;
  3397. if(config.options[cookie] == label)
  3398. validTab = true;
  3399. }
  3400. if(!validTab)
  3401. config.options[cookie] = params[1];
  3402. place.appendChild(wrapper);
  3403. this.switchTab(tabset,config.options[cookie]);
  3404. };
  3405. config.macros.tabs.onClickTab = function(e)
  3406. {
  3407. config.macros.tabs.switchTab(this.parentNode,this.getAttribute("tab"));
  3408. return false;
  3409. };
  3410. config.macros.tabs.switchTab = function(tabset,tab)
  3411. {
  3412. var cookie = tabset.getAttribute("cookie");
  3413. var theTab = null;
  3414. var nodes = tabset.childNodes;
  3415. for(var t=0; t<nodes.length; t++) {
  3416. if(nodes[t].getAttribute && nodes[t].getAttribute("tab") == tab) {
  3417. theTab = nodes[t];
  3418. theTab.className = "tab tabSelected";
  3419. } else {
  3420. nodes[t].className = "tab tabUnselected";
  3421. }
  3422. }
  3423. if(theTab) {
  3424. if(tabset.nextSibling && tabset.nextSibling.className == "tabContents")
  3425. removeNode(tabset.nextSibling);
  3426. var tabContent = createTiddlyElement(null,"div",null,"tabContents");
  3427. tabset.parentNode.insertBefore(tabContent,tabset.nextSibling);
  3428. var contentTitle = theTab.getAttribute("content");
  3429. wikify(store.getTiddlerText(contentTitle),tabContent,null,store.getTiddler(contentTitle));
  3430. if(cookie) {
  3431. config.options[cookie] = tab;
  3432. saveOptionCookie(cookie);
  3433. }
  3434. }
  3435. };
  3436. // <<gradient [[tiddler name]] vert|horiz rgb rgb rgb rgb... >>
  3437. config.macros.gradient.handler = function(place,macroName,params,wikifier)
  3438. {
  3439. var terminator = ">>";
  3440. var panel;
  3441. if(wikifier)
  3442. panel = createTiddlyElement(place,"div",null,"gradient");
  3443. else
  3444. panel = place;
  3445. panel.style.position = "relative";
  3446. panel.style.overflow = "hidden";
  3447. panel.style.zIndex = "0";
  3448. var t;
  3449. if(wikifier) {
  3450. var styles = config.formatterHelpers.inlineCssHelper(wikifier);
  3451. config.formatterHelpers.applyCssHelper(panel,styles);
  3452. }
  3453. var colours = [];
  3454. for(t=1; t<params.length; t++) {
  3455. var c = new RGB(params[t]);
  3456. if(c)
  3457. colours.push(c);
  3458. }
  3459. drawGradient(panel,params[0] != "vert",colours);
  3460. if(wikifier)
  3461. wikifier.subWikify(panel,terminator);
  3462. if(document.all) {
  3463. panel.style.height = "100%";
  3464. panel.style.width = "100%";
  3465. }
  3466. };
  3467. config.macros.message.handler = function(place,macroName,params)
  3468. {
  3469. if(params[0]) {
  3470. var m = config;
  3471. var p = params[0].split(".");
  3472. for(var t=0; t<p.length; t++) {
  3473. if(p[t] in m)
  3474. m = m[p[t]];
  3475. else
  3476. break;
  3477. }
  3478. createTiddlyText(place,m.toString().format(params.splice(1)));
  3479. }
  3480. };
  3481. config.macros.view.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3482. {
  3483. if((tiddler instanceof Tiddler) && params[0]) {
  3484. var value = store.getValue(tiddler,params[0]);
  3485. if(value != undefined) {
  3486. switch(params[1]) {
  3487. case undefined:
  3488. highlightify(value,place,highlightHack,tiddler);
  3489. break;
  3490. case "link":
  3491. createTiddlyLink(place,value,true);
  3492. break;
  3493. case "wikified":
  3494. wikify(value,place,highlightHack,tiddler);
  3495. break;
  3496. case "date":
  3497. value = Date.convertFromYYYYMMDDHHMM(value);
  3498. createTiddlyText(place,value.formatString(params[2] ? params[2] : config.views.wikified.dateFormat));
  3499. break;
  3500. }
  3501. }
  3502. }
  3503. };
  3504. config.macros.edit.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3505. {
  3506. var field = params[0];
  3507. var rows = params[1];
  3508. if((tiddler instanceof Tiddler) && field) {
  3509. story.setDirty(tiddler.title,true);
  3510. if(field != "text" && !rows) {
  3511. var e = createTiddlyElement(null,"input");
  3512. if(tiddler.isReadOnly())
  3513. e.setAttribute("readOnly","readOnly");
  3514. e.setAttribute("edit",field);
  3515. e.setAttribute("type","text");
  3516. var v = store.getValue(tiddler,field);
  3517. if(!v)
  3518. v = "";
  3519. e.value = v;
  3520. e.setAttribute("size","40");
  3521. e.setAttribute("autocomplete","off");
  3522. place.appendChild(e);
  3523. } else {
  3524. var wrapper1 = createTiddlyElement(null,"fieldset",null,"fieldsetFix");
  3525. var wrapper2 = createTiddlyElement(wrapper1,"div");
  3526. var e = createTiddlyElement(wrapper2,"textarea");
  3527. if(tiddler.isReadOnly())
  3528. e.setAttribute("readOnly","readOnly");
  3529. var v = store.getValue(tiddler,field);
  3530. if(!v)
  3531. v = "";
  3532. e.value = v;
  3533. var rows = rows ? rows : 10;
  3534. var lines = v.match(/\n/mg);
  3535. var maxLines = Math.max(parseInt(config.options.txtMaxEditRows),5);
  3536. if(lines != null && lines.length > rows)
  3537. rows = lines.length + 5;
  3538. rows = Math.min(rows,maxLines);
  3539. e.setAttribute("rows",rows);
  3540. e.setAttribute("edit",field);
  3541. place.appendChild(wrapper1);
  3542. }
  3543. }
  3544. };
  3545. config.macros.tagChooser.onClick = function(e)
  3546. {
  3547. if(!e) var e = window.event;
  3548. var lingo = config.views.editor.tagChooser;
  3549. var popup = Popup.create(this);
  3550. var tags = store.getTags();
  3551. if(tags.length == 0)
  3552. createTiddlyText(createTiddlyElement(popup,"li"),lingo.popupNone);
  3553. for(var t=0; t<tags.length; t++) {
  3554. var theTag = createTiddlyButton(createTiddlyElement(popup,"li"),tags[t][0],lingo.tagTooltip.format([tags[t][0]]),config.macros.tagChooser.onTagClick);
  3555. theTag.setAttribute("tag",tags[t][0]);
  3556. theTag.setAttribute("tiddler",this.getAttribute("tiddler"));
  3557. }
  3558. Popup.show();
  3559. e.cancelBubble = true;
  3560. if(e.stopPropagation) e.stopPropagation();
  3561. return false;
  3562. };
  3563. config.macros.tagChooser.onTagClick = function(e)
  3564. {
  3565. if(!e) var e = window.event;
  3566. var tag = this.getAttribute("tag");
  3567. var title = this.getAttribute("tiddler");
  3568. if(!readOnly)
  3569. story.setTiddlerTag(title,tag,0);
  3570. return false;
  3571. };
  3572. config.macros.tagChooser.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3573. {
  3574. if(tiddler instanceof Tiddler) {
  3575. var title = tiddler.title;
  3576. var lingo = config.views.editor.tagChooser;
  3577. var btn = createTiddlyButton(place,lingo.text,lingo.tooltip,this.onClick);
  3578. btn.setAttribute("tiddler",title);
  3579. }
  3580. };
  3581. // Create a toolbar command button
  3582. config.macros.toolbar.createCommand = function(place,commandName,tiddler,theClass)
  3583. {
  3584. if(typeof commandName != "string") {
  3585. var c = null;
  3586. for(var t in config.commands) {
  3587. if(config.commands[t] == commandName)
  3588. c = t;
  3589. }
  3590. commandName = c;
  3591. }
  3592. if((tiddler instanceof Tiddler) && (typeof commandName == "string")) {
  3593. var command = config.commands[commandName];
  3594. if(command.isEnabled ? command.isEnabled(tiddler) : this.isCommandEnabled(command,tiddler)) {
  3595. var text = command.getText ? command.getText(tiddler) : this.getCommandText(command,tiddler);
  3596. var tooltip = command.getTooltip ? command.getTooltip(tiddler) : this.getCommandTooltip(command,tiddler);
  3597. var cmd;
  3598. switch(command.type) {
  3599. case "popup":
  3600. cmd = this.onClickPopup;
  3601. break;
  3602. case "command":
  3603. default:
  3604. cmd = this.onClickCommand;
  3605. break;
  3606. }
  3607. var btn = createTiddlyButton(null,text,tooltip,cmd);
  3608. btn.setAttribute("commandName",commandName);
  3609. btn.setAttribute("tiddler",tiddler.title);
  3610. if(theClass)
  3611. addClass(btn,theClass);
  3612. place.appendChild(btn);
  3613. }
  3614. }
  3615. };
  3616. config.macros.toolbar.isCommandEnabled = function(command,tiddler)
  3617. {
  3618. var title = tiddler.title;
  3619. var ro = tiddler.isReadOnly();
  3620. var shadow = store.isShadowTiddler(title) && !store.tiddlerExists(title);
  3621. return (!ro || (ro && !command.hideReadOnly)) && !(shadow && command.hideShadow);
  3622. };
  3623. config.macros.toolbar.getCommandText = function(command,tiddler)
  3624. {
  3625. return tiddler.isReadOnly() && command.readOnlyText ? command.readOnlyText : command.text;
  3626. };
  3627. config.macros.toolbar.getCommandTooltip = function(command,tiddler)
  3628. {
  3629. return tiddler.isReadOnly() && command.readOnlyTooltip ? command.readOnlyTooltip : command.tooltip;
  3630. };
  3631. config.macros.toolbar.onClickCommand = function(e)
  3632. {
  3633. if(!e) var e = window.event;
  3634. e.cancelBubble = true;
  3635. if (e.stopPropagation) e.stopPropagation();
  3636. var command = config.commands[this.getAttribute("commandName")];
  3637. return command.handler(e,this,this.getAttribute("tiddler"));
  3638. };
  3639. config.macros.toolbar.onClickPopup = function(e)
  3640. {
  3641. if(!e) var e = window.event;
  3642. e.cancelBubble = true;
  3643. if (e.stopPropagation) e.stopPropagation();
  3644. var popup = Popup.create(this);
  3645. var command = config.commands[this.getAttribute("commandName")];
  3646. var title = this.getAttribute("tiddler");
  3647. var tiddler = store.fetchTiddler(title);
  3648. popup.setAttribute("tiddler",title);
  3649. command.handlePopup(popup,title);
  3650. Popup.show();
  3651. return false;
  3652. };
  3653. // Invoke the first command encountered from a given place that is tagged with a specified class
  3654. config.macros.toolbar.invokeCommand = function(place,theClass,event)
  3655. {
  3656. var children = place.getElementsByTagName("a");
  3657. for(var t=0; t<children.length; t++) {
  3658. var c = children[t];
  3659. if(hasClass(c,theClass) && c.getAttribute && c.getAttribute("commandName")) {
  3660. if(c.onclick instanceof Function)
  3661. c.onclick.call(c,event);
  3662. break;
  3663. }
  3664. }
  3665. };
  3666. config.macros.toolbar.onClickMore = function(e)
  3667. {
  3668. var e = this.nextSibling;
  3669. e.style.display = "inline";
  3670. removeNode(this);
  3671. return false;
  3672. };
  3673. config.macros.toolbar.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3674. {
  3675. for(var t=0; t<params.length; t++) {
  3676. var c = params[t];
  3677. switch(c) {
  3678. case '>':
  3679. var btn = createTiddlyButton(place,this.moreLabel,this.morePrompt,config.macros.toolbar.onClickMore);
  3680. addClass(btn,"moreCommand");
  3681. var e = createTiddlyElement(place,"span",null,"moreCommand");
  3682. e.style.display = "none";
  3683. place = e;
  3684. break;
  3685. default:
  3686. var theClass = "";
  3687. switch(c.substr(0,1)) {
  3688. case "+":
  3689. theClass = "defaultCommand";
  3690. c = c.substr(1);
  3691. break;
  3692. case "-":
  3693. theClass = "cancelCommand";
  3694. c = c.substr(1);
  3695. break;
  3696. }
  3697. if(c in config.commands)
  3698. this.createCommand(place,c,tiddler,theClass);
  3699. break;
  3700. }
  3701. }
  3702. };
  3703. config.macros.refreshDisplay.handler = function(place)
  3704. {
  3705. createTiddlyButton(place,this.label,this.prompt,this.onClick);
  3706. };
  3707. config.macros.refreshDisplay.onClick = function(e)
  3708. {
  3709. refreshAll();
  3710. return false;
  3711. };
  3712. config.macros.annotations.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  3713. {
  3714. var title = tiddler ? tiddler.title : null;
  3715. var a = title ? config.annotations[title] : null;
  3716. if(!tiddler || !title || !a)
  3717. return;
  3718. var text = a.format([title]);
  3719. wikify(text,createTiddlyElement(place,"div",null,"annotation"),null,tiddler);
  3720. };
  3721. //--
  3722. //-- Menu and toolbar commands
  3723. //--
  3724. config.commands.closeTiddler.handler = function(event,src,title)
  3725. {
  3726. story.closeTiddler(title,true);
  3727. return false;
  3728. };
  3729. config.commands.closeOthers.handler = function(event,src,title)
  3730. {
  3731. story.closeAllTiddlers(title);
  3732. return false;
  3733. };
  3734. config.commands.editTiddler.handler = function(event,src,title)
  3735. {
  3736. clearMessage();
  3737. var tiddlerElem = document.getElementById(story.idPrefix + title);
  3738. var fields = tiddlerElem.getAttribute("tiddlyFields");
  3739. story.displayTiddler(null,title,DEFAULT_EDIT_TEMPLATE,false,null,fields);
  3740. story.focusTiddler(title,"text");
  3741. return false;
  3742. };
  3743. config.commands.saveTiddler.handler = function(event,src,title)
  3744. {
  3745. var newTitle = story.saveTiddler(title,event.shiftKey);
  3746. if(newTitle)
  3747. story.displayTiddler(null,newTitle);
  3748. return false;
  3749. };
  3750. config.commands.cancelTiddler.handler = function(event,src,title)
  3751. {
  3752. if(story.hasChanges(title) && !readOnly) {
  3753. if(!confirm(this.warning.format([title])))
  3754. return false;
  3755. }
  3756. story.setDirty(title,false);
  3757. story.displayTiddler(null,title);
  3758. return false;
  3759. };
  3760. config.commands.deleteTiddler.handler = function(event,src,title)
  3761. {
  3762. var deleteIt = true;
  3763. if (config.options.chkConfirmDelete)
  3764. deleteIt = confirm(this.warning.format([title]));
  3765. if (deleteIt) {
  3766. store.removeTiddler(title);
  3767. story.closeTiddler(title,true);
  3768. autoSaveChanges();
  3769. }
  3770. return false;
  3771. };
  3772. config.commands.permalink.handler = function(event,src,title)
  3773. {
  3774. var t = encodeURIComponent(String.encodeTiddlyLink(title));
  3775. if(window.location.hash != t)
  3776. window.location.hash = t;
  3777. return false;
  3778. };
  3779. config.commands.references.handlePopup = function(popup,title)
  3780. {
  3781. var references = store.getReferringTiddlers(title);
  3782. var c = false;
  3783. for(var r=0; r<references.length; r++) {
  3784. if(references[r].title != title && !references[r].isTagged("excludeLists")) {
  3785. createTiddlyLink(createTiddlyElement(popup,"li"),references[r].title,true);
  3786. c = true;
  3787. }
  3788. }
  3789. if(!c)
  3790. createTiddlyText(createTiddlyElement(popup,"li",null,"disabled"),this.popupNone);
  3791. };
  3792. config.commands.jump.handlePopup = function(popup,title)
  3793. {
  3794. story.forEachTiddler(function(title,element) {
  3795. createTiddlyLink(createTiddlyElement(popup,"li"),title,true,null,false,null,true);
  3796. });
  3797. };
  3798. config.commands.syncing.handlePopup = function(popup,title)
  3799. {
  3800. var tiddler = store.fetchTiddler(title);
  3801. if(!tiddler)
  3802. return;
  3803. var serverType = tiddler.getServerType();
  3804. var serverHost = tiddler.fields['server.host'];
  3805. var serverWorkspace = tiddler.fields['server.workspace'];
  3806. if(!serverWorkspace)
  3807. serverWorkspace = "";
  3808. if(serverType) {
  3809. var e = createTiddlyElement(popup,"li",null,"popupMessage");
  3810. e.innerHTML = config.commands.syncing.currentlySyncing.format([serverType,serverHost,serverWorkspace]);
  3811. } else {
  3812. createTiddlyElement(popup,"li",null,"popupMessage",config.commands.syncing.notCurrentlySyncing);
  3813. }
  3814. if(serverType) {
  3815. createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
  3816. var btn = createTiddlyButton(createTiddlyElement(popup,"li"),this.captionUnSync,null,config.commands.syncing.onChooseServer);
  3817. btn.setAttribute("tiddler",title);
  3818. btn.setAttribute("server.type","");
  3819. }
  3820. createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
  3821. createTiddlyElement(popup,"li",null,"popupMessage",config.commands.syncing.chooseServer);
  3822. var feeds = store.getTaggedTiddlers("systemServer","title");
  3823. for(var t=0; t<feeds.length; t++) {
  3824. var f = feeds[t];
  3825. var feedServerType = store.getTiddlerSlice(f.title,"Type");
  3826. if(!feedServerType)
  3827. feedServerType = "file";
  3828. var feedServerHost = store.getTiddlerSlice(f.title,"URL");
  3829. if(!feedServerHost)
  3830. feedServerHost = "";
  3831. var feedServerWorkspace = store.getTiddlerSlice(f.title,"Workspace");
  3832. if(!feedServerWorkspace)
  3833. feedServerWorkspace = "";
  3834. var caption = f.title;
  3835. if(serverType == feedServerType && serverHost == feedServerHost && serverWorkspace == feedServerWorkspace) {
  3836. caption = config.commands.syncing.currServerMarker + caption;
  3837. } else {
  3838. caption = config.commands.syncing.notCurrServerMarker + caption;
  3839. }
  3840. btn = createTiddlyButton(createTiddlyElement(popup,"li"),caption,null,config.commands.syncing.onChooseServer);
  3841. btn.setAttribute("tiddler",title);
  3842. btn.setAttribute("server.type",feedServerType);
  3843. btn.setAttribute("server.host",feedServerHost);
  3844. btn.setAttribute("server.workspace",feedServerWorkspace);
  3845. }
  3846. };
  3847. config.commands.syncing.onChooseServer = function(e)
  3848. {
  3849. var tiddler = this.getAttribute("tiddler");
  3850. var serverType = this.getAttribute("server.type");
  3851. if(serverType) {
  3852. store.addTiddlerFields(tiddler,{
  3853. 'server.type': serverType,
  3854. 'server.host': this.getAttribute("server.host"),
  3855. 'server.workspace': this.getAttribute("server.workspace")
  3856. });
  3857. } else {
  3858. store.setValue(tiddler,'server',null);
  3859. }
  3860. return false;
  3861. };
  3862. config.commands.fields.handlePopup = function(popup,title)
  3863. {
  3864. var tiddler = store.fetchTiddler(title);
  3865. if(!tiddler)
  3866. return;
  3867. var fields = {};
  3868. store.forEachField(tiddler,function(tiddler,fieldName,value) {fields[fieldName] = value;},true);
  3869. var items = [];
  3870. for(var t in fields) {
  3871. items.push({field: t,value: fields[t]});
  3872. }
  3873. items.sort(function(a,b) {return a.field < b.field ? -1 : (a.field == b.field ? 0 : +1);});
  3874. if(items.length > 0)
  3875. ListView.create(popup,items,this.listViewTemplate);
  3876. else
  3877. createTiddlyElement(popup,"div",null,null,this.emptyText);
  3878. };
  3879. //--
  3880. //-- Tiddler() object
  3881. //--
  3882. function Tiddler(title)
  3883. {
  3884. this.title = title;
  3885. this.text = null;
  3886. this.modifier = null;
  3887. this.modified = new Date();
  3888. this.created = new Date();
  3889. this.links = [];
  3890. this.linksUpdated = false;
  3891. this.tags = [];
  3892. this.fields = {};
  3893. return this;
  3894. }
  3895. Tiddler.prototype.getLinks = function()
  3896. {
  3897. if(this.linksUpdated==false)
  3898. this.changed();
  3899. return this.links;
  3900. };
  3901. // Returns the fields that are inherited in string field:"value" field2:"value2" format
  3902. Tiddler.prototype.getInheritedFields = function()
  3903. {
  3904. var f = {};
  3905. for(i in this.fields) {
  3906. if(i=="server.host" || i=="server.workspace" || i=="wikiformat"|| i=="server.type") {
  3907. f[i] = this.fields[i];
  3908. }
  3909. }
  3910. return String.encodeHashMap(f);
  3911. };
  3912. // Increment the changeCount of a tiddler
  3913. Tiddler.prototype.incChangeCount = function()
  3914. {
  3915. var c = this.fields['changecount'];
  3916. c = c ? parseInt(c) : 0;
  3917. this.fields['changecount'] = String(c+1);
  3918. };
  3919. // Clear the changeCount of a tiddler
  3920. Tiddler.prototype.clearChangeCount = function()
  3921. {
  3922. if(this.fields['changecount']) {
  3923. delete this.fields['changecount'];
  3924. }
  3925. };
  3926. // Returns true if the tiddler has been updated since the tiddler was created or downloaded
  3927. Tiddler.prototype.isTouched = function()
  3928. {
  3929. var changeCount = this.fields['changecount'];
  3930. if(changeCount === undefined)
  3931. changeCount = 0;
  3932. return changeCount > 0;
  3933. };
  3934. // Format the text for storage in an RSS item
  3935. Tiddler.prototype.saveToRss = function(url)
  3936. {
  3937. var s = [];
  3938. s.push("<item>");
  3939. s.push("<title" + ">" + this.title.htmlEncode() + "</title" + ">");
  3940. s.push("<description>" + wikifyStatic(this.text,null,this).htmlEncode() + "</description>");
  3941. for(var t=0; t<this.tags.length; t++)
  3942. s.push("<category>" + this.tags[t] + "</category>");
  3943. s.push("<link>" + url + "#" + encodeURIComponent(String.encodeTiddlyLink(this.title)) + "</link>");
  3944. s.push("<pubDate>" + this.modified.toGMTString() + "</pubDate>");
  3945. s.push("</item>");
  3946. return s.join("\n");
  3947. };
  3948. // Change the text and other attributes of a tiddler
  3949. Tiddler.prototype.set = function(title,text,modifier,modified,tags,created,fields)
  3950. {
  3951. this.assign(title,text,modifier,modified,tags,created,fields);
  3952. this.changed();
  3953. return this;
  3954. };
  3955. // Change the text and other attributes of a tiddler without triggered a tiddler.changed() call
  3956. Tiddler.prototype.assign = function(title,text,modifier,modified,tags,created,fields)
  3957. {
  3958. if(title != undefined)
  3959. this.title = title;
  3960. if(text != undefined)
  3961. this.text = text;
  3962. if(modifier != undefined)
  3963. this.modifier = modifier;
  3964. if(modified != undefined)
  3965. this.modified = modified;
  3966. if(created != undefined)
  3967. this.created = created;
  3968. if(fields != undefined)
  3969. this.fields = fields;
  3970. if(tags != undefined)
  3971. this.tags = (typeof tags == "string") ? tags.readBracketedList() : tags;
  3972. else if(this.tags == undefined)
  3973. this.tags = [];
  3974. return this;
  3975. };
  3976. // Get the tags for a tiddler as a string (space delimited, using [[brackets]] for tags containing spaces)
  3977. Tiddler.prototype.getTags = function()
  3978. {
  3979. return String.encodeTiddlyLinkList(this.tags);
  3980. };
  3981. // Test if a tiddler carries a tag
  3982. Tiddler.prototype.isTagged = function(tag)
  3983. {
  3984. return this.tags.indexOf(tag) != -1;
  3985. };
  3986. // Static method to convert "\n" to newlines, "\s" to "\"
  3987. Tiddler.unescapeLineBreaks = function(text)
  3988. {
  3989. return text ? text.unescapeLineBreaks() : "";
  3990. };
  3991. // Convert newlines to "\n", "\" to "\s"
  3992. Tiddler.prototype.escapeLineBreaks = function()
  3993. {
  3994. return this.text.escapeLineBreaks();
  3995. };
  3996. // Updates the secondary information (like links[] array) after a change to a tiddler
  3997. Tiddler.prototype.changed = function()
  3998. {
  3999. this.links = [];
  4000. var t = this.autoLinkWikiWords() ? 0 : 1;
  4001. var tiddlerLinkRegExp = t==0 ? config.textPrimitives.tiddlerAnyLinkRegExp : config.textPrimitives.tiddlerForcedLinkRegExp;
  4002. tiddlerLinkRegExp.lastIndex = 0;
  4003. var formatMatch = tiddlerLinkRegExp.exec(this.text);
  4004. while(formatMatch) {
  4005. var lastIndex = tiddlerLinkRegExp.lastIndex;
  4006. if(t==0 && formatMatch[1] && formatMatch[1] != this.title) {
  4007. // wikiWordLink
  4008. if(formatMatch.index > 0) {
  4009. var preRegExp = new RegExp(config.textPrimitives.unWikiLink+"|"+config.textPrimitives.anyLetter,"mg");
  4010. preRegExp.lastIndex = formatMatch.index-1;
  4011. var preMatch = preRegExp.exec(this.text);
  4012. if(preMatch.index != formatMatch.index-1)
  4013. this.links.pushUnique(formatMatch[1]);
  4014. } else {
  4015. this.links.pushUnique(formatMatch[1]);
  4016. }
  4017. }
  4018. else if(formatMatch[2-t] && !config.formatterHelpers.isExternalLink(formatMatch[3-t])) // titledBrackettedLink
  4019. this.links.pushUnique(formatMatch[3-t]);
  4020. else if(formatMatch[4-t] && formatMatch[4-t] != this.title) // brackettedLink
  4021. this.links.pushUnique(formatMatch[4-t]);
  4022. tiddlerLinkRegExp.lastIndex = lastIndex;
  4023. formatMatch = tiddlerLinkRegExp.exec(this.text);
  4024. }
  4025. this.linksUpdated = true;
  4026. };
  4027. Tiddler.prototype.getSubtitle = function()
  4028. {
  4029. var theModifier = this.modifier;
  4030. if(!theModifier)
  4031. theModifier = config.messages.subtitleUnknown;
  4032. var theModified = this.modified;
  4033. if(theModified)
  4034. theModified = theModified.toLocaleString();
  4035. else
  4036. theModified = config.messages.subtitleUnknown;
  4037. return config.messages.tiddlerLinkTooltip.format([this.title,theModifier,theModified]);
  4038. };
  4039. Tiddler.prototype.isReadOnly = function()
  4040. {
  4041. return readOnly;
  4042. };
  4043. Tiddler.prototype.autoLinkWikiWords = function()
  4044. {
  4045. return !(this.isTagged("systemConfig") || this.isTagged("excludeMissing"));
  4046. };
  4047. Tiddler.prototype.generateFingerprint = function()
  4048. {
  4049. return "0x" + Crypto.hexSha1Str(this.text);
  4050. };
  4051. Tiddler.prototype.getServerType = function()
  4052. {
  4053. var serverType = null;
  4054. if(this.fields && this.fields['server.type'])
  4055. serverType = this.fields['server.type'];
  4056. if(!serverType)
  4057. serverType = this.fields['wikiformat'];
  4058. if(serverType && !config.adaptors[serverType])
  4059. serverType = null;
  4060. return serverType;
  4061. };
  4062. Tiddler.prototype.getAdaptor = function()
  4063. {
  4064. var serverType = this.getServerType();
  4065. if(serverType)
  4066. return new config.adaptors[serverType];
  4067. else
  4068. return null;
  4069. };
  4070. //--
  4071. //-- TiddlyWiki() object contains Tiddler()s
  4072. //--
  4073. function TiddlyWiki()
  4074. {
  4075. var tiddlers = {}; // Hashmap by name of tiddlers
  4076. this.tiddlersUpdated = false;
  4077. this.namedNotifications = []; // Array of {name:,notify:} of notification functions
  4078. this.notificationLevel = 0;
  4079. this.slices = {}; // map tiddlerName->(map sliceName->sliceValue). Lazy.
  4080. this.clear = function() {
  4081. tiddlers = {};
  4082. this.setDirty(false);
  4083. };
  4084. this.fetchTiddler = function(title) {
  4085. return tiddlers[title];
  4086. };
  4087. this.deleteTiddler = function(title) {
  4088. delete this.slices[title];
  4089. delete tiddlers[title];
  4090. };
  4091. this.addTiddler = function(tiddler) {
  4092. delete this.slices[tiddler.title];
  4093. tiddlers[tiddler.title] = tiddler;
  4094. };
  4095. this.forEachTiddler = function(callback) {
  4096. for(var t in tiddlers) {
  4097. var tiddler = tiddlers[t];
  4098. if(tiddler instanceof Tiddler)
  4099. callback.call(this,t,tiddler);
  4100. }
  4101. };
  4102. }
  4103. TiddlyWiki.prototype.setDirty = function(dirty)
  4104. {
  4105. this.dirty = dirty;
  4106. };
  4107. TiddlyWiki.prototype.isDirty = function()
  4108. {
  4109. return this.dirty;
  4110. };
  4111. TiddlyWiki.prototype.suspendNotifications = function()
  4112. {
  4113. this.notificationLevel--;
  4114. };
  4115. TiddlyWiki.prototype.resumeNotifications = function()
  4116. {
  4117. this.notificationLevel++;
  4118. };
  4119. // Invoke the notification handlers for a particular tiddler
  4120. TiddlyWiki.prototype.notify = function(title,doBlanket)
  4121. {
  4122. if(!this.notificationLevel) {
  4123. for(var t=0; t<this.namedNotifications.length; t++) {
  4124. var n = this.namedNotifications[t];
  4125. if((n.name == null && doBlanket) || (n.name == title))
  4126. n.notify(title);
  4127. }
  4128. }
  4129. };
  4130. // Invoke the notification handlers for all tiddlers
  4131. TiddlyWiki.prototype.notifyAll = function()
  4132. {
  4133. if(!this.notificationLevel) {
  4134. for(var t=0; t<this.namedNotifications.length; t++) {
  4135. var n = this.namedNotifications[t];
  4136. if(n.name)
  4137. n.notify(n.name);
  4138. }
  4139. }
  4140. };
  4141. // Add a notification handler to a tiddler
  4142. TiddlyWiki.prototype.addNotification = function(title,fn)
  4143. {
  4144. for(var i=0; i<this.namedNotifications.length; i++) {
  4145. if((this.namedNotifications[i].name == title) && (this.namedNotifications[i].notify == fn))
  4146. return this;
  4147. }
  4148. this.namedNotifications.push({name: title, notify: fn});
  4149. return this;
  4150. };
  4151. TiddlyWiki.prototype.removeTiddler = function(title)
  4152. {
  4153. var tiddler = this.fetchTiddler(title);
  4154. if(tiddler) {
  4155. this.deleteTiddler(title);
  4156. this.notify(title,true);
  4157. this.setDirty(true);
  4158. }
  4159. };
  4160. TiddlyWiki.prototype.tiddlerExists = function(title)
  4161. {
  4162. var t = this.fetchTiddler(title);
  4163. return t != undefined;
  4164. };
  4165. TiddlyWiki.prototype.isShadowTiddler = function(title)
  4166. {
  4167. return typeof config.shadowTiddlers[title] == "string";
  4168. };
  4169. TiddlyWiki.prototype.getTiddler = function(title)
  4170. {
  4171. var t = this.fetchTiddler(title);
  4172. if(t != undefined)
  4173. return t;
  4174. else
  4175. return null;
  4176. };
  4177. TiddlyWiki.prototype.getTiddlerText = function(title,defaultText)
  4178. {
  4179. var tiddler = this.fetchTiddler(title);
  4180. if(tiddler)
  4181. return tiddler.text;
  4182. if(!title)
  4183. return defaultText;
  4184. var pos = title.indexOf(config.textPrimitives.sliceSeparator);
  4185. if(pos != -1) {
  4186. var slice = this.getTiddlerSlice(title.substr(0,pos),title.substr(pos + config.textPrimitives.sliceSeparator.length));
  4187. if(slice)
  4188. return slice;
  4189. }
  4190. if(this.isShadowTiddler(title))
  4191. return config.shadowTiddlers[title];
  4192. if(defaultText != undefined)
  4193. return defaultText;
  4194. return null;
  4195. };
  4196. TiddlyWiki.prototype.slicesRE = /(?:[\'\/]*~?([\.\w]+)[\'\/]*\:[\'\/]*\s*(.*?)\s*$)|(?:\|[\'\/]*~?([\.\w]+)\:?[\'\/]*\|\s*(.*?)\s*\|)/gm;
  4197. // @internal
  4198. TiddlyWiki.prototype.calcAllSlices = function(title)
  4199. {
  4200. var slices = {};
  4201. var text = this.getTiddlerText(title,"");
  4202. this.slicesRE.lastIndex = 0;
  4203. do {
  4204. var m = this.slicesRE.exec(text);
  4205. if(m) {
  4206. if(m[1])
  4207. slices[m[1]] = m[2];
  4208. else
  4209. slices[m[3]] = m[4];
  4210. }
  4211. } while(m);
  4212. return slices;
  4213. };
  4214. // Returns the slice of text of the given name
  4215. TiddlyWiki.prototype.getTiddlerSlice = function(title,sliceName)
  4216. {
  4217. var slices = this.slices[title];
  4218. if(!slices) {
  4219. slices = this.calcAllSlices(title);
  4220. this.slices[title] = slices;
  4221. }
  4222. return slices[sliceName];
  4223. };
  4224. // Build an hashmap of the specified named slices of a tiddler
  4225. TiddlyWiki.prototype.getTiddlerSlices = function(title,sliceNames)
  4226. {
  4227. var r = {};
  4228. for(var t=0; t<sliceNames.length; t++) {
  4229. var slice = this.getTiddlerSlice(title,sliceNames[t]);
  4230. if(slice)
  4231. r[sliceNames[t]] = slice;
  4232. }
  4233. return r;
  4234. };
  4235. TiddlyWiki.prototype.getRecursiveTiddlerText = function(title,defaultText,depth)
  4236. {
  4237. var bracketRegExp = new RegExp("(?:\\[\\[([^\\]]+)\\]\\])","mg");
  4238. var text = this.getTiddlerText(title,null);
  4239. if(text == null)
  4240. return defaultText;
  4241. var textOut = [];
  4242. var lastPos = 0;
  4243. do {
  4244. var match = bracketRegExp.exec(text);
  4245. if(match) {
  4246. textOut.push(text.substr(lastPos,match.index-lastPos));
  4247. if(match[1]) {
  4248. if(depth <= 0)
  4249. textOut.push(match[1]);
  4250. else
  4251. textOut.push(this.getRecursiveTiddlerText(match[1],"[[" + match[1] + "]]",depth-1));
  4252. }
  4253. lastPos = match.index + match[0].length;
  4254. } else {
  4255. textOut.push(text.substr(lastPos));
  4256. }
  4257. } while(match);
  4258. return textOut.join("");
  4259. };
  4260. TiddlyWiki.prototype.setTiddlerTag = function(title,status,tag)
  4261. {
  4262. var tiddler = this.fetchTiddler(title);
  4263. if(tiddler) {
  4264. var t = tiddler.tags.indexOf(tag);
  4265. if(t != -1)
  4266. tiddler.tags.splice(t,1);
  4267. if(status)
  4268. tiddler.tags.push(tag);
  4269. tiddler.changed();
  4270. this.incChangeCount(title);
  4271. this.notify(title,true);
  4272. this.setDirty(true);
  4273. }
  4274. };
  4275. TiddlyWiki.prototype.addTiddlerFields = function(title,fields)
  4276. {
  4277. var tiddler = this.fetchTiddler(title);
  4278. if(!tiddler)
  4279. return;
  4280. merge(tiddler.fields,fields);
  4281. tiddler.changed();
  4282. this.incChangeCount(title);
  4283. this.notify(title,true);
  4284. this.setDirty(true);
  4285. };
  4286. TiddlyWiki.prototype.saveTiddler = function(title,newTitle,newBody,modifier,modified,tags,fields,clearChangeCount,created)
  4287. {
  4288. var tiddler = this.fetchTiddler(title);
  4289. if(tiddler) {
  4290. created = created ? created : tiddler.created; // Preserve created date
  4291. this.deleteTiddler(title);
  4292. } else {
  4293. created = created ? created : modified;
  4294. tiddler = new Tiddler();
  4295. }
  4296. tiddler.set(newTitle,newBody,modifier,modified,tags,created,fields);
  4297. this.addTiddler(tiddler);
  4298. if(clearChangeCount)
  4299. tiddler.clearChangeCount();
  4300. else
  4301. tiddler.incChangeCount();
  4302. if(title != newTitle)
  4303. this.notify(title,true);
  4304. this.notify(newTitle,true);
  4305. this.setDirty(true);
  4306. return tiddler;
  4307. };
  4308. // Reset the sync status of a freshly synced tiddler
  4309. TiddlyWiki.prototype.resetTiddler = function(title)
  4310. {
  4311. var tiddler = this.fetchTiddler(title);
  4312. if(tiddler) {
  4313. tiddler.clearChangeCount();
  4314. this.notify(title,true);
  4315. this.setDirty(true);
  4316. }
  4317. };
  4318. TiddlyWiki.prototype.incChangeCount = function(title)
  4319. {
  4320. var tiddler = this.fetchTiddler(title);
  4321. if(tiddler)
  4322. tiddler.incChangeCount();
  4323. };
  4324. TiddlyWiki.prototype.createTiddler = function(title)
  4325. {
  4326. var tiddler = this.fetchTiddler(title);
  4327. if(!tiddler) {
  4328. tiddler = new Tiddler();
  4329. tiddler.title = title;
  4330. this.addTiddler(tiddler);
  4331. this.setDirty(true);
  4332. }
  4333. return tiddler;
  4334. };
  4335. // Load contents of a TiddlyWiki from an HTML DIV
  4336. TiddlyWiki.prototype.loadFromDiv = function(src,idPrefix,noUpdate)
  4337. {
  4338. this.idPrefix = idPrefix;
  4339. var storeElem = (typeof src == "string") ? document.getElementById(src) : src;
  4340. if(!storeElem)
  4341. return;
  4342. var tiddlers = this.getLoader().loadTiddlers(this,storeElem.childNodes);
  4343. this.setDirty(false);
  4344. if(!noUpdate) {
  4345. for(var i = 0;i<tiddlers.length; i++)
  4346. tiddlers[i].changed();
  4347. }
  4348. };
  4349. // Load contents of a TiddlyWiki from a string
  4350. // Returns null if there's an error
  4351. TiddlyWiki.prototype.importTiddlyWiki = function(text)
  4352. {
  4353. var posDiv = locateStoreArea(text);
  4354. if(!posDiv)
  4355. return null;
  4356. var content = "<" + "html><" + "body>" + text.substring(posDiv[0],posDiv[1] + endSaveArea.length) + "<" + "/body><" + "/html>";
  4357. // Create the iframe
  4358. var iframe = document.createElement("iframe");
  4359. iframe.style.display = "none";
  4360. document.body.appendChild(iframe);
  4361. var doc = iframe.document;
  4362. if(iframe.contentDocument)
  4363. doc = iframe.contentDocument; // For NS6
  4364. else if(iframe.contentWindow)
  4365. doc = iframe.contentWindow.document; // For IE5.5 and IE6
  4366. // Put the content in the iframe
  4367. doc.open();
  4368. doc.writeln(content);
  4369. doc.close();
  4370. // Load the content into a TiddlyWiki() object
  4371. var storeArea = doc.getElementById("storeArea");
  4372. this.loadFromDiv(storeArea,"store");
  4373. // Get rid of the iframe
  4374. iframe.parentNode.removeChild(iframe);
  4375. return this;
  4376. };
  4377. TiddlyWiki.prototype.updateTiddlers = function()
  4378. {
  4379. this.tiddlersUpdated = true;
  4380. this.forEachTiddler(function(title,tiddler) {
  4381. tiddler.changed();
  4382. });
  4383. };
  4384. // Return all tiddlers formatted as an HTML string
  4385. TiddlyWiki.prototype.allTiddlersAsHtml = function()
  4386. {
  4387. return store.getSaver().externalize(store);
  4388. };
  4389. // Return an array of tiddlers matching a search regular expression
  4390. TiddlyWiki.prototype.search = function(searchRegExp,sortField,excludeTag)
  4391. {
  4392. var candidates = this.reverseLookup("tags",excludeTag,false);
  4393. var results = [];
  4394. for(var t=0; t<candidates.length; t++) {
  4395. if((candidates[t].title.search(searchRegExp) != -1) || (candidates[t].text.search(searchRegExp) != -1))
  4396. results.push(candidates[t]);
  4397. }
  4398. if(!sortField)
  4399. sortField = "title";
  4400. results.sort(function(a,b) {return a[sortField] < b[sortField] ? -1 : (a[sortField] == b[sortField] ? 0 : +1);});
  4401. return results;
  4402. };
  4403. // Return an array of all the tags in use. Each member of the array is another array where [0] is the name of the tag and [1] is the number of occurances
  4404. TiddlyWiki.prototype.getTags = function(excludeTag)
  4405. {
  4406. var results = [];
  4407. this.forEachTiddler(function(title,tiddler) {
  4408. for(var g=0; g<tiddler.tags.length; g++) {
  4409. var tag = tiddler.tags[g];
  4410. if(excludeTag) {
  4411. var t = store.fetchTiddler(tag);
  4412. if(t && t.isTagged(excludeTag))
  4413. return false;
  4414. }
  4415. var f = false;
  4416. for(var c=0; c<results.length; c++) {
  4417. if(results[c][0] == tag) {
  4418. f = true;
  4419. results[c][1]++;
  4420. }
  4421. }
  4422. if(!f)
  4423. results.push([tag,1]);
  4424. }
  4425. });
  4426. results.sort(function(a,b) {return a[0].toLowerCase() < b[0].toLowerCase() ? -1 : (a[0].toLowerCase() == b[0].toLowerCase() ? 0 : +1);});
  4427. return results;
  4428. };
  4429. // Return an array of the tiddlers that are tagged with a given tag
  4430. TiddlyWiki.prototype.getTaggedTiddlers = function(tag,sortField)
  4431. {
  4432. return this.reverseLookup("tags",tag,true,sortField);
  4433. };
  4434. // Return an array of the tiddlers that link to a given tiddler
  4435. TiddlyWiki.prototype.getReferringTiddlers = function(title,unusedParameter,sortField)
  4436. {
  4437. if(!this.tiddlersUpdated)
  4438. this.updateTiddlers();
  4439. return this.reverseLookup("links",title,true,sortField);
  4440. };
  4441. // Return an array of the tiddlers that do or do not have a specified entry in the specified storage array (ie, "links" or "tags")
  4442. // lookupMatch == true to match tiddlers, false to exclude tiddlers
  4443. TiddlyWiki.prototype.reverseLookup = function(lookupField,lookupValue,lookupMatch,sortField)
  4444. {
  4445. var results = [];
  4446. this.forEachTiddler(function(title,tiddler) {
  4447. var f = !lookupMatch;
  4448. for(var lookup=0; lookup<tiddler[lookupField].length; lookup++) {
  4449. if(tiddler[lookupField][lookup] == lookupValue)
  4450. f = lookupMatch;
  4451. }
  4452. if(f)
  4453. results.push(tiddler);
  4454. });
  4455. if(!sortField)
  4456. sortField = "title";
  4457. results.sort(function(a,b) {return a[sortField] < b[sortField] ? -1 : (a[sortField] == b[sortField] ? 0 : +1);});
  4458. return results;
  4459. };
  4460. // Return the tiddlers as a sorted array
  4461. TiddlyWiki.prototype.getTiddlers = function(field,excludeTag)
  4462. {
  4463. var results = [];
  4464. this.forEachTiddler(function(title,tiddler) {
  4465. if(excludeTag == undefined || !tiddler.isTagged(excludeTag))
  4466. results.push(tiddler);
  4467. });
  4468. if(field)
  4469. results.sort(function(a,b) {return a[field] < b[field] ? -1 : (a[field] == b[field] ? 0 : +1);});
  4470. return results;
  4471. };
  4472. // Return array of names of tiddlers that are referred to but not defined
  4473. TiddlyWiki.prototype.getMissingLinks = function(sortField)
  4474. {
  4475. if(!this.tiddlersUpdated)
  4476. this.updateTiddlers();
  4477. var results = [];
  4478. this.forEachTiddler(function (title,tiddler) {
  4479. if(tiddler.isTagged("excludeMissing") || tiddler.isTagged("systemConfig"))
  4480. return;
  4481. for(var n=0; n<tiddler.links.length;n++) {
  4482. var link = tiddler.links[n];
  4483. if(this.fetchTiddler(link) == null && !this.isShadowTiddler(link))
  4484. results.pushUnique(link);
  4485. }
  4486. });
  4487. results.sort();
  4488. return results;
  4489. };
  4490. // Return an array of names of tiddlers that are defined but not referred to
  4491. TiddlyWiki.prototype.getOrphans = function()
  4492. {
  4493. var results = [];
  4494. this.forEachTiddler(function (title,tiddler) {
  4495. if(this.getReferringTiddlers(title).length == 0 && !tiddler.isTagged("excludeLists"))
  4496. results.push(title);
  4497. });
  4498. results.sort();
  4499. return results;
  4500. };
  4501. // Return an array of names of all the shadow tiddlers
  4502. TiddlyWiki.prototype.getShadowed = function()
  4503. {
  4504. var results = [];
  4505. for(var t in config.shadowTiddlers) {
  4506. if(typeof config.shadowTiddlers[t] == "string")
  4507. results.push(t);
  4508. }
  4509. results.sort();
  4510. return results;
  4511. };
  4512. // Return an array of tiddlers that have been touched since they were downloaded or created
  4513. TiddlyWiki.prototype.getTouched = function()
  4514. {
  4515. var results = [];
  4516. this.forEachTiddler(function(title,tiddler) {
  4517. if(tiddler.isTouched())
  4518. results.push(tiddler);
  4519. });
  4520. results.sort();
  4521. return results;
  4522. };
  4523. // Resolves a Tiddler reference or tiddler title into a Tiddler object, or null if it doesn't exist
  4524. TiddlyWiki.prototype.resolveTiddler = function(tiddler)
  4525. {
  4526. var t = (typeof tiddler == 'string') ? this.getTiddler(tiddler) : tiddler;
  4527. return t instanceof Tiddler ? t : null;
  4528. };
  4529. TiddlyWiki.prototype.getLoader = function()
  4530. {
  4531. if(!this.loader)
  4532. this.loader = new TW21Loader();
  4533. return this.loader;
  4534. };
  4535. TiddlyWiki.prototype.getSaver = function()
  4536. {
  4537. if(!this.saver)
  4538. this.saver = new TW21Saver();
  4539. return this.saver;
  4540. };
  4541. // Returns true if path is a valid field name (path),
  4542. // i.e. a sequence of identifiers, separated by '.'
  4543. TiddlyWiki.isValidFieldName = function(name)
  4544. {
  4545. var match = /[a-zA-Z_]\w*(\.[a-zA-Z_]\w*)*/.exec(name);
  4546. return match && (match[0] == name);
  4547. };
  4548. // Throws an exception when name is not a valid field name.
  4549. TiddlyWiki.checkFieldName = function(name)
  4550. {
  4551. if(!TiddlyWiki.isValidFieldName(name))
  4552. throw config.messages.invalidFieldName.format([name]);
  4553. };
  4554. function StringFieldAccess(n,readOnly)
  4555. {
  4556. this.set = readOnly ?
  4557. function(t,v) {if(v != t[n]) throw config.messages.fieldCannotBeChanged.format([n]);} :
  4558. function(t,v) {if(v != t[n]) {t[n] = v; return true;}};
  4559. this.get = function(t) {return t[n];};
  4560. }
  4561. function DateFieldAccess(n)
  4562. {
  4563. this.set = function(t,v) {
  4564. var d = v instanceof Date ? v : Date.convertFromYYYYMMDDHHMM(v);
  4565. if(d != t[n]) {
  4566. t[n] = d; return true;
  4567. }
  4568. };
  4569. this.get = function(t) {return t[n].convertToYYYYMMDDHHMM();};
  4570. }
  4571. function LinksFieldAccess(n)
  4572. {
  4573. this.set = function(t,v) {
  4574. var s = (typeof v == "string") ? v.readBracketedList() : v;
  4575. if(s.toString() != t[n].toString()) {
  4576. t[n] = s; return true;
  4577. }
  4578. };
  4579. this.get = function(t) {return String.encodeTiddlyLinkList(t[n]);};
  4580. }
  4581. TiddlyWiki.standardFieldAccess = {
  4582. // The set functions return true when setting the data has changed the value.
  4583. "title": new StringFieldAccess("title",true),
  4584. // Handle the "tiddler" field name as the title
  4585. "tiddler": new StringFieldAccess("title",true),
  4586. "text": new StringFieldAccess("text"),
  4587. "modifier": new StringFieldAccess("modifier"),
  4588. "modified": new DateFieldAccess("modified"),
  4589. "created": new DateFieldAccess("created"),
  4590. "tags": new LinksFieldAccess("tags")
  4591. };
  4592. TiddlyWiki.isStandardField = function(name)
  4593. {
  4594. return TiddlyWiki.standardFieldAccess[name] != undefined;
  4595. };
  4596. // Sets the value of the given field of the tiddler to the value.
  4597. // Setting an ExtendedField's value to null or undefined removes the field.
  4598. // Setting a namespace to undefined removes all fields of that namespace.
  4599. // The fieldName is case-insensitive.
  4600. // All values will be converted to a string value.
  4601. TiddlyWiki.prototype.setValue = function(tiddler,fieldName,value)
  4602. {
  4603. TiddlyWiki.checkFieldName(fieldName);
  4604. var t = this.resolveTiddler(tiddler);
  4605. if(!t)
  4606. return;
  4607. fieldName = fieldName.toLowerCase();
  4608. var isRemove = (value === undefined) || (value === null);
  4609. var accessor = TiddlyWiki.standardFieldAccess[fieldName];
  4610. if(accessor) {
  4611. if(isRemove)
  4612. // don't remove StandardFields
  4613. return;
  4614. var h = TiddlyWiki.standardFieldAccess[fieldName];
  4615. if(!h.set(t,value))
  4616. return;
  4617. } else {
  4618. var oldValue = t.fields[fieldName];
  4619. if(isRemove) {
  4620. if(oldValue !== undefined) {
  4621. // deletes a single field
  4622. delete t.fields[fieldName];
  4623. } else {
  4624. // no concrete value is defined for the fieldName
  4625. // so we guess this is a namespace path.
  4626. // delete all fields in a namespace
  4627. var re = new RegExp('^'+fieldName+'\\.');
  4628. var dirty = false;
  4629. for(var n in t.fields) {
  4630. if(n.match(re)) {
  4631. delete t.fields[n];
  4632. dirty = true;
  4633. }
  4634. }
  4635. if(!dirty)
  4636. return;
  4637. }
  4638. } else {
  4639. // the "normal" set case. value is defined (not null/undefined)
  4640. // For convenience provide a nicer conversion Date->String
  4641. value = value instanceof Date ? value.convertToYYYYMMDDHHMMSSMMM() : String(value);
  4642. if(oldValue == value)
  4643. return;
  4644. t.fields[fieldName] = value;
  4645. }
  4646. }
  4647. // When we are here the tiddler/store really was changed.
  4648. this.notify(t.title,true);
  4649. if(!fieldName.match(/^temp\./))
  4650. this.setDirty(true);
  4651. };
  4652. // Returns the value of the given field of the tiddler.
  4653. // The fieldName is case-insensitive.
  4654. // Will only return String values (or undefined).
  4655. TiddlyWiki.prototype.getValue = function(tiddler,fieldName)
  4656. {
  4657. var t = this.resolveTiddler(tiddler);
  4658. if(!t)
  4659. return undefined;
  4660. fieldName = fieldName.toLowerCase();
  4661. var accessor = TiddlyWiki.standardFieldAccess[fieldName];
  4662. if(accessor) {
  4663. return accessor.get(t);
  4664. }
  4665. return t.fields[fieldName];
  4666. };
  4667. // Calls the callback function for every field in the tiddler.
  4668. // When callback function returns a non-false value the iteration stops
  4669. // and that value is returned.
  4670. // The order of the fields is not defined.
  4671. // @param callback a function(tiddler,fieldName,value).
  4672. TiddlyWiki.prototype.forEachField = function(tiddler,callback,onlyExtendedFields)
  4673. {
  4674. var t = this.resolveTiddler(tiddler);
  4675. if(!t)
  4676. return undefined;
  4677. for(var n in t.fields) {
  4678. var result = callback(t,n,t.fields[n]);
  4679. if(result)
  4680. return result;
  4681. }
  4682. if(onlyExtendedFields)
  4683. return undefined;
  4684. for(var n in TiddlyWiki.standardFieldAccess) {
  4685. if(n == "tiddler")
  4686. // even though the "title" field can also be referenced through the name "tiddler"
  4687. // we only visit this field once.
  4688. continue;
  4689. var result = callback(t,n,TiddlyWiki.standardFieldAccess[n].get(t));
  4690. if(result)
  4691. return result;
  4692. }
  4693. return undefined;
  4694. };
  4695. //--
  4696. //-- Story functions
  4697. //--
  4698. function Story(container,idPrefix)
  4699. {
  4700. this.container = container;
  4701. this.idPrefix = idPrefix;
  4702. this.highlightRegExp = null;
  4703. }
  4704. Story.prototype.forEachTiddler = function(fn)
  4705. {
  4706. var place = document.getElementById(this.container);
  4707. if(!place)
  4708. return;
  4709. var e = place.firstChild;
  4710. while(e) {
  4711. var n = e.nextSibling;
  4712. var title = e.getAttribute("tiddler");
  4713. fn.call(this,title,e);
  4714. e = n;
  4715. }
  4716. };
  4717. Story.prototype.displayTiddlers = function(srcElement,titles,template,animate,unused,customFields,toggle)
  4718. {
  4719. for(var t = titles.length-1;t>=0;t--)
  4720. this.displayTiddler(srcElement,titles[t],template,animate,unused,customFields);
  4721. };
  4722. Story.prototype.displayTiddler = function(srcElement,title,template,animate,unused,customFields,toggle)
  4723. {
  4724. var place = document.getElementById(this.container);
  4725. var tiddlerElem = document.getElementById(this.idPrefix + title);
  4726. if(tiddlerElem) {
  4727. if(toggle)
  4728. this.closeTiddler(title,true);
  4729. else
  4730. this.refreshTiddler(title,template,false,customFields);
  4731. } else {
  4732. var before = this.positionTiddler(srcElement);
  4733. tiddlerElem = this.createTiddler(place,before,title,template,customFields);
  4734. }
  4735. if(srcElement && typeof srcElement !== "string") {
  4736. if(config.options.chkAnimate && (animate == undefined || animate == true) && anim && typeof Zoomer == "function" && typeof Scroller == "function")
  4737. anim.startAnimating(new Zoomer(title,srcElement,tiddlerElem),new Scroller(tiddlerElem));
  4738. else
  4739. window.scrollTo(0,ensureVisible(tiddlerElem));
  4740. }
  4741. };
  4742. Story.prototype.positionTiddler = function(srcElement)
  4743. {
  4744. var place = document.getElementById(this.container);
  4745. var before = null;
  4746. if(typeof srcElement == "string") {
  4747. switch(srcElement) {
  4748. case "top":
  4749. before = place.firstChild;
  4750. break;
  4751. case "bottom":
  4752. before = null;
  4753. break;
  4754. }
  4755. } else {
  4756. var after = this.findContainingTiddler(srcElement);
  4757. if(after == null) {
  4758. before = place.firstChild;
  4759. } else if(after.nextSibling) {
  4760. before = after.nextSibling;
  4761. if(before.nodeType != 1)
  4762. before = null;
  4763. }
  4764. }
  4765. return before;
  4766. };
  4767. Story.prototype.createTiddler = function(place,before,title,template,customFields)
  4768. {
  4769. var tiddlerElem = createTiddlyElement(null,"div",this.idPrefix + title,"tiddler");
  4770. tiddlerElem.setAttribute("refresh","tiddler");
  4771. if(customFields)
  4772. tiddlerElem.setAttribute("tiddlyFields",customFields);
  4773. place.insertBefore(tiddlerElem,before);
  4774. var defaultText = null;
  4775. if(!store.tiddlerExists(title) && !store.isShadowTiddler(title))
  4776. defaultText = this.loadMissingTiddler(title,customFields,tiddlerElem);
  4777. this.refreshTiddler(title,template,false,customFields,defaultText);
  4778. return tiddlerElem;
  4779. };
  4780. Story.prototype.loadMissingTiddler = function(title,fields,tiddlerElem)
  4781. {
  4782. var tiddler = new Tiddler(title);
  4783. tiddler.fields = typeof fields == "string" ? fields.decodeHashMap() : (fields ? fields : {});
  4784. var serverType = tiddler.getServerType();
  4785. var host = tiddler.fields['server.host'];
  4786. var workspace = tiddler.fields['server.workspace'];
  4787. if(!serverType | !host)
  4788. return null;
  4789. var sm = new SyncMachine(serverType,{
  4790. start: function() {
  4791. return this.openHost(host,"openWorkspace");
  4792. },
  4793. openWorkspace: function() {
  4794. return this.openWorkspace(workspace,"getTiddler");
  4795. },
  4796. getTiddler: function() {
  4797. return this.getTiddler(title,"gotTiddler");
  4798. },
  4799. gotTiddler: function(tiddler) {
  4800. if(tiddler && tiddler.text) {
  4801. var downloaded = new Date();
  4802. if(!tiddler.created)
  4803. tiddler.created = downloaded;
  4804. if(!tiddler.modified)
  4805. tiddler.modified = tiddler.created;
  4806. store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields,true,tiddler.created);
  4807. autoSaveChanges();
  4808. }
  4809. delete this;
  4810. return true;
  4811. },
  4812. error: function(message) {
  4813. displayMessage("Error loading missing tiddler from %0: %1".format([host,message]));
  4814. }
  4815. });
  4816. sm.go();
  4817. return config.messages.loadingMissingTiddler.format([title,serverType,host,workspace]);
  4818. };
  4819. Story.prototype.chooseTemplateForTiddler = function(title,template)
  4820. {
  4821. if(!template)
  4822. template = DEFAULT_VIEW_TEMPLATE;
  4823. if(template == DEFAULT_VIEW_TEMPLATE || template == DEFAULT_EDIT_TEMPLATE)
  4824. template = config.tiddlerTemplates[template];
  4825. return template;
  4826. };
  4827. Story.prototype.getTemplateForTiddler = function(title,template,tiddler)
  4828. {
  4829. return store.getRecursiveTiddlerText(template,null,10);
  4830. };
  4831. Story.prototype.refreshTiddler = function(title,template,force,customFields,defaultText)
  4832. {
  4833. var tiddlerElem = document.getElementById(this.idPrefix + title);
  4834. if(tiddlerElem) {
  4835. if(tiddlerElem.getAttribute("dirty") == "true" && !force)
  4836. return tiddlerElem;
  4837. template = this.chooseTemplateForTiddler(title,template);
  4838. var currTemplate = tiddlerElem.getAttribute("template");
  4839. if((template != currTemplate) || force) {
  4840. var tiddler = store.getTiddler(title);
  4841. if(!tiddler) {
  4842. tiddler = new Tiddler();
  4843. if(store.isShadowTiddler(title)) {
  4844. tiddler.set(title,store.getTiddlerText(title),config.views.wikified.shadowModifier,version.date,[],version.date);
  4845. } else {
  4846. var text = template=="EditTemplate" ?
  4847. config.views.editor.defaultText.format([title]) :
  4848. config.views.wikified.defaultText.format([title]);
  4849. text = defaultText ? defaultText : text;
  4850. var fields = customFields ? customFields.decodeHashMap() : null;
  4851. tiddler.set(title,text,config.views.wikified.defaultModifier,version.date,[],version.date,fields);
  4852. }
  4853. }
  4854. tiddlerElem.setAttribute("tags",tiddler.tags.join(" "));
  4855. tiddlerElem.setAttribute("tiddler",title);
  4856. tiddlerElem.setAttribute("template",template);
  4857. var me = this;
  4858. tiddlerElem.onmouseover = this.onTiddlerMouseOver;
  4859. tiddlerElem.onmouseout = this.onTiddlerMouseOut;
  4860. tiddlerElem.ondblclick = this.onTiddlerDblClick;
  4861. tiddlerElem[window.event?"onkeydown":"onkeypress"] = this.onTiddlerKeyPress;
  4862. var html = this.getTemplateForTiddler(title,template,tiddler);
  4863. tiddlerElem.innerHTML = html;
  4864. applyHtmlMacros(tiddlerElem,tiddler);
  4865. if(store.getTaggedTiddlers(title).length > 0)
  4866. addClass(tiddlerElem,"isTag");
  4867. else
  4868. removeClass(tiddlerElem,"isTag");
  4869. if(!store.tiddlerExists(title)) {
  4870. if(store.isShadowTiddler(title))
  4871. addClass(tiddlerElem,"shadow");
  4872. else
  4873. addClass(tiddlerElem,"missing");
  4874. } else {
  4875. removeClass(tiddlerElem,"shadow");
  4876. removeClass(tiddlerElem,"missing");
  4877. }
  4878. if(customFields)
  4879. this.addCustomFields(tiddlerElem,customFields);
  4880. forceReflow();
  4881. }
  4882. }
  4883. return tiddlerElem;
  4884. };
  4885. Story.prototype.addCustomFields = function(place,customFields)
  4886. {
  4887. var fields = customFields.decodeHashMap();
  4888. var w = document.createElement("div");
  4889. w.style.display = "none";
  4890. place.appendChild(w);
  4891. for(var t in fields) {
  4892. var e = document.createElement("input");
  4893. e.setAttribute("type","text");
  4894. e.setAttribute("value",fields[t]);
  4895. w.appendChild(e);
  4896. e.setAttribute("edit",t);
  4897. }
  4898. };
  4899. Story.prototype.refreshAllTiddlers = function()
  4900. {
  4901. var place = document.getElementById(this.container);
  4902. var e = place.firstChild;
  4903. if(!e)
  4904. return;
  4905. this.refreshTiddler(e.getAttribute("tiddler"),e.getAttribute("template"),true);
  4906. while((e = e.nextSibling) != null)
  4907. this.refreshTiddler(e.getAttribute("tiddler"),e.getAttribute("template"),true);
  4908. };
  4909. Story.prototype.onTiddlerMouseOver = function(e)
  4910. {
  4911. if(window.addClass instanceof Function)
  4912. addClass(this,"selected");
  4913. };
  4914. Story.prototype.onTiddlerMouseOut = function(e)
  4915. {
  4916. if(window.removeClass instanceof Function)
  4917. removeClass(this,"selected");
  4918. };
  4919. Story.prototype.onTiddlerDblClick = function(e)
  4920. {
  4921. if(!e) var e = window.event;
  4922. var theTarget = resolveTarget(e);
  4923. if(theTarget && theTarget.nodeName.toLowerCase() != "input" && theTarget.nodeName.toLowerCase() != "textarea") {
  4924. if(document.selection && document.selection.empty)
  4925. document.selection.empty();
  4926. config.macros.toolbar.invokeCommand(this,"defaultCommand",e);
  4927. e.cancelBubble = true;
  4928. if(e.stopPropagation) e.stopPropagation();
  4929. return true;
  4930. } else {
  4931. return false;
  4932. }
  4933. };
  4934. Story.prototype.onTiddlerKeyPress = function(e)
  4935. {
  4936. if(!e) var e = window.event;
  4937. clearMessage();
  4938. var consume = false;
  4939. var title = this.getAttribute("tiddler");
  4940. var target = resolveTarget(e);
  4941. switch(e.keyCode) {
  4942. case 9: // Tab
  4943. if(config.options.chkInsertTabs && target.tagName.toLowerCase() == "textarea") {
  4944. replaceSelection(target,String.fromCharCode(9));
  4945. consume = true;
  4946. }
  4947. if(config.isOpera) {
  4948. target.onblur = function() {
  4949. this.focus();
  4950. this.onblur = null;
  4951. };
  4952. }
  4953. break;
  4954. case 13: // Ctrl-Enter
  4955. case 10: // Ctrl-Enter on IE PC
  4956. case 77: // Ctrl-Enter is "M" on some platforms
  4957. if(e.ctrlKey) {
  4958. blurElement(this);
  4959. config.macros.toolbar.invokeCommand(this,"defaultCommand",e);
  4960. consume = true;
  4961. }
  4962. break;
  4963. case 27: // Escape
  4964. blurElement(this);
  4965. config.macros.toolbar.invokeCommand(this,"cancelCommand",e);
  4966. consume = true;
  4967. break;
  4968. }
  4969. e.cancelBubble = consume;
  4970. if(consume) {
  4971. if(e.stopPropagation) e.stopPropagation(); // Stop Propagation
  4972. e.returnValue = true; // Cancel The Event in IE
  4973. if(e.preventDefault ) e.preventDefault(); // Cancel The Event in Moz
  4974. }
  4975. return !consume;
  4976. };
  4977. Story.prototype.getTiddlerField = function(title,field)
  4978. {
  4979. var tiddlerElem = document.getElementById(this.idPrefix + title);
  4980. var e = null;
  4981. if(tiddlerElem != null) {
  4982. var children = tiddlerElem.getElementsByTagName("*");
  4983. for(var t=0; t<children.length; t++) {
  4984. var c = children[t];
  4985. if(c.tagName.toLowerCase() == "input" || c.tagName.toLowerCase() == "textarea") {
  4986. if(!e)
  4987. e = c;
  4988. if(c.getAttribute("edit") == field)
  4989. e = c;
  4990. }
  4991. }
  4992. }
  4993. return e;
  4994. };
  4995. Story.prototype.focusTiddler = function(title,field)
  4996. {
  4997. var e = this.getTiddlerField(title,field);
  4998. if(e) {
  4999. e.focus();
  5000. e.select();
  5001. }
  5002. };
  5003. Story.prototype.blurTiddler = function(title)
  5004. {
  5005. var tiddlerElem = document.getElementById(this.idPrefix + title);
  5006. if(tiddlerElem != null && tiddlerElem.focus && tiddlerElem.blur) {
  5007. tiddlerElem.focus();
  5008. tiddlerElem.blur();
  5009. }
  5010. };
  5011. Story.prototype.setTiddlerField = function(title,tag,mode,field)
  5012. {
  5013. var c = story.getTiddlerField(title,field);
  5014. var tags = c.value.readBracketedList();
  5015. tags.setItem(tag,mode);
  5016. c.value = String.encodeTiddlyLinkList(tags);
  5017. };
  5018. Story.prototype.setTiddlerTag = function(title,tag,mode)
  5019. {
  5020. Story.prototype.setTiddlerField(title,tag,mode,"tags");
  5021. };
  5022. Story.prototype.closeTiddler = function(title,animate,unused)
  5023. {
  5024. var tiddlerElem = document.getElementById(this.idPrefix + title);
  5025. if(tiddlerElem != null) {
  5026. clearMessage();
  5027. this.scrubTiddler(tiddlerElem);
  5028. if(config.options.chkAnimate && animate && anim && typeof Slider == "function")
  5029. anim.startAnimating(new Slider(tiddlerElem,false,null,"all"));
  5030. else {
  5031. removeNode(tiddlerElem);
  5032. forceReflow();
  5033. }
  5034. }
  5035. };
  5036. Story.prototype.scrubTiddler = function(tiddlerElem)
  5037. {
  5038. tiddlerElem.id = null;
  5039. };
  5040. Story.prototype.setDirty = function(title,dirty)
  5041. {
  5042. var tiddlerElem = document.getElementById(this.idPrefix + title);
  5043. if(tiddlerElem != null)
  5044. tiddlerElem.setAttribute("dirty",dirty ? "true" : "false");
  5045. };
  5046. Story.prototype.isDirty = function(title)
  5047. {
  5048. var tiddlerElem = document.getElementById(this.idPrefix + title);
  5049. if(tiddlerElem != null)
  5050. return tiddlerElem.getAttribute("dirty") == "true";
  5051. return null;
  5052. };
  5053. Story.prototype.areAnyDirty = function()
  5054. {
  5055. var r = false;
  5056. this.forEachTiddler(function(title,element) {
  5057. if(this.isDirty(title))
  5058. r = true;
  5059. });
  5060. return r;
  5061. };
  5062. Story.prototype.closeAllTiddlers = function(exclude)
  5063. {
  5064. clearMessage();
  5065. this.forEachTiddler(function(title,element) {
  5066. if((title != exclude) && element.getAttribute("dirty") != "true")
  5067. this.closeTiddler(title);
  5068. });
  5069. window.scrollTo(0,ensureVisible(this.container));
  5070. };
  5071. Story.prototype.isEmpty = function()
  5072. {
  5073. var place = document.getElementById(this.container);
  5074. return place && place.firstChild == null;
  5075. };
  5076. Story.prototype.search = function(text,useCaseSensitive,useRegExp)
  5077. {
  5078. this.closeAllTiddlers();
  5079. highlightHack = new RegExp(useRegExp ? text : text.escapeRegExp(),useCaseSensitive ? "mg" : "img");
  5080. var matches = store.search(highlightHack,"title","excludeSearch");
  5081. var titles = [];
  5082. for(var t=0;t<matches.length;t++)
  5083. titles.push(matches[t].title);
  5084. this.displayTiddlers(null,titles);
  5085. highlightHack = null;
  5086. var q = useRegExp ? "/" : "'";
  5087. if(matches.length > 0)
  5088. displayMessage(config.macros.search.successMsg.format([titles.length.toString(),q + text + q]));
  5089. else
  5090. displayMessage(config.macros.search.failureMsg.format([q + text + q]));
  5091. };
  5092. Story.prototype.findContainingTiddler = function(e)
  5093. {
  5094. while(e && !hasClass(e,"tiddler"))
  5095. e = e.parentNode;
  5096. return e;
  5097. };
  5098. Story.prototype.gatherSaveFields = function(e,fields)
  5099. {
  5100. if(e && e.getAttribute) {
  5101. var f = e.getAttribute("edit");
  5102. if(f)
  5103. fields[f] = e.value.replace(/\r/mg,"");
  5104. if(e.hasChildNodes()) {
  5105. var c = e.childNodes;
  5106. for(var t=0; t<c.length; t++)
  5107. this.gatherSaveFields(c[t],fields);
  5108. }
  5109. }
  5110. };
  5111. Story.prototype.hasChanges = function(title)
  5112. {
  5113. var e = document.getElementById(this.idPrefix + title);
  5114. if(e != null) {
  5115. var fields = {};
  5116. this.gatherSaveFields(e,fields);
  5117. var tiddler = store.fetchTiddler(title);
  5118. if(!tiddler)
  5119. return false;
  5120. for(var n in fields) {
  5121. if(store.getValue(title,n) != fields[n])
  5122. return true;
  5123. }
  5124. }
  5125. return false;
  5126. };
  5127. Story.prototype.saveTiddler = function(title,minorUpdate)
  5128. {
  5129. var tiddlerElem = document.getElementById(this.idPrefix + title);
  5130. if(tiddlerElem != null) {
  5131. var fields = {};
  5132. this.gatherSaveFields(tiddlerElem,fields);
  5133. var newTitle = fields.title ? fields.title : title;
  5134. if(store.tiddlerExists(newTitle) && newTitle != title) {
  5135. if(!confirm(config.messages.overwriteWarning.format([newTitle.toString()])))
  5136. return null;
  5137. }
  5138. if(newTitle != title)
  5139. this.closeTiddler(newTitle,false);
  5140. tiddlerElem.id = this.idPrefix + newTitle;
  5141. tiddlerElem.setAttribute("tiddler",newTitle);
  5142. tiddlerElem.setAttribute("template",DEFAULT_VIEW_TEMPLATE);
  5143. tiddlerElem.setAttribute("dirty","false");
  5144. if(config.options.chkForceMinorUpdate)
  5145. minorUpdate = !minorUpdate;
  5146. if(!store.tiddlerExists(newTitle))
  5147. minorUpdate = false;
  5148. var newDate = new Date();
  5149. var extendedFields = store.tiddlerExists(newTitle) ? store.fetchTiddler(newTitle).fields : {};
  5150. for(var n in fields) {
  5151. if(!TiddlyWiki.isStandardField(n))
  5152. extendedFields[n] = fields[n];
  5153. }
  5154. var tiddler = store.saveTiddler(title,newTitle,fields.text,minorUpdate ? undefined : config.options.txtUserName,minorUpdate ? undefined : newDate,fields.tags,extendedFields);
  5155. autoSaveChanges(null,[tiddler]);
  5156. return newTitle;
  5157. }
  5158. return null;
  5159. };
  5160. Story.prototype.permaView = function()
  5161. {
  5162. var links = [];
  5163. this.forEachTiddler(function(title,element) {
  5164. links.push(String.encodeTiddlyLink(title));
  5165. });
  5166. var t = encodeURIComponent(links.join(" "));
  5167. if(t == "")
  5168. t = "#";
  5169. if(window.location.hash != t)
  5170. window.location.hash = t;
  5171. };
  5172. //--
  5173. //-- Backstage
  5174. //--
  5175. var backstage = {
  5176. area: null,
  5177. toolbar: null,
  5178. button: null,
  5179. showButton: null,
  5180. hideButton: null,
  5181. cloak: null,
  5182. panel: null,
  5183. panelBody: null,
  5184. panelFooter: null,
  5185. currTabName: null,
  5186. currTabElem: null,
  5187. content: null,
  5188. init: function() {
  5189. var cmb = config.messages.backstage;
  5190. this.area = document.getElementById("backstageArea");
  5191. this.toolbar = document.getElementById("backstageToolbar");
  5192. this.button = document.getElementById("backstageButton");
  5193. this.button.style.display = "block";
  5194. var t = cmb.open.text + " " + glyph("bentArrowLeft");
  5195. this.showButton = createTiddlyButton(this.button,t,cmb.open.tooltip,
  5196. function (e) {backstage.show(); return false;},null,"backstageShow");
  5197. t = glyph("bentArrowRight") + " " + cmb.close.text;
  5198. this.hideButton = createTiddlyButton(this.button,t,cmb.close.tooltip,
  5199. function (e) {backstage.hide(); return false;},null,"backstageHide");
  5200. this.cloak = document.getElementById("backstageCloak");
  5201. this.panel = document.getElementById("backstagePanel");
  5202. this.panelFooter = createTiddlyElement(this.panel,"div",null,"backstagePanelFooter");
  5203. this.panelBody = createTiddlyElement(this.panel,"div",null,"backstagePanelBody");
  5204. this.cloak.onmousedown = function(e) {
  5205. backstage.switchTab(null);
  5206. };
  5207. createTiddlyText(this.toolbar,cmb.prompt);
  5208. for(t=0; t<config.backstageTasks.length; t++) {
  5209. var taskName = config.backstageTasks[t];
  5210. var task = config.tasks[taskName];
  5211. var handler = task.action ? this.onClickCommand : this.onClickTab;
  5212. var text = task.text + (task.action ? "" : glyph("downTriangle"));
  5213. var btn = createTiddlyButton(this.toolbar,text,task.tooltip,handler,"backstageTab");
  5214. btn.setAttribute("task",taskName);
  5215. addClass(btn,task.action ? "backstageAction" : "backstageTask");
  5216. }
  5217. this.content = document.getElementById("contentWrapper");
  5218. if(config.options.chkBackstage)
  5219. this.show();
  5220. else
  5221. this.hide();
  5222. },
  5223. isVisible: function () {
  5224. return this.area ? this.area.style.display == "block" : false;
  5225. },
  5226. show: function() {
  5227. this.area.style.display = "block";
  5228. if(anim && config.options.chkAnimate) {
  5229. backstage.toolbar.style.left = findWindowWidth() + "px";
  5230. var p = [
  5231. {style: "left", start: findWindowWidth(), end: 0, template: "%0px"}
  5232. ];
  5233. anim.startAnimating(new Morpher(backstage.toolbar,config.animDuration,p));
  5234. } else {
  5235. backstage.area.style.left = "0px";
  5236. }
  5237. this.showButton.style.display = "none";
  5238. this.hideButton.style.display = "block";
  5239. config.options.chkBackstage = true;
  5240. saveOptionCookie("chkBackstage");
  5241. addClass(this.content,"backstageVisible");
  5242. },
  5243. hide: function() {
  5244. if(this.currTabElem) {
  5245. this.switchTab(null);
  5246. } else {
  5247. backstage.toolbar.style.left = "0px";
  5248. if(anim && config.options.chkAnimate) {
  5249. var p = [
  5250. {style: "left", start: 0, end: findWindowWidth(), template: "%0px"}
  5251. ];
  5252. var c = function(element,properties) {backstage.area.style.display = "none";};
  5253. anim.startAnimating(new Morpher(backstage.toolbar,config.animDuration,p,c));
  5254. } else {
  5255. this.area.style.display = "none";
  5256. }
  5257. this.showButton.style.display = "block";
  5258. this.hideButton.style.display = "none";
  5259. config.options.chkBackstage = false;
  5260. saveOptionCookie("chkBackstage");
  5261. removeClass(this.content,"backstageVisible");
  5262. }
  5263. },
  5264. onClickCommand: function(e) {
  5265. var task = config.tasks[this.getAttribute("task")];
  5266. displayMessage(task);
  5267. if(task.action) {
  5268. backstage.switchTab(null);
  5269. task.action();
  5270. }
  5271. return false;
  5272. },
  5273. onClickTab: function(e) {
  5274. backstage.switchTab(this.getAttribute("task"));
  5275. return false;
  5276. },
  5277. // Switch to a given tab, or none if null is passed
  5278. switchTab: function(tabName) {
  5279. var tabElem = null;
  5280. var e = this.toolbar.firstChild;
  5281. while(e)
  5282. {
  5283. if(e.getAttribute && e.getAttribute("task") == tabName)
  5284. tabElem = e;
  5285. e = e.nextSibling;
  5286. }
  5287. if(tabName == backstage.currTabName)
  5288. return;
  5289. if(backstage.currTabElem) {
  5290. removeClass(this.currTabElem,"backstageSelTab");
  5291. }
  5292. if(tabElem && tabName) {
  5293. backstage.preparePanel();
  5294. addClass(tabElem,"backstageSelTab");
  5295. var task = config.tasks[tabName];
  5296. wikify(task.content,backstage.panelBody,null,null);
  5297. backstage.showPanel();
  5298. } else if(backstage.currTabElem) {
  5299. backstage.hidePanel();
  5300. }
  5301. backstage.currTabName = tabName;
  5302. backstage.currTabElem = tabElem;
  5303. },
  5304. isPanelVisible: function() {
  5305. return backstage.panel ? backstage.panel.style.display == "block" : false;
  5306. },
  5307. preparePanel: function() {
  5308. backstage.cloak.style.height = findWindowHeight() + "px";
  5309. backstage.cloak.style.display = "block";
  5310. removeChildren(backstage.panelBody);
  5311. return backstage.panelBody;
  5312. },
  5313. showPanel: function() {
  5314. backstage.panel.style.display = "block";
  5315. if(anim && config.options.chkAnimate) {
  5316. backstage.panel.style.top = (-backstage.panel.offsetHeight) + "px";
  5317. var p = [
  5318. {style: "top", start: -backstage.panel.offsetHeight, end: 0, template: "%0px"}
  5319. ];
  5320. anim.startAnimating(new Morpher(backstage.panel,config.animDuration,p),new Scroller(backstage.panel,false));
  5321. } else {
  5322. backstage.panel.style.top = "0px";
  5323. }
  5324. return backstage.panelBody;
  5325. },
  5326. hidePanel: function() {
  5327. backstage.currTabName = null;
  5328. backstage.currTabElem = null;
  5329. if(anim && config.options.chkAnimate) {
  5330. var p = [
  5331. {style: "top", start: 0, end: -(backstage.panel.offsetHeight), template: "%0px"},
  5332. {style: "display", atEnd: "none"}
  5333. ];
  5334. var c = function(element,properties) {backstage.cloak.style.display = "none";};
  5335. anim.startAnimating(new Morpher(backstage.panel,config.animDuration,p,c));
  5336. } else {
  5337. backstage.panel.style.display = "none";
  5338. backstage.cloak.style.display = "none";
  5339. }
  5340. }
  5341. };
  5342. config.macros.backstage = {};
  5343. config.macros.backstage.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  5344. {
  5345. var backstageTask = config.tasks[params[0]];
  5346. if(backstageTask)
  5347. createTiddlyButton(place,backstageTask.text,backstageTask.tooltip,function(e) {backstage.switchTab(params[0]); return false;});
  5348. };
  5349. //--
  5350. //-- ImportTiddlers macro
  5351. //--
  5352. config.macros.importTiddlers.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  5353. {
  5354. if(readOnly) {
  5355. createTiddlyElement(place,"div",null,"marked",this.readOnlyWarning);
  5356. return;
  5357. }
  5358. var w = new Wizard();
  5359. w.createWizard(place,this.wizardTitle);
  5360. this.restart(w);
  5361. };
  5362. config.macros.importTiddlers.onCancel = function(e)
  5363. {
  5364. var wizard = new Wizard(this);
  5365. var place = wizard.clear();
  5366. config.macros.importTiddlers.restart(wizard);
  5367. return false;
  5368. };
  5369. config.macros.importTiddlers.restart = function(wizard)
  5370. {
  5371. wizard.addStep(this.step1Title,this.step1Html);
  5372. var s = wizard.getElement("selTypes");
  5373. for(var t in config.adaptors) {
  5374. var e = createTiddlyElement(s,"option",null,null,t);
  5375. e.value = t;
  5376. }
  5377. s = wizard.getElement("selFeeds");
  5378. var feeds = this.getFeeds();
  5379. for(t in feeds) {
  5380. e = createTiddlyElement(s,"option",null,null,t);
  5381. e.value = t;
  5382. }
  5383. wizard.setValue("feeds",feeds);
  5384. s.onchange = config.macros.importTiddlers.onFeedChange;
  5385. var fileInput = wizard.getElement("txtBrowse");
  5386. fileInput.onchange = config.macros.importTiddlers.onBrowseChange;
  5387. fileInput.onkeyup = config.macros.importTiddlers.onBrowseChange;
  5388. wizard.setButtons([{caption: this.openLabel, tooltip: this.openPrompt, onClick: config.macros.importTiddlers.onOpen}]);
  5389. };
  5390. config.macros.importTiddlers.getFeeds = function()
  5391. {
  5392. var feeds = {};
  5393. var tagged = store.getTaggedTiddlers("systemServer","title");
  5394. for(var t=0; t<tagged.length; t++) {
  5395. var title = tagged[t].title;
  5396. var serverType = store.getTiddlerSlice(title,"Type");
  5397. if(!serverType)
  5398. serverType = "file";
  5399. feeds[title] = {title: title,
  5400. url: store.getTiddlerSlice(title,"URL"),
  5401. workspace: store.getTiddlerSlice(title,"Workspace"),
  5402. workspaceList: store.getTiddlerSlice(title,"WorkspaceList"),
  5403. tiddlerFilter: store.getTiddlerSlice(title,"TiddlerFilter"),
  5404. serverType: serverType,
  5405. description: store.getTiddlerSlice(title,"Description")};
  5406. }
  5407. return feeds;
  5408. };
  5409. config.macros.importTiddlers.onFeedChange = function(e)
  5410. {
  5411. var wizard = new Wizard(this);
  5412. var selTypes = wizard.getElement("selTypes");
  5413. var fileInput = wizard.getElement("txtPath");
  5414. var feeds = wizard.getValue("feeds");
  5415. var f = feeds[this.value];
  5416. if(f) {
  5417. selTypes.value = f.serverType;
  5418. fileInput.value = f.url;
  5419. this.selectedIndex = 0;
  5420. wizard.setValue("feedName",f.serverType);
  5421. wizard.setValue("feedHost",f.url);
  5422. wizard.setValue("feedWorkspace",f.workspace);
  5423. wizard.setValue("feedWorkspaceList",f.workspaceList);
  5424. wizard.setValue("feedTiddlerFilter",f.tiddlerFilter);
  5425. }
  5426. return false;
  5427. };
  5428. config.macros.importTiddlers.onBrowseChange = function(e)
  5429. {
  5430. var wizard = new Wizard(this);
  5431. var fileInput = wizard.getElement("txtPath");
  5432. fileInput.value = "file://" + this.value;
  5433. var serverType = wizard.getElement("selTypes");
  5434. serverType.value = "file";
  5435. return false;
  5436. };
  5437. config.macros.importTiddlers.onOpen = function(e)
  5438. {
  5439. var wizard = new Wizard(this);
  5440. var fileInput = wizard.getElement("txtPath");
  5441. var url = fileInput.value;
  5442. var serverType = wizard.getElement("selTypes").value;
  5443. var adaptor = new config.adaptors[serverType];
  5444. wizard.setValue("adaptor",adaptor);
  5445. wizard.setValue("serverType",serverType);
  5446. wizard.setValue("host",url);
  5447. var context = {};
  5448. var ret = adaptor.openHost(url,context,wizard,config.macros.importTiddlers.onOpenHost);
  5449. if(ret !== true)
  5450. displayMessage(ret);
  5451. wizard.setButtons([{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}],config.macros.importTiddlers.statusOpenHost);
  5452. return false;
  5453. };
  5454. config.macros.importTiddlers.onOpenHost = function(context,wizard)
  5455. {
  5456. var adaptor = wizard.getValue("adaptor");
  5457. if(context.status !== true)
  5458. displayMessage("Error in importTiddlers.onOpenHost: " + context.statusText);
  5459. var ret = adaptor.getWorkspaceList(context,wizard,config.macros.importTiddlers.onGetWorkspaceList);
  5460. if(ret !== true)
  5461. displayMessage(ret);
  5462. wizard.setButtons([{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}],config.macros.importTiddlers.statusGetWorkspaceList);
  5463. };
  5464. config.macros.importTiddlers.onGetWorkspaceList = function(context,wizard)
  5465. {
  5466. if(context.status !== true)
  5467. displayMessage("Error in importTiddlers.onGetWorkspaceList: " + context.statusText);
  5468. wizard.addStep(config.macros.importTiddlers.step2Title,config.macros.importTiddlers.step2Html);
  5469. var s = wizard.getElement("selWorkspace");
  5470. s.onchange = config.macros.importTiddlers.onWorkspaceChange;
  5471. for(var t=0; t<context.workspaces.length; t++) {
  5472. var e = createTiddlyElement(s,"option",null,null,context.workspaces[t].title);
  5473. e.value = context.workspaces[t].title;
  5474. }
  5475. var workspaceList = wizard.getValue("feedWorkspaceList");
  5476. if(workspaceList) {
  5477. var list = workspaceList.parseParams("workspace",null,false,true);
  5478. for(var n=1; n<list.length; n++) {
  5479. if(context.workspaces.findByField("title",list[n].value) == null) {
  5480. e = createTiddlyElement(s,"option",null,null,list[n].value);
  5481. e.value = list[n].value;
  5482. }
  5483. }
  5484. }
  5485. var workspace = wizard.getValue("feedWorkspace");
  5486. if(workspace) {
  5487. t = wizard.getElement("txtWorkspace");
  5488. t.value = workspace;
  5489. }
  5490. wizard.setButtons([{caption: config.macros.importTiddlers.openLabel, tooltip: config.macros.importTiddlers.openPrompt, onClick: config.macros.importTiddlers.onChooseWorkspace}]);
  5491. };
  5492. config.macros.importTiddlers.onWorkspaceChange = function(e)
  5493. {
  5494. var wizard = new Wizard(this);
  5495. var t = wizard.getElement("txtWorkspace");
  5496. t.value = this.value;
  5497. this.selectedIndex = 0;
  5498. return false;
  5499. };
  5500. config.macros.importTiddlers.onChooseWorkspace = function(e)
  5501. {
  5502. var wizard = new Wizard(this);
  5503. var adaptor = wizard.getValue("adaptor");
  5504. var workspace = wizard.getElement("txtWorkspace").value;
  5505. wizard.setValue("workspace",workspace);
  5506. var context = {};
  5507. var ret = adaptor.openWorkspace(workspace,context,wizard,config.macros.importTiddlers.onOpenWorkspace);
  5508. if(ret !== true)
  5509. displayMessage(ret);
  5510. wizard.setButtons([{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}],config.macros.importTiddlers.statusOpenWorkspace);
  5511. return false;
  5512. };
  5513. config.macros.importTiddlers.onOpenWorkspace = function(context,wizard)
  5514. {
  5515. if(context.status !== true)
  5516. displayMessage("Error in importTiddlers.onOpenWorkspace: " + context.statusText);
  5517. var adaptor = wizard.getValue("adaptor");
  5518. var ret = adaptor.getTiddlerList(context,wizard,config.macros.importTiddlers.onGetTiddlerList,wizard.getValue("feedTiddlerFilter"));
  5519. if(ret !== true)
  5520. displayMessage(ret);
  5521. wizard.setButtons([{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}],config.macros.importTiddlers.statusGetTiddlerList);
  5522. };
  5523. config.macros.importTiddlers.onGetTiddlerList = function(context,wizard)
  5524. {
  5525. if(context.status !== true)
  5526. displayMessage("Error in importTiddlers.onGetTiddlerList: " + context.statusText);
  5527. // Extract data for the listview
  5528. var listedTiddlers = [];
  5529. if(context.tiddlers) {
  5530. for(var n=0; n<context.tiddlers.length; n++) {
  5531. var tiddler = context.tiddlers[n];
  5532. listedTiddlers.push({
  5533. title: tiddler.title,
  5534. modified: tiddler.modified,
  5535. modifier: tiddler.modifier,
  5536. text: tiddler.text ? wikifyPlainText(tiddler.text,100) : "",
  5537. tags: tiddler.tags,
  5538. size: tiddler.text ? tiddler.text.length : 0,
  5539. tiddler: tiddler
  5540. });
  5541. }
  5542. }
  5543. listedTiddlers.sort(function(a,b) {return a.title < b.title ? -1 : (a.title == b.title ? 0 : +1);});
  5544. // Display the listview
  5545. wizard.addStep(config.macros.importTiddlers.step3Title,config.macros.importTiddlers.step3Html);
  5546. var markList = wizard.getElement("markList");
  5547. var listWrapper = document.createElement("div");
  5548. markList.parentNode.insertBefore(listWrapper,markList);
  5549. var listView = ListView.create(listWrapper,listedTiddlers,config.macros.importTiddlers.listViewTemplate);
  5550. wizard.setValue("listView",listView);
  5551. var txtSaveTiddler = wizard.getElement("txtSaveTiddler");
  5552. txtSaveTiddler.value = config.macros.importTiddlers.generateSystemServerName(wizard);
  5553. wizard.setButtons([
  5554. {caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel},
  5555. {caption: config.macros.importTiddlers.importLabel, tooltip: config.macros.importTiddlers.importPrompt, onClick: config.macros.importTiddlers.doImport}
  5556. ]);
  5557. };
  5558. config.macros.importTiddlers.generateSystemServerName = function(wizard)
  5559. {
  5560. var serverType = wizard.getValue("serverType");
  5561. var host = wizard.getValue("host");
  5562. var workspace = wizard.getValue("workspace");
  5563. var pattern = config.macros.importTiddlers[workspace ? "systemServerNamePattern" : "systemServerNamePatternNoWorkspace"];
  5564. return pattern.format([serverType,host,workspace]);
  5565. };
  5566. config.macros.importTiddlers.saveServerTiddler = function(wizard)
  5567. {
  5568. var txtSaveTiddler = wizard.getElement("txtSaveTiddler").value;
  5569. if(store.tiddlerExists(txtSaveTiddler)) {
  5570. if(!confirm(config.macros.importTiddlers.confirmOverwriteSaveTiddler.format([txtSaveTiddler])))
  5571. return;
  5572. store.suspendNotifications();
  5573. store.removeTiddler(txtSaveTiddler);
  5574. store.resumeNotifications();
  5575. }
  5576. var serverType = wizard.getValue("serverType");
  5577. var host = wizard.getValue("host");
  5578. var workspace = wizard.getValue("workspace");
  5579. var text = config.macros.importTiddlers.serverSaveTemplate.format([serverType,host,workspace]);
  5580. store.saveTiddler(txtSaveTiddler,txtSaveTiddler,text,config.macros.importTiddlers.serverSaveModifier,new Date(),["systemServer"]);
  5581. };
  5582. config.macros.importTiddlers.doImport = function(e)
  5583. {
  5584. var wizard = new Wizard(this);
  5585. if(wizard.getElement("chkSave").checked)
  5586. config.macros.importTiddlers.saveServerTiddler(wizard);
  5587. var chkSync = wizard.getElement("chkSync").checked;
  5588. wizard.setValue("sync",chkSync);
  5589. var listView = wizard.getValue("listView");
  5590. var rowNames = ListView.getSelectedRows(listView);
  5591. var adaptor = wizard.getValue("adaptor");
  5592. var overwrite = new Array();
  5593. var t;
  5594. for(t=0; t<rowNames.length; t++) {
  5595. if(store.tiddlerExists(rowNames[t]))
  5596. overwrite.push(rowNames[t]);
  5597. }
  5598. if(overwrite.length > 0) {
  5599. if(!confirm(config.macros.importTiddlers.confirmOverwriteText.format([overwrite.join(", ")])))
  5600. return false;
  5601. }
  5602. wizard.addStep(config.macros.importTiddlers.step4Title.format([rowNames.length]),config.macros.importTiddlers.step4Html);
  5603. for(t=0; t<rowNames.length; t++) {
  5604. var link = document.createElement("div");
  5605. createTiddlyLink(link,rowNames[t],true);
  5606. var place = wizard.getElement("markReport");
  5607. place.parentNode.insertBefore(link,place);
  5608. }
  5609. wizard.setValue("remainingImports",rowNames.length);
  5610. wizard.setButtons([
  5611. {caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}
  5612. ],config.macros.importTiddlers.statusDoingImport);
  5613. for(t=0; t<rowNames.length; t++) {
  5614. var context = {};
  5615. context.allowSynchronous = true;
  5616. var inbound = adaptor.getTiddler(rowNames[t],context,wizard,config.macros.importTiddlers.onGetTiddler);
  5617. }
  5618. return false;
  5619. };
  5620. config.macros.importTiddlers.onGetTiddler = function(context,wizard)
  5621. {
  5622. if(!context.status)
  5623. displayMessage("Error in importTiddlers.onGetTiddler: " + context.statusText);
  5624. var tiddler = context.tiddler;
  5625. store.suspendNotifications();
  5626. store.saveTiddler(tiddler.title, tiddler.title, tiddler.text, tiddler.modifier, tiddler.modified, tiddler.tags, tiddler.fields, true, tiddler.created);
  5627. if(!wizard.getValue("sync")) {
  5628. store.setValue(tiddler.title,'server',null);
  5629. }
  5630. store.resumeNotifications();
  5631. if(!context.isSynchronous)
  5632. store.notify(tiddler.title,true);
  5633. var remainingImports = wizard.getValue("remainingImports")-1;
  5634. wizard.setValue("remainingImports",remainingImports);
  5635. if(remainingImports == 0) {
  5636. if(context.isSynchronous) {
  5637. store.notifyAll();
  5638. refreshDisplay();
  5639. }
  5640. wizard.setButtons([
  5641. {caption: config.macros.importTiddlers.doneLabel, tooltip: config.macros.importTiddlers.donePrompt, onClick: config.macros.importTiddlers.onCancel}
  5642. ],config.macros.importTiddlers.statusDoneImport);
  5643. autoSaveChanges();
  5644. }
  5645. };
  5646. //--
  5647. //-- Sync macro
  5648. //--
  5649. // Synchronisation handlers
  5650. config.syncers = {};
  5651. // Sync state.
  5652. var currSync = null;
  5653. // sync macro
  5654. config.macros.sync.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  5655. {
  5656. if(!wikifier.isStatic)
  5657. this.startSync(place);
  5658. };
  5659. config.macros.sync.startSync = function(place)
  5660. {
  5661. if(currSync)
  5662. config.macros.sync.cancelSync();
  5663. currSync = {};
  5664. currSync.syncList = this.getSyncableTiddlers();
  5665. this.createSyncTasks();
  5666. this.preProcessSyncableTiddlers();
  5667. var wizard = new Wizard();
  5668. currSync.wizard = wizard;
  5669. wizard.createWizard(place,this.wizardTitle);
  5670. wizard.addStep(this.step1Title,this.step1Html);
  5671. var markList = wizard.getElement("markList");
  5672. var listWrapper = document.createElement("div");
  5673. markList.parentNode.insertBefore(listWrapper,markList);
  5674. currSync.listView = ListView.create(listWrapper,currSync.syncList,this.listViewTemplate);
  5675. this.processSyncableTiddlers();
  5676. wizard.setButtons([
  5677. {caption: this.syncLabel, tooltip: this.syncPrompt, onClick: this.doSync}
  5678. ]);
  5679. };
  5680. config.macros.sync.getSyncableTiddlers = function ()
  5681. {
  5682. var list = [];
  5683. store.forEachTiddler(function(title,tiddler) {
  5684. var syncItem = {};
  5685. syncItem.serverType = tiddler.getServerType();
  5686. syncItem.serverHost = tiddler.fields['server.host'];
  5687. syncItem.serverWorkspace = tiddler.fields['server.workspace'];
  5688. syncItem.tiddler = tiddler;
  5689. syncItem.title = tiddler.title;
  5690. syncItem.isTouched = tiddler.isTouched();
  5691. syncItem.selected = syncItem.isTouched;
  5692. syncItem.syncStatus = config.macros.sync.syncStatusList[syncItem.isTouched ? "changedLocally" : "none"];
  5693. syncItem.status = syncItem.syncStatus.text;
  5694. if(syncItem.serverType && syncItem.serverHost)
  5695. list.push(syncItem);
  5696. });
  5697. list.sort(function(a,b) {return a.title < b.title ? -1 : (a.title == b.title ? 0 : +1);});
  5698. return list;
  5699. };
  5700. config.macros.sync.preProcessSyncableTiddlers = function()
  5701. {
  5702. for(var t=0; t<currSync.syncList.length; t++) {
  5703. si = currSync.syncList[t];
  5704. var ti = si.syncTask.syncMachine.generateTiddlerInfo(si.tiddler);
  5705. si.serverUrl = ti.uri;
  5706. }
  5707. };
  5708. config.macros.sync.processSyncableTiddlers = function()
  5709. {
  5710. for(var t=0; t<currSync.syncList.length; t++) {
  5711. si = currSync.syncList[t];
  5712. si.rowElement.style.backgroundColor = si.syncStatus.color;
  5713. }
  5714. };
  5715. config.macros.sync.createSyncTasks = function()
  5716. {
  5717. currSync.syncTasks = [];
  5718. for(var t=0; t<currSync.syncList.length; t++) {
  5719. var si = currSync.syncList[t];
  5720. var r = null;
  5721. for(var st=0; st<currSync.syncTasks.length; st++) {
  5722. var cst = currSync.syncTasks[st];
  5723. if(si.serverType == cst.serverType && si.serverHost == cst.serverHost && si.serverWorkspace == cst.serverWorkspace)
  5724. r = cst;
  5725. }
  5726. if(r == null) {
  5727. si.syncTask = this.createSyncTask(si);
  5728. currSync.syncTasks.push(si.syncTask);
  5729. } else {
  5730. si.syncTask = r;
  5731. r.syncItems.push(si);
  5732. }
  5733. }
  5734. };
  5735. config.macros.sync.createSyncTask = function(syncItem)
  5736. {
  5737. var st = {};
  5738. st.serverType = syncItem.serverType;
  5739. st.serverHost = syncItem.serverHost;
  5740. st.serverWorkspace = syncItem.serverWorkspace;
  5741. st.syncItems = [syncItem];
  5742. st.syncMachine = new SyncMachine(st.serverType,{
  5743. start: function() {
  5744. return this.openHost(st.serverHost,"openWorkspace");
  5745. },
  5746. openWorkspace: function() {
  5747. return this.openWorkspace(st.serverWorkspace,"getTiddlerList");
  5748. },
  5749. getTiddlerList: function() {
  5750. return this.getTiddlerList("gotTiddlerList");
  5751. },
  5752. gotTiddlerList: function(tiddlers) {
  5753. for(var t=0; t<st.syncItems.length; t++) {
  5754. var si = st.syncItems[t];
  5755. var f = tiddlers.findByField("title",si.title);
  5756. if(f !== null) {
  5757. if(tiddlers[f].fields['server.page.revision'] > si.tiddler.fields['server.page.revision']) {
  5758. si.syncStatus = config.macros.sync.syncStatusList[si.isTouched ? 'changedBoth' : 'changedServer'];
  5759. }
  5760. } else {
  5761. si.syncStatus = config.macros.sync.syncStatusList.notFound;
  5762. }
  5763. config.macros.sync.updateSyncStatus(si);
  5764. }
  5765. },
  5766. getTiddler: function(title) {
  5767. return this.getTiddler(title,"onGetTiddler");
  5768. },
  5769. onGetTiddler: function(tiddler) {
  5770. var syncItem = st.syncItems.findByField("title",tiddler.title);
  5771. if(syncItem !== null) {
  5772. syncItem = st.syncItems[syncItem];
  5773. store.saveTiddler(tiddler.title, tiddler.title, tiddler.text, tiddler.modifier, tiddler.modified, tiddler.tags, tiddler.fields, true, tiddler.created);
  5774. syncItem.syncStatus = config.macros.sync.syncStatusList.gotFromServer;
  5775. config.macros.sync.updateSyncStatus(syncItem);
  5776. }
  5777. },
  5778. putTiddler: function(tiddler) {
  5779. return this.putTiddler(tiddler,"onPutTiddler");
  5780. },
  5781. onPutTiddler: function(tiddler) {
  5782. var syncItem = st.syncItems.findByField("title",tiddler.title);
  5783. if(syncItem !== null) {
  5784. syncItem = st.syncItems[syncItem];
  5785. store.resetTiddler(tiddler.title);
  5786. syncItem.syncStatus = config.macros.sync.syncStatusList.putToServer;
  5787. config.macros.sync.updateSyncStatus(syncItem);
  5788. }
  5789. }
  5790. });
  5791. st.syncMachine.go();
  5792. return st;
  5793. };
  5794. config.macros.sync.updateSyncStatus = function(syncItem)
  5795. {
  5796. var e = syncItem.colElements["status"];
  5797. removeChildren(e);
  5798. createTiddlyText(e,syncItem.syncStatus.text);
  5799. syncItem.rowElement.style.backgroundColor = syncItem.syncStatus.color;
  5800. };
  5801. config.macros.sync.doSync = function(e)
  5802. {
  5803. var rowNames = ListView.getSelectedRows(currSync.listView);
  5804. for(var t=0; t<currSync.syncList.length; t++) {
  5805. var si = currSync.syncList[t];
  5806. if(rowNames.indexOf(si.title) != -1) {
  5807. config.macros.sync.doSyncItem(si);
  5808. }
  5809. }
  5810. return false;
  5811. };
  5812. config.macros.sync.doSyncItem = function(syncItem)
  5813. {
  5814. var r = true;
  5815. var sl = config.macros.sync.syncStatusList;
  5816. switch(syncItem.syncStatus) {
  5817. case sl.changedServer:
  5818. r = syncItem.syncTask.syncMachine.go("getTiddler",syncItem.title);
  5819. break;
  5820. case sl.notFound:
  5821. case sl.changedLocally:
  5822. case sl.changedBoth:
  5823. r = syncItem.syncTask.syncMachine.go("putTiddler",syncItem.tiddler);
  5824. break;
  5825. default:
  5826. break;
  5827. }
  5828. if(r !== true)
  5829. displayMessage("Error in doSyncItem: " + r);
  5830. };
  5831. config.macros.sync.cancelSync = function()
  5832. {
  5833. currSync = null;
  5834. };
  5835. function SyncMachine(serverType,steps)
  5836. {
  5837. this.serverType = serverType;
  5838. this.adaptor = new config.adaptors[serverType];
  5839. this.steps = steps;
  5840. }
  5841. SyncMachine.prototype.go = function(step,varargs)
  5842. {
  5843. if(!step)
  5844. step = "start";
  5845. var h = this.steps[step];
  5846. if(!h)
  5847. return null;
  5848. var a = [];
  5849. for(var t=1; t<arguments.length; t++)
  5850. a.push(arguments[t]);
  5851. var r = h.apply(this,a);
  5852. if(typeof r == "string")
  5853. this.invokeError(r);
  5854. return r;
  5855. };
  5856. SyncMachine.prototype.invokeError = function(message)
  5857. {
  5858. if(this.steps.error)
  5859. this.steps.error(message);
  5860. };
  5861. SyncMachine.prototype.openHost = function(host,nextStep)
  5862. {
  5863. var me = this;
  5864. return me.adaptor.openHost(host,null,null,function(context) {
  5865. if(typeof context.status == "string")
  5866. me.invokeError(context.status);
  5867. else
  5868. me.go(nextStep);
  5869. });
  5870. };
  5871. SyncMachine.prototype.getWorkspaceList = function(nextStep)
  5872. {
  5873. var me = this;
  5874. return me.adaptor.getWorkspaceList(null,null,function(context) {
  5875. if(typeof context.status == "string")
  5876. me.invokeError(context.status);
  5877. else
  5878. me.go(nextStep,context.workspaces);
  5879. });
  5880. };
  5881. SyncMachine.prototype.openWorkspace = function(workspace,nextStep)
  5882. {
  5883. var me = this;
  5884. return me.adaptor.openWorkspace(workspace,null,null,function(context) {
  5885. if(typeof context.status == "string")
  5886. me.invokeError(context.status);
  5887. else
  5888. me.go(nextStep);
  5889. });
  5890. };
  5891. SyncMachine.prototype.getTiddlerList = function(nextStep)
  5892. {
  5893. var me = this;
  5894. return me.adaptor.getTiddlerList(null,null,function(context) {
  5895. if(typeof context.status == "string")
  5896. me.invokeError(context.status);
  5897. else
  5898. me.go(nextStep,context.tiddlers);
  5899. });
  5900. };
  5901. SyncMachine.prototype.generateTiddlerInfo = function(tiddler)
  5902. {
  5903. return this.adaptor.generateTiddlerInfo(tiddler);
  5904. };
  5905. SyncMachine.prototype.getTiddler = function(title,nextStep)
  5906. {
  5907. var me = this;
  5908. return me.adaptor.getTiddler(title,null,null,function(context) {
  5909. if(typeof context.status == "string")
  5910. me.invokeError(context.status);
  5911. else
  5912. me.go(nextStep,context.tiddler);
  5913. });
  5914. };
  5915. SyncMachine.prototype.putTiddler = function(tiddler,nextStep)
  5916. {
  5917. var me = this;
  5918. return me.adaptor.putTiddler(tiddler,null,null,function(context) {
  5919. if(typeof context.status == "string")
  5920. me.invokeError(context.status);
  5921. else
  5922. me.go(nextStep,tiddler);
  5923. });
  5924. };
  5925. //--
  5926. //-- Manager UI for groups of tiddlers
  5927. //--
  5928. config.macros.plugins.handler = function(place,macroName,params,wikifier,paramString,tiddler)
  5929. {
  5930. var wizard = new Wizard();
  5931. wizard.createWizard(place,this.wizardTitle);
  5932. wizard.addStep(this.step1Title,this.step1Html);
  5933. var markList = wizard.getElement("markList");
  5934. var listWrapper = document.createElement("div");
  5935. markList.parentNode.insertBefore(listWrapper,markList);
  5936. listWrapper.setAttribute("refresh","macro");
  5937. listWrapper.setAttribute("macroName","plugins");
  5938. listWrapper.setAttribute("params",paramString);
  5939. this.refresh(listWrapper,paramString);
  5940. };
  5941. config.macros.plugins.refresh = function(listWrapper,params)
  5942. {
  5943. var wizard = new Wizard(listWrapper);
  5944. var selectedRows = [];
  5945. ListView.forEachSelector(listWrapper,function(e,rowName) {
  5946. if(e.checked)
  5947. selectedRows.push(e.getAttribute("rowName"));
  5948. });
  5949. removeChildren(listWrapper);
  5950. params = params.parseParams("anon");
  5951. var plugins = installedPlugins.slice(0);
  5952. var t,tiddler,p;
  5953. var configTiddlers = store.getTaggedTiddlers("systemConfig");
  5954. for(t=0; t<configTiddlers.length; t++) {
  5955. tiddler = configTiddlers[t];
  5956. if(plugins.findByField("title",tiddler.title) == null) {
  5957. p = getPluginInfo(tiddler);
  5958. p.executed = false;
  5959. p.log.splice(0,0,this.skippedText);
  5960. plugins.push(p);
  5961. }
  5962. }
  5963. for(t=0; t<plugins.length; t++) {
  5964. p = plugins[t];
  5965. p.size = p.tiddler.text ? p.tiddler.text.length : 0;
  5966. p.forced = p.tiddler.isTagged("systemConfigForce");
  5967. p.disabled = p.tiddler.isTagged("systemConfigDisable");
  5968. p.Selected = selectedRows.indexOf(plugins[t].title) != -1;
  5969. }
  5970. if(plugins.length == 0) {
  5971. createTiddlyElement(listWrapper,"em",null,null,this.noPluginText);
  5972. wizard.setButtons([]);
  5973. } else {
  5974. var listView = ListView.create(listWrapper,plugins,this.listViewTemplate,this.onSelectCommand);
  5975. wizard.setValue("listView",listView);
  5976. wizard.setButtons([
  5977. {caption: config.macros.plugins.removeLabel, tooltip: config.macros.plugins.removePrompt, onClick: config.macros.plugins.doRemoveTag},
  5978. {caption: config.macros.plugins.deleteLabel, tooltip: config.macros.plugins.deletePrompt, onClick: config.macros.plugins.doDelete}
  5979. ]);
  5980. }
  5981. };
  5982. config.macros.plugins.doRemoveTag = function(e)
  5983. {
  5984. var wizard = new Wizard(this);
  5985. var listView = wizard.getValue("listView");
  5986. var rowNames = ListView.getSelectedRows(listView);
  5987. if(rowNames.length == 0) {
  5988. alert(config.messages.nothingSelected);
  5989. } else {
  5990. for(var t=0; t<rowNames.length; t++)
  5991. store.setTiddlerTag(rowNames[t],false,"systemConfig");
  5992. }
  5993. };
  5994. config.macros.plugins.doDelete = function(e)
  5995. {
  5996. var wizard = new Wizard(this);
  5997. var listView = wizard.getValue("listView");
  5998. var rowNames = ListView.getSelectedRows(listView);
  5999. if(rowNames.length == 0) {
  6000. alert(config.messages.nothingSelected);
  6001. } else {
  6002. if(confirm(config.macros.plugins.confirmDeleteText.format([rowNames.join(", ")]))) {
  6003. for(t=0; t<rowNames.length; t++) {
  6004. store.removeTiddler(rowNames[t]);
  6005. story.closeTiddler(rowNames[t],true);
  6006. }
  6007. }
  6008. }
  6009. };
  6010. //--
  6011. //-- Message area
  6012. //--
  6013. function getMessageDiv()
  6014. {
  6015. var msgArea = document.getElementById("messageArea");
  6016. if(!msgArea)
  6017. return null;
  6018. if(!msgArea.hasChildNodes())
  6019. createTiddlyButton(createTiddlyElement(msgArea,"div",null,"messageToolbar"),
  6020. config.messages.messageClose.text,
  6021. config.messages.messageClose.tooltip,
  6022. clearMessage);
  6023. msgArea.style.display = "block";
  6024. return createTiddlyElement(msgArea,"div");
  6025. }
  6026. function displayMessage(text,linkText)
  6027. {
  6028. var e = getMessageDiv();
  6029. if(!e) {
  6030. alert(text);
  6031. return;
  6032. }
  6033. if(linkText) {
  6034. var link = createTiddlyElement(e,"a",null,null,text);
  6035. link.href = linkText;
  6036. link.target = "_blank";
  6037. } else {
  6038. e.appendChild(document.createTextNode(text));
  6039. }
  6040. }
  6041. function clearMessage()
  6042. {
  6043. var msgArea = document.getElementById("messageArea");
  6044. if(msgArea) {
  6045. removeChildren(msgArea);
  6046. msgArea.style.display = "none";
  6047. }
  6048. return false;
  6049. }
  6050. //--
  6051. //-- Refresh mechanism
  6052. //--
  6053. config.refreshers = {
  6054. link: function(e,changeList)
  6055. {
  6056. var title = e.getAttribute("tiddlyLink");
  6057. refreshTiddlyLink(e,title);
  6058. return true;
  6059. },
  6060. tiddler: function(e,changeList)
  6061. {
  6062. var title = e.getAttribute("tiddler");
  6063. var template = e.getAttribute("template");
  6064. if(changeList && changeList.indexOf(title) != -1 && !story.isDirty(title))
  6065. story.refreshTiddler(title,template,true);
  6066. else
  6067. refreshElements(e,changeList);
  6068. return true;
  6069. },
  6070. content: function(e,changeList)
  6071. {
  6072. var title = e.getAttribute("tiddler");
  6073. var force = e.getAttribute("force");
  6074. if(force != null || changeList == null || changeList.indexOf(title) != -1) {
  6075. removeChildren(e);
  6076. wikify(store.getTiddlerText(title,title),e,null);
  6077. return true;
  6078. } else
  6079. return false;
  6080. },
  6081. macro: function(e,changeList)
  6082. {
  6083. var macro = e.getAttribute("macroName");
  6084. var params = e.getAttribute("params");
  6085. if(macro)
  6086. macro = config.macros[macro];
  6087. if(macro && macro.refresh)
  6088. macro.refresh(e,params);
  6089. return true;
  6090. }
  6091. };
  6092. function refreshElements(root,changeList)
  6093. {
  6094. var nodes = root.childNodes;
  6095. for(var c=0; c<nodes.length; c++) {
  6096. var e = nodes[c], type = null;
  6097. if(e.getAttribute && (e.tagName ? e.tagName != "IFRAME" : true))
  6098. type = e.getAttribute("refresh");
  6099. var refresher = config.refreshers[type];
  6100. var refreshed = false;
  6101. if(refresher != undefined)
  6102. refreshed = refresher(e,changeList);
  6103. if(e.hasChildNodes() && !refreshed)
  6104. refreshElements(e,changeList);
  6105. }
  6106. }
  6107. function applyHtmlMacros(root,tiddler)
  6108. {
  6109. var e = root.firstChild;
  6110. while(e) {
  6111. var nextChild = e.nextSibling;
  6112. if(e.getAttribute) {
  6113. var macro = e.getAttribute("macro");
  6114. if(macro) {
  6115. var params = "";
  6116. var p = macro.indexOf(" ");
  6117. if(p != -1) {
  6118. params = macro.substr(p+1);
  6119. macro = macro.substr(0,p);
  6120. }
  6121. invokeMacro(e,macro,params,null,tiddler);
  6122. }
  6123. }
  6124. if(e.hasChildNodes())
  6125. applyHtmlMacros(e,tiddler);
  6126. e = nextChild;
  6127. }
  6128. }
  6129. function refreshPageTemplate(title)
  6130. {
  6131. var stash = createTiddlyElement(document.body,"div");
  6132. stash.style.display = "none";
  6133. var display = document.getElementById("tiddlerDisplay");
  6134. var nodes,t;
  6135. if(display) {
  6136. nodes = display.childNodes;
  6137. for(t=nodes.length-1; t>=0; t--)
  6138. stash.appendChild(nodes[t]);
  6139. }
  6140. var wrapper = document.getElementById("contentWrapper");
  6141. if(!title)
  6142. title = "PageTemplate";
  6143. var html = store.getRecursiveTiddlerText(title,null,10);
  6144. wrapper.innerHTML = html;
  6145. applyHtmlMacros(wrapper);
  6146. refreshElements(wrapper);
  6147. display = document.getElementById("tiddlerDisplay");
  6148. removeChildren(display);
  6149. if(!display)
  6150. display = createTiddlyElement(wrapper,"div","tiddlerDisplay");
  6151. nodes = stash.childNodes;
  6152. for(t=nodes.length-1; t>=0; t--)
  6153. display.appendChild(nodes[t]);
  6154. removeNode(stash);
  6155. }
  6156. function refreshDisplay(hint)
  6157. {
  6158. if(typeof hint == "string")
  6159. hint = [hint];
  6160. var e = document.getElementById("contentWrapper");
  6161. refreshElements(e,hint);
  6162. if(backstage.isPanelVisible()) {
  6163. e = document.getElementById("backstage");
  6164. refreshElements(e,hint);
  6165. }
  6166. }
  6167. function refreshPageTitle()
  6168. {
  6169. document.title = getPageTitle();
  6170. }
  6171. function getPageTitle()
  6172. {
  6173. var st = wikifyPlain("SiteTitle");
  6174. var ss = wikifyPlain("SiteSubtitle");
  6175. return st + ((st == "" || ss == "") ? "" : " - ") + ss;
  6176. }
  6177. function refreshStyles(title,doc)
  6178. {
  6179. if(!doc)
  6180. doc = document;
  6181. setStylesheet(title == null ? "" : store.getRecursiveTiddlerText(title,"",10),title,doc);
  6182. }
  6183. function refreshColorPalette(title)
  6184. {
  6185. if(!startingUp)
  6186. refreshAll();
  6187. }
  6188. function refreshAll()
  6189. {
  6190. refreshPageTemplate();
  6191. refreshDisplay();
  6192. refreshStyles("StyleSheetLayout");
  6193. refreshStyles("StyleSheetColors");
  6194. refreshStyles("StyleSheet");
  6195. refreshStyles("StyleSheetPrint");
  6196. }
  6197. //--
  6198. //-- Options cookie stuff
  6199. //--
  6200. config.optionHandlers = {
  6201. 'txt': {
  6202. get: function(name) {return encodeCookie(config.options[name].toString());},
  6203. set: function(name,value) {config.options[name] = decodeCookie(value);}
  6204. },
  6205. 'chk': {
  6206. get: function(name) {return config.options[name] ? "true" : "false";},
  6207. set: function(name,value) {config.options[name] = value == "true";}
  6208. }
  6209. };
  6210. function loadOptionsCookie()
  6211. {
  6212. if(safeMode)
  6213. return;
  6214. var cookies = document.cookie.split(";");
  6215. for(var c=0; c<cookies.length; c++) {
  6216. var p = cookies[c].indexOf("=");
  6217. if(p != -1) {
  6218. var name = cookies[c].substr(0,p).trim();
  6219. var value = cookies[c].substr(p+1).trim();
  6220. var optType = name.substr(0,3);
  6221. if(config.optionHandlers[optType] && config.optionHandlers[optType].set)
  6222. config.optionHandlers[optType].set(name,value);
  6223. }
  6224. }
  6225. }
  6226. function saveOptionCookie(name)
  6227. {
  6228. if(safeMode)
  6229. return;
  6230. var c = name + "=";
  6231. var optType = name.substr(0,3);
  6232. if(config.optionHandlers[optType] && config.optionHandlers[optType].get)
  6233. c += config.optionHandlers[optType].get(name);
  6234. c += "; expires=Fri, 1 Jan 2038 12:00:00 UTC; path=/";
  6235. document.cookie = c;
  6236. }
  6237. function encodeCookie(s)
  6238. {
  6239. return escape(manualConvertUnicodeToUTF8(s));
  6240. }
  6241. function decodeCookie(s)
  6242. {
  6243. s = unescape(s);
  6244. var re = /&#[0-9]{1,5};/g;
  6245. return s.replace(re,function($0) {return String.fromCharCode(eval($0.replace(/[&#;]/g,"")));});
  6246. }
  6247. //--
  6248. //-- Saving
  6249. //--
  6250. var saveUsingSafari = false;
  6251. var startSaveArea = '<div id="' + 'storeArea">'; // Split up into two so that indexOf() of this source doesn't find it
  6252. var endSaveArea = '</d' + 'iv>';
  6253. // If there are unsaved changes, force the user to confirm before exitting
  6254. function confirmExit()
  6255. {
  6256. hadConfirmExit = true;
  6257. if((store && store.isDirty && store.isDirty()) || (story && story.areAnyDirty && story.areAnyDirty()))
  6258. return config.messages.confirmExit;
  6259. }
  6260. // Give the user a chance to save changes before exitting
  6261. function checkUnsavedChanges()
  6262. {
  6263. if(store && store.isDirty && store.isDirty() && window.hadConfirmExit === false) {
  6264. if(confirm(config.messages.unsavedChangesWarning))
  6265. saveChanges();
  6266. }
  6267. }
  6268. function updateLanguageAttribute(s)
  6269. {
  6270. if(config.locale) {
  6271. var mRE = /(<html(?:.*?)?)(?: xml:lang\="([a-z]+)")?(?: lang\="([a-z]+)")?>/;
  6272. var m = mRE.exec(s);
  6273. if(m) {
  6274. var t = m[1];
  6275. if(m[2])
  6276. t += ' xml:lang="' + config.locale + '"';
  6277. if(m[3])
  6278. t += ' lang="' + config.locale + '"';
  6279. t += ">";
  6280. s = s.substr(0,m.index) + t + s.substr(m.index+m[0].length);
  6281. }
  6282. }
  6283. return s;
  6284. }
  6285. function updateMarkupBlock(s,blockName,tiddlerName)
  6286. {
  6287. return s.replaceChunk(
  6288. "<!--%0-START-->".format([blockName]),
  6289. "<!--%0-END-->".format([blockName]),
  6290. "\n" + store.getRecursiveTiddlerText(tiddlerName,"") + "\n");
  6291. }
  6292. function updateOriginal(original,posDiv)
  6293. {
  6294. if(!posDiv)
  6295. posDiv = locateStoreArea(original);
  6296. if(!posDiv) {
  6297. alert(config.messages.invalidFileError.format([localPath]));
  6298. return null;
  6299. }
  6300. var revised = original.substr(0,posDiv[0] + startSaveArea.length) + "\n" +
  6301. convertUnicodeToUTF8(store.allTiddlersAsHtml()) + "\n" +
  6302. original.substr(posDiv[1]);
  6303. var newSiteTitle = convertUnicodeToUTF8(getPageTitle()).htmlEncode();
  6304. revised = revised.replaceChunk("<title"+">","</title"+">"," " + newSiteTitle + " ");
  6305. revised = updateLanguageAttribute(revised);
  6306. revised = updateMarkupBlock(revised,"PRE-HEAD","MarkupPreHead");
  6307. revised = updateMarkupBlock(revised,"POST-HEAD","MarkupPostHead");
  6308. revised = updateMarkupBlock(revised,"PRE-BODY","MarkupPreBody");
  6309. revised = updateMarkupBlock(revised,"POST-SCRIPT","MarkupPostBody");
  6310. return revised;
  6311. }
  6312. function locateStoreArea(original)
  6313. {
  6314. // Locate the storeArea div's
  6315. var posOpeningDiv = original.indexOf(startSaveArea);
  6316. var limitClosingDiv = original.indexOf("<"+"!--POST-STOREAREA--"+">");
  6317. if(limitClosingDiv == -1)
  6318. limitClosingDiv = original.indexOf("<"+"!--POST-BODY-START--"+">");
  6319. var posClosingDiv = original.lastIndexOf(endSaveArea,limitClosingDiv == -1 ? original.length : limitClosingDiv);
  6320. return (posOpeningDiv != -1 && posClosingDiv != -1) ? [posOpeningDiv,posClosingDiv] : null;
  6321. }
  6322. function autoSaveChanges(onlyIfDirty,tiddlers)
  6323. {
  6324. if(config.options.chkAutoSave)
  6325. saveChanges(onlyIfDirty,tiddlers);
  6326. }
  6327. // Save this tiddlywiki with the pending changes
  6328. function saveChanges(onlyIfDirty,tiddlers)
  6329. {
  6330. if(onlyIfDirty && !store.isDirty())
  6331. return;
  6332. clearMessage();
  6333. // Get the URL of the document
  6334. var originalPath = document.location.toString();
  6335. // Check we were loaded from a file URL
  6336. if(originalPath.substr(0,5) != "file:") {
  6337. alert(config.messages.notFileUrlError);
  6338. if(store.tiddlerExists(config.messages.saveInstructions))
  6339. story.displayTiddler(null,config.messages.saveInstructions);
  6340. return;
  6341. }
  6342. var localPath = getLocalPath(originalPath);
  6343. // Load the original file
  6344. var original = loadFile(localPath);
  6345. if(original == null) {
  6346. alert(config.messages.cantSaveError);
  6347. if(store.tiddlerExists(config.messages.saveInstructions))
  6348. story.displayTiddler(null,config.messages.saveInstructions);
  6349. return;
  6350. }
  6351. // Locate the storeArea div's
  6352. var posDiv = locateStoreArea(original);
  6353. if(!posDiv) {
  6354. alert(config.messages.invalidFileError.format([localPath]));
  6355. return;
  6356. }
  6357. saveBackup(localPath,original);
  6358. saveRss(localPath);
  6359. saveEmpty(localPath,original,posDiv);
  6360. saveMain(localPath,original,posDiv);
  6361. }
  6362. function saveBackup(localPath,original)
  6363. {
  6364. // Save the backup
  6365. if(config.options.chkSaveBackups) {
  6366. var backupPath = getBackupPath(localPath);
  6367. var backup = config.browser.isIE ? ieCopyFile(backupPath,localPath) : saveFile(backupPath,original);
  6368. if(backup)
  6369. displayMessage(config.messages.backupSaved,"file://" + backupPath);
  6370. else
  6371. alert(config.messages.backupFailed);
  6372. }
  6373. }
  6374. function saveRss(localPath)
  6375. {
  6376. if(config.options.chkGenerateAnRssFeed) {
  6377. var rssPath = localPath.substr(0,localPath.lastIndexOf(".")) + ".xml";
  6378. var rssSave = saveFile(rssPath,convertUnicodeToUTF8(generateRss()));
  6379. if(rssSave)
  6380. displayMessage(config.messages.rssSaved,"file://" + rssPath);
  6381. else
  6382. alert(config.messages.rssFailed);
  6383. }
  6384. }
  6385. function saveEmpty(localPath,original,posDiv)
  6386. {
  6387. if(config.options.chkSaveEmptyTemplate) {
  6388. var emptyPath,p;
  6389. if((p = localPath.lastIndexOf("/")) != -1)
  6390. emptyPath = localPath.substr(0,p) + "/empty.html";
  6391. else if((p = localPath.lastIndexOf("\\")) != -1)
  6392. emptyPath = localPath.substr(0,p) + "\\empty.html";
  6393. else
  6394. emptyPath = localPath + ".empty.html";
  6395. var empty = original.substr(0,posDiv[0] + startSaveArea.length) + original.substr(posDiv[1]);
  6396. var emptySave = saveFile(emptyPath,empty);
  6397. if(emptySave)
  6398. displayMessage(config.messages.emptySaved,"file://" + emptyPath);
  6399. else
  6400. alert(config.messages.emptyFailed);
  6401. }
  6402. }
  6403. function saveMain(localPath,original,posDiv)
  6404. {
  6405. var save;
  6406. try {
  6407. var revised = updateOriginal(original,posDiv);
  6408. save = saveFile(localPath,revised);
  6409. } catch (ex) {
  6410. showException(ex);
  6411. }
  6412. if(save) {
  6413. displayMessage(config.messages.mainSaved,"file://" + localPath);
  6414. store.setDirty(false);
  6415. } else {
  6416. alert(config.messages.mainFailed);
  6417. }
  6418. }
  6419. function getLocalPath(origPath)
  6420. {
  6421. var originalPath = convertUriToUTF8(origPath,config.options.txtFileSystemCharSet);
  6422. // Remove any location or query part of the URL
  6423. var argPos = originalPath.indexOf("?");
  6424. if(argPos != -1)
  6425. originalPath = originalPath.substr(0,argPos);
  6426. var hashPos = originalPath.indexOf("#");
  6427. if(hashPos != -1)
  6428. originalPath = originalPath.substr(0,hashPos);
  6429. // Convert file://localhost/ to file:///
  6430. if(originalPath.indexOf("file://localhost/") == 0)
  6431. originalPath = "file://" + originalPath.substr(16);
  6432. // Convert to a native file format
  6433. var localPath;
  6434. if(originalPath.charAt(9) == ":") // pc local file
  6435. localPath = unescape(originalPath.substr(8)).replace(new RegExp("/","g"),"\\");
  6436. else if(originalPath.indexOf("file://///") == 0) // FireFox pc network file
  6437. localPath = "\\\\" + unescape(originalPath.substr(10)).replace(new RegExp("/","g"),"\\");
  6438. else if(originalPath.indexOf("file:///") == 0) // mac/unix local file
  6439. localPath = unescape(originalPath.substr(7));
  6440. else if(originalPath.indexOf("file:/") == 0) // mac/unix local file
  6441. localPath = unescape(originalPath.substr(5));
  6442. else // pc network file
  6443. localPath = "\\\\" + unescape(originalPath.substr(7)).replace(new RegExp("/","g"),"\\");
  6444. return localPath;
  6445. }
  6446. function getBackupPath(localPath)
  6447. {
  6448. var backSlash = true;
  6449. var dirPathPos = localPath.lastIndexOf("\\");
  6450. if(dirPathPos == -1) {
  6451. dirPathPos = localPath.lastIndexOf("/");
  6452. backSlash = false;
  6453. }
  6454. var backupFolder = config.options.txtBackupFolder;
  6455. if(!backupFolder || backupFolder == "")
  6456. backupFolder = ".";
  6457. var backupPath = localPath.substr(0,dirPathPos) + (backSlash ? "\\" : "/") + backupFolder + localPath.substr(dirPathPos);
  6458. backupPath = backupPath.substr(0,backupPath.lastIndexOf(".")) + "." + (new Date()).convertToYYYYMMDDHHMMSSMMM() + ".html";
  6459. return backupPath;
  6460. }
  6461. function generateRss()
  6462. {
  6463. var s = [];
  6464. var d = new Date();
  6465. var u = store.getTiddlerText("SiteUrl");
  6466. // Assemble the header
  6467. s.push("<" + "?xml version=\"1.0\"?" + ">");
  6468. s.push("<rss version=\"2.0\">");
  6469. s.push("<channel>");
  6470. s.push("<title" + ">" + wikifyPlain("SiteTitle").htmlEncode() + "</title" + ">");
  6471. if(u)
  6472. s.push("<link>" + u.htmlEncode() + "</link>");
  6473. s.push("<description>" + wikifyPlain("SiteSubtitle").htmlEncode() + "</description>");
  6474. s.push("<language>en-us</language>");
  6475. s.push("<copyright>Copyright " + d.getFullYear() + " " + config.options.txtUserName.htmlEncode() + "</copyright>");
  6476. s.push("<pubDate>" + d.toGMTString() + "</pubDate>");
  6477. s.push("<lastBuildDate>" + d.toGMTString() + "</lastBuildDate>");
  6478. s.push("<docs>http://blogs.law.harvard.edu/tech/rss</docs>");
  6479. s.push("<generator>TiddlyWiki " + version.major + "." + version.minor + "." + version.revision + "</generator>");
  6480. // The body
  6481. var tiddlers = store.getTiddlers("modified","excludeLists");
  6482. var n = config.numRssItems > tiddlers.length ? 0 : tiddlers.length-config.numRssItems;
  6483. for (var t=tiddlers.length-1; t>=n; t--)
  6484. s.push(tiddlers[t].saveToRss(u));
  6485. // And footer
  6486. s.push("</channel>");
  6487. s.push("</rss>");
  6488. // Save it all
  6489. return s.join("\n");
  6490. }
  6491. //--
  6492. //-- Filesystem code
  6493. //--
  6494. function convertUTF8ToUnicode(u)
  6495. {
  6496. if(window.netscape == undefined)
  6497. return manualConvertUTF8ToUnicode(u);
  6498. else
  6499. return mozConvertUTF8ToUnicode(u);
  6500. }
  6501. function manualConvertUTF8ToUnicode(utf)
  6502. {
  6503. var uni = utf;
  6504. var src = 0;
  6505. var dst = 0;
  6506. var b1, b2, b3;
  6507. var c;
  6508. while(src < utf.length) {
  6509. b1 = utf.charCodeAt(src++);
  6510. if(b1 < 0x80) {
  6511. dst++;
  6512. } else if(b1 < 0xE0) {
  6513. b2 = utf.charCodeAt(src++);
  6514. c = String.fromCharCode(((b1 & 0x1F) << 6) | (b2 & 0x3F));
  6515. uni = uni.substring(0,dst++).concat(c,utf.substr(src));
  6516. } else {
  6517. b2 = utf.charCodeAt(src++);
  6518. b3 = utf.charCodeAt(src++);
  6519. c = String.fromCharCode(((b1 & 0xF) << 12) | ((b2 & 0x3F) << 6) | (b3 & 0x3F));
  6520. uni = uni.substring(0,dst++).concat(c,utf.substr(src));
  6521. }
  6522. }
  6523. return uni;
  6524. }
  6525. function mozConvertUTF8ToUnicode(u)
  6526. {
  6527. try {
  6528. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  6529. var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
  6530. converter.charset = "UTF-8";
  6531. } catch(ex) {
  6532. return manualConvertUTF8ToUnicode(u);
  6533. } // fallback
  6534. var s = converter.ConvertToUnicode(u);
  6535. var fin = converter.Finish();
  6536. return (fin.length > 0) ? s+fin : s;
  6537. }
  6538. function convertUnicodeToUTF8(s)
  6539. {
  6540. if(window.netscape == undefined)
  6541. return manualConvertUnicodeToUTF8(s);
  6542. else
  6543. return mozConvertUnicodeToUTF8(s);
  6544. }
  6545. function manualConvertUnicodeToUTF8(s)
  6546. {
  6547. var re = /[^\u0000-\u007F]/g ;
  6548. return s.replace(re,function($0) {return "&#" + $0.charCodeAt(0).toString() + ";";});
  6549. }
  6550. function mozConvertUnicodeToUTF8(s)
  6551. {
  6552. try {
  6553. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  6554. var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
  6555. converter.charset = "UTF-8";
  6556. } catch(ex) {
  6557. return manualConvertUnicodeToUTF8(s);
  6558. } // fallback
  6559. var u = converter.ConvertFromUnicode(s);
  6560. var fin = converter.Finish();
  6561. if(fin.length > 0)
  6562. return u + fin;
  6563. else
  6564. return u;
  6565. }
  6566. function convertUriToUTF8(uri,charSet)
  6567. {
  6568. if(window.netscape == undefined || charSet == undefined || charSet == "")
  6569. return uri;
  6570. try {
  6571. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  6572. var converter = Components.classes["@mozilla.org/intl/utf8converterservice;1"].getService(Components.interfaces.nsIUTF8ConverterService);
  6573. } catch(ex) {
  6574. return uri;
  6575. }
  6576. return converter.convertURISpecToUTF8(uri,charSet);
  6577. }
  6578. function saveFile(fileUrl,content)
  6579. {
  6580. var r = null;
  6581. if(!r)
  6582. r = mozillaSaveFile(fileUrl,content);
  6583. if(!r)
  6584. r = ieSaveFile(fileUrl,content);
  6585. if(!r)
  6586. r = javaSaveFile(fileUrl,content);
  6587. return r;
  6588. }
  6589. function loadFile(fileUrl)
  6590. {
  6591. var r = null;
  6592. if((r == null) || (r == false))
  6593. r = mozillaLoadFile(fileUrl);
  6594. if((r == null) || (r == false))
  6595. r = ieLoadFile(fileUrl);
  6596. if((r == null) || (r == false))
  6597. r = javaLoadFile(fileUrl);
  6598. return r;
  6599. }
  6600. // Returns null if it can't do it, false if there's an error, true if it saved OK
  6601. function ieSaveFile(filePath,content)
  6602. {
  6603. try {
  6604. var fso = new ActiveXObject("Scripting.FileSystemObject");
  6605. } catch(ex) {
  6606. return null;
  6607. }
  6608. var file = fso.OpenTextFile(filePath,2,-1,0);
  6609. file.Write(content);
  6610. file.Close();
  6611. return true;
  6612. }
  6613. // Returns null if it can't do it, false if there's an error, or a string of the content if successful
  6614. function ieLoadFile(filePath)
  6615. {
  6616. try {
  6617. var fso = new ActiveXObject("Scripting.FileSystemObject");
  6618. var file = fso.OpenTextFile(filePath,1);
  6619. var content = file.ReadAll();
  6620. file.Close();
  6621. } catch(ex) {
  6622. return null;
  6623. }
  6624. return content;
  6625. }
  6626. function ieCopyFile(dest,source)
  6627. {
  6628. try {
  6629. var fso = new ActiveXObject("Scripting.FileSystemObject");
  6630. fso.GetFile(source).Copy(dest);
  6631. } catch(ex) {
  6632. return false;
  6633. }
  6634. return true;
  6635. }
  6636. // Returns null if it can't do it, false if there's an error, true if it saved OK
  6637. function mozillaSaveFile(filePath,content)
  6638. {
  6639. if(window.Components) {
  6640. try {
  6641. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  6642. var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  6643. file.initWithPath(filePath);
  6644. if(!file.exists())
  6645. file.create(0,0664);
  6646. var out = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
  6647. out.init(file,0x20|0x02,00004,null);
  6648. out.write(content,content.length);
  6649. out.flush();
  6650. out.close();
  6651. return true;
  6652. } catch(ex) {
  6653. return false;
  6654. }
  6655. }
  6656. return null;
  6657. }
  6658. // Returns null if it can't do it, false if there's an error, or a string of the content if successful
  6659. function mozillaLoadFile(filePath)
  6660. {
  6661. if(window.Components) {
  6662. try {
  6663. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  6664. var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  6665. file.initWithPath(filePath);
  6666. if(!file.exists())
  6667. return null;
  6668. var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
  6669. inputStream.init(file,0x01,00004,null);
  6670. var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
  6671. sInputStream.init(inputStream);
  6672. return sInputStream.read(sInputStream.available());
  6673. } catch(ex) {
  6674. return false;
  6675. }
  6676. }
  6677. return null;
  6678. }
  6679. function javaUrlToFilename(url)
  6680. {
  6681. var f = "//localhost";
  6682. if(url.indexOf(f) == 0)
  6683. return url.substring(f.length);
  6684. var i = url.indexOf(":");
  6685. if(i > 0)
  6686. return url.substring(i-1);
  6687. return url;
  6688. }
  6689. function javaSaveFile(filePath,content)
  6690. {
  6691. try {
  6692. if(document.applets["TiddlySaver"])
  6693. return document.applets["TiddlySaver"].saveFile(javaUrlToFilename(filePath),"UTF-8",content);
  6694. } catch(ex) {
  6695. }
  6696. try {
  6697. var s = new java.io.PrintStream(new java.io.FileOutputStream(javaUrlToFilename(filePath)));
  6698. s.print(content);
  6699. s.close();
  6700. } catch(ex) {
  6701. return null;
  6702. }
  6703. return true;
  6704. }
  6705. function javaLoadFile(filePath)
  6706. {
  6707. try {
  6708. if(document.applets["TiddlySaver"])
  6709. return String(document.applets["TiddlySaver"].loadFile(javaUrlToFilename(filePath),"UTF-8"));
  6710. } catch(ex) {
  6711. }
  6712. var content = [];
  6713. try {
  6714. var r = new java.io.BufferedReader(new java.io.FileReader(javaUrlToFilename(filePath)));
  6715. var line;
  6716. while((line = r.readLine()) != null)
  6717. content.push(new String(line));
  6718. r.close();
  6719. } catch(ex) {
  6720. return null;
  6721. }
  6722. return content.join("\n");
  6723. }
  6724. //--
  6725. //-- Server adaptor for talking to static files
  6726. //--
  6727. function FileAdaptor()
  6728. {
  6729. this.host = null;
  6730. this.store = null;
  6731. return this;
  6732. }
  6733. FileAdaptor.NotLoadedError = "TiddlyWiki file has not been loaded";
  6734. FileAdaptor.serverType = 'file';
  6735. // Open the specified host/server
  6736. FileAdaptor.prototype.openHost = function(host,context,userParams,callback)
  6737. {
  6738. this.host = host;
  6739. if(!context)
  6740. context = {};
  6741. context.adaptor = this;
  6742. context.callback = callback;
  6743. context.userParams = userParams;
  6744. var ret = loadRemoteFile(host,FileAdaptor.openHostCallback,context);
  6745. return typeof(ret) == "string" ? ret : true;
  6746. };
  6747. FileAdaptor.openHostCallback = function(status,context,responseText,url,xhr)
  6748. {
  6749. var adaptor = context.adaptor;
  6750. context.status = status;
  6751. if(!status) {
  6752. context.statusText = "Error reading file: " + xhr.statusText;
  6753. } else {
  6754. // Load the content into a TiddlyWiki() object
  6755. adaptor.store = new TiddlyWiki();
  6756. if(!adaptor.store.importTiddlyWiki(responseText))
  6757. context.statusText = config.messages.invalidFileError.format([url]);
  6758. }
  6759. context.callback(context,context.userParams);
  6760. };
  6761. // Gets the list of workspaces on a given server
  6762. FileAdaptor.prototype.getWorkspaceList = function(context,userParams,callback)
  6763. {
  6764. if(!context)
  6765. context = {};
  6766. context.workspaces = [{title:"(default)"}];
  6767. context.status = true;
  6768. window.setTimeout(function() {callback(context,userParams);},10);
  6769. return true;
  6770. };
  6771. // Open the specified workspace
  6772. FileAdaptor.prototype.openWorkspace = function(workspace,context,userParams,callback)
  6773. {
  6774. if(!context)
  6775. context = {};
  6776. context.status = true;
  6777. window.setTimeout(function() {callback(context,userParams);},10);
  6778. return true;
  6779. };
  6780. // Gets the list of tiddlers within a given workspace
  6781. FileAdaptor.prototype.getTiddlerList = function(context,userParams,callback)
  6782. {
  6783. if(!this.store)
  6784. return FileAdaptor.NotLoadedError;
  6785. if(!context)
  6786. context = {};
  6787. context.tiddlers = [];
  6788. this.store.forEachTiddler(function(title,tiddler)
  6789. {
  6790. var t = new Tiddler(title);
  6791. t.text = tiddler.text;
  6792. t.modified = tiddler.modified;
  6793. t.modifier = tiddler.modifier;
  6794. t.fields['server.page.revision'] = tiddler.modified.convertToYYYYMMDDHHMM();
  6795. t.tags = tiddler.tags;
  6796. context.tiddlers.push(t);
  6797. });
  6798. context.status = true;
  6799. window.setTimeout(function() {callback(context,userParams);},10);
  6800. return true;
  6801. };
  6802. FileAdaptor.prototype.generateTiddlerInfo = function(tiddler)
  6803. {
  6804. var info = {};
  6805. info.uri = tiddler.fields['server.host'] + "#" + tiddler.title;
  6806. return info;
  6807. };
  6808. // Retrieves a tiddler from a given workspace on a given server
  6809. FileAdaptor.prototype.getTiddler = function(title,context,userParams,callback)
  6810. {
  6811. if(!this.store)
  6812. return FileAdaptor.NotLoadedError;
  6813. if(!context)
  6814. context = {};
  6815. context.tiddler = this.store.fetchTiddler(title);
  6816. if(context.tiddler) {
  6817. context.tiddler.fields['server.type'] = FileAdaptor.serverType;
  6818. context.tiddler.fields['server.host'] = this.host;
  6819. context.tiddler.fields['server.page.revision'] = context.tiddler.modified.convertToYYYYMMDDHHMM();
  6820. }
  6821. context.status = true;
  6822. if(context.allowSynchronous) {
  6823. context.isSynchronous = true;
  6824. callback(context,userParams);
  6825. } else {
  6826. window.setTimeout(function() {callback(context,userParams);},10);
  6827. }
  6828. return true;
  6829. };
  6830. FileAdaptor.prototype.close = function()
  6831. {
  6832. delete this.store;
  6833. this.store = null;
  6834. };
  6835. config.adaptors[FileAdaptor.serverType] = FileAdaptor;
  6836. //--
  6837. //-- Remote HTTP requests
  6838. //--
  6839. function loadRemoteFile(url,callback,params)
  6840. {
  6841. return doHttp("GET",url,null,null,null,null,callback,params,null);
  6842. }
  6843. // HTTP status codes
  6844. var httpStatus = {
  6845. OK: 200,
  6846. ContentCreated: 201,
  6847. NoContent: 204,
  6848. Unauthorized: 401,
  6849. Forbidden: 403,
  6850. NotFound: 404,
  6851. MethodNotAllowed: 405
  6852. };
  6853. function doHttp(type,url,data,contentType,username,password,callback,params,headers)
  6854. {
  6855. // Get an xhr object
  6856. var x = getXMLHttpRequest();
  6857. if(!x)
  6858. return "Can't create XMLHttpRequest object";
  6859. // Install callback
  6860. x.onreadystatechange = function() {
  6861. if (x.readyState == 4 && callback && (x.status !== undefined)) {
  6862. if([0, httpStatus.OK, httpStatus.ContentCreated, httpStatus.NoContent].contains(x.status))
  6863. callback(true,params,x.responseText,url,x);
  6864. else
  6865. callback(false,params,null,url,x);
  6866. x.onreadystatechange = function(){};
  6867. x = null;
  6868. }
  6869. };
  6870. // Send request
  6871. if(window.Components && window.netscape && window.netscape.security && document.location.protocol.indexOf("http") == -1)
  6872. window.netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
  6873. try {
  6874. url = url + (url.indexOf("?") < 0 ? "?" : "&") + "nocache=" + Math.random();
  6875. x.open(type,url,true,username,password);
  6876. if (data)
  6877. x.setRequestHeader("Content-Type", contentType ? contentType : "application/x-www-form-urlencoded");
  6878. if (x.overrideMimeType)
  6879. x.setRequestHeader("Connection", "close");
  6880. if(headers) {
  6881. for(n in headers)
  6882. x.setRequestHeader(n,headers[n]);
  6883. }
  6884. x.setRequestHeader("X-Requested-With", "TiddlyWiki " + version.major + "." + version.minor + "." + version.revision + (version.beta ? " (beta " + version.beta + ")" : ""));
  6885. x.send(data);
  6886. } catch (ex) {
  6887. return exceptionText(ex);
  6888. }
  6889. return x;
  6890. }
  6891. function getXMLHttpRequest()
  6892. {
  6893. try {
  6894. var x = new XMLHttpRequest(); // Modern
  6895. } catch(ex) {
  6896. try {
  6897. x = new ActiveXObject("Msxml2.XMLHTTP"); // IE 6
  6898. } catch (ex2) {
  6899. return null;
  6900. }
  6901. }
  6902. return x;
  6903. }
  6904. //--
  6905. //-- TiddlyWiki-specific utility functions
  6906. //--
  6907. function createTiddlyButton(theParent,theText,theTooltip,theAction,theClass,theId,theAccessKey)
  6908. {
  6909. var theButton = document.createElement("a");
  6910. if(theAction) {
  6911. theButton.onclick = theAction;
  6912. theButton.setAttribute("href","javascript:;");
  6913. }
  6914. if(theTooltip)
  6915. theButton.setAttribute("title",theTooltip);
  6916. if(theText)
  6917. theButton.appendChild(document.createTextNode(theText));
  6918. if(theClass)
  6919. theButton.className = theClass;
  6920. else
  6921. theButton.className = "button";
  6922. if(theId)
  6923. theButton.id = theId;
  6924. if(theParent)
  6925. theParent.appendChild(theButton);
  6926. if(theAccessKey)
  6927. theButton.setAttribute("accessKey",theAccessKey);
  6928. return theButton;
  6929. }
  6930. function createTiddlyLink(place,title,includeText,theClass,isStatic,linkedFromTiddler,noToggle)
  6931. {
  6932. var text = includeText ? title : null;
  6933. var i = getTiddlyLinkInfo(title,theClass);
  6934. var btn = isStatic ? createExternalLink(place,store.getTiddlerText("SiteUrl",null) + "#" + title) : createTiddlyButton(place,text,i.subTitle,onClickTiddlerLink,i.classes);
  6935. btn.setAttribute("refresh","link");
  6936. btn.setAttribute("tiddlyLink",title);
  6937. if(noToggle)
  6938. btn.setAttribute("noToggle","true");
  6939. if(linkedFromTiddler) {
  6940. var fields = linkedFromTiddler.getInheritedFields();
  6941. if(fields)
  6942. btn.setAttribute("tiddlyFields",fields);
  6943. }
  6944. return btn;
  6945. }
  6946. function refreshTiddlyLink(e,title)
  6947. {
  6948. var i = getTiddlyLinkInfo(title,e.className);
  6949. e.className = i.classes;
  6950. e.title = i.subTitle;
  6951. }
  6952. function getTiddlyLinkInfo(title,currClasses)
  6953. {
  6954. var classes = currClasses ? currClasses.split(" ") : [];
  6955. classes.pushUnique("tiddlyLink");
  6956. var tiddler = store.fetchTiddler(title);
  6957. var subTitle;
  6958. if(tiddler) {
  6959. subTitle = tiddler.getSubtitle();
  6960. classes.pushUnique("tiddlyLinkExisting");
  6961. classes.remove("tiddlyLinkNonExisting");
  6962. classes.remove("shadow");
  6963. } else {
  6964. classes.remove("tiddlyLinkExisting");
  6965. classes.pushUnique("tiddlyLinkNonExisting");
  6966. if(store.isShadowTiddler(title)) {
  6967. subTitle = config.messages.shadowedTiddlerToolTip.format([title]);
  6968. classes.pushUnique("shadow");
  6969. } else {
  6970. subTitle = config.messages.undefinedTiddlerToolTip.format([title]);
  6971. classes.remove("shadow");
  6972. }
  6973. }
  6974. if(config.annotations[title])
  6975. subTitle = config.annotations[title];
  6976. return {classes: classes.join(" "),subTitle: subTitle};
  6977. }
  6978. function createExternalLink(place,url)
  6979. {
  6980. var theLink = document.createElement("a");
  6981. theLink.className = "externalLink";
  6982. theLink.href = url;
  6983. theLink.title = config.messages.externalLinkTooltip.format([url]);
  6984. if(config.options.chkOpenInNewWindow)
  6985. theLink.target = "_blank";
  6986. place.appendChild(theLink);
  6987. return theLink;
  6988. }
  6989. // Event handler for clicking on a tiddly link
  6990. function onClickTiddlerLink(e)
  6991. {
  6992. if(!e) e = window.event;
  6993. var theTarget = resolveTarget(e);
  6994. var theLink = theTarget;
  6995. var title = null;
  6996. var fields = null;
  6997. var noToggle = null;
  6998. do {
  6999. title = theLink.getAttribute("tiddlyLink");
  7000. fields = theLink.getAttribute("tiddlyFields");
  7001. noToggle = theLink.getAttribute("noToggle");
  7002. theLink = theLink.parentNode;
  7003. } while(title == null && theLink != null);
  7004. if(!fields && !store.isShadowTiddler(title))
  7005. fields = String.encodeHashMap(config.defaultCustomFields);
  7006. if(title) {
  7007. var toggling = e.metaKey || e.ctrlKey;
  7008. if(config.options.chkToggleLinks)
  7009. toggling = !toggling;
  7010. if(noToggle)
  7011. toggling = false;
  7012. story.displayTiddler(theTarget,title,null,true,null,fields,toggling);
  7013. }
  7014. clearMessage();
  7015. return false;
  7016. }
  7017. // Create a button for a tag with a popup listing all the tiddlers that it tags
  7018. function createTagButton(place,tag,excludeTiddler)
  7019. {
  7020. var theTag = createTiddlyButton(place,tag,config.views.wikified.tag.tooltip.format([tag]),onClickTag);
  7021. theTag.setAttribute("tag",tag);
  7022. if(excludeTiddler)
  7023. theTag.setAttribute("tiddler",excludeTiddler);
  7024. return theTag;
  7025. }
  7026. // Event handler for clicking on a tiddler tag
  7027. function onClickTag(e)
  7028. {
  7029. if(!e) var e = window.event;
  7030. var theTarget = resolveTarget(e);
  7031. var popup = Popup.create(this);
  7032. var tag = this.getAttribute("tag");
  7033. var title = this.getAttribute("tiddler");
  7034. if(popup && tag) {
  7035. var tagged = store.getTaggedTiddlers(tag);
  7036. var titles = [];
  7037. var li,r;
  7038. for(r=0;r<tagged.length;r++) {
  7039. if(tagged[r].title != title)
  7040. titles.push(tagged[r].title);
  7041. }
  7042. var lingo = config.views.wikified.tag;
  7043. if(titles.length > 0) {
  7044. var openAll = createTiddlyButton(createTiddlyElement(popup,"li"),lingo.openAllText.format([tag]),lingo.openAllTooltip,onClickTagOpenAll);
  7045. openAll.setAttribute("tag",tag);
  7046. createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
  7047. for(r=0; r<titles.length; r++) {
  7048. createTiddlyLink(createTiddlyElement(popup,"li"),titles[r],true);
  7049. }
  7050. } else {
  7051. createTiddlyText(createTiddlyElement(popup,"li",null,"disabled"),lingo.popupNone.format([tag]));
  7052. }
  7053. createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
  7054. var h = createTiddlyLink(createTiddlyElement(popup,"li"),tag,false);
  7055. createTiddlyText(h,lingo.openTag.format([tag]));
  7056. }
  7057. Popup.show();
  7058. e.cancelBubble = true;
  7059. if(e.stopPropagation) e.stopPropagation();
  7060. return false;
  7061. }
  7062. // Event handler for 'open all' on a tiddler popup
  7063. function onClickTagOpenAll(e)
  7064. {
  7065. if(!e) var e = window.event;
  7066. var tag = this.getAttribute("tag");
  7067. var tagged = store.getTaggedTiddlers(tag);
  7068. var titles = [];
  7069. for(var t=0; t<tagged.length; t++)
  7070. titles.push(tagged[t].title);
  7071. story.displayTiddlers(this,titles);
  7072. return false;
  7073. }
  7074. function onClickError(e)
  7075. {
  7076. if(!e) var e = window.event;
  7077. var popup = Popup.create(this);
  7078. var lines = this.getAttribute("errorText").split("\n");
  7079. for(var t=0; t<lines.length; t++)
  7080. createTiddlyElement(popup,"li",null,null,lines[t]);
  7081. Popup.show();
  7082. e.cancelBubble = true;
  7083. if(e.stopPropagation) e.stopPropagation();
  7084. return false;
  7085. }
  7086. function createTiddlyDropDown(place,onchange,options,defaultValue)
  7087. {
  7088. var sel = createTiddlyElement(place,"select");
  7089. sel.onchange = onchange;
  7090. for(var t=0; t<options.length; t++) {
  7091. var e = createTiddlyElement(sel,"option",null,null,options[t].caption);
  7092. e.value = options[t].name;
  7093. if(options[t].name == defaultValue)
  7094. e.selected = true;
  7095. }
  7096. return sel;
  7097. }
  7098. function createTiddlyPopup(place,caption,tooltip,tiddler)
  7099. {
  7100. if(tiddler.text) {
  7101. createTiddlyLink(place,caption,true);
  7102. var btn = createTiddlyButton(place,glyph("downArrow"),tooltip,onClickTiddlyPopup,"tiddlerPopupButton");
  7103. btn.tiddler = tiddler;
  7104. } else {
  7105. createTiddlyText(place,caption);
  7106. }
  7107. }
  7108. function onClickTiddlyPopup(e)
  7109. {
  7110. if(!e) var e = window.event;
  7111. var tiddler = this.tiddler;
  7112. if(tiddler.text) {
  7113. var popup = Popup.create(this,"div","popupTiddler");
  7114. wikify(tiddler.text,popup,null,tiddler);
  7115. Popup.show();
  7116. }
  7117. if(e) e.cancelBubble = true;
  7118. if(e && e.stopPropagation) e.stopPropagation();
  7119. return false;
  7120. }
  7121. function createTiddlyError(place,title,text)
  7122. {
  7123. var btn = createTiddlyButton(place,title,null,onClickError,"errorButton");
  7124. if(text) btn.setAttribute("errorText",text);
  7125. }
  7126. function merge(dst,src,preserveExisting)
  7127. {
  7128. for(p in src) {
  7129. if(!preserveExisting || dst[p] === undefined)
  7130. dst[p] = src[p];
  7131. }
  7132. return dst;
  7133. }
  7134. // Returns a string containing the description of an exception, optionally prepended by a message
  7135. function exceptionText(e,message)
  7136. {
  7137. var s = e.description ? e.description : e.toString();
  7138. return message ? "%0:\n%1".format([message,s]) : s;
  7139. }
  7140. // Displays an alert of an exception description with optional message
  7141. function showException(e,message)
  7142. {
  7143. alert(exceptionText(e,message));
  7144. }
  7145. function alertAndThrow(m)
  7146. {
  7147. alert(m);
  7148. throw(m);
  7149. }
  7150. function glyph(name)
  7151. {
  7152. var g = config.glyphs;
  7153. var b = g.currBrowser;
  7154. if(b == null) {
  7155. b = 0;
  7156. while(!g.browsers[b]() && b < g.browsers.length-1)
  7157. b++;
  7158. g.currBrowser = b;
  7159. }
  7160. if(!g.codes[name])
  7161. return "";
  7162. return g.codes[name][b];
  7163. }
  7164. //-
  7165. //- Animation engine
  7166. //-
  7167. function Animator()
  7168. {
  7169. this.running = 0; // Incremented at start of each animation, decremented afterwards. If zero, the interval timer is disabled
  7170. this.timerID = 0; // ID of the timer used for animating
  7171. this.animations = []; // List of animations in progress
  7172. return this;
  7173. }
  7174. // Start animation engine
  7175. Animator.prototype.startAnimating = function() // Variable number of arguments
  7176. {
  7177. for(var t=0; t<arguments.length; t++)
  7178. this.animations.push(arguments[t]);
  7179. if(this.running == 0) {
  7180. var me = this;
  7181. this.timerID = window.setInterval(function() {me.doAnimate(me);},10);
  7182. }
  7183. this.running += arguments.length;
  7184. };
  7185. // Perform an animation engine tick, calling each of the known animation modules
  7186. Animator.prototype.doAnimate = function(me)
  7187. {
  7188. var a = 0;
  7189. while(a < me.animations.length) {
  7190. var animation = me.animations[a];
  7191. if(animation.tick()) {
  7192. a++;
  7193. } else {
  7194. me.animations.splice(a,1);
  7195. if(--me.running == 0)
  7196. window.clearInterval(me.timerID);
  7197. }
  7198. }
  7199. };
  7200. // Map a 0..1 value to 0..1, but slow down at the start and end
  7201. Animator.slowInSlowOut = function(progress)
  7202. {
  7203. return(1-((Math.cos(progress * Math.PI)+1)/2));
  7204. };
  7205. //--
  7206. //-- Morpher animation
  7207. //--
  7208. // Animate a set of properties of an element
  7209. function Morpher(element,duration,properties,callback)
  7210. {
  7211. this.element = element;
  7212. this.duration = duration;
  7213. this.properties = properties;
  7214. this.startTime = new Date();
  7215. this.endTime = Number(this.startTime) + duration;
  7216. this.callback = callback;
  7217. this.tick();
  7218. return this;
  7219. }
  7220. Morpher.prototype.assignStyle = function(element,style,value)
  7221. {
  7222. switch(style) {
  7223. case "-tw-vertScroll":
  7224. window.scrollTo(findScrollX(),value);
  7225. break;
  7226. case "-tw-horizScroll":
  7227. window.scrollTo(value,findScrollY());
  7228. break;
  7229. default:
  7230. element.style[style] = value;
  7231. break;
  7232. }
  7233. };
  7234. Morpher.prototype.stop = function()
  7235. {
  7236. for(var t=0; t<this.properties.length; t++) {
  7237. var p = this.properties[t];
  7238. if(p.atEnd !== undefined) {
  7239. this.assignStyle(this.element,p.style,p.atEnd);
  7240. }
  7241. }
  7242. if(this.callback)
  7243. this.callback(this.element,this.properties);
  7244. };
  7245. Morpher.prototype.tick = function()
  7246. {
  7247. var currTime = Number(new Date());
  7248. progress = Animator.slowInSlowOut(Math.min(1,(currTime-this.startTime)/this.duration));
  7249. for(var t=0; t<this.properties.length; t++) {
  7250. var p = this.properties[t];
  7251. if(p.start !== undefined && p.end !== undefined) {
  7252. var template = p.template ? p.template : "%0";
  7253. switch(p.format) {
  7254. case undefined:
  7255. case "style":
  7256. var v = p.start + (p.end-p.start) * progress;
  7257. this.assignStyle(this.element,p.style,template.format([v]));
  7258. break;
  7259. case "color":
  7260. break;
  7261. }
  7262. }
  7263. }
  7264. if(currTime >= this.endTime) {
  7265. this.stop();
  7266. return false;
  7267. }
  7268. return true;
  7269. };
  7270. //--
  7271. //-- Zoomer animation
  7272. //--
  7273. function Zoomer(text,startElement,targetElement,unused)
  7274. {
  7275. var e = createTiddlyElement(document.body,"div",null,"zoomer");
  7276. createTiddlyElement(e,"div",null,null,text);
  7277. var winWidth = findWindowWidth();
  7278. var winHeight = findWindowHeight();
  7279. var p = [
  7280. {style: 'left', start: findPosX(startElement), end: findPosX(targetElement), template: '%0px'},
  7281. {style: 'top', start: findPosY(startElement), end: findPosY(targetElement), template: '%0px'},
  7282. {style: 'width', start: Math.min(startElement.scrollWidth,winWidth), end: Math.min(targetElement.scrollWidth,winWidth), template: '%0px', atEnd: 'auto'},
  7283. {style: 'height', start: Math.min(startElement.scrollHeight,winHeight), end: Math.min(targetElement.scrollHeight,winHeight), template: '%0px', atEnd: 'auto'},
  7284. {style: 'fontSize', start: 8, end: 24, template: '%0pt'}
  7285. ];
  7286. var c = function(element,properties) {removeNode(element);};
  7287. return new Morpher(e,config.animDuration,p,c);
  7288. }
  7289. //--
  7290. //-- Scroller animation
  7291. //--
  7292. function Scroller(targetElement,unused)
  7293. {
  7294. var p = [
  7295. {style: '-tw-vertScroll', start: findScrollY(), end: ensureVisible(targetElement)}
  7296. ];
  7297. return new Morpher(targetElement,config.animDuration,p);
  7298. }
  7299. //--
  7300. //-- Slider animation
  7301. //--
  7302. // deleteMode - "none", "all" [delete target element and it's children], [only] "children" [but not the target element]
  7303. function Slider(element,opening,unused,deleteMode)
  7304. {
  7305. element.style.overflow = 'hidden';
  7306. if(opening)
  7307. element.style.height = '0px'; // Resolves a Firefox flashing bug
  7308. element.style.display = 'block';
  7309. var left = findPosX(element);
  7310. var width = element.scrollWidth;
  7311. var height = element.scrollHeight;
  7312. var winWidth = findWindowWidth();
  7313. var p = [];
  7314. var c = null;
  7315. if(opening) {
  7316. p.push({style: 'height', start: 0, end: height, template: '%0px', atEnd: 'auto'});
  7317. p.push({style: 'opacity', start: 0, end: 1, template: '%0'});
  7318. p.push({style: 'filter', start: 0, end: 100, template: 'alpha(opacity:%0)'});
  7319. } else {
  7320. p.push({style: 'height', start: height, end: 0, template: '%0px'});
  7321. p.push({style: 'display', atEnd: 'none'});
  7322. p.push({style: 'opacity', start: 1, end: 0, template: '%0'});
  7323. p.push({style: 'filter', start: 100, end: 0, template: 'alpha(opacity:%0)'});
  7324. switch(deleteMode) {
  7325. case "all":
  7326. c = function(element,properties) {removeNode(element);};
  7327. break;
  7328. case "children":
  7329. c = function(element,properties) {removeChildren(element);};
  7330. break;
  7331. }
  7332. }
  7333. return new Morpher(element,config.animDuration,p,c);
  7334. }
  7335. //--
  7336. //-- Popup menu
  7337. //--
  7338. var Popup = {
  7339. stack: [] // Array of objects with members root: and popup:
  7340. };
  7341. Popup.create = function(root,elem,theClass)
  7342. {
  7343. Popup.remove();
  7344. var popup = createTiddlyElement(document.body,elem ? elem : "ol","popup",theClass ? theClass : "popup");
  7345. Popup.stack.push({root: root, popup: popup});
  7346. return popup;
  7347. };
  7348. Popup.onDocumentClick = function(e)
  7349. {
  7350. if (!e) var e = window.event;
  7351. var target = resolveTarget(e);
  7352. if(e.eventPhase == undefined)
  7353. Popup.remove();
  7354. else if(e.eventPhase == Event.BUBBLING_PHASE || e.eventPhase == Event.AT_TARGET)
  7355. Popup.remove();
  7356. return true;
  7357. };
  7358. Popup.show = function(unused1,unused2)
  7359. {
  7360. var curr = Popup.stack[Popup.stack.length-1];
  7361. this.place(curr.root,curr.popup);
  7362. addClass(curr.root,"highlight");
  7363. if(config.options.chkAnimate && anim && typeof Scroller == "function")
  7364. anim.startAnimating(new Scroller(curr.popup));
  7365. else
  7366. window.scrollTo(0,ensureVisible(curr.popup));
  7367. };
  7368. Popup.place = function(root,popup,offset)
  7369. {
  7370. if(!offset) var offset = {x:0, y:0};
  7371. var rootLeft = findPosX(root);
  7372. var rootTop = findPosY(root);
  7373. var rootHeight = root.offsetHeight;
  7374. var popupLeft = rootLeft + offset.x;
  7375. var popupTop = rootTop + rootHeight + offset.y;
  7376. var winWidth = findWindowWidth();
  7377. if(popup.offsetWidth > winWidth*0.75)
  7378. popup.style.width = winWidth*0.75 + "px";
  7379. var popupWidth = popup.offsetWidth;
  7380. if(popupLeft + popupWidth > winWidth)
  7381. popupLeft = winWidth - popupWidth;
  7382. popup.style.left = popupLeft + "px";
  7383. popup.style.top = popupTop + "px";
  7384. popup.style.display = "block";
  7385. }
  7386. Popup.remove = function()
  7387. {
  7388. if(Popup.stack.length > 0) {
  7389. Popup.removeFrom(0);
  7390. }
  7391. };
  7392. Popup.removeFrom = function(from)
  7393. {
  7394. for(var t=Popup.stack.length-1; t>=from; t--) {
  7395. var p = Popup.stack[t];
  7396. removeClass(p.root,"highlight");
  7397. removeNode(p.popup);
  7398. }
  7399. Popup.stack = Popup.stack.slice(0,from);
  7400. };
  7401. //--
  7402. //-- Wizard support
  7403. //--
  7404. function Wizard(elem)
  7405. {
  7406. if(elem) {
  7407. this.formElem = findRelated(elem,"wizard","className");
  7408. this.bodyElem = findRelated(this.formElem.firstChild,"wizardBody","className","nextSibling");
  7409. this.footElem = findRelated(this.formElem.firstChild,"wizardFooter","className","nextSibling");
  7410. } else {
  7411. this.formElem = null;
  7412. this.bodyElem = null;
  7413. this.footElem = null;
  7414. }
  7415. }
  7416. Wizard.prototype.setValue = function(name,value)
  7417. {
  7418. if(this.formElem)
  7419. this.formElem[name] = value;
  7420. };
  7421. Wizard.prototype.getValue = function(name)
  7422. {
  7423. return this.formElem ? this.formElem[name] : null;
  7424. };
  7425. Wizard.prototype.createWizard = function(place,title)
  7426. {
  7427. this.formElem = createTiddlyElement(place,"form",null,"wizard");
  7428. createTiddlyElement(this.formElem,"h1",null,null,title);
  7429. this.bodyElem = createTiddlyElement(this.formElem,"div",null,"wizardBody");
  7430. this.footElem = createTiddlyElement(this.formElem,"div",null,"wizardFooter");
  7431. };
  7432. Wizard.prototype.clear = function()
  7433. {
  7434. removeChildren(this.bodyElem);
  7435. };
  7436. Wizard.prototype.setButtons = function(buttonInfo,status)
  7437. {
  7438. removeChildren(this.footElem);
  7439. for(var t=0; t<buttonInfo.length; t++) {
  7440. createTiddlyButton(this.footElem,buttonInfo[t].caption,buttonInfo[t].tooltip,buttonInfo[t].onClick);
  7441. insertSpacer(this.footElem);
  7442. }
  7443. if(typeof status == "string") {
  7444. createTiddlyElement(this.footElem,"span",null,"status",status);
  7445. }
  7446. };
  7447. Wizard.prototype.addStep = function(stepTitle,html)
  7448. {
  7449. removeChildren(this.bodyElem);
  7450. var w = createTiddlyElement(this.bodyElem,"div");
  7451. createTiddlyElement(w,"h2",null,null,stepTitle);
  7452. var step = createTiddlyElement(w,"div",null,"wizardStep");
  7453. step.innerHTML = html;
  7454. applyHtmlMacros(step,tiddler);
  7455. };
  7456. Wizard.prototype.getElement = function(name)
  7457. {
  7458. return this.formElem.elements[name];
  7459. };
  7460. //--
  7461. //-- ListView gadget
  7462. //--
  7463. var ListView = {};
  7464. // Create a listview
  7465. ListView.create = function(place,listObject,listTemplate,callback,className)
  7466. {
  7467. var table = createTiddlyElement(place,"table",null,className ? className : "listView twtable");
  7468. var thead = createTiddlyElement(table,"thead");
  7469. var r = createTiddlyElement(thead,"tr");
  7470. for(var t=0; t<listTemplate.columns.length; t++) {
  7471. var columnTemplate = listTemplate.columns[t];
  7472. var c = createTiddlyElement(r,"th");
  7473. var colType = ListView.columnTypes[columnTemplate.type];
  7474. if(colType && colType.createHeader)
  7475. colType.createHeader(c,columnTemplate,t);
  7476. }
  7477. var tbody = createTiddlyElement(table,"tbody");
  7478. for(var rc=0; rc<listObject.length; rc++) {
  7479. rowObject = listObject[rc];
  7480. r = createTiddlyElement(tbody,"tr");
  7481. for(c=0; c<listTemplate.rowClasses.length; c++) {
  7482. if(rowObject[listTemplate.rowClasses[c].field])
  7483. addClass(r,listTemplate.rowClasses[c].className);
  7484. }
  7485. rowObject.rowElement = r;
  7486. rowObject.colElements = {};
  7487. for(var cc=0; cc<listTemplate.columns.length; cc++) {
  7488. c = createTiddlyElement(r,"td");
  7489. columnTemplate = listTemplate.columns[cc];
  7490. var field = columnTemplate.field;
  7491. colType = ListView.columnTypes[columnTemplate.type];
  7492. if(colType && colType.createItem)
  7493. colType.createItem(c,rowObject,field,columnTemplate,cc,rc);
  7494. rowObject.colElements[field] = c;
  7495. }
  7496. }
  7497. if(callback && listTemplate.actions)
  7498. createTiddlyDropDown(place,ListView.getCommandHandler(callback),listTemplate.actions);
  7499. if(callback && listTemplate.buttons) {
  7500. for(t=0; t<listTemplate.buttons.length; t++) {
  7501. var a = listTemplate.buttons[t];
  7502. if(a && a.name != "")
  7503. createTiddlyButton(place,a.caption,null,ListView.getCommandHandler(callback,a.name,a.allowEmptySelection));
  7504. }
  7505. }
  7506. return table;
  7507. };
  7508. ListView.getCommandHandler = function(callback,name,allowEmptySelection)
  7509. {
  7510. return function(e) {
  7511. var view = findRelated(this,"TABLE",null,"previousSibling");
  7512. var tiddlers = [];
  7513. ListView.forEachSelector(view,function(e,rowName) {
  7514. if(e.checked)
  7515. tiddlers.push(rowName);
  7516. });
  7517. if(tiddlers.length == 0 && !allowEmptySelection) {
  7518. alert(config.messages.nothingSelected);
  7519. } else {
  7520. if(this.nodeName.toLowerCase() == "select") {
  7521. callback(view,this.value,tiddlers);
  7522. this.selectedIndex = 0;
  7523. } else {
  7524. callback(view,name,tiddlers);
  7525. }
  7526. }
  7527. };
  7528. };
  7529. // Invoke a callback for each selector checkbox in the listview
  7530. ListView.forEachSelector = function(view,callback)
  7531. {
  7532. var checkboxes = view.getElementsByTagName("input");
  7533. var hadOne = false;
  7534. for(var t=0; t<checkboxes.length; t++) {
  7535. var cb = checkboxes[t];
  7536. if(cb.getAttribute("type") == "checkbox") {
  7537. var rn = cb.getAttribute("rowName");
  7538. if(rn) {
  7539. callback(cb,rn);
  7540. hadOne = true;
  7541. }
  7542. }
  7543. }
  7544. return hadOne;
  7545. };
  7546. ListView.getSelectedRows = function(view)
  7547. {
  7548. var rowNames = [];
  7549. ListView.forEachSelector(view,function(e,rowName) {
  7550. if(e.checked)
  7551. rowNames.push(rowName);
  7552. });
  7553. return rowNames;
  7554. };
  7555. ListView.columnTypes = {};
  7556. ListView.columnTypes.String = {
  7557. createHeader: function(place,columnTemplate,col)
  7558. {
  7559. createTiddlyText(place,columnTemplate.title);
  7560. },
  7561. createItem: function(place,listObject,field,columnTemplate,col,row)
  7562. {
  7563. var v = listObject[field];
  7564. if(v != undefined)
  7565. createTiddlyText(place,v);
  7566. }
  7567. };
  7568. ListView.columnTypes.WikiText = {
  7569. createHeader: ListView.columnTypes.String.createHeader,
  7570. createItem: function(place,listObject,field,columnTemplate,col,row)
  7571. {
  7572. var v = listObject[field];
  7573. if(v != undefined)
  7574. wikify(v,place,null,null);
  7575. }
  7576. };
  7577. ListView.columnTypes.Tiddler = {
  7578. createHeader: ListView.columnTypes.String.createHeader,
  7579. createItem: function(place,listObject,field,columnTemplate,col,row)
  7580. {
  7581. var v = listObject[field];
  7582. if(v != undefined && v.title)
  7583. createTiddlyPopup(place,v.title,config.messages.listView.tiddlerTooltip,v);
  7584. }
  7585. };
  7586. ListView.columnTypes.Size = {
  7587. createHeader: ListView.columnTypes.String.createHeader,
  7588. createItem: function(place,listObject,field,columnTemplate,col,row)
  7589. {
  7590. var v = listObject[field];
  7591. if(v != undefined) {
  7592. var t = 0;
  7593. while(t<config.messages.sizeTemplates.length-1 && v<config.messages.sizeTemplates[t].unit)
  7594. t++;
  7595. createTiddlyText(place,config.messages.sizeTemplates[t].template.format([Math.round(v/config.messages.sizeTemplates[t].unit)]));
  7596. }
  7597. }
  7598. };
  7599. ListView.columnTypes.Link = {
  7600. createHeader: ListView.columnTypes.String.createHeader,
  7601. createItem: function(place,listObject,field,columnTemplate,col,row)
  7602. {
  7603. var v = listObject[field];
  7604. var c = columnTemplate.text;
  7605. if(v != undefined)
  7606. createTiddlyText(createExternalLink(place,v),c ? c : v);
  7607. }
  7608. };
  7609. ListView.columnTypes.Date = {
  7610. createHeader: ListView.columnTypes.String.createHeader,
  7611. createItem: function(place,listObject,field,columnTemplate,col,row)
  7612. {
  7613. var v = listObject[field];
  7614. if(v != undefined)
  7615. createTiddlyText(place,v.formatString(columnTemplate.dateFormat));
  7616. }
  7617. };
  7618. ListView.columnTypes.StringList = {
  7619. createHeader: ListView.columnTypes.String.createHeader,
  7620. createItem: function(place,listObject,field,columnTemplate,col,row)
  7621. {
  7622. var v = listObject[field];
  7623. if(v != undefined) {
  7624. for(var t=0; t<v.length; t++) {
  7625. createTiddlyText(place,v[t]);
  7626. createTiddlyElement(place,"br");
  7627. }
  7628. }
  7629. }
  7630. };
  7631. ListView.columnTypes.Selector = {
  7632. createHeader: function(place,columnTemplate,col)
  7633. {
  7634. createTiddlyCheckbox(place,null,false,this.onHeaderChange);
  7635. },
  7636. createItem: function(place,listObject,field,columnTemplate,col,row)
  7637. {
  7638. var e = createTiddlyCheckbox(place,null,listObject[field],null);
  7639. e.setAttribute("rowName",listObject[columnTemplate.rowName]);
  7640. },
  7641. onHeaderChange: function(e)
  7642. {
  7643. var state = this.checked;
  7644. var view = findRelated(this,"TABLE");
  7645. if(!view)
  7646. return;
  7647. ListView.forEachSelector(view,function(e,rowName) {
  7648. e.checked = state;
  7649. });
  7650. }
  7651. };
  7652. ListView.columnTypes.Tags = {
  7653. createHeader: ListView.columnTypes.String.createHeader,
  7654. createItem: function(place,listObject,field,columnTemplate,col,row)
  7655. {
  7656. var tags = listObject[field];
  7657. createTiddlyText(place,String.encodeTiddlyLinkList(tags));
  7658. }
  7659. };
  7660. ListView.columnTypes.Boolean = {
  7661. createHeader: ListView.columnTypes.String.createHeader,
  7662. createItem: function(place,listObject,field,columnTemplate,col,row)
  7663. {
  7664. if(listObject[field] == true)
  7665. createTiddlyText(place,columnTemplate.trueText);
  7666. if(listObject[field] == false)
  7667. createTiddlyText(place,columnTemplate.falseText);
  7668. }
  7669. };
  7670. ListView.columnTypes.TagCheckbox = {
  7671. createHeader: ListView.columnTypes.String.createHeader,
  7672. createItem: function(place,listObject,field,columnTemplate,col,row)
  7673. {
  7674. var e = createTiddlyCheckbox(place,null,listObject[field],this.onChange);
  7675. e.setAttribute("tiddler",listObject.title);
  7676. e.setAttribute("tag",columnTemplate.tag);
  7677. },
  7678. onChange : function(e)
  7679. {
  7680. var tag = this.getAttribute("tag");
  7681. var tiddler = this.getAttribute("tiddler");
  7682. store.setTiddlerTag(tiddler,this.checked,tag);
  7683. }
  7684. };
  7685. ListView.columnTypes.TiddlerLink = {
  7686. createHeader: ListView.columnTypes.String.createHeader,
  7687. createItem: function(place,listObject,field,columnTemplate,col,row)
  7688. {
  7689. var v = listObject[field];
  7690. if(v != undefined) {
  7691. var link = createTiddlyLink(place,listObject[columnTemplate.tiddlerLink],false,null);
  7692. createTiddlyText(link,listObject[field]);
  7693. }
  7694. }
  7695. };
  7696. //--
  7697. //-- Augmented methods for the JavaScript Number(), Array(), String() and Date() objects
  7698. //--
  7699. // Clamp a number to a range
  7700. Number.prototype.clamp = function(min,max)
  7701. {
  7702. var c = this;
  7703. if(c < min)
  7704. c = min;
  7705. if(c > max)
  7706. c = max;
  7707. return c;
  7708. };
  7709. // Add indexOf function if browser does not support it
  7710. if(!Array.indexOf) {
  7711. Array.prototype.indexOf = function(item,from)
  7712. {
  7713. if(!from)
  7714. from = 0;
  7715. for(var i=from; i<this.length; i++) {
  7716. if(this[i] === item)
  7717. return i;
  7718. }
  7719. return -1;
  7720. };}
  7721. // Find an entry in a given field of the members of an array
  7722. Array.prototype.findByField = function(field,value)
  7723. {
  7724. for(var t=0; t<this.length; t++) {
  7725. if(this[t][field] == value)
  7726. return t;
  7727. }
  7728. return null;
  7729. };
  7730. // Return whether an entry exists in an array
  7731. Array.prototype.contains = function(item)
  7732. {
  7733. return this.indexOf(item) != -1;
  7734. };
  7735. // Adds, removes or toggles a particular value within an array
  7736. // value - value to add
  7737. // mode - +1 to add value, -1 to remove value, 0 to toggle it
  7738. Array.prototype.setItem = function(value,mode)
  7739. {
  7740. var p = this.indexOf(value);
  7741. if(mode == 0)
  7742. mode = (p == -1) ? +1 : -1;
  7743. if(mode == +1) {
  7744. if(p == -1)
  7745. this.push(value);
  7746. } else if(mode == -1) {
  7747. if(p != -1)
  7748. this.splice(p,1);
  7749. }
  7750. };
  7751. // Return whether one of a list of values exists in an array
  7752. Array.prototype.containsAny = function(items)
  7753. {
  7754. for(var i=0; i<items.length; i++) {
  7755. if (this.indexOf(items[i]) != -1)
  7756. return true;
  7757. }
  7758. return false;
  7759. };
  7760. // Return whether all of a list of values exists in an array
  7761. Array.prototype.containsAll = function(items)
  7762. {
  7763. for (var i = 0; i<items.length; i++) {
  7764. if (this.indexOf(items[i]) == -1)
  7765. return false;
  7766. }
  7767. return true;
  7768. };
  7769. // Push a new value into an array only if it is not already present in the array. If the optional unique parameter is false, it reverts to a normal push
  7770. Array.prototype.pushUnique = function(item,unique)
  7771. {
  7772. if(unique === false) {
  7773. this.push(item);
  7774. } else {
  7775. if(this.indexOf(item) == -1)
  7776. this.push(item);
  7777. }
  7778. };
  7779. Array.prototype.remove = function(item)
  7780. {
  7781. var p = this.indexOf(item);
  7782. if(p != -1)
  7783. this.splice(p,1);
  7784. };
  7785. // Get characters from the right end of a string
  7786. String.prototype.right = function(n)
  7787. {
  7788. return n < this.length ? this.slice(this.length-n) : this;
  7789. };
  7790. // Trim whitespace from both ends of a string
  7791. String.prototype.trim = function()
  7792. {
  7793. return this.replace(/^\s*|\s*$/g,"");
  7794. };
  7795. // Convert a string from a CSS style property name to a JavaScript style name ("background-color" -> "backgroundColor")
  7796. String.prototype.unDash = function()
  7797. {
  7798. var s = this.split("-");
  7799. if(s.length > 1) {
  7800. for(var t=1; t<s.length; t++)
  7801. s[t] = s[t].substr(0,1).toUpperCase() + s[t].substr(1);
  7802. }
  7803. return s.join("");
  7804. };
  7805. // Substitute substrings from an array into a format string that includes '%1'-type specifiers
  7806. String.prototype.format = function(substrings)
  7807. {
  7808. var subRegExp = /(?:%(\d+))/mg;
  7809. var currPos = 0;
  7810. var r = [];
  7811. do {
  7812. var match = subRegExp.exec(this);
  7813. if(match && match[1]) {
  7814. if(match.index > currPos)
  7815. r.push(this.substring(currPos,match.index));
  7816. r.push(substrings[parseInt(match[1])]);
  7817. currPos = subRegExp.lastIndex;
  7818. }
  7819. } while(match);
  7820. if(currPos < this.length)
  7821. r.push(this.substring(currPos,this.length));
  7822. return r.join("");
  7823. };
  7824. // Escape any special RegExp characters with that character preceded by a backslash
  7825. String.prototype.escapeRegExp = function()
  7826. {
  7827. var s = "\\^$*+?()=!|,{}[].";
  7828. var c = this;
  7829. for(var t=0; t<s.length; t++)
  7830. c = c.replace(new RegExp("\\" + s.substr(t,1),"g"),"\\" + s.substr(t,1));
  7831. return c;
  7832. };
  7833. // Convert "\" to "\s", newlines to "\n" (and remove carriage returns)
  7834. String.prototype.escapeLineBreaks = function()
  7835. {
  7836. return this.replace(/\\/mg,"\\s").replace(/\n/mg,"\\n").replace(/\r/mg,"");
  7837. };
  7838. // Convert "\n" to newlines, "\b" to " ", "\s" to "\" (and remove carriage returns)
  7839. String.prototype.unescapeLineBreaks = function()
  7840. {
  7841. return this.replace(/\\n/mg,"\n").replace(/\\b/mg," ").replace(/\\s/mg,"\\").replace(/\r/mg,"");
  7842. };
  7843. // Convert & to "&amp;", < to "&lt;", > to "&gt;" and " to "&quot;"
  7844. String.prototype.htmlEncode = function()
  7845. {
  7846. return this.replace(/&/mg,"&amp;").replace(/</mg,"&lt;").replace(/>/mg,"&gt;").replace(/\"/mg,"&quot;");
  7847. };
  7848. // Convert "&amp;" to &, "&lt;" to <, "&gt;" to > and "&quot;" to "
  7849. String.prototype.htmlDecode = function()
  7850. {
  7851. return this.replace(/&lt;/mg,"<").replace(/&gt;/mg,">").replace(/&quot;/mg,"\"").replace(/&amp;/mg,"&");
  7852. };
  7853. // Convert a string to it's JSON representation by encoding control characters, double quotes and backslash. See json.org
  7854. String.prototype.toJSONString = function()
  7855. {
  7856. var m = {
  7857. '\b': '\\b',
  7858. '\f': '\\f',
  7859. '\n': '\\n',
  7860. '\r': '\\r',
  7861. '\t': '\\t',
  7862. '"' : '\\"',
  7863. '\\': '\\\\'
  7864. };
  7865. var replaceFn = function(a,b) {
  7866. var c = m[b];
  7867. if(c)
  7868. return c;
  7869. c = b.charCodeAt();
  7870. return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
  7871. };
  7872. if(/["\\\x00-\x1f]/.test(this))
  7873. return '"' + this.replace(/([\x00-\x1f\\"])/g,replaceFn) + '"';
  7874. return '"' + this + '"';
  7875. };
  7876. // Parse a space-separated string of name:value parameters
  7877. // The result is an array of objects:
  7878. // result[0] = object with a member for each parameter name, value of that member being an array of values
  7879. // result[1..n] = one object for each parameter, with 'name' and 'value' members
  7880. String.prototype.parseParams = function(defaultName,defaultValue,allowEval,noNames,cascadeDefaults)
  7881. {
  7882. var parseToken = function(match,p) {
  7883. var n;
  7884. if(match[p]) // Double quoted
  7885. n = match[p];
  7886. else if(match[p+1]) // Single quoted
  7887. n = match[p+1];
  7888. else if(match[p+2]) // Double-square-bracket quoted
  7889. n = match[p+2];
  7890. else if(match[p+3]) // Double-brace quoted
  7891. try {
  7892. n = match[p+3];
  7893. if(allowEval)
  7894. n = window.eval(n);
  7895. } catch(ex) {
  7896. throw "Unable to evaluate {{" + match[p+3] + "}}: " + exceptionText(ex);
  7897. }
  7898. else if(match[p+4]) // Unquoted
  7899. n = match[p+4];
  7900. else if(match[p+5]) // empty quote
  7901. n = "";
  7902. return n;
  7903. };
  7904. var r = [{}];
  7905. var dblQuote = "(?:\"((?:(?:\\\\\")|[^\"])+)\")";
  7906. var sngQuote = "(?:'((?:(?:\\\\\')|[^'])+)')";
  7907. var dblSquare = "(?:\\[\\[((?:\\s|\\S)*?)\\]\\])";
  7908. var dblBrace = "(?:\\{\\{((?:\\s|\\S)*?)\\}\\})";
  7909. var unQuoted = noNames ? "([^\"'\\s]\\S*)" : "([^\"':\\s][^\\s:]*)";
  7910. var emptyQuote = "((?:\"\")|(?:''))";
  7911. var skipSpace = "(?:\\s*)";
  7912. var token = "(?:" + dblQuote + "|" + sngQuote + "|" + dblSquare + "|" + dblBrace + "|" + unQuoted + "|" + emptyQuote + ")";
  7913. var re = noNames ? new RegExp(token,"mg") : new RegExp(skipSpace + token + skipSpace + "(?:(\\:)" + skipSpace + token + ")?","mg");
  7914. var params = [];
  7915. do {
  7916. var match = re.exec(this);
  7917. if(match) {
  7918. var n = parseToken(match,1);
  7919. if(noNames) {
  7920. r.push({name:"",value:n});
  7921. } else {
  7922. var v = parseToken(match,8);
  7923. if(v == null && defaultName) {
  7924. v = n;
  7925. n = defaultName;
  7926. } else if(v == null && defaultValue) {
  7927. v = defaultValue;
  7928. }
  7929. r.push({name:n,value:v});
  7930. if(cascadeDefaults) {
  7931. defaultName = n;
  7932. defaultValue = v;
  7933. }
  7934. }
  7935. }
  7936. } while(match);
  7937. // Summarise parameters into first element
  7938. for(var t=1; t<r.length; t++) {
  7939. if(r[0][r[t].name])
  7940. r[0][r[t].name].push(r[t].value);
  7941. else
  7942. r[0][r[t].name] = [r[t].value];
  7943. }
  7944. return r;
  7945. };
  7946. // Process a string list of macro parameters into an array. Parameters can be quoted with "", '',
  7947. // [[]], {{ }} or left unquoted (and therefore space-separated). Double-braces {{}} results in
  7948. // an *evaluated* parameter: e.g. {{config.options.txtUserName}} results in the current user's name.
  7949. String.prototype.readMacroParams = function()
  7950. {
  7951. var p = this.parseParams("list",null,true,true);
  7952. var n = [];
  7953. for(var t=1; t<p.length; t++)
  7954. n.push(p[t].value);
  7955. return n;
  7956. };
  7957. // Process a string list of unique tiddler names into an array. Tiddler names that have spaces in them must be [[bracketed]]
  7958. String.prototype.readBracketedList = function(unique)
  7959. {
  7960. var p = this.parseParams("list",null,false,true);
  7961. var n = [];
  7962. for(var t=1; t<p.length; t++)
  7963. n.pushUnique(p[t].value,unique);
  7964. return n;
  7965. };
  7966. // Returns array with start and end index of chunk between given start and end marker, or undefined.
  7967. String.prototype.getChunkRange = function(start,end)
  7968. {
  7969. var s = this.indexOf(start);
  7970. if(s != -1) {
  7971. s += start.length;
  7972. var e = this.indexOf(end,s);
  7973. if(e != -1)
  7974. return [s,e];
  7975. }
  7976. };
  7977. // Replace a chunk of a string given start and end markers
  7978. String.prototype.replaceChunk = function(start,end,sub)
  7979. {
  7980. var r = this.getChunkRange(start,end);
  7981. return r ? this.substring(0,r[0]) + sub + this.substring(r[1]) : this;
  7982. };
  7983. // Returns a chunk of a string between start and end markers, or undefined
  7984. String.prototype.getChunk = function(start,end)
  7985. {
  7986. var r = this.getChunkRange(start,end);
  7987. if(r)
  7988. return this.substring(r[0],r[1]);
  7989. };
  7990. // Static method to bracket a string with double square brackets if it contains a space
  7991. String.encodeTiddlyLink = function(title)
  7992. {
  7993. return title.indexOf(" ") == -1 ? title : "[[" + title + "]]";
  7994. };
  7995. // Static method to encodeTiddlyLink for every item in an array and join them with spaces
  7996. String.encodeTiddlyLinkList = function(list)
  7997. {
  7998. if(list) {
  7999. var results = [];
  8000. for(var t=0; t<list.length; t++)
  8001. results.push(String.encodeTiddlyLink(list[t]));
  8002. return results.join(" ");
  8003. } else {
  8004. return "";
  8005. }
  8006. };
  8007. // Convert a string as a sequence of name:"value" pairs into a hashmap
  8008. String.prototype.decodeHashMap = function()
  8009. {
  8010. var fields = this.parseParams("anon","",false);
  8011. var r = {};
  8012. for(var t=1; t<fields.length; t++)
  8013. r[fields[t].name] = fields[t].value;
  8014. return r;
  8015. };
  8016. // Static method to encode a hashmap into a name:"value"... string
  8017. String.encodeHashMap = function(hashmap)
  8018. {
  8019. var r = [];
  8020. for(var t in hashmap)
  8021. r.push(t + ':"' + hashmap[t] + '"');
  8022. return r.join(" ");
  8023. };
  8024. // Static method to left-pad a string with 0s to a certain width
  8025. String.zeroPad = function(n,d)
  8026. {
  8027. var s = n.toString();
  8028. if(s.length < d)
  8029. s = "000000000000000000000000000".substr(0,d-s.length) + s;
  8030. return s;
  8031. };
  8032. String.prototype.startsWith = function(prefix)
  8033. {
  8034. return !prefix || this.substring(0,prefix.length) == prefix;
  8035. };
  8036. // Returns the first value of the given named parameter.
  8037. function getParam(params,name,defaultValue)
  8038. {
  8039. if(!params)
  8040. return defaultValue;
  8041. var p = params[0][name];
  8042. return p ? p[0] : defaultValue;
  8043. }
  8044. // Returns the first value of the given boolean named parameter.
  8045. function getFlag(params,name,defaultValue)
  8046. {
  8047. return !!getParam(params,name,defaultValue);
  8048. }
  8049. // Substitute date components into a string
  8050. Date.prototype.formatString = function(template)
  8051. {
  8052. var t = template.replace(/0hh12/g,String.zeroPad(this.getHours12(),2));
  8053. t = t.replace(/hh12/g,this.getHours12());
  8054. t = t.replace(/0hh/g,String.zeroPad(this.getHours(),2));
  8055. t = t.replace(/hh/g,this.getHours());
  8056. t = t.replace(/mmm/g,config.messages.dates.shortMonths[this.getMonth()]);
  8057. t = t.replace(/0mm/g,String.zeroPad(this.getMinutes(),2));
  8058. t = t.replace(/mm/g,this.getMinutes());
  8059. t = t.replace(/0ss/g,String.zeroPad(this.getSeconds(),2));
  8060. t = t.replace(/ss/g,this.getSeconds());
  8061. t = t.replace(/[ap]m/g,this.getAmPm().toLowerCase());
  8062. t = t.replace(/[AP]M/g,this.getAmPm().toUpperCase());
  8063. t = t.replace(/wYYYY/g,this.getYearForWeekNo());
  8064. t = t.replace(/wYY/g,String.zeroPad(this.getYearForWeekNo()-2000,2));
  8065. t = t.replace(/YYYY/g,this.getFullYear());
  8066. t = t.replace(/YY/g,String.zeroPad(this.getFullYear()-2000,2));
  8067. t = t.replace(/MMM/g,config.messages.dates.months[this.getMonth()]);
  8068. t = t.replace(/0MM/g,String.zeroPad(this.getMonth()+1,2));
  8069. t = t.replace(/MM/g,this.getMonth()+1);
  8070. t = t.replace(/0WW/g,String.zeroPad(this.getWeek(),2));
  8071. t = t.replace(/WW/g,this.getWeek());
  8072. t = t.replace(/DDD/g,config.messages.dates.days[this.getDay()]);
  8073. t = t.replace(/ddd/g,config.messages.dates.shortDays[this.getDay()]);
  8074. t = t.replace(/0DD/g,String.zeroPad(this.getDate(),2));
  8075. t = t.replace(/DDth/g,this.getDate()+this.daySuffix());
  8076. t = t.replace(/DD/g,this.getDate());
  8077. return t;
  8078. };
  8079. Date.prototype.getWeek = function()
  8080. {
  8081. var dt = new Date(this.getTime());
  8082. var d = dt.getDay();
  8083. if (d==0) d=7;// JavaScript Sun=0, ISO Sun=7
  8084. dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week to calculate weekNo
  8085. var n = Math.floor((dt.getTime()-new Date(dt.getFullYear(),0,1)+3600000)/86400000);
  8086. return Math.floor(n/7)+1;
  8087. };
  8088. Date.prototype.getYearForWeekNo = function()
  8089. {
  8090. var dt = new Date(this.getTime());
  8091. var d = dt.getDay();
  8092. if (d==0) d=7;// JavaScript Sun=0, ISO Sun=7
  8093. dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week
  8094. return dt.getFullYear();
  8095. };
  8096. Date.prototype.getHours12 = function()
  8097. {
  8098. var h = this.getHours();
  8099. return h > 12 ? h-12 : ( h > 0 ? h : 12 );
  8100. };
  8101. Date.prototype.getAmPm = function()
  8102. {
  8103. return this.getHours() >= 12 ? config.messages.dates.pm : config.messages.dates.am;
  8104. };
  8105. Date.prototype.daySuffix = function()
  8106. {
  8107. return config.messages.dates.daySuffixes[this.getDate()-1];
  8108. };
  8109. // Convert a date to local YYYYMMDDHHMM string format
  8110. Date.prototype.convertToLocalYYYYMMDDHHMM = function()
  8111. {
  8112. return String.zeroPad(this.getFullYear(),4) + String.zeroPad(this.getMonth()+1,2) + String.zeroPad(this.getDate(),2) + String.zeroPad(this.getHours(),2) + String.zeroPad(this.getMinutes(),2);
  8113. };
  8114. // Convert a date to UTC YYYYMMDDHHMM string format
  8115. Date.prototype.convertToYYYYMMDDHHMM = function()
  8116. {
  8117. return String.zeroPad(this.getUTCFullYear(),4) + String.zeroPad(this.getUTCMonth()+1,2) + String.zeroPad(this.getUTCDate(),2) + String.zeroPad(this.getUTCHours(),2) + String.zeroPad(this.getUTCMinutes(),2);
  8118. };
  8119. // Convert a date to UTC YYYYMMDD.HHMMSSMMM string format
  8120. Date.prototype.convertToYYYYMMDDHHMMSSMMM = function()
  8121. {
  8122. return String.zeroPad(this.getUTCFullYear(),4) + String.zeroPad(this.getUTCMonth()+1,2) + String.zeroPad(this.getUTCDate(),2) + "." + String.zeroPad(this.getUTCHours(),2) + String.zeroPad(this.getUTCMinutes(),2) + String.zeroPad(this.getUTCSeconds(),2) + String.zeroPad(this.getUTCMilliseconds(),4);
  8123. };
  8124. // Static method to create a date from a UTC YYYYMMDDHHMM format string
  8125. Date.convertFromYYYYMMDDHHMM = function(d)
  8126. {
  8127. return new Date(Date.UTC(parseInt(d.substr(0,4),10),
  8128. parseInt(d.substr(4,2),10)-1,
  8129. parseInt(d.substr(6,2),10),
  8130. parseInt(d.substr(8,2),10),
  8131. parseInt(d.substr(10,2),10),0,0));
  8132. };
  8133. //--
  8134. //-- Crypto functions and associated conversion routines
  8135. //--
  8136. // Crypto "namespace"
  8137. function Crypto() {}
  8138. // Convert a string to an array of big-endian 32-bit words
  8139. Crypto.strToBe32s = function(str)
  8140. {
  8141. var be = Array();
  8142. var len = Math.floor(str.length/4);
  8143. var i, j;
  8144. for(i=0, j=0; i<len; i++, j+=4) {
  8145. be[i] = ((str.charCodeAt(j)&0xff) << 24)|((str.charCodeAt(j+1)&0xff) << 16)|((str.charCodeAt(j+2)&0xff) << 8)|(str.charCodeAt(j+3)&0xff);
  8146. }
  8147. while (j<str.length) {
  8148. be[j>>2] |= (str.charCodeAt(j)&0xff)<<(24-(j*8)%32);
  8149. j++;
  8150. }
  8151. return be;
  8152. };
  8153. // Convert an array of big-endian 32-bit words to a string
  8154. Crypto.be32sToStr = function(be)
  8155. {
  8156. var str = "";
  8157. for(var i=0;i<be.length*32;i+=8)
  8158. str += String.fromCharCode((be[i>>5]>>>(24-i%32)) & 0xff);
  8159. return str;
  8160. };
  8161. // Convert an array of big-endian 32-bit words to a hex string
  8162. Crypto.be32sToHex = function(be)
  8163. {
  8164. var hex = "0123456789ABCDEF";
  8165. var str = "";
  8166. for(var i=0;i<be.length*4;i++)
  8167. str += hex.charAt((be[i>>2]>>((3-i%4)*8+4))&0xF) + hex.charAt((be[i>>2]>>((3-i%4)*8))&0xF);
  8168. return str;
  8169. };
  8170. // Return, in hex, the SHA-1 hash of a string
  8171. Crypto.hexSha1Str = function(str)
  8172. {
  8173. return Crypto.be32sToHex(Crypto.sha1Str(str));
  8174. };
  8175. // Return the SHA-1 hash of a string
  8176. Crypto.sha1Str = function(str)
  8177. {
  8178. return Crypto.sha1(Crypto.strToBe32s(str),str.length);
  8179. };
  8180. // Calculate the SHA-1 hash of an array of blen bytes of big-endian 32-bit words
  8181. Crypto.sha1 = function(x,blen)
  8182. {
  8183. // Add 32-bit integers, wrapping at 32 bits
  8184. add32 = function(a,b)
  8185. {
  8186. var lsw = (a&0xFFFF)+(b&0xFFFF);
  8187. var msw = (a>>16)+(b>>16)+(lsw>>16);
  8188. return (msw<<16)|(lsw&0xFFFF);
  8189. };
  8190. // Add five 32-bit integers, wrapping at 32 bits
  8191. add32x5 = function(a,b,c,d,e)
  8192. {
  8193. var lsw = (a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF);
  8194. var msw = (a>>16)+(b>>16)+(c>>16)+(d>>16)+(e>>16)+(lsw>>16);
  8195. return (msw<<16)|(lsw&0xFFFF);
  8196. };
  8197. // Bitwise rotate left a 32-bit integer by 1 bit
  8198. rol32 = function(n)
  8199. {
  8200. return (n>>>31)|(n<<1);
  8201. };
  8202. var len = blen*8;
  8203. // Append padding so length in bits is 448 mod 512
  8204. x[len>>5] |= 0x80 << (24-len%32);
  8205. // Append length
  8206. x[((len+64>>9)<<4)+15] = len;
  8207. var w = Array(80);
  8208. var k1 = 0x5A827999;
  8209. var k2 = 0x6ED9EBA1;
  8210. var k3 = 0x8F1BBCDC;
  8211. var k4 = 0xCA62C1D6;
  8212. var h0 = 0x67452301;
  8213. var h1 = 0xEFCDAB89;
  8214. var h2 = 0x98BADCFE;
  8215. var h3 = 0x10325476;
  8216. var h4 = 0xC3D2E1F0;
  8217. for(var i=0;i<x.length;i+=16) {
  8218. var j,t;
  8219. var a = h0;
  8220. var b = h1;
  8221. var c = h2;
  8222. var d = h3;
  8223. var e = h4;
  8224. for(j = 0;j<16;j++) {
  8225. w[j] = x[i+j];
  8226. t = add32x5(e,(a>>>27)|(a<<5),d^(b&(c^d)),w[j],k1);
  8227. e=d; d=c; c=(b>>>2)|(b<<30); b=a; a = t;
  8228. }
  8229. for(j=16;j<20;j++) {
  8230. w[j] = rol32(w[j-3]^w[j-8]^w[j-14]^w[j-16]);
  8231. t = add32x5(e,(a>>>27)|(a<<5),d^(b&(c^d)),w[j],k1);
  8232. e=d; d=c; c=(b>>>2)|(b<<30); b=a; a = t;
  8233. }
  8234. for(j=20;j<40;j++) {
  8235. w[j] = rol32(w[j-3]^w[j-8]^w[j-14]^w[j-16]);
  8236. t = add32x5(e,(a>>>27)|(a<<5),b^c^d,w[j],k2);
  8237. e=d; d=c; c=(b>>>2)|(b<<30); b=a; a = t;
  8238. }
  8239. for(j=40;j<60;j++) {
  8240. w[j] = rol32(w[j-3]^w[j-8]^w[j-14]^w[j-16]);
  8241. t = add32x5(e,(a>>>27)|(a<<5),(b&c)|(d&(b|c)),w[j],k3);
  8242. e=d; d=c; c=(b>>>2)|(b<<30); b=a; a = t;
  8243. }
  8244. for(j=60;j<80;j++) {
  8245. w[j] = rol32(w[j-3]^w[j-8]^w[j-14]^w[j-16]);
  8246. t = add32x5(e,(a>>>27)|(a<<5),b^c^d,w[j],k4);
  8247. e=d; d=c; c=(b>>>2)|(b<<30); b=a; a = t;
  8248. }
  8249. h0 = add32(h0,a);
  8250. h1 = add32(h1,b);
  8251. h2 = add32(h2,c);
  8252. h3 = add32(h3,d);
  8253. h4 = add32(h4,e);
  8254. }
  8255. return Array(h0,h1,h2,h3,h4);
  8256. };
  8257. //--
  8258. //-- RGB colour object
  8259. //--
  8260. // Construct an RGB colour object from a '#rrggbb', '#rgb' or 'rgb(n,n,n)' string or from separate r,g,b values
  8261. function RGB(r,g,b)
  8262. {
  8263. this.r = 0;
  8264. this.g = 0;
  8265. this.b = 0;
  8266. if(typeof r == "string") {
  8267. if(r.substr(0,1) == "#") {
  8268. if(r.length == 7) {
  8269. this.r = parseInt(r.substr(1,2),16)/255;
  8270. this.g = parseInt(r.substr(3,2),16)/255;
  8271. this.b = parseInt(r.substr(5,2),16)/255;
  8272. } else {
  8273. this.r = parseInt(r.substr(1,1),16)/15;
  8274. this.g = parseInt(r.substr(2,1),16)/15;
  8275. this.b = parseInt(r.substr(3,1),16)/15;
  8276. }
  8277. } else {
  8278. var rgbPattern = /rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/;
  8279. var c = r.match(rgbPattern);
  8280. if(c) {
  8281. this.r = parseInt(c[1],10)/255;
  8282. this.g = parseInt(c[2],10)/255;
  8283. this.b = parseInt(c[3],10)/255;
  8284. }
  8285. }
  8286. } else {
  8287. this.r = r;
  8288. this.g = g;
  8289. this.b = b;
  8290. }
  8291. return this;
  8292. }
  8293. // Mixes this colour with another in a specified proportion
  8294. // c = other colour to mix
  8295. // f = 0..1 where 0 is this colour and 1 is the new colour
  8296. // Returns an RGB object
  8297. RGB.prototype.mix = function(c,f)
  8298. {
  8299. return new RGB(this.r + (c.r-this.r) * f,this.g + (c.g-this.g) * f,this.b + (c.b-this.b) * f);
  8300. };
  8301. // Return an rgb colour as a #rrggbb format hex string
  8302. RGB.prototype.toString = function()
  8303. {
  8304. return "#" + ("0" + Math.floor(this.r.clamp(0,1) * 255).toString(16)).right(2) +
  8305. ("0" + Math.floor(this.g.clamp(0,1) * 255).toString(16)).right(2) +
  8306. ("0" + Math.floor(this.b.clamp(0,1) * 255).toString(16)).right(2);
  8307. };
  8308. //--
  8309. //-- DOM utilities - many derived from www.quirksmode.org
  8310. //--
  8311. function drawGradient(place,horiz,colours)
  8312. {
  8313. for(var t=0; t<= 100; t+=2) {
  8314. var bar = document.createElement("div");
  8315. place.appendChild(bar);
  8316. bar.style.position = "absolute";
  8317. bar.style.left = horiz ? t + "%" : 0;
  8318. bar.style.top = horiz ? 0 : t + "%";
  8319. bar.style.width = horiz ? (101-t) + "%" : "100%";
  8320. bar.style.height = horiz ? "100%" : (101-t) + "%";
  8321. bar.style.zIndex = -1;
  8322. var f = t/100;
  8323. var p = f*(colours.length-1);
  8324. bar.style.backgroundColor = colours[Math.floor(p)].mix(colours[Math.ceil(p)],p-Math.floor(p)).toString();
  8325. }
  8326. }
  8327. function createTiddlyText(theParent,theText)
  8328. {
  8329. return theParent.appendChild(document.createTextNode(theText));
  8330. }
  8331. function createTiddlyCheckbox(theParent,caption,checked,onChange)
  8332. {
  8333. var cb = document.createElement("input");
  8334. cb.setAttribute("type","checkbox");
  8335. cb.onclick = onChange;
  8336. theParent.appendChild(cb);
  8337. cb.checked = checked;
  8338. cb.className = "chkOptionInput";
  8339. if(caption)
  8340. wikify(caption,theParent);
  8341. return cb;
  8342. }
  8343. function createTiddlyElement(theParent,theElement,theID,theClass,theText)
  8344. {
  8345. var e = document.createElement(theElement);
  8346. if(theClass != null)
  8347. e.className = theClass;
  8348. if(theID != null)
  8349. e.setAttribute("id",theID);
  8350. if(theText != null)
  8351. e.appendChild(document.createTextNode(theText));
  8352. if(theParent != null)
  8353. theParent.appendChild(e);
  8354. return e;
  8355. }
  8356. function addEvent(obj,type,fn)
  8357. {
  8358. if(obj.attachEvent) {
  8359. obj['e'+type+fn] = fn;
  8360. obj[type+fn] = function(){obj['e'+type+fn](window.event);};
  8361. obj.attachEvent('on'+type,obj[type+fn]);
  8362. } else {
  8363. obj.addEventListener(type,fn,false);
  8364. }
  8365. }
  8366. function removeEvent(obj,type,fn)
  8367. {
  8368. if(obj.detachEvent) {
  8369. obj.detachEvent('on'+type,obj[type+fn]);
  8370. obj[type+fn] = null;
  8371. } else {
  8372. obj.removeEventListener(type,fn,false);
  8373. }
  8374. }
  8375. function addClass(e,theClass)
  8376. {
  8377. var currClass = e.className.split(" ");
  8378. if(currClass.indexOf(theClass) == -1)
  8379. e.className += " " + theClass;
  8380. }
  8381. function removeClass(e,theClass)
  8382. {
  8383. var currClass = e.className.split(" ");
  8384. var i = currClass.indexOf(theClass);
  8385. while(i != -1) {
  8386. currClass.splice(i,1);
  8387. i = currClass.indexOf(theClass);
  8388. }
  8389. e.className = currClass.join(" ");
  8390. }
  8391. function hasClass(e,theClass)
  8392. {
  8393. if(e.className) {
  8394. if(e.className.split(" ").indexOf(theClass) != -1)
  8395. return true;
  8396. }
  8397. return false;
  8398. }
  8399. // Find the closest relative with a given property value (property defaults to tagName, relative defaults to parentNode)
  8400. function findRelated(e,value,name,relative)
  8401. {
  8402. name = name ? name : "tagName";
  8403. relative = relative ? relative : "parentNode";
  8404. if(name == "className") {
  8405. while(e && !hasClass(e,value)) {
  8406. e = e[relative];
  8407. }
  8408. } else {
  8409. while(e && e[name] != value) {
  8410. e = e[relative];
  8411. }
  8412. }
  8413. return e;
  8414. }
  8415. // Resolve the target object of an event
  8416. function resolveTarget(e)
  8417. {
  8418. var obj;
  8419. if(e.target)
  8420. obj = e.target;
  8421. else if(e.srcElement)
  8422. obj = e.srcElement;
  8423. if(obj.nodeType == 3) // defeat Safari bug
  8424. obj = obj.parentNode;
  8425. return obj;
  8426. }
  8427. // Return the content of an element as plain text with no formatting
  8428. function getPlainText(e)
  8429. {
  8430. var text = "";
  8431. if(e.innerText)
  8432. text = e.innerText;
  8433. else if(e.textContent)
  8434. text = e.textContent;
  8435. return text;
  8436. }
  8437. // Get the scroll position for window.scrollTo necessary to scroll a given element into view
  8438. function ensureVisible(e)
  8439. {
  8440. var posTop = findPosY(e);
  8441. var posBot = posTop + e.offsetHeight;
  8442. var winTop = findScrollY();
  8443. var winHeight = findWindowHeight();
  8444. var winBot = winTop + winHeight;
  8445. if(posTop < winTop) {
  8446. return posTop;
  8447. } else if(posBot > winBot) {
  8448. if(e.offsetHeight < winHeight)
  8449. return posTop - (winHeight - e.offsetHeight);
  8450. else
  8451. return posTop;
  8452. } else {
  8453. return winTop;
  8454. }
  8455. }
  8456. // Get the current width of the display window
  8457. function findWindowWidth()
  8458. {
  8459. return window.innerWidth ? window.innerWidth : document.documentElement.clientWidth;
  8460. }
  8461. // Get the current height of the display window
  8462. function findWindowHeight()
  8463. {
  8464. return window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
  8465. }
  8466. // Get the current horizontal page scroll position
  8467. function findScrollX()
  8468. {
  8469. return window.scrollX ? window.scrollX : document.documentElement.scrollLeft;
  8470. }
  8471. // Get the current vertical page scroll position
  8472. function findScrollY()
  8473. {
  8474. return window.scrollY ? window.scrollY : document.documentElement.scrollTop;
  8475. }
  8476. function findPosX(obj)
  8477. {
  8478. var curleft = 0;
  8479. while(obj.offsetParent) {
  8480. curleft += obj.offsetLeft;
  8481. obj = obj.offsetParent;
  8482. }
  8483. return curleft;
  8484. }
  8485. function findPosY(obj)
  8486. {
  8487. var curtop = 0;
  8488. while(obj.offsetParent) {
  8489. curtop += obj.offsetTop;
  8490. obj = obj.offsetParent;
  8491. }
  8492. return curtop;
  8493. }
  8494. // Blur a particular element
  8495. function blurElement(e)
  8496. {
  8497. if(e != null && e.focus && e.blur) {
  8498. e.focus();
  8499. e.blur();
  8500. }
  8501. }
  8502. // Create a non-breaking space
  8503. function insertSpacer(place)
  8504. {
  8505. var e = document.createTextNode(String.fromCharCode(160));
  8506. if(place)
  8507. place.appendChild(e);
  8508. return e;
  8509. }
  8510. // Remove all children of a node
  8511. function removeChildren(e)
  8512. {
  8513. while(e && e.hasChildNodes())
  8514. removeNode(e.firstChild);
  8515. }
  8516. // Remove a node and all it's children
  8517. function removeNode(e)
  8518. {
  8519. scrubNode(e);
  8520. e.parentNode.removeChild(e);
  8521. }
  8522. // Remove any event handlers or non-primitve custom attributes
  8523. function scrubNode(e)
  8524. {
  8525. var att = e.attributes;
  8526. if(att) {
  8527. for(var t=0; t<att.length; t++) {
  8528. var n = att[t].name;
  8529. if(n !== 'style' && (typeof e[n] === 'function' || (typeof e[n] === 'object' && e[n] != null))) {
  8530. try {
  8531. e[n] = null;
  8532. } catch(ex) {
  8533. }
  8534. }
  8535. }
  8536. }
  8537. var c = e.firstChild;
  8538. while(c) {
  8539. scrubNode(c);
  8540. c = c.nextSibling;
  8541. }
  8542. }
  8543. // Add a stylesheet, replacing any previous custom stylesheet
  8544. function setStylesheet(s,id,doc)
  8545. {
  8546. if(!id)
  8547. id = "customStyleSheet";
  8548. if(!doc)
  8549. doc = document;
  8550. var n = doc.getElementById(id);
  8551. if(doc.createStyleSheet) {
  8552. // Test for IE's non-standard createStyleSheet method
  8553. if(n)
  8554. n.parentNode.removeChild(n);
  8555. // This failed without the &nbsp;
  8556. doc.getElementsByTagName("head")[0].insertAdjacentHTML("beforeEnd","&nbsp;<style id='" + id + "'>" + s + "</style>");
  8557. } else {
  8558. if(n) {
  8559. n.replaceChild(doc.createTextNode(s),n.firstChild);
  8560. } else {
  8561. n = doc.createElement("style");
  8562. n.type = "text/css";
  8563. n.id = id;
  8564. n.appendChild(doc.createTextNode(s));
  8565. doc.getElementsByTagName("head")[0].appendChild(n);
  8566. }
  8567. }
  8568. }
  8569. // Force the browser to do a document reflow when needed to workaround browser bugs
  8570. function forceReflow()
  8571. {
  8572. if(config.browser.isGecko) {
  8573. setStylesheet("body {top:-1em;margin-top:1em;}");
  8574. setStylesheet("");
  8575. }
  8576. }
  8577. // Replace the current selection of a textarea or text input and scroll it into view
  8578. function replaceSelection(e,text)
  8579. {
  8580. if(e.setSelectionRange) {
  8581. var oldpos = e.selectionStart;
  8582. var isRange = e.selectionEnd > e.selectionStart;
  8583. e.value = e.value.substr(0,e.selectionStart) + text + e.value.substr(e.selectionEnd);
  8584. e.setSelectionRange(isRange ? oldpos : oldpos + text.length,oldpos + text.length);
  8585. var linecount = e.value.split('\n').length;
  8586. var thisline = e.value.substr(0,e.selectionStart).split('\n').length-1;
  8587. e.scrollTop = Math.floor((thisline - e.rows / 2) * e.scrollHeight / linecount);
  8588. } else if(document.selection) {
  8589. var range = document.selection.createRange();
  8590. if(range.parentElement() == e) {
  8591. var isCollapsed = range.text == "";
  8592. range.text = text;
  8593. if(!isCollapsed) {
  8594. range.moveStart('character', -text.length);
  8595. range.select();
  8596. }
  8597. }
  8598. }
  8599. }
  8600. // Returns the text of the given (text) node, possibly merging subsequent text nodes
  8601. function getNodeText(e)
  8602. {
  8603. var t = "";
  8604. while(e && e.nodeName == "#text") {
  8605. t += e.nodeValue;
  8606. e = e.nextSibling;
  8607. }
  8608. return t;
  8609. }
  8610. //--
  8611. //-- LoaderBase and SaverBase
  8612. //--
  8613. function LoaderBase() {}
  8614. LoaderBase.prototype.loadTiddler = function(store,node,tiddlers)
  8615. {
  8616. var title = this.getTitle(store,node);
  8617. if(title) {
  8618. var tiddler = store.createTiddler(title);
  8619. this.internalizeTiddler(store,tiddler,title,node);
  8620. tiddlers.push(tiddler);
  8621. }
  8622. };
  8623. LoaderBase.prototype.loadTiddlers = function(store,nodes)
  8624. {
  8625. var tiddlers = [];
  8626. for(var t = 0; t < nodes.length; t++) {
  8627. try {
  8628. this.loadTiddler(store,nodes[t],tiddlers);
  8629. } catch(ex) {
  8630. showException(ex,config.messages.tiddlerLoadError.format([this.getTitle(store,nodes[t])]));
  8631. }
  8632. }
  8633. return tiddlers;
  8634. };
  8635. function SaverBase() {}
  8636. SaverBase.prototype.externalize = function(store)
  8637. {
  8638. var results = [];
  8639. var tiddlers = store.getTiddlers("title");
  8640. for(var t = 0; t < tiddlers.length; t++)
  8641. results.push(this.externalizeTiddler(store,tiddlers[t]));
  8642. return results.join("\n");
  8643. };
  8644. //--
  8645. //-- TW21Loader (inherits from LoaderBase)
  8646. //--
  8647. function TW21Loader() {}
  8648. TW21Loader.prototype = new LoaderBase();
  8649. TW21Loader.prototype.getTitle = function(store,node)
  8650. {
  8651. var title = null;
  8652. if(node.getAttribute) {
  8653. title = node.getAttribute("title");
  8654. if(!title)
  8655. title = node.getAttribute("tiddler");
  8656. }
  8657. if(!title && node.id) {
  8658. var lenPrefix = store.idPrefix.length;
  8659. if (node.id.substr(0,lenPrefix) == store.idPrefix)
  8660. title = node.id.substr(lenPrefix);
  8661. }
  8662. return title;
  8663. };
  8664. TW21Loader.prototype.internalizeTiddler = function(store,tiddler,title,node)
  8665. {
  8666. var e = node.firstChild;
  8667. var text = null;
  8668. if(node.getAttribute("tiddler")) {
  8669. text = getNodeText(e).unescapeLineBreaks();
  8670. } else {
  8671. while(e.nodeName!="PRE" && e.nodeName!="pre") {
  8672. e = e.nextSibling;
  8673. }
  8674. text = e.innerHTML.replace(/\r/mg,"").htmlDecode();
  8675. }
  8676. var modifier = node.getAttribute("modifier");
  8677. var c = node.getAttribute("created");
  8678. var m = node.getAttribute("modified");
  8679. var created = c ? Date.convertFromYYYYMMDDHHMM(c) : version.date;
  8680. var modified = m ? Date.convertFromYYYYMMDDHHMM(m) : created;
  8681. var tags = node.getAttribute("tags");
  8682. var fields = {};
  8683. var attrs = node.attributes;
  8684. for(var i = attrs.length-1; i >= 0; i--) {
  8685. var name = attrs[i].name;
  8686. if (attrs[i].specified && !TiddlyWiki.isStandardField(name)) {
  8687. fields[name] = attrs[i].value.unescapeLineBreaks();
  8688. }
  8689. }
  8690. tiddler.assign(title,text,modifier,modified,tags,created,fields);
  8691. return tiddler;
  8692. };
  8693. //--
  8694. //-- TW21Saver (inherits from SaverBase)
  8695. //--
  8696. function TW21Saver() {}
  8697. TW21Saver.prototype = new SaverBase();
  8698. TW21Saver.prototype.externalizeTiddler = function(store,tiddler)
  8699. {
  8700. try {
  8701. var extendedAttributes = "";
  8702. var usePre = config.options.chkUsePreForStorage;
  8703. store.forEachField(tiddler,
  8704. function(tiddler,fieldName,value) {
  8705. // don't store stuff from the temp namespace
  8706. if(typeof value != "string")
  8707. value = "";
  8708. if (!fieldName.match(/^temp\./))
  8709. extendedAttributes += ' %0="%1"'.format([fieldName,value.escapeLineBreaks().htmlEncode()]);
  8710. },true);
  8711. var created = tiddler.created.convertToYYYYMMDDHHMM();
  8712. var modified = tiddler.modified.convertToYYYYMMDDHHMM();
  8713. var vdate = version.date.convertToYYYYMMDDHHMM();
  8714. var attributes = tiddler.modifier ? ' modifier="' + tiddler.modifier.htmlEncode() + '"' : "";
  8715. attributes += (usePre && modified == created) ? "" : ' modified="' + modified +'"';
  8716. attributes += (usePre && created == vdate) ? "" :' created="' + created + '"';
  8717. var tags = tiddler.getTags();
  8718. if(!usePre || tags)
  8719. attributes += ' tags="' + tags.htmlEncode() + '"';
  8720. return ('<div %0="%1"%2%3>%4</'+'div>').format([
  8721. usePre ? "title" : "tiddler",
  8722. tiddler.title.htmlEncode(),
  8723. attributes,
  8724. extendedAttributes,
  8725. usePre ? "\n<pre>" + tiddler.text.htmlEncode() + "</pre>\n" : tiddler.text.escapeLineBreaks().htmlEncode()
  8726. ]);
  8727. } catch (ex) {
  8728. throw exceptionText(ex,config.messages.tiddlerSaveError.format([tiddler.title]));
  8729. }
  8730. };
  8731. //--
  8732. //-- Deprecated code
  8733. //--
  8734. // @Deprecated: Use createElementAndWikify and this.termRegExp instead
  8735. config.formatterHelpers.charFormatHelper = function(w)
  8736. {
  8737. w.subWikify(createTiddlyElement(w.output,this.element),this.terminator);
  8738. };
  8739. // @Deprecated: Use enclosedTextHelper and this.lookaheadRegExp instead
  8740. config.formatterHelpers.monospacedByLineHelper = function(w)
  8741. {
  8742. var lookaheadRegExp = new RegExp(this.lookahead,"mg");
  8743. lookaheadRegExp.lastIndex = w.matchStart;
  8744. var lookaheadMatch = lookaheadRegExp.exec(w.source);
  8745. if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
  8746. var text = lookaheadMatch[1];
  8747. if(config.browser.isIE)
  8748. text = text.replace(/\n/g,"\r");
  8749. createTiddlyElement(w.output,"pre",null,null,text);
  8750. w.nextMatch = lookaheadRegExp.lastIndex;
  8751. }
  8752. };
  8753. // @Deprecated: Use <br> or <br /> instead of <<br>>
  8754. config.macros.br.handler = function(place)
  8755. {
  8756. createTiddlyElement(place,"br");
  8757. };
  8758. // Find an entry in an array. Returns the array index or null
  8759. // @Deprecated: Use indexOf instead
  8760. Array.prototype.find = function(item)
  8761. {
  8762. var i = this.indexOf(item);
  8763. return i == -1 ? null : i;
  8764. };
  8765. // Load a tiddler from an HTML DIV. The caller should make sure to later call Tiddler.changed()
  8766. // @Deprecated: Use store.getLoader().internalizeTiddler instead
  8767. Tiddler.prototype.loadFromDiv = function(divRef,title)
  8768. {
  8769. return store.getLoader().internalizeTiddler(store,this,title,divRef);
  8770. };
  8771. // Format the text for storage in an HTML DIV
  8772. // @Deprecated Use store.getSaver().externalizeTiddler instead.
  8773. Tiddler.prototype.saveToDiv = function()
  8774. {
  8775. return store.getSaver().externalizeTiddler(store,this);
  8776. };
  8777. // @Deprecated: Use store.allTiddlersAsHtml() instead
  8778. function allTiddlersAsHtml()
  8779. {
  8780. return store.allTiddlersAsHtml();
  8781. }
  8782. // @Deprecated: Use refreshPageTemplate instead
  8783. function applyPageTemplate(title)
  8784. {
  8785. refreshPageTemplate(title);
  8786. }
  8787. // @Deprecated: Use story.displayTiddlers instead
  8788. function displayTiddlers(srcElement,titles,template,unused1,unused2,animate,unused3)
  8789. {
  8790. story.displayTiddlers(srcElement,titles,template,animate);
  8791. }
  8792. // @Deprecated: Use story.displayTiddler instead
  8793. function displayTiddler(srcElement,title,template,unused1,unused2,animate,unused3)
  8794. {
  8795. story.displayTiddler(srcElement,title,template,animate);
  8796. }
  8797. // @Deprecated: Use functions on right hand side directly instead
  8798. var createTiddlerPopup = Popup.create;
  8799. var scrollToTiddlerPopup = Popup.show;
  8800. var hideTiddlerPopup = Popup.remove;
  8801. // @Deprecated: Use right hand side directly instead
  8802. var regexpBackSlashEn = new RegExp("\\\\n","mg");
  8803. var regexpBackSlash = new RegExp("\\\\","mg");
  8804. var regexpBackSlashEss = new RegExp("\\\\s","mg");
  8805. var regexpNewLine = new RegExp("\n","mg");
  8806. var regexpCarriageReturn = new RegExp("\r","mg");
  8807. //--
  8808. //-- End of scripts
  8809. //--
  8810. //]]>
  8811. </script>
  8812. <script type="text/javascript">
  8813. //<![CDATA[
  8814. if(useJavaSaver)
  8815. document.write("<applet style='position:absolute;left:-1px' name='TiddlySaver' code='TiddlySaver.class' archive='TiddlySaver.jar' width='1' height='1'></applet>");
  8816. //]]>
  8817. </script>
  8818. <!--POST-SCRIPT-START-->
  8819. <!--POST-SCRIPT-END-->
  8820. </body>
  8821. </html>