mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-06 22:04:19 +00:00
Refactor saver handler
Fixing problems caused by c4b76ceb0bc786bcceb12fc3417bb8c4bfde27a9: * We still need to initialise the saver-handler even when syncing to a server, otherwise offline snapshots can’t be saved * We need to override the default save template a bit further up the stack, to avoid the server side serving the offline version of the wiki at `/`
This commit is contained in:
parent
fbf307c648
commit
a105b52399
@ -15,43 +15,50 @@ The saver handler tracks changes to the store and handles saving the entire wiki
|
|||||||
/*
|
/*
|
||||||
Instantiate the saver handler with the following options:
|
Instantiate the saver handler with the following options:
|
||||||
wiki: wiki to be synced
|
wiki: wiki to be synced
|
||||||
|
dirtyTracking: true if dirty tracking should be performed
|
||||||
*/
|
*/
|
||||||
function SaverHandler(options) {
|
function SaverHandler(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.wiki = options.wiki;
|
this.wiki = options.wiki;
|
||||||
|
this.dirtyTracking = options.dirtyTracking;
|
||||||
// Make a logger
|
// Make a logger
|
||||||
this.logger = new $tw.utils.Logger("saver-handler");
|
this.logger = new $tw.utils.Logger("saver-handler");
|
||||||
// Initialise our savers
|
// Initialise our savers
|
||||||
if($tw.browser) {
|
if($tw.browser) {
|
||||||
this.initSavers();
|
this.initSavers();
|
||||||
}
|
}
|
||||||
// Compile the dirty tiddler filter
|
// Only do dirty tracking if required
|
||||||
this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter));
|
if(this.dirtyTracking) {
|
||||||
// Count of tiddlers that have been changed but not yet saved
|
// Compile the dirty tiddler filter
|
||||||
this.numTasksInQueue = 0;
|
this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter));
|
||||||
// Listen out for changes to tiddlers
|
// Count of tiddlers that have been changed but not yet saved
|
||||||
this.wiki.addEventListener("change",function(changes) {
|
this.numTasksInQueue = 0;
|
||||||
var filteredChanges = self.filterFn.call(self.wiki,function(callback) {
|
// Listen out for changes to tiddlers
|
||||||
$tw.utils.each(changes,function(change,title) {
|
this.wiki.addEventListener("change",function(changes) {
|
||||||
var tiddler = self.wiki.getTiddler(title);
|
var filteredChanges = self.filterFn.call(self.wiki,function(callback) {
|
||||||
callback(tiddler,title);
|
$tw.utils.each(changes,function(change,title) {
|
||||||
|
var tiddler = self.wiki.getTiddler(title);
|
||||||
|
callback(tiddler,title);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
self.numTasksInQueue += filteredChanges.length;
|
||||||
|
self.updateDirtyStatus();
|
||||||
});
|
});
|
||||||
self.numTasksInQueue += filteredChanges.length;
|
// Browser event handlers
|
||||||
self.updateDirtyStatus();
|
if($tw.browser) {
|
||||||
});
|
// Set up our beforeunload handler
|
||||||
// Browser event handlers
|
window.addEventListener("beforeunload",function(event) {
|
||||||
|
var confirmationMessage = undefined;
|
||||||
|
if(self.isDirty()) {
|
||||||
|
confirmationMessage = $tw.language.getString("UnsavedChangesWarning");
|
||||||
|
event.returnValue = confirmationMessage; // Gecko
|
||||||
|
}
|
||||||
|
return confirmationMessage;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Install the save action handlers
|
||||||
if($tw.browser) {
|
if($tw.browser) {
|
||||||
// Set up our beforeunload handler
|
|
||||||
window.addEventListener("beforeunload",function(event) {
|
|
||||||
var confirmationMessage = undefined;
|
|
||||||
if(self.isDirty()) {
|
|
||||||
confirmationMessage = $tw.language.getString("UnsavedChangesWarning");
|
|
||||||
event.returnValue = confirmationMessage; // Gecko
|
|
||||||
}
|
|
||||||
return confirmationMessage;
|
|
||||||
});
|
|
||||||
// Install the save action handlers
|
|
||||||
$tw.rootWidget.addEventListener("tw-save-wiki",function(event) {
|
$tw.rootWidget.addEventListener("tw-save-wiki",function(event) {
|
||||||
self.saveWiki({
|
self.saveWiki({
|
||||||
template: event.param,
|
template: event.param,
|
||||||
|
@ -69,12 +69,12 @@ exports.startup = function() {
|
|||||||
$tw.syncadaptor = new module.adaptorClass({wiki: $tw.wiki});
|
$tw.syncadaptor = new module.adaptorClass({wiki: $tw.wiki});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Set up the syncer object if we've got a syncadaptor, otherwise setup the saverhandler
|
// Set up the syncer object if we've got a syncadaptor
|
||||||
if($tw.syncadaptor) {
|
if($tw.syncadaptor) {
|
||||||
$tw.syncer = new $tw.Syncer({wiki: $tw.wiki, syncadaptor: $tw.syncadaptor});
|
$tw.syncer = new $tw.Syncer({wiki: $tw.wiki, syncadaptor: $tw.syncadaptor});
|
||||||
} else {
|
}
|
||||||
$tw.saverHandler = new $tw.SaverHandler({wiki: $tw.wiki});
|
// Setup the saver handler
|
||||||
}
|
$tw.saverHandler = new $tw.SaverHandler({wiki: $tw.wiki, dirtyTracking: !$tw.syncadaptor});
|
||||||
// Host-specific startup
|
// Host-specific startup
|
||||||
if($tw.browser) {
|
if($tw.browser) {
|
||||||
// Install the popup manager
|
// Install the popup manager
|
||||||
|
3
core/ui/PageControls/SaveWikiButtonTemplate.tid
Normal file
3
core/ui/PageControls/SaveWikiButtonTemplate.tid
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
title: $:/config/SaveWikiButton/Template
|
||||||
|
|
||||||
|
$:/core/save/all
|
@ -3,7 +3,7 @@ tags: $:/tags/PageControls
|
|||||||
caption: {{$:/core/images/save-button}} {{$:/language/Buttons/SaveWiki/Caption}}
|
caption: {{$:/core/images/save-button}} {{$:/language/Buttons/SaveWiki/Caption}}
|
||||||
description: {{$:/language/Buttons/SaveWiki/Hint}}
|
description: {{$:/language/Buttons/SaveWiki/Hint}}
|
||||||
|
|
||||||
<$button message="tw-save-wiki" title={{$:/language/Buttons/SaveWiki/Hint}} aria-label={{$:/language/Buttons/SaveWiki/Caption}} class=<<tw-config-toolbar-class>>>
|
<$button message="tw-save-wiki" param={{$:/config/SaveWikiButton/Template}} title={{$:/language/Buttons/SaveWiki/Hint}} aria-label={{$:/language/Buttons/SaveWiki/Caption}} class=<<tw-config-toolbar-class>>>
|
||||||
<span class="tw-dirty-indicator">
|
<span class="tw-dirty-indicator">
|
||||||
<$list filter="[<tw-config-toolbar-icons>prefix[yes]]">
|
<$list filter="[<tw-config-toolbar-icons>prefix[yes]]">
|
||||||
{{$:/core/images/save-button}}
|
{{$:/core/images/save-button}}
|
||||||
|
3
plugins/tiddlywiki/tiddlyweb/SaveWikiButtonTemplate.tid
Normal file
3
plugins/tiddlywiki/tiddlyweb/SaveWikiButtonTemplate.tid
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
title: $:/config/SaveWikiButton/Template
|
||||||
|
|
||||||
|
$:/plugins/tiddlywiki/tiddlyweb/save/offline
|
@ -1,4 +1,4 @@
|
|||||||
title: $:/core/save/all
|
title: $:/plugins/tiddlywiki/tiddlyweb/save/offline
|
||||||
|
|
||||||
\define saveTiddlerFilter()
|
\define saveTiddlerFilter()
|
||||||
[is[tiddler]] -[[$:/boot/boot.css]] -[[$:/HistoryList]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] -[[$:/plugins/tiddlywiki/filesystem]] -[[$:/plugins/tiddlywiki/tiddlyweb]] +[sort[title]]
|
[is[tiddler]] -[[$:/boot/boot.css]] -[[$:/HistoryList]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] -[[$:/plugins/tiddlywiki/filesystem]] -[[$:/plugins/tiddlywiki/tiddlyweb]] +[sort[title]]
|
Loading…
x
Reference in New Issue
Block a user