diff --git a/core/boot.js b/core/boot.js index 3b30fdb29..5be7bce53 100644 --- a/core/boot.js +++ b/core/boot.js @@ -585,7 +585,7 @@ $tw.Wiki.prototype.getTiddler = function(title) { } else if($tw.utils.hop(this.bundledTiddlers,title)) { return this.bundledTiddlers[title]; } else { - return null; + return undefined; } }; diff --git a/core/modules/macros/view/view.js b/core/modules/macros/view/view.js index 310dbfd67..5082a5d3f 100644 --- a/core/modules/macros/view/view.js +++ b/core/modules/macros/view/view.js @@ -28,7 +28,11 @@ exports.executeMacro = function() { value; // Get the value to display if(tiddler) { - value = tiddler.fields[field]; + if(field === "text") { + value = this.wiki.getTiddlerText(this.tiddlerTitle); + } else { + value = tiddler.fields[field]; + } } else { // Use a special value if the tiddler is missing switch(field) { case "text": diff --git a/core/modules/tiddler.js b/core/modules/tiddler.js index 84feb23bf..f9c74d25d 100644 --- a/core/modules/tiddler.js +++ b/core/modules/tiddler.js @@ -30,7 +30,7 @@ exports.isTemporary = function() { exports.getFieldString = function(field) { var value = this.fields[field]; // Check for a missing field - if(value === undefined) { + if(value === undefined || value === null) { return ""; } // Parse the field with the associated module (if any) diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 6ac5b2683..543ad1a0f 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -730,6 +730,17 @@ exports.initServerConnections = function() { }); }; +/* +Invoke all the active server connections +*/ +exports.invokeServerConnections = function(method /* ,args */) { + var args = Array.prototype.slice.call(arguments,1); + for(var title in this.serverConnections) { + var connection = this.serverConnections[title]; + connection.syncer[method].apply(connection.syncer,[connection.connection].concat(args)); + } +}; + /* Handle a syncer message */ @@ -739,4 +750,24 @@ exports.handleSyncerEvent = function(event) { } }; +/* +Trigger a load for a tiddler if it is skinny. Returns the text, or undefined if the tiddler is missing, null if the tiddler is being lazily loaded. +*/ +exports.getTiddlerText = function(title) { + var tiddler = this.getTiddler(title); + // Return undefined if the tiddler isn't found + if(!tiddler) { + return undefined; + } + if(tiddler.fields.text) { + // Just return the text if we've got it + return tiddler.fields.text; + } else { + // Ask all the server connections to load the tiddler if they can + this.invokeServerConnections("lazyLoad",title,tiddler); + // Indicate that the text is being loaded + return null; + } +}; + })(); diff --git a/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js b/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js index 12f24f151..2481a8ce9 100644 --- a/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js +++ b/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js @@ -197,6 +197,26 @@ TiddlyWebSyncer.prototype.logout = function(options) { }); }; +/* +Convert a TiddlyWeb JSON tiddler into a TiddlyWiki5 tiddler +*/ +TiddlyWebSyncer.prototype.convertTiddler = function(tiddlerFields) { + var result = {}; + for(var f in tiddlerFields) { + switch(f) { + case "fields": + for(var ff in tiddlerFields[f]) { + result[ff] = tiddlerFields[f][ff]; + } + break; + default: + result[f] = tiddlerFields[f]; + break; + } + } + return result; +}; + /* Synchronise from the server by reading the tiddler list from the recipe and queuing up GETs for any tiddlers that we don't already have */ @@ -211,34 +231,42 @@ console.log("error in syncFromServer",err); } var json = JSON.parse(data); for(var t=0; t