1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +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;
this.wiki = options.wiki;
this.syncadaptor = options.syncadaptor;
this.disableUI = !!options.disableUI;
this.titleIsLoggedIn = options.titleIsLoggedIn || this.titleIsLoggedIn;
this.titleUserName = options.titleUserName || this.titleUserName;
this.titleSyncFilter = options.titleSyncFilter || this.titleSyncFilter;
@ -57,7 +58,7 @@ function Syncer(options) {
self.syncToServer(changes);
});
// Browser event handlers
if($tw.browser) {
if($tw.browser && !this.disableUI) {
// Set up our beforeunload handler
$tw.addUnloadTask(function(event) {
var confirmationMessage;
@ -79,9 +80,11 @@ function Syncer(options) {
});
}
// Listen out for lazyLoad events
this.wiki.addEventListener("lazyLoad",function(title) {
self.handleLazyLoadEvent(title);
});
if(!this.disableUI) {
this.wiki.addEventListener("lazyLoad",function(title) {
self.handleLazyLoadEvent(title);
});
}
// Get the login status
this.getStatus(function(err,isLoggedIn) {
// 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
*/
Syncer.prototype.updateDirtyStatus = function() {
if($tw.browser) {
if($tw.browser && !this.disableUI) {
$tw.utils.toggleClass(document.body,"tc-dirty",this.isDirty());
}
};

View File

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