1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-27 02:20:28 +00:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Bram Chen 2014-08-27 20:47:23 +08:00
commit 92abcb4f5a
17 changed files with 61 additions and 56 deletions

View File

@ -28,7 +28,7 @@ function SaverHandler(options) {
this.initSavers(); this.initSavers();
} }
// Only do dirty tracking if required // Only do dirty tracking if required
if(this.dirtyTracking) { if($tw.browser && this.dirtyTracking) {
// Compile the dirty tiddler filter // Compile the dirty tiddler filter
this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter)); this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter));
// Count of tiddlers that have been changed but not yet saved // Count of tiddlers that have been changed but not yet saved
@ -43,6 +43,9 @@ function SaverHandler(options) {
}); });
self.numTasksInQueue += filteredChanges.length; self.numTasksInQueue += filteredChanges.length;
self.updateDirtyStatus(); self.updateDirtyStatus();
if(self.numTasksInQueue > 0) {
self.saveWiki({method: "autosave"});
}
}); });
// Browser event handlers // Browser event handlers
if($tw.browser) { if($tw.browser) {
@ -65,13 +68,6 @@ function SaverHandler(options) {
downloadType: "text/plain" downloadType: "text/plain"
}); });
}); });
$tw.rootWidget.addEventListener("tw-auto-save-wiki",function(event) {
self.saveWiki({
method: "autosave",
template: event.param,
downloadType: "text/plain"
});
});
$tw.rootWidget.addEventListener("tw-download-file",function(event) { $tw.rootWidget.addEventListener("tw-download-file",function(event) {
self.saveWiki({ self.saveWiki({
method: "download", method: "download",
@ -82,7 +78,7 @@ function SaverHandler(options) {
} }
} }
SaverHandler.prototype.titleSyncFilter = "$:/config/SyncFilter"; SaverHandler.prototype.titleSyncFilter = "$:/config/SaverFilter";
SaverHandler.prototype.titleAutoSave = "$:/config/AutoSave"; SaverHandler.prototype.titleAutoSave = "$:/config/AutoSave";
SaverHandler.prototype.titleSavedNotification = "$:/language/Notifications/Save/Done"; SaverHandler.prototype.titleSavedNotification = "$:/language/Notifications/Save/Done";
@ -115,7 +111,7 @@ SaverHandler.prototype.initSavers = function(moduleType) {
/* /*
Save the wiki contents. Options are: Save the wiki contents. Options are:
method: "save" or "download" method: "save", "autosave" or "download"
template: the tiddler containing the template to save template: the tiddler containing the template to save
downloadType: the content type for the saved file downloadType: the content type for the saved file
*/ */
@ -130,6 +126,11 @@ SaverHandler.prototype.saveWiki = function(options) {
if(err) { if(err) {
alert("Error while saving:\n\n" + err); alert("Error while saving:\n\n" + err);
} else { } else {
// Clear the task queue if we're saving (rather than downloading)
if(method !== "download") {
self.numTasksInQueue = 0;
self.updateDirtyStatus();
}
$tw.notifier.display(self.titleSavedNotification); $tw.notifier.display(self.titleSavedNotification);
if(options.callback) { if(options.callback) {
options.callback(); options.callback();
@ -145,11 +146,6 @@ SaverHandler.prototype.saveWiki = function(options) {
var saver = this.savers[t]; var saver = this.savers[t];
if(saver.info.capabilities.indexOf(method) !== -1 && saver.save(text,method,callback)) { if(saver.info.capabilities.indexOf(method) !== -1 && saver.save(text,method,callback)) {
this.logger.log("Saving wiki with method",method,"through saver",saver.info.name); this.logger.log("Saving wiki with method",method,"through saver",saver.info.name);
// Clear the task queue if we're saving (rather than downloading)
if(method !== "download") {
this.numTasksInQueue = 0;
this.updateDirtyStatus();
}
return true; return true;
} }
} }

View File

@ -38,6 +38,8 @@ DownloadSaver.prototype.save = function(text,method,callback) {
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
document.body.removeChild(link); document.body.removeChild(link);
// Callback that we succeeded
callback(null);
return true; return true;
}; };

View File

@ -33,14 +33,16 @@ FSOSaver.prototype.save = function(text,method,callback) {
pathname = pathname.substr(1); pathname = pathname.substr(1);
// reconstruct UNC path // reconstruct UNC path
pathname = "\\\\" + document.location.hostname + pathname; pathname = "\\\\" + document.location.hostname + pathname;
} else return false; } else {
return false;
}
// Save the file (as UTF-16) // Save the file (as UTF-16)
var fso = new ActiveXObject("Scripting.FileSystemObject"); var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile(pathname,2,-1,-1); var file = fso.OpenTextFile(pathname,2,-1,-1);
file.Write(text); file.Write(text);
file.Close(); file.Close();
// Callback that we succeeded
callback(null);
return true; return true;
}; };

View File

@ -25,6 +25,8 @@ ManualDownloadSaver.prototype.save = function(text,method,callback) {
$tw.modal.display(downloadInstructionsTitle,{ $tw.modal.display(downloadInstructionsTitle,{
downloadLink: "data:text/html," + encodeURIComponent(text) downloadLink: "data:text/html," + encodeURIComponent(text)
}); });
// Callback that we succeeded
callback(null);
return true; return true;
}; };

View File

@ -28,6 +28,8 @@ MsDownloadSaver.prototype.save = function(text,method,callback) {
// Set up the link // Set up the link
var blob = new Blob([text], {type: "text/html"}); var blob = new Blob([text], {type: "text/html"});
window.navigator.msSaveBlob(blob,filename); window.navigator.msSaveBlob(blob,filename);
// Callback that we succeeded
callback(null);
return true; return true;
}; };

View File

@ -43,7 +43,6 @@ TiddlyFoxSaver.prototype.save = function(text,method,callback) {
} }
// Create the message element and put it in the message box // Create the message element and put it in the message box
var message = document.createElement("div"); var message = document.createElement("div");
console.log("Pathname",pathname);
message.setAttribute("data-tiddlyfox-path",decodeURIComponent(pathname)); message.setAttribute("data-tiddlyfox-path",decodeURIComponent(pathname));
message.setAttribute("data-tiddlyfox-content",text); message.setAttribute("data-tiddlyfox-content",text);
messageBox.appendChild(message); messageBox.appendChild(message);

View File

@ -35,9 +35,10 @@ TiddlyIESaver.prototype.save = function(text,method,callback) {
// reconstruct UNC path // reconstruct UNC path
pathname = "\\\\" + document.location.hostname + pathname; pathname = "\\\\" + document.location.hostname + pathname;
} else return false; } else return false;
// Prompt the user to save the file // Prompt the user to save the file
window.TiddlyIE.save(pathname, text); window.TiddlyIE.save(pathname, text);
// Callback that we succeeded
callback(null);
return true; return true;
} else { } else {
return false; return false;

View File

@ -71,8 +71,6 @@ exports.repackPlugin = function(title,additionalTiddlers,excludeTiddlers) {
$tw.wiki.deleteTiddler(title); $tw.wiki.deleteTiddler(title);
} }
}); });
// Trigger an autosave
$tw.rootWidget.dispatchEvent({type: "tw-auto-save-wiki"});
// Return a heartwarming confirmation // Return a heartwarming confirmation
return "Plugin " + title + " successfully saved"; return "Plugin " + title + " successfully saved";
} }

