From eef32e70e347bc2a91284f1876adb705bc11f331 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 24 Dec 2013 09:08:25 +0000 Subject: [PATCH] Added support for dynamic favicons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now it’s possible to edit $:/favicon.ico with the image editor, and see the changes instantly reflected in the browser. --- core/modules/startup.js | 15 +++++++++++++++ core/templates/tiddlywiki5.html.tid | 2 +- editions/tw5.com/tiddlers/Release 5.0.5beta.tid | 2 +- .../tiddlers/howtos/Setting a favicon.tid | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 editions/tw5.com/tiddlers/howtos/Setting a favicon.tid diff --git a/core/modules/startup.js b/core/modules/startup.js index 2303b9849..9ea7e6685 100755 --- a/core/modules/startup.js +++ b/core/modules/startup.js @@ -112,6 +112,21 @@ exports.startup = function() { $tw.rootWidget.addEventListener("tw-clear-password",function(event) { $tw.crypto.setPassword(null); }); + // Set up the favicon + var faviconTitle = "$:/favicon.ico", + faviconLink = document.getElementById("faviconLink"), + setFavicon = function() { + var tiddler = $tw.wiki.getTiddler(faviconTitle); + if(tiddler) { + faviconLink.setAttribute("href","data:" + tiddler.fields.type + ";base64," + tiddler.fields.text); + } + }; + setFavicon(); + $tw.wiki.addEventListener("change",function(changes) { + if($tw.utils.hop(changes,faviconTitle)) { + setFavicon(); + } + }); // Set up the styles var styleTemplateTitle = "$:/core/ui/PageStylesheet", styleParser = $tw.wiki.parseTiddler(styleTemplateTitle); diff --git a/core/templates/tiddlywiki5.html.tid b/core/templates/tiddlywiki5.html.tid index 981de1614..e2929361e 100644 --- a/core/templates/tiddlywiki5.html.tid +++ b/core/templates/tiddlywiki5.html.tid @@ -14,7 +14,7 @@ title: $:/core/templates/tiddlywiki5.html - + {{$:/core/wiki/title}} diff --git a/editions/tw5.com/tiddlers/Release 5.0.5beta.tid b/editions/tw5.com/tiddlers/Release 5.0.5beta.tid index 3fec0f180..a62f26355 100644 --- a/editions/tw5.com/tiddlers/Release 5.0.5beta.tid +++ b/editions/tw5.com/tiddlers/Release 5.0.5beta.tid @@ -8,7 +8,7 @@ type: text/vnd.tiddlywiki !! Improvements -* +* Added support for [[Setting a favicon]] !! Bug Fixes diff --git a/editions/tw5.com/tiddlers/howtos/Setting a favicon.tid b/editions/tw5.com/tiddlers/howtos/Setting a favicon.tid new file mode 100644 index 000000000..c9bcdf543 --- /dev/null +++ b/editions/tw5.com/tiddlers/howtos/Setting a favicon.tid @@ -0,0 +1,17 @@ +created: 20131224074240979 +modified: 20131224075348329 +tags: howto +title: Setting a favicon +type: text/vnd.tiddlywiki + +"favicons" are small icons that most browsers display to help users identify websites. + +! favicons in the Browser + +When TiddlyWiki starts up in the browser it looks for a tiddler called [[$:/favicon.ico]] and dynamically uses it as the favicon for the page. If you modify the image then the favicon changes instantly to reflect it. + +! favicons on the Server + +On the server, the ServerCommand will serve the tiddler [[$:/favicon.ico]] at the path `/favicon.ico`. + +