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 31aa763470f9dfc3df5280c2f2fab47c15432afd
Author:     Henry Castro <hcas...@collabora.com>
AuthorDate: Sat Feb 16 18:09:52 2019 -0400
Commit:     Henry Castro <hcas...@collabora.com>
CommitDate: Tue Mar 5 23:55:39 2019 -0400

    loleaflet: remove timeago.min.js
    
    simplify using Date.toLocaleDateString
    
    Change-Id: Ib264cd90edd7ddacb3b944ee7f252648a629ab3f

diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am
index d3e0160e0..953add0c6 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -232,8 +232,6 @@ NODE_MODULES_JS =\
        node_modules/jquery-mousewheel/jquery.mousewheel.js \
        node_modules/jquery-contextmenu/dist/jquery.contextMenu.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 68080b9fa..3fe3cb2c7 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -322,7 +322,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 9f7f35af3..b0a5b9da5 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 $ _ */
+/* global closebutton vex $ _ */
 L.Map = L.Evented.extend({
 
        options: {
@@ -312,20 +312,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