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.
print-window-tiddler
Jermolene 2013-12-24 09:08:25 +00:00
rodzic ad6bf4f9c5
commit eef32e70e3
4 zmienionych plików z 34 dodań i 2 usunięć

Wyświetl plik

@ -112,6 +112,21 @@ exports.startup = function() {
$tw.rootWidget.addEventListener("tw-clear-password",function(event) { $tw.rootWidget.addEventListener("tw-clear-password",function(event) {
$tw.crypto.setPassword(null); $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 // Set up the styles
var styleTemplateTitle = "$:/core/ui/PageStylesheet", var styleTemplateTitle = "$:/core/ui/PageStylesheet",
styleParser = $tw.wiki.parseTiddler(styleTemplateTitle); styleParser = $tw.wiki.parseTiddler(styleTemplateTitle);

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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