1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-26 07:13:15 +00:00

Added support for dynamic favicons

Now it’s possible to edit $:/favicon.ico with the image editor, and see
the changes instantly reflected in the browser.
This commit is contained in:
Jermolene 2013-12-24 09:08:25 +00:00
parent ad6bf4f9c5
commit eef32e70e3
4 changed files with 34 additions and 2 deletions

View File

@ -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);

View File

@ -14,7 +14,7 @@ title: $:/core/templates/tiddlywiki5.html
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="format-detection" content="telephone=no" />
<meta name="copyright" content="{{$:/core/copyright.txt}}" />
<link rel="shortcut icon" href="favicon.ico">
<link id="faviconLink" rel="shortcut icon" href="favicon.ico">
<title>{{$:/core/wiki/title}}</title>
<!--~~ This is a Tiddlywiki file. The points of interest in the file are marked with this pattern ~~-->

View File

@ -8,7 +8,7 @@ type: text/vnd.tiddlywiki
!! Improvements
*
* Added support for [[Setting a favicon]]
!! Bug Fixes

View File

@ -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`.