From f723585758e1d6bd9193db81af6615badfc25798 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 13 Feb 2017 10:42:17 +0100 Subject: [PATCH] add api to check whether the realtime has synced with the server --- www/common/cryptpad-common.js | 12 ++++++++++++ www/register/main.js | 16 ++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index fc7bee587..de671f457 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -44,6 +44,18 @@ define([ return; }; + var whenRealtimeSyncs = common.whenRealtimeSyncs = function (realtime, cb) { + realtime.sync(); + var interval = 300; + var check = function () { + if (realtime.getAuthDoc() !== realtime.getUserDoc()) { + return window.setTimeout(check, interval); + } + cb(); + }; + window.setTimeout(check, interval); + }; + var getWebsocketURL = common.getWebsocketURL = function () { if (!Config.websocketPath) { return Config.websocketURL; } var path = Config.websocketPath; diff --git a/www/register/main.js b/www/register/main.js index 3ea0bf0ab..247a216fe 100644 --- a/www/register/main.js +++ b/www/register/main.js @@ -51,7 +51,7 @@ define([ } [ $uname, $passwd, $confirm] - .some(function ($el) { if (!$el.val()) { return ($el.focus(), true); } }); + .some(function ($el) { if (!$el.val()) { $el.focus(); return true; } }); // checkboxes var $checkImport = $('#import-recent'); @@ -60,18 +60,6 @@ define([ var $register = $('button#register'); - var proxyIsSynced = function (realtime, cb) { - realtime.sync(); - var interval = 300; - var check = function () { - if (realtime.getAuthDoc() !== realtime.getUserDoc()) { - return window.setTimeout(check, interval); - } - cb(); - }; - window.setTimeout(check, interval); - }; - $register.click(function () { var uname = $uname.val(); var passwd = $passwd.val(); @@ -108,7 +96,7 @@ define([ proxy.login_name = uname; - proxyIsSynced(result.realtime, function () { + Cryptpad.whenRealtimeSyncs(result.realtime, function () { document.location.href = '/drive/'; }); });