Display the spinner in the toolbar for local changes

pull/1/head
yflory 8 years ago
parent 54d271c4e7
commit 46a5eee597

@ -29,6 +29,7 @@ define(function () {
out.loading = "Chargement..."; out.loading = "Chargement...";
out.error = "Erreur"; out.error = "Erreur";
out.saved = "Enregistré"; out.saved = "Enregistré";
out.synced = "Tout est enregistré";
out.disconnected = 'Déconnecté'; out.disconnected = 'Déconnecté';
out.synchronizing = 'Synchronisation'; out.synchronizing = 'Synchronisation';

@ -31,6 +31,7 @@ define(function () {
out.loading = "Loading..."; out.loading = "Loading...";
out.error = "Error"; out.error = "Error";
out.saved = "Saved"; out.saved = "Saved";
out.synced = "Everything is saved";
out.disconnected = 'Disconnected'; out.disconnected = 'Disconnected';
out.synchronizing = 'Synchronizing'; out.synchronizing = 'Synchronizing';

@ -93,22 +93,37 @@ define([
var createSpinner = function ($container, config) { var createSpinner = function ($container, config) {
if (config.displayed.indexOf('spinner') !== -1) { if (config.displayed.indexOf('spinner') !== -1) {
var $spin = $('<span>');
var $spinner = $('<span>', { var $spinner = $('<span>', {
id: uid(), id: uid(),
'class': SPINNER_CLS + ' fa fa-spinner fa-pulse', 'class': SPINNER_CLS + ' spin fa fa-spinner fa-pulse',
}).hide(); }).appendTo($spin).hide();
$container.prepend($spinner); var $spinner = $('<span>', {
return $spinner[0]; id: uid(),
'class': SPINNER_CLS + ' synced fa fa-check',
title: Messages.synced
}).appendTo($spin);
$container.prepend($spin);
return $spin[0];
} }
}; };
var kickSpinner = function (spinnerElement) { var kickSpinner = function (Cryptpad, realtime, local, spinnerElement) {
if (!spinnerElement) { return; } if (!spinnerElement) { return; }
$(spinnerElement).show(); $(spinnerElement).find('.spin').show();
$(spinnerElement).find('.synced').hide();
var onSynced = function () {
if (spinnerElement.timeout) { clearTimeout(spinnerElement.timeout); } if (spinnerElement.timeout) { clearTimeout(spinnerElement.timeout); }
spinnerElement.timeout = setTimeout(function () { spinnerElement.timeout = setTimeout(function () {
$(spinnerElement).hide(); $(spinnerElement).find('.spin').hide();
}, SPINNER_DISAPPEAR_TIME); $(spinnerElement).find('.synced').show();
}, local ? 0 : SPINNER_DISAPPEAR_TIME);
};
if (Cryptpad) {
Cryptpad.whenRealtimeSyncs(realtime, onSynced);
return;
}
onSynced();
}; };
var createUserButtons = function ($userlistElement, config, readOnly, Cryptpad) { var createUserButtons = function ($userlistElement, config, readOnly, Cryptpad) {
@ -749,13 +764,14 @@ define([
}); });
} }
var ks = function () { var ks = function (local) {
if (connected) { kickSpinner(spinner); } return function () {
if (connected) { kickSpinner(Cryptpad, realtime, local, spinner); }
};
}; };
realtime.onPatch(ks); realtime.onPatch(ks());
// Try to filter out non-patch messages, doesn't have to be perfect this is just the spinner realtime.onMessage(ks(true));
realtime.onMessage(function (msg) { if (msg.indexOf(':[2,') > -1) { ks(); } });
checkLag(getLag, lagElement); checkLag(getLag, lagElement);
setInterval(function () { setInterval(function () {

Loading…
Cancel
Save