From 46a5eee5979ba2e299095e02580cc01f874a9426 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 5 Apr 2017 14:57:07 +0200 Subject: [PATCH] Display the spinner in the toolbar for local changes --- customize.dist/translations/messages.fr.js | 1 + customize.dist/translations/messages.js | 1 + www/common/toolbar.js | 46 +++++++++++++++------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index f03468b8d..b663a044c 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -29,6 +29,7 @@ define(function () { out.loading = "Chargement..."; out.error = "Erreur"; out.saved = "Enregistré"; + out.synced = "Tout est enregistré"; out.disconnected = 'Déconnecté'; out.synchronizing = 'Synchronisation'; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 85319eff9..adf0f92a6 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -31,6 +31,7 @@ define(function () { out.loading = "Loading..."; out.error = "Error"; out.saved = "Saved"; + out.synced = "Everything is saved"; out.disconnected = 'Disconnected'; out.synchronizing = 'Synchronizing'; diff --git a/www/common/toolbar.js b/www/common/toolbar.js index ae64c062d..ab657a779 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -93,22 +93,37 @@ define([ var createSpinner = function ($container, config) { if (config.displayed.indexOf('spinner') !== -1) { + var $spin = $(''); var $spinner = $('', { id: uid(), - 'class': SPINNER_CLS + ' fa fa-spinner fa-pulse', - }).hide(); - $container.prepend($spinner); - return $spinner[0]; + 'class': SPINNER_CLS + ' spin fa fa-spinner fa-pulse', + }).appendTo($spin).hide(); + var $spinner = $('', { + 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; } - $(spinnerElement).show(); - if (spinnerElement.timeout) { clearTimeout(spinnerElement.timeout); } - spinnerElement.timeout = setTimeout(function () { - $(spinnerElement).hide(); - }, SPINNER_DISAPPEAR_TIME); + $(spinnerElement).find('.spin').show(); + $(spinnerElement).find('.synced').hide(); + var onSynced = function () { + if (spinnerElement.timeout) { clearTimeout(spinnerElement.timeout); } + spinnerElement.timeout = setTimeout(function () { + $(spinnerElement).find('.spin').hide(); + $(spinnerElement).find('.synced').show(); + }, local ? 0 : SPINNER_DISAPPEAR_TIME); + }; + if (Cryptpad) { + Cryptpad.whenRealtimeSyncs(realtime, onSynced); + return; + } + onSynced(); }; var createUserButtons = function ($userlistElement, config, readOnly, Cryptpad) { @@ -749,13 +764,14 @@ define([ }); } - var ks = function () { - if (connected) { kickSpinner(spinner); } + var ks = function (local) { + return function () { + if (connected) { kickSpinner(Cryptpad, realtime, local, spinner); } + }; }; - realtime.onPatch(ks); - // Try to filter out non-patch messages, doesn't have to be perfect this is just the spinner - realtime.onMessage(function (msg) { if (msg.indexOf(':[2,') > -1) { ks(); } }); + realtime.onPatch(ks()); + realtime.onMessage(ks(true)); checkLag(getLag, lagElement); setInterval(function () {