| | @@ -1,28 +1,28 @@ |
| 1 | 1 | # Use of JavaScript in Fossil |
| 2 | 2 | |
| 3 | | -## Philosophy |
| 3 | +## Philosophy & Policy |
| 4 | 4 | |
| 5 | 5 | The Fossil development project’s policy is to use JavaScript where it |
| 6 | 6 | helps make its web UI better, but to offer graceful fallbacks wherever |
| 7 | | -practical. The intent is that the UI be usable with JavaScript entirely |
| 8 | | -disabled. In every place where Fossil uses JavaScript, it is an |
| 9 | | -enhancement to provided functionality, and there is always another way |
| 10 | | -to accomplish a given end without using JavaScript. |
| 7 | +practical. The intent is that the UI be usable with JavaScript |
| 8 | +entirely disabled. In almost all places where Fossil uses JavaScript, |
| 9 | +it is an enhancement to provided functionality, and there is always |
| 10 | +another way to accomplish a given end without using JavaScript. |
| 11 | 11 | |
| 12 | 12 | This is not to say that Fossil’s fall-backs for such cases are always as |
| 13 | 13 | elegant and functional as a no-JS purist might wish. That is simply |
| 14 | | -because [the vast majority of web users run with JS enabled](#stats), |
| 15 | | -and a minority of those run with some kind of conditional JavaScript |
| 16 | | -blocking in place. Fossil’s active developers do not deviate from that |
| 14 | +because [the vast majority of web users run with JavaScript enabled](#stats), |
| 15 | +and a minority of those run with some kind of [conditional JavaScript |
| 16 | +blocking](#block) in place. Fossil’s active developers do not deviate from that |
| 17 | 17 | norm enough that we have many no-JS purists among us, so the no-JS case |
| 18 | 18 | doesn’t get as much attention as some might want. We do [accept code |
| 19 | 19 | contributions][cg], and we are philosophically in favor of graceful |
| 20 | 20 | fall-backs, so you are welcome to appoint yourself the position of no-JS |
| 21 | 21 | czar for the Fossil project! |
| 22 | 22 | |
| 23 | | -Evil is in actions, not in nouns, so we do not believe JavaScript *can* |
| 23 | +Evil is in actions, not in nouns: we do not believe JavaScript *can* |
| 24 | 24 | be evil. It is an active technology, but the actions that matter here |
| 25 | 25 | are those of writing the code and checking it into the Fossil project |
| 26 | 26 | repository. None of the JavaScript code in Fossil is evil, a fact we |
| 27 | 27 | enforce by being careful about who we give check-in rights on the |
| 28 | 28 | repository to and by policing what code does get contributed. The Fossil |
| | @@ -30,98 +30,264 @@ |
| 30 | 30 | |
| 31 | 31 | We think it’s better to ask not whether Fossil requires JavaScript but |
| 32 | 32 | whether Fossil uses JavaScript *well*, so that [you can decide](#block) |
| 33 | 33 | to block or allow Fossil’s use of JavaScript. |
| 34 | 34 | |
| 35 | +The Fossil developers want to see the project thrive, and we achieve |
| 36 | +that best by making it usable and friendly to a wider audience than the |
| 37 | +minority of static web app purists. Modern users generally expect a |
| 38 | +smoother experience than was available with 1990s style HTTP |
| 39 | +POST-and-response `<form>` based interaction. We also increase the set |
| 40 | +of potential Fossil developers if we do not restrict them to such |
| 41 | +antiquated methods. |
| 42 | + |
| 43 | +JavaScript is not perfect, but it's what we have, so we will use it |
| 44 | +where we find it advantageous. |
| 45 | + |
| 35 | 46 | [cg]: ./contribute.wiki |
| 36 | 47 | |
| 37 | 48 | |
| 38 | | -## <a id="block"></a>Blocking JavaScript |
| 39 | | - |
| 40 | | -Rather than either block JavaScript wholesale or give up on blocking |
| 41 | | -JavaScript entirely, we recommend that you use tools like [NoScript][ns] |
| 42 | | -or [uBlock Origin][ub] to selectively block problematic uses of |
| 43 | | -JavaScript so the rest of the web can use the technology productively, |
| 44 | | -as it was intended. There are doubtless other useful tools of this sort; |
| 45 | | -we recommend only these two due to our limited experience, not out of |
| 46 | | -any wish to exclude other tools. |
| 47 | | - |
| 48 | | -The primary difference between these two for our purposes is that |
| 49 | | -NoScript lets you select scripts to run on a page on a case-by-case |
| 50 | | -basis, whereas uBlock Origin delegates those choices to a group of |
| 51 | | -motivated volunteers who maintain whitelists and blacklists to control |
| 52 | | -all of this; you can then override UBO’s stock rules as needed. |
| 53 | | - |
| 54 | | -[ns]: https://noscript.net/ |
| 55 | | -[ub]: https://github.com/gorhill/uBlock/ |
| 56 | | - |
| 57 | | - |
| 58 | | -## <a id="stats"></a>How Many Users Run with JavaScript Disabled Anyway? |
| 59 | | - |
| 60 | | -There are several studies that have directly measured the web audience |
| 61 | | -to answer this question: |
| 62 | | - |
| 63 | | -* [What percentage of browsers with javascript disabled?][s1] |
| 64 | | -* [How many people are missing out on JavaScript enhancement?][s2] |
| 65 | | -* [Just how many web users really disable cookies or JavaScript?][s3] |
| 66 | | - |
| 67 | | -Our sense of this data is that only about 0.2% of web users had |
| 68 | | -JavaScript disabled while participating in these studies. |
| 69 | | - |
| 70 | | -The Fossil user community is not typical of the wider web, but if we |
| 71 | | -were able to comprehensively survey our users, we’d expect to find an |
| 72 | | -interesting dichotomy. Because Fossil is targeted at software |
| 73 | | -developers, who in turn are more likely to be power-users, we’d expect |
| 74 | | -to find Fossil users to be more in favor of some amount of JavaScript |
| 75 | | -blocking than the average web user. Yet, we’d also expect to find that |
| 76 | | -our user base has a disproportionately high number who run [powerful |
| 77 | | -conditional blocking plugins](#block) in their browsers, rather than |
| 78 | | -block JS entirely. We suspect that between these two forces, the number |
| 79 | | -of no-JS purists among Fossil’s user base is still a tiny minority. |
| 80 | | - |
| 81 | | -[s1]: https://blockmetry.com/blog/javascript-disabled |
| 82 | | -[s2]: https://gds.blog.gov.uk/2013/10/21/how-many-people-are-missing-out-on-javascript-enhancement/ |
| 83 | | -[s3]: https://w3techs.com/technologies/overview/client_side_language/all |
| 84 | | - |
| 85 | | - |
| 86 | | -## <a id="3pjs"></a>No Third-Party JavaScript in Fossil |
| 87 | | - |
| 88 | | -Fossil does not use any third-party JavaScript libraries, not even very |
| 89 | | -common ones like jQuery. Every bit of JavaScript served by the stock |
| 90 | | -version of Fossil was written specifically for the Fossil project and is |
| 91 | | -stored [in its code repository](https://fossil-scm.org/fossil/file). |
| 92 | | - |
| 93 | | -Therefore, if you want to hack on the JavaScript code served by Fossil |
| 94 | | -and mechanisms like [skin editing][cs] don’t suffice for your purposes, |
| 95 | | -you can hack on the JavaScript in your local instance directly, just as |
| 96 | | -you can hack on its C, SQL, and Tcl code. Fossil is free and open source |
| 97 | | -software, under [a single license][2cbsd]. |
| 98 | | - |
| 99 | | -[2cbsd]: https://fossil-scm.org/home/doc/trunk/COPYRIGHT-BSD2.txt |
| 100 | | -[cs]: ./customskin.md |
| 101 | | - |
| 102 | | - |
| 103 | | -## <a id="snoop"></a>Fossil Does Not Snoop On You |
| 104 | | - |
| 105 | | -There is no tracking or other snooping technology in Fossil other than |
| 106 | | -that necessary for basic security, such as IP address logging on |
| 107 | | -check-ins. (This is in part why we have no [comprehensive user |
| 108 | | -statistics](#stats)!) |
| 109 | | - |
| 110 | | -Fossil attempts to set two cookies on all web clients: a login session |
| 111 | | -cookie and a display preferences cookie. These cookies are restricted to |
| 112 | | -the Fossil instance, so even this limited data cannot leak between |
| 113 | | -Fossil instances or into other web sites. |
| 114 | | - |
| 115 | | -There is some server-side event logging, but that is done entirely |
| 116 | | -without JavaScript, so it’s off-topic here. |
| 117 | | - |
| 49 | +## <a id="debate"></a>Arguments Against JavaScript & Our Rebuttals |
| 50 | + |
| 51 | +There are many common arguments against the use of JavaScript. Rather than |
| 52 | +rehash these same arguments on the [forum][ffor], we distill the common |
| 53 | +ones we’ve heard before and give our stock answers to them here: |
| 54 | + |
| 55 | +1. “**It increases the size of the page download.**” |
| 56 | + |
| 57 | + The heaviest such pages served by Fossil only have about 8 kB of |
| 58 | + compressed JavaScript. (You have to go out of your way to get Fossil |
| 59 | + to serve uncompressed pages.) This is negligible, even over very |
| 60 | + slow data connections. If you are still somehow on a 56 kbit/sec |
| 61 | + analog telephone modem, this extra script code would download in |
| 62 | + about a second. |
| 63 | + |
| 64 | + Most JavaScript-based Fossil pages use less code than that. |
| 65 | + |
| 66 | + Atop that, Fossil 2.12 adds new script delivery methods with |
| 67 | + aggressive caching enabled so that typical page loads will skip |
| 68 | + re-loading this content on subsequent loads. These features are |
| 69 | + currently optional: you must either set the new [`fossil server |
| 70 | + --jsmode` option][fsrv] or the corresponding `jsmode` control line |
| 71 | + in your [`fossil cgi`][fcgi] script when setting up your |
| 72 | + [Fossil server][fshome]. That done, Fossil’s JavaScript files will |
| 73 | + load almost instantly from the browser’s cache after the initial |
| 74 | + page load, rather than be re-transferred over the network. |
| 75 | + |
| 76 | + Between the improved caching and the fact that it’s quicker to |
| 77 | + transfer a partial Ajax page load than reload the entire page, the |
| 78 | + aggregate cost of such pages is typically *lower* than the older |
| 79 | + methods based on HTTP POST with a full server round-trip. You can |
| 80 | + expect to recover the cost of the initial page load in 1-2 |
| 81 | + round-trips. If we were to double the amount of JavaScript code in |
| 82 | + Fossil, the payoff time would increase to 2-4 round-trips. |
| 83 | + |
| 84 | +2. “**JavaScript is slow.**” |
| 85 | + |
| 86 | + It *was*, before September 2008. Google's introduction of [their V8 |
| 87 | + JavaScript engine][v8] taught the world that JavaScript need not be |
| 88 | + slow. This competitive pressure caused the other common JavaScript |
| 89 | + interpreters to either improve or be replaced by one of the engines |
| 90 | + that did improve to approach V8’s speed. |
| 91 | + |
| 92 | + Nowadays JavaScript is, as a rule, astoundingly fast. As the world |
| 93 | + continues to move more and more to web-based applications and |
| 94 | + services, JavaScript engine developers have ample motivation to keep |
| 95 | + their engines fast and competitive. |
| 96 | + |
| 97 | + Once the scripts are cached, Ajax based page updates are faster than |
| 98 | + the alternative, a full HTTP POST round-trip. |
| 99 | + |
| 100 | +3. <a id="3pjs"></a>“**Third-party JavaScript cannot be trusted.**” |
| 101 | + |
| 102 | + Fossil does not use any third-party JavaScript libraries, not even |
| 103 | + very common ones like jQuery. Every bit of JavaScript served by the |
| 104 | + stock version of Fossil was written specifically for the Fossil |
| 105 | + project and is stored [in its code repository][fsrc]. |
| 106 | + |
| 107 | + Therefore, if you want to hack on the JavaScript code served by |
| 108 | + Fossil and mechanisms like [skin editing][cskin] don’t suffice for your |
| 109 | + purposes, you can hack on the JavaScript in your local instance |
| 110 | + directly, just as you can hack on its C, SQL, and Tcl code. Fossil |
| 111 | + is free and open source software, under [a single license][2cbsd]. |
| 112 | + |
| 113 | +4. <a id="snoop"></a>“**JavaScript and cookies are used to snoop on web users.**” |
| 114 | + |
| 115 | + There is no tracking or other snooping technology in Fossil other than |
| 116 | + that necessary for basic security, such as IP address logging on |
| 117 | + check-ins. (This is in part why we have no [comprehensive user |
| 118 | + statistics](#stats)!) |
| 119 | + |
| 120 | + Fossil attempts to set two cookies on all web clients: a login session |
| 121 | + cookie and a display preferences cookie. These cookies are restricted to |
| 122 | + the Fossil instance, so even this limited data cannot leak between |
| 123 | + Fossil instances or into other web sites. |
| 124 | + |
| 125 | +5. “**JavaScript is fundamentally insecure.**” |
| 126 | + |
| 127 | + JavaScript is certainly sometimes used for nefarious ends, but if we |
| 128 | + wish to have more features in Fossil, the alternative is to add more |
| 129 | + code to the Fossil binary, [most likely in C][fslpl], a language |
| 130 | + implicated in [over 4× more security vulnerabilities][whmsl]. |
| 131 | + |
| 132 | + Therefore, does it not make sense to place approximately four times |
| 133 | + as much trust in Fossil’s JavaScript code as in its C code? |
| 134 | + |
| 135 | + The question is not whether JavaScript is itself evil, it is whether |
| 136 | + its *authors* are evil. *Every byte* of JavaScript code used within |
| 137 | + the Fossil UI is: |
| 138 | + |
| 139 | + * ...written by the Fossil developers, vetted by their peers. |
| 140 | + |
| 141 | + * ...[open source][flic] and [available][fsrc] to be inspected, |
| 142 | + audited, and changed by its users. |
| 143 | + |
| 144 | + * ...compiled directly into the `fossil` binary in a |
| 145 | + non-obfuscated form during the build process, so there are no |
| 146 | + third-party servers delivering mysterious, obfuscated JavaScript |
| 147 | + code blobs to the user. |
| 148 | + |
| 149 | + Local administrators can [modify the repository’s skin][cskin] to |
| 150 | + inject additional JavaScript code into pages served by their Fossil |
| 151 | + server. A typical case is to add a syntax highlighter like |
| 152 | + [Prism.js][pjs] or [highlightjs][hljs] to the local repository. At |
| 153 | + that point, your trust concern is not with Fossil’s use of |
| 154 | + JavaScript, but with your trust in that repository’s administrator. |
| 155 | + |
| 156 | + Fossil's [default content security policy][dcsp] (CSP) |
| 157 | + prohibits execution of JavaScript code which is delivered from |
| 158 | + anywhere but the Fossil server which delivers the page. A local |
| 159 | + administrator can change this CSP, but again this comes down to a |
| 160 | + matter of trust with the administrator, not with Fossil itself. |
| 161 | + |
| 162 | +6. “**Cross-browser compatibility is poor.**” |
| 163 | + |
| 164 | + It most certainly was in the first decade or so of JavaScript’s |
| 165 | + lifetime, resulting in the creation of powerful libraries like |
| 166 | + jQuery to patch over the incompatibilities. Over time, the need for |
| 167 | + such libraries has dropped as browser vendors have fixed the |
| 168 | + incompatibilities. Cross-browser JavaScript compatibility issues |
| 169 | + which affect web developers are, by and large, a thing of the past. |
| 170 | + |
| 171 | +7. “**Fossil UI works fine today without JavaScript. Why break it?**” |
| 172 | + |
| 173 | + While this is true today, and we have no philosophical objection to |
| 174 | + it remaining true, we do not intend to limit ourselves to only those |
| 175 | + features that can be created without JavaScript. The mere |
| 176 | + availability of alternatives is not a good justification for holding |
| 177 | + back on notable improvements when they're within easy reach. |
| 178 | + |
| 179 | + The no-JS case is a [minority position](#stats), so those that want |
| 180 | + Fossil to have no-JS alternatives and graceful fallbacks will need |
| 181 | + to get involved with the development if they want this state of |
| 182 | + affairs to continue. |
| 183 | + |
| 184 | +8. <a id="stats"></a>“**A large number of users run without JavaScript enabled.**” |
| 185 | + |
| 186 | + That’s not what web audience measurements say: |
| 187 | + |
| 188 | + * [What percentage of browsers with javascript disabled?][s1] |
| 189 | + * [How many people are missing out on JavaScript enhancement?][s2] |
| 190 | + * [Just how many web users really disable cookies or JavaScript?][s3] |
| 191 | + |
| 192 | + Our sense of this data is that only about 0.2% of web users had |
| 193 | + JavaScript disabled while participating in these studies. |
| 194 | + |
| 195 | + The Fossil user community is not typical of the wider web, but if we |
| 196 | + were able to comprehensively survey our users, we’d expect to find |
| 197 | + an interesting dichotomy. Because Fossil is targeted at software |
| 198 | + developers, who in turn are more likely to be power-users, we’d |
| 199 | + expect to find Fossil users to be more in favor of some amount of |
| 200 | + JavaScript blocking than the average web user. Yet, we’d also expect |
| 201 | + to find that our user base has a disproportionately high number who |
| 202 | + run [powerful conditional blocking plugins](#block) in their |
| 203 | + browsers, rather than block JavaScript entirely. We suspect that |
| 204 | + between these two forces, the number of no-JS purists among Fossil’s |
| 205 | + user base is still a tiny minority. |
| 206 | + |
| 207 | +9. <a id="block"></a>“**I block JavaScript entirely in my browser. That breaks Fossil.**” |
| 208 | + |
| 209 | + First, see our philosophy statements above. Briefly, we intend that |
| 210 | + there always be some other way to get any given result without using |
| 211 | + JavaScript, developer interest willing. |
| 212 | + |
| 213 | + But second, it doesn’t have to be all-or-nothing. We recommend that |
| 214 | + those interested in blocking problematic uses of JavaScript use |
| 215 | + tools like [NoScript][ns] or [uBlock Origin][ubo] to *selectively* |
| 216 | + block JavaScript so the rest of the web can use the technology |
| 217 | + productively, as it was intended. |
| 218 | + |
| 219 | + There are doubtless other useful tools of this sort. We recommend |
| 220 | + these two only from our limited experience, not out of any wish to |
| 221 | + exclude other tools. |
| 222 | + |
| 223 | + The primary difference between these two for our purposes is that |
| 224 | + NoScript lets you select scripts to run on a page on a case-by-case |
| 225 | + basis, whereas uBlock Origin delegates those choices to a group of |
| 226 | + motivated volunteers who maintain allow/block lists to control all |
| 227 | + of this; you can then override UBO’s stock rules as needed. |
| 228 | + |
| 229 | +10. “**My browser doesn’t even *have* a JavaScript interpreter.**” |
| 230 | + |
| 231 | + The Fossil open source project has no full-time developers, and only |
| 232 | + a few of these part-timers are responsible for the bulk of the code |
| 233 | + in Fossil. If you want Fossil to support such niche use cases, then |
| 234 | + you will have to [get involved with its development][cg]: it’s |
| 235 | + *your* uncommon itch. |
| 236 | + |
| 237 | +11. <a id="compat"></a>“**Fossil’s JavaScript code isn’t compatible with my browser.**” |
| 238 | + |
| 239 | + The Fossil project’s developers aim to remain compatible with |
| 240 | + the largest portions of the client-side browser base. We use only |
| 241 | + standards-defined JavaScript features which are known to work in the |
| 242 | + overwhelmingly vast majority of browsers going back approximately 5 |
| 243 | + years, at minimum, as documented by [Can I Use...?][ciu] We avoid use of |
| 244 | + features added to the language more recently or those which are still in |
| 245 | + flux in standards committees. |
| 246 | + |
| 247 | + We set this threshold based on the amount of time it typically takes for |
| 248 | + new standards to propagate through the installed base. |
| 249 | + |
| 250 | + As of this writing, this means we are only using features defined in |
| 251 | + [ECMAScript 2015][es2015], colloquially called “JavaScript 6.” That |
| 252 | + is a sufficiently rich standard that it more than suffices for our |
| 253 | + purposes, and it is [widely deployed][es6dep]. The biggest single |
| 254 | + outlier remaining is MSIE 11, and [even Microsoft is moving their |
| 255 | + own products off of it][ie11x]. |
| 256 | + |
| 257 | +[2cbsd]: https://fossil-scm.org/home/doc/trunk/COPYRIGHT-BSD2.txt |
| 258 | +[ciu]: https://caniuse.com/ |
| 259 | +[cskin]: ./customskin.md |
| 260 | +[dcsp]: ./defcsp.md |
| 261 | +[es2015]: https://ecma-international.org/ecma-262/6.0/ |
| 262 | +[es6dep]: https://caniuse.com/#feat=es6 |
| 263 | +[fcgi]: /help?cmd=cgi |
| 264 | +[ffor]: https://fossil-scm.org/forum/ |
| 265 | +[flic]: /doc/trunk/COPYRIGHT-BSD2.txt |
| 266 | +[fshome]: /doc/trunk/www/server/ |
| 267 | +[fslpl]: /doc/trunk/www/fossil-v-git.wiki#portable |
| 268 | +[fsrc]: https://fossil-scm.org/home/file/src |
| 269 | +[fsrv]: /help?cmd=server |
| 270 | +[hljs]: https://fossil-scm.org/forum/forumpost/9150bc22ca |
| 271 | +[ie11x]: https://techcommunity.microsoft.com/t5/microsoft-365-blog/microsoft-365-apps-say-farewell-to-internet-explorer-11-and/ba-p/1591666 |
| 272 | +[ns]: https://noscript.net/ |
| 273 | +[pjs]: https://fossil-scm.org/forum/forumpost/1198651c6d |
| 274 | +[s1]: https://blockmetry.com/blog/javascript-disabled |
| 275 | +[s2]: https://gds.blog.gov.uk/2013/10/21/how-many-people-are-missing-out-on-javascript-enhancement/ |
| 276 | +[s3]: https://w3techs.com/technologies/overview/client_side_language/all |
| 277 | +[ubo]: https://github.com/gorhill/uBlock/ |
| 278 | +[v8]: https://en.wikipedia.org/wiki/V8_(JavaScript_engine) |
| 279 | +[whmsl]: https://www.whitesourcesoftware.com/most-secure-programming-languages/ |
| 280 | + |
| 281 | + |
| 282 | +---- |
| 118 | 283 | |
| 119 | 284 | ## <a id="uses"></a>Places Where Fossil’s Web UI Uses JavaScript |
| 120 | 285 | |
| 121 | | -The remainder of this document will explain how Fossil currently uses |
| 122 | | -JavaScript and what it does when these uses are blocked. |
| 286 | +This section documents the areas where Fossil currently uses JavaScript |
| 287 | +and what it does when these uses are blocked. It also gives common |
| 288 | +workarounds where necessary. |
| 123 | 289 | |
| 124 | 290 | |
| 125 | 291 | ### <a id="timeline"></a>Timeline Graph |
| 126 | 292 | |
| 127 | 293 | Fossil’s [web timeline][wt] uses JavaScript to render the graph |
| | @@ -140,45 +306,144 @@ |
| 140 | 306 | command, by clicking around within the web UI, etc. |
| 141 | 307 | |
| 142 | 308 | _Potential Workaround:_ The timeline could be enhanced with `<noscript>` |
| 143 | 309 | tags that replace the graph with a column of checkboxes that control |
| 144 | 310 | what a series of form submit buttons do when clicked, replicating the |
| 145 | | -current JS-based features of the graph using client-server round-trips. |
| 311 | +current JavaScript-based features of the graph using client-server round-trips. |
| 146 | 312 | For example, you could click two of those checkboxes and then a button |
| 147 | 313 | labeled “Diff Selected” to replicate the current “click two nodes to |
| 148 | 314 | diff them” feature. |
| 149 | 315 | |
| 150 | 316 | [wt]: https://fossil-scm.org/fossil/timeline |
| 151 | 317 | |
| 152 | 318 | |
| 153 | | -### <a id="wedit"></a>WYSIWYG Wiki Editor |
| 154 | | - |
| 155 | | -The Admin → Wiki → “Enable WYSIWYG Wiki Editing” toggle switches the |
| 156 | | -default plaintext editor for [Fossil wiki][fw] documents to one that |
| 157 | | -works like a basic word processor. This feature requires JavaScript in |
| 158 | | -order to react to editor button clicks like the “**B**” button, meaning |
| 159 | | -“make \[selected\] text boldface.” There is no standard WYSIWYG editor |
| 160 | | -component in browsers, doubtless because it’s relatively straightforward |
| 161 | | -to create one using JavaScript. |
| 162 | | - |
| 163 | | -_Graceful Fallback:_ Edit your wiki documents in the default plain text |
| 164 | | -wiki editor. Fossil’s wiki and Markdown language processors were |
| 165 | | -designed to be edited that way. |
| 166 | | - |
| 167 | | -[fw]: ./wikitheory.wiki |
| 319 | +### <a id="wedit"></a>The New Wiki Editor |
| 320 | + |
| 321 | +The [new wiki editor][fwt] added in Fossil 2.12 has many new features, a |
| 322 | +few of which are impossible to get without use of JavaScript. |
| 323 | + |
| 324 | +First, it allows in-browser previews without losing client-side editor |
| 325 | +state, such as where your cursor is. With the old editor, you had to |
| 326 | +re-locate the place you were last editing on each preview, which would |
| 327 | +reduce the incentive to use the preview function. In the new wiki |
| 328 | +editor, you just click the Preview tab to see how Fossil interprets your |
| 329 | +markup, then click back to the Editor tab to resume work with the prior |
| 330 | +context undisturbed. |
| 331 | + |
| 332 | +Second, it continually saves your document state in client-side storage |
| 333 | +in the background while you’re editing it so that if the browser closes |
| 334 | +without saving the changes back to the Fossil repository, you can resume |
| 335 | +editing from the stored copy without losing work. This feature is not so |
| 336 | +much about saving you from crashes of various sorts, since computers are |
| 337 | +so much more reliable these days. It is far more likely to save you from |
| 338 | +the features of mobile OSes like Android and iOS which aggressively shut |
| 339 | +down and restart apps to save on RAM. That OS design philosophy assumes |
| 340 | +that there is a way for the app to restore its prior state from |
| 341 | +persistent media when it’s restarted, giving the illusion that it was |
| 342 | +never shut down in the first place. This feature of Fossil’s new wiki |
| 343 | +editor provides that. |
| 344 | + |
| 345 | +With this change, we lost the old WYSIWYG wiki editor, available since |
| 346 | +Fossil version 1.24. It hadn’t been maintained for years, it was |
| 347 | +disabled by default, and no one stepped up to defend its existence when |
| 348 | +this new editor was created, replacing it. If someone rescues that |
| 349 | +feature, merging it in with the new editor, it will doubtless require |
| 350 | +JavaScript in order to react to editor button clicks like the “**B**” |
| 351 | +button, meaning “make \[selected\] text boldface.” There is no standard |
| 352 | +WYSIWYG editor component in browsers, doubtless because it’s relatively |
| 353 | +straightforward to create one using JavaScript. |
| 354 | + |
| 355 | +_Graceful Fallback:_ Unlike in the Fossil 2.11 and earlier days, there |
| 356 | +is no longer a script-free wiki editor mode. This is not from lack of |
| 357 | +desire, only because the person who wrote the new wiki editor didn’t |
| 358 | +want to maintain three different editors. (New Ajaxy editor, old |
| 359 | +script-free HTML form based editor, and the old WYSIWYG JavaScript-based |
| 360 | +editor.) If someone wants to implement a `<noscript>` alternative to the |
| 361 | +new wiki editor, we will likely accept that [contribution][cg] as long |
| 362 | +as it doesn’t interfere with the new editor. (The same goes for adding |
| 363 | +a WYSIWYG mode to the new Ajaxy wiki editor.) |
| 364 | + |
| 365 | +_Workaround:_ You don’t have to use the browser-based wiki editor to |
| 366 | +maintain your repository’s wiki at all. Fossil’s [`wiki` command][fwc] |
| 367 | +lets you manipulate wiki documents from the command line. For example, |
| 368 | +consider this Vi based workflow: |
| 369 | + |
| 370 | +```shell |
| 371 | + $ vi 'My Article.wiki' # begin work on new article |
| 372 | + ...write, write, write... |
| 373 | + :w # save changes to disk copy |
| 374 | + :!fossil wiki create 'My Article' '%' # current file (%) to new article |
| 375 | + ...write, write, write some more... |
| 376 | + :w # save again |
| 377 | + :!fossil wiki commit 'My Article' '%' # update article from disk |
| 378 | + :q # done writing for today |
| 379 | + |
| 380 | + ....days later... |
| 381 | + $ vi # work sans named file today |
| 382 | + :r !fossil wiki export 'My Article' - # pull article text into vi buffer |
| 383 | + ...write, write, write yet more... |
| 384 | + :w !fossil wiki commit - # vi buffer updates article |
| 385 | +``` |
| 386 | + |
| 387 | +Extending this concept to other text editors is an exercise left to the |
| 388 | +reader. |
| 389 | + |
| 390 | +[fwc]: /help?cmd=wiki |
| 391 | +[fwt]: ./wikitheory.wiki |
| 392 | + |
| 393 | + |
| 394 | +### <a id="fedit"></a>The File Editor |
| 395 | + |
| 396 | +Fossil 2.12 adds the [optional file editor feature][fedit], which works |
| 397 | +much like [the new wiki editor](#wedit), only on files committed to the |
| 398 | +repository. |
| 399 | + |
| 400 | +The original designed purpose for this feature is to allow [embedded |
| 401 | +documentation][edoc] to be interactively edited in the same way that |
| 402 | +wiki articles can be. (Indeed, the associated `fileedit-glob` feature |
| 403 | +allows you to restrict the editor to working *only* on files that can be |
| 404 | +treated as embedded documentation.) This feature operates in much the |
| 405 | +same way as the new wiki editor, so most of what we said above applies. |
| 406 | + |
| 407 | +_Workaround:_ This feature is an alternative to Fossil’s traditional |
| 408 | +mode of file management: clone the repository, open it somewhere, edit a |
| 409 | +file locally, and commit the changes. |
| 410 | + |
| 411 | +_Graceful Fallback:_ There is no technical reason why someone could not |
| 412 | +write a `<noscript>` wrapped alternative to the current JavaScript based |
| 413 | +`/fileedit` implementation. It would have all of the same downsides as |
| 414 | +the old wiki editor: the users would lose their place on each save, they |
| 415 | +would have no local backup if something crashes, etc. Still, we are |
| 416 | +likely to accept such a [contribution][cg] as long as it doesn’t |
| 417 | +interfere with the new editor. |
| 418 | + |
| 419 | +[edoc]: /doc/trunk/www/embeddeddoc.wiki |
| 420 | +[fedit]: /doc/trunk/www/fileedit-page.md |
| 168 | 421 | |
| 169 | 422 | |
| 170 | 423 | ### <a id="ln"></a>Line Numbering |
| 171 | 424 | |
| 172 | 425 | When viewing source files, Fossil offers to show line numbers in some |
| 173 | | -cases. Toggling them on and off is currently handled in JavaScript. |
| 174 | | -([Example][mainc].) |
| 426 | +cases. ([Example][mainc].) Toggling them on and off is currently handled |
| 427 | +in JavaScript, rather than forcing a page-reload via a button click. |
| 428 | + |
| 429 | +_Workaround:_ Manually edit the URL to give the “`ln`” query parameter |
| 430 | +per [the `/file` docs](/help?cmd=/file). |
| 431 | + |
| 432 | +_Potential Better Workaround:_ Someone sufficiently interested could |
| 433 | +[provide a patch][cg] to add a `<noscript>` wrapped HTML button that |
| 434 | +would reload the page with this parameter included/excluded to implement |
| 435 | +the toggle via a server round-trip. |
| 436 | + |
| 437 | +As of Fossil 2.12, there is also a JavaScript-based interactive method |
| 438 | +for selecting a range of lines by clicking the line numbers when they’re |
| 439 | +visible, then copying the resulting URL to share your selection with |
| 440 | +others. |
| 175 | 441 | |
| 176 | | -_Workaround:_ Edit the URL to give the “`ln`” query parameter per [the |
| 177 | | -`/file` docs](/help?cmd=/file), or provide a patch to reload the page |
| 178 | | -with this parameter included/excluded to implement the toggle via a |
| 179 | | -server round-trip. |
| 442 | +_Workaround:_ These interactive features would be difficult and |
| 443 | +expensive (in terms of network I/O) to implement without JavaScript. A |
| 444 | +far simpler alternative is to manually edit the URL, per above. |
| 180 | 445 | |
| 181 | 446 | [mainc]: https://fossil-scm.org/fossil/artifact?ln&name=87d67e745 |
| 182 | 447 | |
| 183 | 448 | |
| 184 | 449 | ### <a id="sxsdiff"></a>Side-by-Side Diff Mode |
| | @@ -224,12 +489,12 @@ |
| 224 | 489 | similar, hovering over that check-in shows a tooltip with details about |
| 225 | 490 | the type of artifact the hash refers to and allows you to click to copy |
| 226 | 491 | the hash to the clipboard. |
| 227 | 492 | |
| 228 | 493 | _Graceful Fallback:_ When JavaScript is disabled, these tooltips simply |
| 229 | | -don’t appear. You can then select and copy the hash using your browser, |
| 230 | | -make “`fossil info`” queries on those hashes, etc. |
| 494 | +don’t appear, but you can still select and copy the hash using your |
| 495 | +platform’s “copy selected text” feature. |
| 231 | 496 | |
| 232 | 497 | |
| 233 | 498 | ### <a id="bots"></a>Anti-Bot Defenses |
| 234 | 499 | |
| 235 | 500 | Fossil has [anti-bot defenses][abd], and it has some JavaScript code |
| | @@ -254,26 +519,75 @@ |
| 254 | 519 | |
| 255 | 520 | _Graceful Fallback:_ Clicking the hamburger menu button with JavaScript |
| 256 | 521 | disabled will take you to the `/sitemap` page instead of showing a |
| 257 | 522 | simplified version of that page’s content in a drop-down. |
| 258 | 523 | |
| 259 | | -_Workaround:_ You can remove this button by [editing the skin][cs] |
| 524 | +_Workaround:_ You can remove this button by [editing the skin][cskin] |
| 260 | 525 | header. |
| 261 | 526 | |
| 262 | 527 | |
| 263 | 528 | ### <a id="clock"></a>Clock |
| 264 | 529 | |
| 265 | 530 | Some stock Fossil skins include JavaScript-based features such as the |
| 266 | 531 | current time of day. The Xekri skin includes this in its header, for |
| 267 | | -example. A clock feature requires JavaScript not only to get the time |
| 268 | | -and update inline on the page once a minute, but also so it displays *in |
| 269 | | -the local time zone.* |
| 270 | | - |
| 271 | | -Since none of this code provides a necessary Fossil feature, the core |
| 272 | | -developers are unlikely to try to make these features work better in the |
| 273 | | -absence of JavaScript. |
| 274 | | - |
| 275 | | -However, we are willing to study patches to make this better. For |
| 276 | | -example, the wall clock displays could include the page load time in the |
| 277 | | -dynamically generated HTML shipped from the remote Fossil server, so |
| 278 | | -that in the absence of JavaScript, you at least get the page generation |
| 279 | | -time, expressed in the server’s time zone. |
| 532 | +example. A clock feature requires JavaScript to get the time on initial |
| 533 | +page load and then to update it once a minute. |
| 534 | + |
| 535 | +You may observe that the server could provide the current time when |
| 536 | +generating the page, but the client and server may not be in the same |
| 537 | +time zone, and there is no reliably-provided information from the client |
| 538 | +that would let the server give the page load time in the client’s local |
| 539 | +time zone. The server could only tell you *its* local time at page |
| 540 | +request time, not the client’s time. That still wouldn’t be a “clock,” |
| 541 | +since without client-side JavaScript code running, that part of the page |
| 542 | +couldn’t update once a second. |
| 543 | + |
| 544 | +_Potential Graceful Fallback:_ You may consider showing the server’s |
| 545 | +page generation time rather than the client’s wall clock time in the |
| 546 | +local time zone to be a useful fallback for the current feature, so [a |
| 547 | +patch to do this][cg] may well be accepted. Since this is not a |
| 548 | +*necessary* Fossil feature, an interested user is unlikely to get the |
| 549 | +core developers to do this work for them. |
| 550 | + |
| 551 | +---- |
| 552 | + |
| 553 | +## <a id="future"></a>Future Plans for JavaScript in Fossil |
| 554 | + |
| 555 | +As of mid-2020, the informal provisional plan is to increase Fossil |
| 556 | +UI's use of JavaScript considerably compared to its historically minimal |
| 557 | +uses. To that end, a framework of Fossil-centric APIs is being developed |
| 558 | +in conjunction with new features to consolidate Fossil's historical |
| 559 | +hodgepodge of JavaScript snippets into a coherent code base. |
| 560 | + |
| 561 | +When deciding which features to port to JavaScript, the rules of thumb |
| 562 | +for this ongoing effort are: |
| 563 | + |
| 564 | +- Pages which primarily display data (e.g. the timeline) will remain |
| 565 | + largely static HTML with graceful fallbacks for all places they do |
| 566 | + use JavaScript. Though JavaScript can be used effectively to power |
| 567 | + all sorts of wonderful data presentation, Fossil currently doesn't |
| 568 | + benefit greatly from doing so. We use JavaScript on these pages only |
| 569 | + to improve their usability, not to define their primary operations. |
| 570 | + |
| 571 | +- Pages which act as editors of some sort (e.g. the `/info` page) are |
| 572 | + prime candidates for getting the same treatment as the old wiki |
| 573 | + editor: reimplemented from the ground up in JavaScript using Ajax |
| 574 | + type techniques. Similarly, a JS-driven overhaul is planned for the |
| 575 | + forum’s post editor. |
| 576 | + |
| 577 | +These are guidelines, not immutable requirements. Our development |
| 578 | +direction is guided by our priorities: |
| 579 | + |
| 580 | +1) Features the developers themselves want to have and/or work on. |
| 581 | + |
| 582 | +2) Features end users request which catch the interest of one or more |
| 583 | +developers, provided the developer(s) in question are in a position to |
| 584 | +expend the effort. |
| 585 | + |
| 586 | +3) Features end users and co-contributors can convince a developer into |
| 587 | +coding even when they really don't want to. 😉 |
| 588 | + |
| 589 | +In all of this, Fossil's project lead understandably has the final |
| 590 | +say-so in whether any given feature indeed gets merged into the mainline |
| 591 | +trunk. Development of any given feature, no matter how much effort was |
| 592 | +involved, does not guarantee its eventual inclusion into the public |
| 593 | +releases. |
| 280 | 594 | |