View File

@ -243,8 +243,6 @@ NavigatorWidget.prototype.handleDeleteTiddlerEvent = function(event) {
// Remove the closed tiddler from the story // Remove the closed tiddler from the story
this.removeTitleFromStory(storyList,title); this.removeTitleFromStory(storyList,title);
this.saveStoryList(storyList); this.saveStoryList(storyList);
// Send a notification event
this.dispatchEvent({type: "tw-auto-save-wiki"});
return false; return false;
}; };
@ -333,8 +331,6 @@ NavigatorWidget.prototype.handleSaveTiddlerEvent = function(event) {
if(draftTitle !== this.storyTitle) { if(draftTitle !== this.storyTitle) {
this.saveStoryList(storyList); this.saveStoryList(storyList);
} }
// Send a notification event
this.dispatchEvent({type: "tw-auto-save-wiki"});
} }
} }
} }
@ -376,13 +372,8 @@ NavigatorWidget.prototype.handleNewTiddlerEvent = function(event) {
var storyList = this.getStoryList(); var storyList = this.getStoryList();
// Get the template tiddler if there is one // Get the template tiddler if there is one
var templateTiddler = this.wiki.getTiddler(event.param); var templateTiddler = this.wiki.getTiddler(event.param);
// Create the new tiddler // Title the new tiddler
var title = this.wiki.generateNewTitle((templateTiddler && templateTiddler.fields.title) || "New Tiddler"); var title = this.wiki.generateNewTitle((templateTiddler && templateTiddler.fields.title) || "New Tiddler");
var tiddler = new $tw.Tiddler(this.wiki.getCreationFields(),{
text: "Newly created tiddler",
title: title
},this.wiki.getModificationFields());
this.wiki.addTiddler(tiddler);
// Create the draft tiddler // Create the draft tiddler
var draftTitle = this.generateDraftTitle(title), var draftTitle = this.generateDraftTitle(title),
draftTiddler = new $tw.Tiddler({ draftTiddler = new $tw.Tiddler({
@ -487,8 +478,6 @@ NavigatorWidget.prototype.handlePerformImportEvent = function(event) {
})); }));
// Navigate to the $:/Import tiddler // Navigate to the $:/Import tiddler
this.addToHistory([IMPORT_TITLE]); this.addToHistory([IMPORT_TITLE]);
// Send a notification event
this.dispatchEvent({type: "tw-auto-save-wiki"});
}; };
exports.navigator = NavigatorWidget; exports.navigator = NavigatorWidget;

