1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-04-10 04:36:38 +00:00

Move syncer-browser startup handling into syncer.js

This commit is contained in:
Jermolene 2014-08-13 20:07:08 +01:00
parent d16bff7787
commit 7c1cb97f7f
2 changed files with 13 additions and 36 deletions

View File

@ -1,34 +0,0 @@
/*\
title: $:/core/modules/startup/syncer-browser.js
type: application/javascript
module-type: startup
Startup handling
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
// Export name and synchronous status
exports.name = "syncer-browser";
exports.platforms = ["browser"];
exports.after = ["rootwidget"];
exports.synchronous = true;
exports.startup = function() {
// Listen out for login/logout/refresh events in the browser
$tw.rootWidget.addEventListener("tw-login",function() {
$tw.syncer.handleLoginEvent();
});
$tw.rootWidget.addEventListener("tw-logout",function() {
$tw.syncer.handleLogoutEvent();
});
$tw.rootWidget.addEventListener("tw-server-refresh",function() {
$tw.syncer.handleRefreshEvent();
});
};
})();

View File

@ -45,8 +45,9 @@ function Syncer(options) {
this.wiki.addEventListener("change",function(changes) {
self.syncToServer(changes);
});
// Set up our beforeunload handler
// Browser event handlers
if($tw.browser) {
// Set up our beforeunload handler
window.addEventListener("beforeunload",function(event) {
var confirmationMessage = undefined;
if(self.isDirty()) {
@ -55,6 +56,16 @@ function Syncer(options) {
}
return confirmationMessage;
});
// Listen out for login/logout/refresh events in the browser
$tw.rootWidget.addEventListener("tw-login",function() {
$tw.syncer.handleLoginEvent();
});
$tw.rootWidget.addEventListener("tw-logout",function() {
$tw.syncer.handleLogoutEvent();
});
$tw.rootWidget.addEventListener("tw-server-refresh",function() {
$tw.syncer.handleRefreshEvent();
});
}
// Listen out for lazyLoad events
if(this.syncadaptor) {
@ -509,7 +520,7 @@ Syncer.prototype.chooseNextTask = function() {
// Exclude the task if it is a save and the tiddler has been modified recently, but not hit the fallback time
if(task.type === "save" && (now - task.lastModificationTime) < self.throttleInterval &&
(now - task.queueTime) < self.fallbackInterval) {
return;
return;
}
// Exclude the task if it is newer than the current best candidate
if(candidateTask && candidateTask.queueTime < task.queueTime) {