1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Limited implementation of external text tiddlers in the browser

Triggered by the discussion in #1917
This commit is contained in:
Jermolene 2015-08-29 16:33:04 +01:00
parent abd8201aaa
commit a204784c0c
7 changed files with 3756 additions and 3 deletions

View File

@ -26,6 +26,23 @@ Attributes are stored as hashmaps of the following objects:
var WikiParser = function(type,text,options) {
this.wiki = options.wiki;
var self = this;
// Check for an externally linked tiddler
if($tw.browser && options._canonical_uri) {
$tw.utils.httpRequest({
url: options._canonical_uri,
type: "GET",
callback: function(err,data) {
if(!err) {
var tiddlers = self.wiki.deserializeTiddlers(".tid",data,self.wiki.getCreationFields())
if(tiddlers) {
self.wiki.addTiddlers(tiddlers);
}
}
}
});
text = "Loading external text from ''" + options._canonical_uri + "''\n\nIf this message doesn't disappear you may be using a browser that doesn't support external text in this configuration. See http://tiddlywiki.com/#ExternalText";
}
// Initialise the classes if we don't have them already
if(!this.pragmaRuleClasses) {
WikiParser.prototype.pragmaRuleClasses = $tw.modules.createClassesFromModules("wikirule","pragma",$tw.WikiRuleBase);

View File

@ -43,7 +43,7 @@ exports.convertStyleNameToPropertyName = function(styleName) {
// Convert it by first removing any hyphens
var propertyName = $tw.utils.unHyphenateCss(styleName);
// Then check if it needs a prefix
if(document.body.style[propertyName] === undefined) {
if($tw.browser && document.body.style[propertyName] === undefined) {
var prefixes = ["O","MS","Moz","webkit"];
for(var t=0; t<prefixes.length; t++) {
var prefixedName = prefixes[t] + propertyName.substr(0,1).toUpperCase() + propertyName.substr(1);

View File

@ -58,7 +58,11 @@ exports.httpRequest = function(options) {
if(data && !$tw.utils.hop(headers,"Content-type")) {
request.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");
}
request.send(data);
try {
request.send(data);
} catch(e) {
options.callback(e);
}
return request;
};

View File

@ -0,0 +1,10 @@
title: $:/core/templates/canonical-uri-external-text
<!--
This template is used to assign the ''_canonical_uri'' field to external text files.
Change the `./text/` part to a different base URI. The URI can be relative or absolute.
-->
./text/<$view field="title" format="doubleurlencoded"/>.tid

View File

@ -28,6 +28,17 @@ The new [[Résumé Builder Edition]] by @inmysocks is a custom edition to guide
The new [[Text-Slicer Edition]] is a custom edition with tools to help advanced users slice longer texts up into individual tiddlers.
!! External Text Tiddlers
Limited support for tiddlers stored in external `.tid` files:
* standalone TiddlyWiki HTML files with external text tiddlers can be built under Node.js
* wikis with external text tiddlers can be worked with in the browser, automatically lazily loading the content of external text tiddlers when it is first referenced
** saving changes in the browser doesn't work as expected: if edited, the external text tiddler is replaced with an ordinary tiddler
** lazy loading of external text tiddlers doesn't work in Chrome when viewing the TiddlyWiki HTML file on a ''file:'' URI; it works OK in Firefox. It works on an HTTP URI on all browsers
See [[Alice in Wonderland]] for an example. Try opening it without a network connection.
! Other Improvements
!! Translation Improvements

File diff suppressed because it is too large Load Diff

View File

@ -20,8 +20,10 @@
"build": {
"index": [
"--savetiddlers","[tag[external-image]]","images",
"--rendertiddlers","[tag[external-text]]","$:/core/templates/tid-tiddler","text","text/plain",".tid",
"--setfield","[tag[external-image]]","_canonical_uri","$:/core/templates/canonical-uri-external-image","text/plain",
"--setfield","[tag[external-image]]","text","","text/plain",
"--setfield","[tag[external-text]]","_canonical_uri","$:/core/templates/canonical-uri-external-text","text/plain",
"--setfield","[tag[external-image]] [tag[external-text]]","text","","text/plain",
"--rendertiddler","$:/core/save/all","index.html","text/plain"],
"encrypted": [
"--password", "password",