summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2019-02-16 18:09:52 -0400
committerAshod Nakashian <ashnakash@gmail.com>2020-02-26 02:11:36 +0100
commit68d55526267a4cda3185aefc677fdae6afb220f4 (patch)
treea97a5c93737ca3a9c00a4a7934d98a6eb5eef6f0
parentd622386116376360d679b7c5e4db39598469c4d3 (diff)
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 <jenkinscollaboraoffice@gmail.com> Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
-rw-r--r--loleaflet/Makefile.am2
-rw-r--r--loleaflet/src/core/Socket.js2
-rw-r--r--loleaflet/src/map/Map.js39
3 files changed, 27 insertions, 16 deletions
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);
}
},