loleaflet/Makefile.am        |    2 --
 loleaflet/src/core/Socket.js |    2 +-
 loleaflet/src/map/Map.js     |   39 ++++++++++++++++++++++++++-------------
 3 files changed, 27 insertions(+), 16 deletions(-)

New commits:
commit 68d55526267a4cda3185aefc677fdae6afb220f4
Author:     Henry Castro <hcas...@collabora.com>
AuthorDate: Sat Feb 16 18:09:52 2019 -0400
Commit:     Ashod Nakashian <ashnak...@gmail.com>
CommitDate: Wed Feb 26 02:11:36 2020 +0100

    loleaflet: remove timeago.min.js
    
    simplify using Date.toLocaleDateString
    
    Change-Id: Ib264cd90edd7ddacb3b944ee7f252648a629ab3f
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/89112
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>

diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am
index d32257ab1..98225ec67 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -102,8 +102,6 @@ NODE_MODULES_JS =\
        node_modules/jquery-contextmenu/dist/jquery.contextMenu.js \
        node_modules/jquery-ui/jquery-ui.js \
        node_modules/smartmenus/dist/jquery.smartmenus.js \
-       node_modules/timeago.js/dist/timeago.min.js \
-       node_modules/timeago.js/dist/timeago.locales.min.js \
        node_modules/autolinker/dist/Autolinker.js \
        node_modules/json-js/json2.js \
        node_modules/select2/dist/js/select2.js \
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index e5cead41f..ec55e72b1 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -310,7 +310,7 @@ L.Socket = L.Class.extend({
                        return;
                }
                else if (textMsg.startsWith('lastmodtime: ')) {
-                       var time = textMsg.substring(textMsg.indexOf(' '));
+                       var time = textMsg.substring(textMsg.indexOf(' ') + 1);
                        this._map.updateModificationIndicator(time);
                        return;
                }
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 0e7642925..dabf7023e 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -16,7 +16,7 @@ function moveObjectVertically(obj, diff) {
        }
 }
 
-/* global timeago closebutton vex revHistoryEnabled $ _ */
+/* global closebutton vex revHistoryEnabled $ _ */
 L.Map = L.Evented.extend({
 
        options: {
@@ -326,20 +326,33 @@ L.Map = L.Evented.extend({
        },
 
        updateModificationIndicator: function(newModificationTime) {
-               this._lastmodtime = newModificationTime;
+               var timeout;
+
+               if (typeof newModificationTime === 'string') {
+                       this._lastmodtime = newModificationTime;
+               }
+
+               clearTimeout(this._modTimeout);
+
                if (this.lastModIndicator !== null && this.lastModIndicator !== 
undefined) {
-                       // Get locale
-                       var special = [ 'bn_IN', 'hi_IN', 'id_ID', 'nb_NO', 
'nn_NO', 'pt_BR', 'zh_CN', 'zh_TW'];
-                       var locale = String.locale;
-                       locale = locale.replace('-', '_');
-                       if ($.inArray(locale, special) < 0) {
-                               if (locale.indexOf('_') > 0) {
-                                       locale = locale.substring(0, 
locale.indexOf('_'));
-                               }
+                       var dateTime = new 
Date(this._lastmodtime.replace(/,.*/, 'Z'));
+                       var dateValue = 
dateTime.toLocaleDateString(String.locale,
+                               { year: 'numeric', month: 'short', day: 
'numeric', hour: '2-digit', minute: '2-digit' });
+
+                       var elapsed = Date.now() - dateTime;
+                       if (elapsed < 60000) {
+                               dateValue = Math.round(elapsed / 1000) + ' ' + 
_('seconds ago');
+                               timeout = 6000;
+                       } else if (elapsed < 3600000) {
+                               dateValue = Math.round(elapsed / 60000) + ' ' + 
_('minutes ago');
+                               timeout = 60000;
+                       }
+
+                       this.lastModIndicator.innerHTML = dateValue;
+
+                       if (timeout) {
+                               this._modTimeout = 
setTimeout(L.bind(this.updateModificationIndicator, this, -1), timeout);
                        }
-                       // Real-time auto update
-                       this.lastModIndicator.setAttribute('datetime', 
newModificationTime);
-                       timeago().render(this.lastModIndicator, locale);
                }
        },
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to