From 19deb60f8c5b0ef5f7c67e1c016c02ed1f2ae253 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sun, 6 May 2012 14:14:27 +0100 Subject: [PATCH] Save and restore shadow stylesheets --- core/boot.js | 4 ++++ core/modules/serializers.js | 14 ++++++++++++++ core/static.template.html.tid | 4 ++-- core/tiddlywiki5.template.html.tid | 6 +++--- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/core/boot.js b/core/boot.js index fde327573..bcd9463d5 100644 --- a/core/boot.js +++ b/core/boot.js @@ -506,6 +506,10 @@ $tw.plugins.applyMethods("tiddlerdeserializer",$tw.Wiki.tiddlerDeserializerPlugi $tw.wiki.shadows.addTiddlers( $tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("pluginModules")) ); +// Load the stylesheet tiddlers from the DOM +$tw.wiki.shadows.addTiddlers( + $tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("styleArea")) +); // Load the main store tiddlers from the DOM $tw.wiki.addTiddlers( $tw.wiki.deserializeTiddlers("(DOM)",document.getElementById("storeArea")) diff --git a/core/modules/serializers.js b/core/modules/serializers.js index 94f5749ec..daa864e27 100644 --- a/core/modules/serializers.js +++ b/core/modules/serializers.js @@ -21,6 +21,20 @@ exports["text/html"] = function(tiddler) { return text ? text : ""; }; +exports["application/x-tiddler-css"] = function(tiddler) { + var attributes = {type: "text/css"}; // The script type is set to text/javascript for compatibility with old browsers + for(var f in tiddler.fields) { + if(f !== "text") { + attributes["data-tiddler-" + f] = tiddler.getFieldString(f); + } + } + return $tw.Tree.Element( + "style", + attributes, + [$tw.Tree.Raw(tiddler.fields.text)] + ).render("text/html"); +}; + exports["application/javascript"] = function(tiddler) { var attributes = {type: "text/javascript"}; // The script type is set to text/javascript for compatibility with old browsers for(var f in tiddler.fields) { diff --git a/core/static.template.html.tid b/core/static.template.html.tid index 9e7b43b12..48b2e198d 100644 --- a/core/static.template.html.tid +++ b/core/static.template.html.tid @@ -16,9 +16,9 @@ type: text/x-tiddlywiki-html " /> <<tiddler target:$:/shadows/title>> - + <<^"PageTemplate" text/html>> diff --git a/core/tiddlywiki5.template.html.tid b/core/tiddlywiki5.template.html.tid index bad15ed3b..4fe4cd3cf 100644 --- a/core/tiddlywiki5.template.html.tid +++ b/core/tiddlywiki5.template.html.tid @@ -16,9 +16,9 @@ type: text/x-tiddlywiki-html " /> <<tiddler target:$:/shadows/title>> - +
+<<^"[is[shadowStyle]]" application/x-tiddler-css>> +