Rafał Pitoń 11 лет назад
Родитель
Сommit
cdb4271ffa

+ 39 - 15
misago/static/misago/js/misago-timestamps.js

@@ -1,5 +1,12 @@
 $(function() {
   moment.lang($('html').attr('lang'))
+
+  if (lang_time_units === undefined) {
+    var units_formats = "smhd";
+  } else {
+    var units_formats = lang_time_units;
+  }
+
   var moment_now = moment();
   var time_format = moment_now.lang()._longDateFormat.LT;
 
@@ -11,11 +18,9 @@ $(function() {
       var timestamp = $(this).data('timestamp');
       var rel_moment = moment(timestamp);
 
-      if (moment_now.diff(rel_moment, 'days') <= 7) {
-        moments[timestamp] = {
-          rel_moment: rel_moment,
-          original: $(this).text()
-        }
+      moments[timestamp] = {
+        rel_moment: rel_moment,
+        original: $(this).text()
       }
     });
   }
@@ -25,16 +30,35 @@ $(function() {
   function update_times() {
     $('.time-ago').each(function() {
       var timestamp = $(this).data('timestamp');
-      if (moments[timestamp] != undefined) {
-        if (moment_now.diff(moments[timestamp].rel_moment, 'hours') <= 6 && moment_now.diff(moments[timestamp].rel_moment, 'hours') >= -6) {
-          $(this).text(moments[timestamp].rel_moment.fromNow());
-        } else if (moment_now.diff(moments[timestamp].rel_moment, 'days') < 1 && moment_now.diff(moments[timestamp].rel_moment, 'days') > -1) {
-          $(this).text(moments[timestamp].rel_moment.calendar());
-        } else if (moment_now.diff(moments[timestamp].rel_moment, 'days') < 7 && moment_now.diff(moments[timestamp].rel_moment, 'days') > -7) {
-          $(this).text(moments[timestamp].rel_moment.format("dddd, " + time_format));
-        } else {
-          $(this).text(moments[timestamp].original);
-        }
+
+      if (moment_now.diff(moments[timestamp].rel_moment, 'minutes') <= 6 && moment_now.diff(moments[timestamp].rel_moment, 'hours') >= -6) {
+        $(this).text(moments[timestamp].rel_moment.fromNow());
+      } else if (moment_now.diff(moments[timestamp].rel_moment, 'days') < 1 && moment_now.diff(moments[timestamp].rel_moment, 'days') > -1) {
+        $(this).text(moments[timestamp].rel_moment.calendar());
+      } else if (moment_now.diff(moments[timestamp].rel_moment, 'days') < 7 && moment_now.diff(moments[timestamp].rel_moment, 'days') > -7) {
+        $(this).text(moments[timestamp].rel_moment.format("dddd, " + time_format));
+      } else {
+        $(this).text(moments[timestamp].original);
+      }
+    });
+
+    $('.time-ago-compact').each(function() {
+      var timestamp = $(this).data('timestamp');
+      var diff_seconds = moment_now.diff(moments[timestamp].rel_moment, 'seconds');
+
+      if (diff_seconds < 60) {
+        $(this).text(diff_seconds + units_formats[0]);
+      } else if (diff_seconds < (60 * 56)) {
+        var diff_minutes = Math.floor(diff_seconds / 60);
+        $(this).text(diff_minutes + units_formats[1]);
+      } else if (diff_seconds <= (3600 * 23)) {
+        var diff_hours = Math.floor(diff_seconds / 3600);
+        $(this).text(diff_hours + units_formats[2]);
+      } else if (true | diff_seconds < (3600 * 24 * 15)) {
+        var diff_days = Math.floor(diff_seconds / (3600 * 24));
+        $(this).text(diff_days + units_formats[3]);
+      } else {
+        $(this).text(moments[timestamp].original);
       }
     });
   }

+ 2 - 0
misago/templates/misago/base.html

@@ -33,6 +33,8 @@
     <script lang="JavaScript">
       var is_authenticated = {{ user.is_authenticated|yesno:"true,false" }};
 
+      var lang_time_units = "{% trans "smhd" %}";
+
       var lang_yes = "{% trans "Yes" %}";
       var lang_no = "{% trans "No" %}";
       var ajax_errors = {

+ 1 - 1
misago/templates/misago/threads/base.html

@@ -92,7 +92,7 @@
               </span>
               {% endif %}
 
-              <a href="#" class="dynamic time-ago tooltip-top" data-timestamp="{{ thread.last_post_on|date:"c" }}" title="{% blocktrans with last_post=thread.last_post_on|date %}Last post from {{ last_post }}{% endblocktrans %}">
+              <a href="#" class="dynamic time-ago-compact tooltip-top" data-timestamp="{{ thread.last_post_on|date:"c" }}" title="{% blocktrans with last_post=thread.last_post_on|date %}Last post from {{ last_post }}{% endblocktrans %}">
                 {{ thread.last_post_on|compact_date|lower }}
               </a>
               {% endblock thread-stats %}