1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-25 01:20:30 +00:00

Add support for relative dates

Including: setting date on save tiddler and adding a date to HelloThere
This commit is contained in:
Jeremy Ruston 2012-10-28 14:15:07 +00:00
parent 5ad86388dc
commit ecd933dd25
4 changed files with 35 additions and 2 deletions

View File

@ -127,7 +127,12 @@ exports.eventMap["tw-SaveTiddler"] = function(event) {
var tiddler = this.wiki.getTiddler(event.tiddlerTitle); var tiddler = this.wiki.getTiddler(event.tiddlerTitle);
if(tiddler && $tw.utils.hop(tiddler.fields,"draft.title")) { if(tiddler && $tw.utils.hop(tiddler.fields,"draft.title")) {
// Save the draft tiddler as the real tiddler // Save the draft tiddler as the real tiddler
this.wiki.addTiddler(new $tw.Tiddler(tiddler,{title: tiddler.fields["draft.title"],"draft.title": undefined, "draft.of": undefined})); this.wiki.addTiddler(new $tw.Tiddler(tiddler,{
title: tiddler.fields["draft.title"],
modified: new Date(),
"draft.title": undefined,
"draft.of": undefined
}));
// Remove the draft tiddler // Remove the draft tiddler
this.wiki.deleteTiddler(event.tiddlerTitle); this.wiki.deleteTiddler(event.tiddlerTitle);
// Remove the original tiddler if we're renaming it // Remove the original tiddler if we're renaming it

View File

@ -0,0 +1,27 @@
/*\
title: $:/core/modules/macros/view/viewers/relativedate.js
type: application/javascript
module-type: fieldviewer
A viewer for viewing tiddler fields as a relative date
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
function renderValue(tiddler,field,value,viewMacro) {
if(value === undefined) {
return $tw.Tree.Text("");
} else {
return $tw.Tree.Text(
$tw.utils.getRelativeDate((new Date()) - value).description
);
}
}
exports["relativedate"] = renderValue;
})();

View File

@ -7,7 +7,7 @@ modifier: JeremyRuston
<<button close class:"btn-invisible pull-right"><[img[$:/core/images/close-button.svg]]>> <<button close class:"btn-invisible pull-right"><[img[$:/core/images/close-button.svg]]>>
</div> </div>
<div class="small"> <div class="small">
<<view modifier link>> <<view modified date>> <<view modifier link>> <<view modified relativedate>>
</div> </div>
{{tw-tags-wrapper{ {{tw-tags-wrapper{
((([is[current]tags[]]))($:/templates/TagTemplate)) ((([is[current]tags[]]))($:/templates/TagTemplate))

View File

@ -2,6 +2,7 @@ title: HelloThere
modifier: JeremyRuston modifier: JeremyRuston
tags: introduction greetings tags: introduction greetings
type: text/x-tiddlywiki type: text/x-tiddlywiki
modified: 201208121934
Welcome to TiddlyWiki5, a reboot of TiddlyWiki, the reusable non-linear personal web notebook [[first released in 2004|History]]. It is a complete interactive wiki in JavaScript that can be run from a single HTML file in the browser or as a powerful [[node.js application|node.js]]. Welcome to TiddlyWiki5, a reboot of TiddlyWiki, the reusable non-linear personal web notebook [[first released in 2004|History]]. It is a complete interactive wiki in JavaScript that can be run from a single HTML file in the browser or as a powerful [[node.js application|node.js]].