View File

@ -0,0 +1,3 @@
title: $:/config/SaverFilter
[!is[shadow]] -[[$:/HistoryList]] -[[$:/StoryList]] -[[$:/Import]] -[[$:/isEncrypted]] -[prefix[$:/status]] -[prefix[$:/state]] -[prefix[$:/temp]] -[has[draft.of]]

View File

@ -1,13 +1,34 @@
title: HelloThere title: HelloThere
This is a demo of TiddlyWiki5 incorporating a plugin for the [[markdown-js|https://github.com/evilstreak/markdown-js]] Markdown parser from Dominic Baggott. This is a demo of TiddlyWiki5 incorporating a plugin for the [[markdown-js|https://github.com/evilstreak/markdown-js]] Markdown parser from Dominic Baggott. The MarkdownExample tiddler below is written in Markdown.
The MarkdownExample tiddler below is written in Markdown. Create wiki links with the usual Markdown link syntax targeting `#` and the target tiddler title: ! Installation
To add the plugin to your own TiddlyWiki5, just drag this link to the browser window:
[[$:/plugins/tiddlywiki/markdown]]
! Markdown Dialects
By default the markdown parser recognises the original dialect of Markdown [[as described by John Gruber|http://daringfireball.net/projects/markdown/]]. An extended dialect called "Maruku" is also included that provides table support and other advanced features. The syntax extensions are modelled on those of [[PHP Markdown Extra|https://michelf.ca/projects/php-markdown/extra/]].
The configuration tiddler [[$:/config/markdown/dialect]] determines which dialect is used:
|!Dialect |!Description |
|Gruber |Standard Markdown |
|Maruku |Extended Maruku Markdown |
! Creating ~WikiLinks
Create wiki links with the usual Markdown link syntax targeting `#` and the target tiddler title:
``` ```
[link text](#TiddlerTitle) [link text](#TiddlerTitle)
``` ```
! Images
Markdown image syntax can be used to reference images by tiddler title or an external URI. For example: Markdown image syntax can be used to reference images by tiddler title or an external URI. For example:
``` ```
@ -15,8 +36,3 @@ Markdown image syntax can be used to reference images by tiddler title or an ext
![alt text](Motovun Jack.jpg "Title") ![alt text](Motovun Jack.jpg "Title")
``` ```
To add the plugin to your own TiddlyWiki5, just drag this link to the browser window:
[[$:/plugins/tiddlywiki/markdown]]

View File

@ -9,7 +9,7 @@ type: text/vnd.tiddlywiki
!! Usability Improvements !! Usability Improvements
* * [[Amended|https://github.com/Jermolene/TiddlyWiki5/commit/e47852cb141b384ad2a9097eca795545cb5b2494]] behaviour of the [[tw-browser-refresh|WidgetMessage: tw-browser-refresh]] message so that it no longer clears the location hash
!! Hackability Improvements !! Hackability Improvements

View File

@ -183,7 +183,6 @@ $body$
">> ">>
## <<toc-heading "Widget Messages" " ## <<toc-heading "Widget Messages" "
## WidgetMessages ## WidgetMessages
## [[tw-auto-save-wiki|WidgetMessage: tw-auto-save-wiki]]
## [[tw-cancel-tiddler|WidgetMessage: tw-cancel-tiddler]] ## [[tw-cancel-tiddler|WidgetMessage: tw-cancel-tiddler]]
## [[tw-clear-password|WidgetMessage: tw-clear-password]] ## [[tw-clear-password|WidgetMessage: tw-clear-password]]
## [[tw-close-all-tiddlers|WidgetMessage: tw-close-all-tiddlers]] ## [[tw-close-all-tiddlers|WidgetMessage: tw-close-all-tiddlers]]

View File

@ -1,11 +0,0 @@
created: 20140811112343634
modified: 20140811114420597
tags: message
title: WidgetMessage: tw-auto-save-wiki
type: text/vnd.tiddlywiki
The autosave wiki message causes the current saver module to perform a background save if it is required.
The autosave wiki message should be generated whenever changes are made to the store. For example, the navigator widget generates the autosave wiki message as part of its handling of the [[WidgetMessage: tw-save-tiddler]], [[WidgetMessage: tw-delete-tiddler]] and [[WidgetMessage: tw-perform-import]].
The autosave wiki message is handled by the TiddlyWiki core SyncMechanism which invokes the current [[SaverModule|SaverModules]]. Not all SaverModules can handle autosaving.

View File

@ -4,7 +4,7 @@ tags: message
title: WidgetMessage: tw-save-wiki title: WidgetMessage: tw-save-wiki
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
The save wiki message causes the current saver module to perform a full save operation. The save operation can involve user interaction, unlike the [[WidgetMessage: tw-auto-save-wiki]]/ The save wiki message causes the current saver module to perform a full save operation. The save operation can involve user interaction.
The save wiki message is usually generated by the ButtonWidget. The save wiki message is usually generated by the ButtonWidget.

View File

@ -0,0 +1,3 @@
title: $:/config/markdown/dialect
Gruber

View File

@ -14,6 +14,9 @@ Wraps up the markdown-js parser for use in TiddlyWiki5
var markdown = require("$:/plugins/tiddlywiki/markdown/markdown.js"); var markdown = require("$:/plugins/tiddlywiki/markdown/markdown.js");
var CONFIG_DIALECT_TIDDLER = "$:/config/markdown/dialect",
DEFAULT_DIALECT = "Gruber";
function transformNodes(nodes) { function transformNodes(nodes) {
var results = []; var results = [];
for(var index=0; index<nodes.length; index++) { for(var index=0; index<nodes.length; index++) {
@ -52,7 +55,8 @@ function transformNode(node) {
} }
var MarkdownParser = function(type,text,options) { var MarkdownParser = function(type,text,options) {
var markdownTree = markdown.toHTMLTree(text); var dialect = options.wiki.getTiddlerText(CONFIG_DIALECT_TIDDLER,DEFAULT_DIALECT),
markdownTree = markdown.toHTMLTree(text,dialect);
this.tree = transformNodes(markdownTree.slice(1)); this.tree = transformNodes(markdownTree.slice(1));
}; };