From a3113cce7c6d3770a6e4d55b4804a0b1dca65e47 Mon Sep 17 00:00:00 2001 From: Ruxton <ruxton@thefrontiergroup.com.au> Date: Thu, 4 Jul 2013 23:02:17 +0800 Subject: [PATCH] Switched to using rails-timeago to make keeping on top of new versions of plugin easier --- Gemfile | 3 +- Gemfile.lock | 6 +- app/assets/javascripts/main.js | 2 +- app/assets/javascripts/widgets/timeago.js | 11 +- app/helpers/application_helper.rb | 7 +- app/views/comments/_comment.mobile.haml | 4 +- app/views/conversations/_conversation.haml | 6 +- .../conversations/_conversation.mobile.haml | 2 +- app/views/messages/_message.haml | 3 +- .../notifications/_notify_popup_item.haml | 3 +- app/views/notifications/index.html.haml | 7 +- app/views/notifications/index.mobile.haml | 2 +- app/views/photos/show.mobile.haml | 5 +- app/views/shared/_post_info.mobile.haml | 5 +- vendor/assets/javascripts/timeago.js | 143 ------------------ 15 files changed, 36 insertions(+), 173 deletions(-) delete mode 100644 vendor/assets/javascripts/timeago.js diff --git a/Gemfile b/Gemfile index f1a505f4e1..7a0fb51b8c 100644 --- a/Gemfile +++ b/Gemfile @@ -129,6 +129,8 @@ group :assets do gem 'handlebars_assets', '0.12.0' gem 'jquery-rails', '2.1.4' + gem 'rails-timeago' + # Windows and OSX have an execjs compatible runtime built-in, Linux users should # install Node.js or use 'therubyracer'. # @@ -172,7 +174,6 @@ group :development do gem 'rmagick', '2.13.2', :require => false # Automatic test runs - gem 'guard-cucumber', '1.4.1' gem 'guard-rspec', '4.2.4' gem 'rb-fsevent', '0.9.4', :require => false diff --git a/Gemfile.lock b/Gemfile.lock index f0069cccdf..b1d3588524 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,12 +42,12 @@ GEM activemodel fog (>= 1.8.0) atomic (1.1.14) - bcrypt-ruby (3.1.2) backbone-on-rails (1.1.0.0) eco ejs jquery-rails rails (>= 3.1) + bcrypt-ruby (3.1.2) bootstrap-sass (2.2.2.0) sass (~> 3.2) builder (3.0.4) @@ -306,6 +306,9 @@ GEM railties (= 3.2.16) rails-i18n (0.7.4) i18n (~> 0.5) + rails-timeago (2.4.0) + actionpack (>= 3.1) + activesupport (>= 3.1) rails_admin (0.4.9) bootstrap-sass (~> 2.2) builder (~> 3.0) @@ -498,6 +501,7 @@ DEPENDENCIES rack-ssl (= 1.3.3) rails (= 3.2.16) rails-i18n (= 0.7.4) + rails-timeago rails_admin (= 0.4.9) rails_autolink (= 1.1.5) rb-fsevent (= 0.9.4) diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 2df7a3a006..02bad51489 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -11,7 +11,7 @@ //= require jquery-ui-1.8.9.custom.min //= require jquery.charcount //= require jquery.placeholder -//= require timeago +//= require rails-timeago //= require facebox //= require jquery.events.input //= require jquery.elastic diff --git a/app/assets/javascripts/widgets/timeago.js b/app/assets/javascripts/widgets/timeago.js index c298532678..79e74fd46c 100644 --- a/app/assets/javascripts/widgets/timeago.js +++ b/app/assets/javascripts/widgets/timeago.js @@ -8,8 +8,15 @@ this.subscribe("widget/ready", function() { if(Diaspora.I18n.language !== "en") { - $.each($.timeago.settings.strings, function(index) { - $.timeago.settings.strings[index] = Diaspora.I18n.t("timeago." + index); + $.timeago.settings.lang = Diaspora.I18n.language; + $.timeago.settings.strings[Diaspora.I18n.language] = {} + $.each($.timeago.settings.strings["en"], function(index) { + if(index == "numbers") { + $.timeago.settings.strings[Diaspora.I18n.language][index] = []; + } + else { + $.timeago.settings.strings[Diaspora.I18n.language][index] = Diaspora.I18n.t("timeago." + index); + } }); } }); diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1535f7b89b..48f8bf9517 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -17,13 +17,8 @@ module ApplicationHelper url end - def how_long_ago(obj) - timeago(obj.created_at) - end - def timeago(time, options={}) - options[:class] ||= "timeago" - content_tag(:abbr, time.to_s, options.merge(:title => time.iso8601)) if time + timeago_tag(time, options.merge(:title => time.iso8601)) if time end def bookmarklet diff --git a/app/views/comments/_comment.mobile.haml b/app/views/comments/_comment.mobile.haml index b209efbdf8..342d2f777a 100644 --- a/app/views/comments/_comment.mobile.haml +++ b/app/views/comments/_comment.mobile.haml @@ -12,8 +12,8 @@ = person_image_link(comment.author) = person_link(comment.author) .info - %span.time.timeago{:datetime => comment.created_at} - = comment.created_at ? time_ago_in_words(comment.created_at) : time_ago_in_words(Time.now) + %span + = timeago(comment.created_at ? comment.created_at : Time.now) %div{:class => direction_for(comment.text)} = markdownify(comment) diff --git a/app/views/conversations/_conversation.haml b/app/views/conversations/_conversation.haml index cb8f419ccd..7563f84ae1 100644 --- a/app/views/conversations/_conversation.haml +++ b/app/views/conversations/_conversation.haml @@ -20,11 +20,11 @@ .subject %div{ :class => direction_for(conversation.subject) } = conversation.subject - %time.timeago.timestamp{:datetime => conversation.updated_at.iso8601} - = t('ago', :time => time_ago_in_words(conversation.updated_at)) + .timestamp + = timeago(conversation.updated_at) .last_author - if authors[conversation.id].present? = authors[conversation.id].name .last_message - if conversation.messages.present? - = '»' + conversation.messages.last.text + '«' + = '»' + conversation.messages.last.text + '«' \ No newline at end of file diff --git a/app/views/conversations/_conversation.mobile.haml b/app/views/conversations/_conversation.mobile.haml index 73dd5bd98b..7c30d0e1f5 100644 --- a/app/views/conversations/_conversation.mobile.haml +++ b/app/views/conversations/_conversation.mobile.haml @@ -11,7 +11,7 @@ .last_author .timestamp - = t('ago', :time => time_ago_in_words(conversation.updated_at)) + = timeago(conversation.updated_at) - if authors[conversation.id].present? = authors[conversation.id].name diff --git a/app/views/messages/_message.haml b/app/views/messages/_message.haml index bcce45bda0..8c38eafa24 100644 --- a/app/views/messages/_message.haml +++ b/app/views/messages/_message.haml @@ -8,8 +8,7 @@ = person_image_link(message.author, :size => :thumb_small) .bd = person_link(message.author, :class => 'author from') - %time.timeago{:datetime => message.created_at.iso8601} - = t('ago', :time => time_ago_in_words(message.created_at)) + = timeago(message.created_at) %div{ :class => direction_for(message.text) } = markdownify(message, :oembed => true) diff --git a/app/views/notifications/_notify_popup_item.haml b/app/views/notifications/_notify_popup_item.haml index b761f9bcdc..89da6fa534 100644 --- a/app/views/notifications/_notify_popup_item.haml +++ b/app/views/notifications/_notify_popup_item.haml @@ -2,6 +2,5 @@ = person_image_tag n.actors.first, :thumb_small = notification_message_for(n) %div - %time - = timeago(n.created_at) + = timeago(n.created_at) = link_to t('notifications.index.mark_unread'), "#", :class => "unread-setter" diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 9bce83da02..e7c33777bc 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -21,16 +21,15 @@ - if note.type == "Notifications::StartedSharing" && contact = current_user.contact_for(note.effective_target) .float-right = aspect_membership_dropdown(contact, note.effective_target, 'left') - + .media .bd = person_image_tag note.actors.first, :thumb_medium = notification_message_for(note) %div - %time - = timeago(note.created_at) + = timeago(note.created_at) = link_to t('.mark_unread'), "#", :class => "unread-setter" - + = will_paginate @notifications :javascript diff --git a/app/views/notifications/index.mobile.haml b/app/views/notifications/index.mobile.haml index ac046a65ec..1d334df665 100644 --- a/app/views/notifications/index.mobile.haml +++ b/app/views/notifications/index.mobile.haml @@ -18,6 +18,6 @@ .from = notification_message_for(note) .time_notif - = time_ago_in_words(note.created_at) + = timeago(note.created_at) = will_paginate @notifications, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer diff --git a/app/views/photos/show.mobile.haml b/app/views/photos/show.mobile.haml index d06b34773c..c3bf5bd6af 100644 --- a/app/views/photos/show.mobile.haml +++ b/app/views/photos/show.mobile.haml @@ -14,8 +14,9 @@ = person_image_link(photo.author, :size => :thumb_small) = person_link(photo.author) .info - %span.time{:integer => photo.created_at.to_i} - = link_to(t('ago', :time => time_ago_in_words(photo.created_at)), post_path(photo)) + %span + = link_to(post_path(photo)) do + = timeago(photo.created_at) -if additional_photos && additional_photos.length > 1 #photo_controls diff --git a/app/views/shared/_post_info.mobile.haml b/app/views/shared/_post_info.mobile.haml index 893810cf49..1d74087521 100644 --- a/app/views/shared/_post_info.mobile.haml +++ b/app/views/shared/_post_info.mobile.haml @@ -11,8 +11,9 @@ = link_to(image_tag('deletelabel.png'), post_path(post), :method => :delete, :data => { :confirm => "#{t('are_you_sure')}" }, :class => "remove") .info - %span.time{:integer => post.created_at.to_i} - = link_to(t('ago', :time => time_ago_in_words(post.created_at)), post_path(post)) + %span + = link_to(post_path(post)) do + = timeago(post.created_at) %span.via - if post.activity_streams? = t('shared.stream_element.via', :link => link_to("#{post.provider_display_name}", post.actor_url)).html_safe diff --git a/vendor/assets/javascripts/timeago.js b/vendor/assets/javascripts/timeago.js deleted file mode 100644 index 51443051b2..0000000000 --- a/vendor/assets/javascripts/timeago.js +++ /dev/null @@ -1,143 +0,0 @@ - -/* - * timeago: a jQuery plugin, version: 0.9.2 (2010-09-14) - * @requires jQuery v1.2.3 or later - * - * Timeago is a jQuery plugin that makes it easy to support automatically - * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago"). - * - * For usage and examples, visit: - * http://timeago.yarp.com/ - * - * Licensed under the MIT: - * http://www.opensource.org/licenses/mit-license.php - * - * Copyright (c) 2008-2010, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org) - */ -(function($) { - $.timeago = function(timestamp) { - if (timestamp instanceof Date) return inWords(timestamp); - else if (typeof timestamp == "string") return inWords($.timeago.parse(timestamp)); - else return inWords($.timeago.datetime(timestamp)); - }; - var $t = $.timeago; - - $.extend($.timeago, { - settings: { - refreshMillis: 60000, - allowFuture: false, - strings: { - prefixAgo: null, - prefixFromNow: null, - suffixAgo: "ago", - suffixFromNow: "from now", - seconds: "less than a minute", - minute: "about a minute", - minutes: "%d minutes", - hour: "about an hour", - hours: "about %d hours", - day: "a day", - days: "%d days", - month: "about a month", - months: "%d months", - year: "about a year", - years: "%d years", - numbers: [] - } - }, - inWords: function(distanceMillis) { - var $l = this.settings.strings; - var prefix = $l.prefixAgo; - var suffix = $l.suffixAgo; - if (this.settings.allowFuture) { - if (distanceMillis < 0) { - prefix = $l.prefixFromNow; - suffix = $l.suffixFromNow; - } - distanceMillis = Math.abs(distanceMillis); - } - - var seconds = distanceMillis / 1000; - var minutes = seconds / 60; - var hours = minutes / 60; - var days = hours / 24; - var years = days / 365; - - function substitute(stringOrFunction, number) { - var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction; - var value = ($l.numbers && $l.numbers[number]) || number; - return string.replace(/%d/i, value); - } - - var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) || - seconds < 90 && substitute($l.minute, 1) || - minutes < 45 && substitute($l.minutes, Math.round(minutes)) || - minutes < 90 && substitute($l.hour, 1) || - hours < 24 && substitute($l.hours, Math.round(hours)) || - hours < 48 && substitute($l.day, 1) || - days < 30 && substitute($l.days, Math.floor(days)) || - days < 60 && substitute($l.month, 1) || - days < 365 && substitute($l.months, Math.floor(days / 30)) || - years < 2 && substitute($l.year, 1) || - substitute($l.years, Math.floor(years)); - - return $.trim([prefix, words, suffix].join(" ")); - }, - parse: function(iso8601) { - var s = $.trim(iso8601); - s = s.replace(/\.\d\d\d+/,""); // remove milliseconds - s = s.replace(/-/,"/").replace(/-/,"/"); - s = s.replace(/T/," ").replace(/Z/," UTC"); - s = s.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400 - return new Date(s); - }, - datetime: function(elem) { - // jQuery's `is()` doesn't play well with HTML5 in IE - var isTime = $(elem).get(0).tagName.toLowerCase() == "time"; // $(elem).is("time"); - var iso8601 = isTime ? $(elem).attr("datetime") : $(elem).attr("title"); - return $t.parse(iso8601); - } - }); - - $.fn.timeago = function() { - var self = this; - self.each(refresh); - - var $s = $t.settings; - if ($s.refreshMillis > 0) { - setInterval(function() { self.each(refresh); }, $s.refreshMillis); - } - return self; - }; - - function refresh() { - var data = prepareData(this); - if (!isNaN(data.datetime)) { - $(this).text(inWords(data.datetime)); - } - return this; - } - - function prepareData(element) { - element = $(element); - if (!element.data("timeago")) { - element.data("timeago", { datetime: $t.datetime(element) }); - var text = $.trim(element.text()); - if (text.length > 0) element.attr("title", text); - } - return element.data("timeago"); - } - - function inWords(date) { - return $t.inWords(distance(date)); - } - - function distance(date) { - return (new Date().getTime() - date.getTime()); - } - - // fix for IE6 suckage - document.createElement("abbr"); - document.createElement("time"); -})(jQuery); - -- GitLab