From 37505c5ece2261fafbfb0c17a997bfaf144e4221 Mon Sep 17 00:00:00 2001
From: Tamas Laszlo Fabian <tamas.fabian@vengit.com>
Date: Tue, 25 Jun 2013 11:42:58 +0200
Subject: [PATCH] Fixed timago tooltip in conversations

Fixed timeago errors

Added cucumber stuff to test timeago at inbox

Show localized date/time in tooltip

Remove title attributes
---
 app/assets/javascripts/inbox.js            | 22 +++++++++++++++++++---
 app/views/conversations/_conversation.haml |  2 +-
 app/views/conversations/show.js.erb        | 17 +++++++++++++++--
 app/views/messages/_message.haml           |  2 +-
 features/conversations.feature             |  2 ++
 5 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/app/assets/javascripts/inbox.js b/app/assets/javascripts/inbox.js
index 507032aaa7..c1f367bdb2 100644
--- a/app/assets/javascripts/inbox.js
+++ b/app/assets/javascripts/inbox.js
@@ -10,11 +10,28 @@ $(document).ready(function(){
     $("html").scrollTop($('#first_unread').offset().top-45);
   }
 
+  $('time.timeago').each(function(i,e) {
+    var jqe = $(e);
+    jqe.attr('data-original-title', new Date(jqe.attr('datetime')).toLocaleString());
+    jqe.attr('title', '');
+  });
+
+  $('.timeago').tooltip();
+  $('.timeago').timeago();
+
+  $('time.timeago').each(function(i,e) {
+    var jqe = $(e);
+    jqe.attr('title', '');
+  });
+
   $('.conversation-wrapper').live('click', function(){
-    $.getScript($(this).data('conversation-path'), function() {
+    var conversation_path = $(this).data('conversation-path');
+
+    $.getScript(conversation_path, function() {
       Diaspora.page.directionDetector.updateBinds();
     });
-    history.pushState(null, "", this.href);
+
+    history.pushState(null, "", conversation_path);
 
     var conv = $(this).children('.stream_element'),
         cBadge = $("#message_inbox_badge .badge_count");
@@ -31,7 +48,6 @@ $(document).ready(function(){
       });
     }
 
-    jQuery("abbr.timeago").timeago();
     return false;
   });
 
diff --git a/app/views/conversations/_conversation.haml b/app/views/conversations/_conversation.haml
index 9e18e72b24..264c3767f0 100644
--- a/app/views/conversations/_conversation.haml
+++ b/app/views/conversations/_conversation.haml
@@ -15,7 +15,7 @@
                                :unread_count => unread_counts[conversation.id].to_i })
 
         .last_author
-          .timestamp
+          %time.timeago.timestamp{:datetime => conversation.updated_at.iso8601}
             = t('ago', :time =>  time_ago_in_words(conversation.updated_at))
 
           - if authors[conversation.id].present?
diff --git a/app/views/conversations/show.js.erb b/app/views/conversations/show.js.erb
index e0009ea26c..743b2197e6 100644
--- a/app/views/conversations/show.js.erb
+++ b/app/views/conversations/show.js.erb
@@ -4,6 +4,19 @@ $(".stream_element", "#conversation_inbox").removeClass('selected');
 $(".stream_element[data-guid='<%= @conversation.id %>']", "#conversation_inbox").addClass('selected');
 $(".stream_element[data-guid='<%= @conversation.id %>']", "#conversation_inbox").find(".unread_message_count").remove()
 
-$("html").scrollTop($('#first_unread').offset().top-45);
+$('time.timeago').each(function(i,e) {
+  var jqe = $(e);
+  jqe.attr('data-original-title', new Date(jqe.attr('datetime')).toLocaleString());
+});
 
-Diaspora.page.timeAgo.updateTimeAgo();
+if ($('#first_unread') > 0) {
+  $("html").scrollTop($('#first_unread').offset().top-45);
+}
+
+$(".timeago").tooltip();
+$("time.timeago").timeago();
+
+$('time.timeago').each(function(i,e) {
+  var jqe = $(e);
+  jqe.attr('title', '');
+});
diff --git a/app/views/messages/_message.haml b/app/views/messages/_message.haml
index 12607e0240..bcce45bda0 100644
--- a/app/views/messages/_message.haml
+++ b/app/views/messages/_message.haml
@@ -8,7 +8,7 @@
       = person_image_link(message.author, :size => :thumb_small)
     .bd
       = person_link(message.author, :class => 'author from')
-      %time.timeago{:datetime => message.created_at}
+      %time.timeago{:datetime => message.created_at.iso8601}
         = t('ago', :time =>  time_ago_in_words(message.created_at))
 
       %div{ :class => direction_for(message.text) }
diff --git a/features/conversations.feature b/features/conversations.feature
index 6dd07ef41e..b78e7af43d 100644
--- a/features/conversations.feature
+++ b/features/conversations.feature
@@ -14,6 +14,8 @@ Feature: private messages
     Given I send a message with subject "Greetings" and text "hello, alice!" to "Alice Awesome"
     Then I should see "Greetings" within "#conversation_inbox"
     And I should see "Greetings" within "#conversation_show"
+    And I should see "less than a minute ago" within "#conversation_inbox"
+    And I should see "less than a minute ago" within "#conversation_show"
     And I click on selector "a.participants_link"
     Then I should see the participants popover
     And I should see "Alice Awesome" as part of the participants popover
-- 
GitLab