1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

SaveTrailPlugin: Fix syncer UI interactions

The syncer used by the savetrail plugin shouldn't perform any UI interactions
This commit is contained in:
Jermolene 2017-09-20 16:28:11 +01:00
parent 59505449d2
commit 73953080e3
2 changed files with 11 additions and 7 deletions

View File

@ -33,6 +33,7 @@ function Syncer(options) {
var self = this; var self = this;
this.wiki = options.wiki; this.wiki = options.wiki;
this.syncadaptor = options.syncadaptor; this.syncadaptor = options.syncadaptor;
this.disableUI = !!options.disableUI;
this.titleIsLoggedIn = options.titleIsLoggedIn || this.titleIsLoggedIn; this.titleIsLoggedIn = options.titleIsLoggedIn || this.titleIsLoggedIn;
this.titleUserName = options.titleUserName || this.titleUserName; this.titleUserName = options.titleUserName || this.titleUserName;
this.titleSyncFilter = options.titleSyncFilter || this.titleSyncFilter; this.titleSyncFilter = options.titleSyncFilter || this.titleSyncFilter;
@ -57,7 +58,7 @@ function Syncer(options) {
self.syncToServer(changes); self.syncToServer(changes);
}); });
// Browser event handlers // Browser event handlers
if($tw.browser) { if($tw.browser && !this.disableUI) {
// Set up our beforeunload handler // Set up our beforeunload handler
$tw.addUnloadTask(function(event) { $tw.addUnloadTask(function(event) {
var confirmationMessage; var confirmationMessage;
@ -79,9 +80,11 @@ function Syncer(options) {
}); });
} }
// Listen out for lazyLoad events // Listen out for lazyLoad events
this.wiki.addEventListener("lazyLoad",function(title) { if(!this.disableUI) {
self.handleLazyLoadEvent(title); this.wiki.addEventListener("lazyLoad",function(title) {
}); self.handleLazyLoadEvent(title);
});
}
// Get the login status // Get the login status
this.getStatus(function(err,isLoggedIn) { this.getStatus(function(err,isLoggedIn) {
// Do a sync from the server // Do a sync from the server
@ -134,7 +137,7 @@ Syncer.prototype.isDirty = function() {
Update the document body with the class "tc-dirty" if the wiki has unsaved/unsynced changes Update the document body with the class "tc-dirty" if the wiki has unsaved/unsynced changes
*/ */
Syncer.prototype.updateDirtyStatus = function() { Syncer.prototype.updateDirtyStatus = function() {
if($tw.browser) { if($tw.browser && !this.disableUI) {
$tw.utils.toggleClass(document.body,"tc-dirty",this.isDirty()); $tw.utils.toggleClass(document.body,"tc-dirty",this.isDirty());
} }
}; };

View File

@ -31,7 +31,8 @@ exports.startup = function() {
wiki: $tw.wiki, wiki: $tw.wiki,
syncadaptor: $tw.savetrail.syncadaptor, syncadaptor: $tw.savetrail.syncadaptor,
titleSyncFilter: SYNC_DRAFTS_FILTER_TIDDLER_TITLE, titleSyncFilter: SYNC_DRAFTS_FILTER_TIDDLER_TITLE,
logging: false logging: false,
disableUI: true
}); });
// Add hooks for trapping user actions // Add hooks for trapping user actions
$tw.hooks.addHook("th-saving-tiddler",function(tiddler) { $tw.hooks.addHook("th-saving-tiddler",function(tiddler) {
@ -126,7 +127,7 @@ function saveTiddlerFile(tiddler,options) {
options = options || {}; options = options || {};
var reason = options.reason || "changed", var reason = options.reason || "changed",
illegalFilenameCharacters = /<|>|\:|\"|\/|\\|\||\?|\*|\^|\s/g, illegalFilenameCharacters = /<|>|\:|\"|\/|\\|\||\?|\*|\^|\s/g,
fixedTitle = tiddler.fields.title.replace(illegalFilenameCharacters,"_"), fixedTitle = $tw.utils.transliterate(tiddler.fields.title).replace(illegalFilenameCharacters,"_"),
formattedDate = $tw.utils.stringifyDate(new Date()), formattedDate = $tw.utils.stringifyDate(new Date()),
filename = fixedTitle + "." + formattedDate + "." + reason + ".json", filename = fixedTitle + "." + formattedDate + "." + reason + ".json",
fields = new Object(); fields = new Object();