From ca4339a57d83faaa6fdb9a917d9c50ba661bdbf3 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Thu, 18 Dec 2014 18:57:57 -0800 Subject: [PATCH] Relative Date Title #161 --- src/General/Config.coffee | 6 +++++- src/Miscellaneous/RelativeDates.coffee | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/General/Config.coffee b/src/General/Config.coffee index cfefb01ae..e7deac964 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -42,9 +42,13 @@ Config = 'Localize and format timestamps.' ] 'Relative Post Dates': [ - false + true 'Display dates like "3 minutes ago". Tooltip shows the timestamp.' ] + 'Relative Date Title': [ + true + 'Show relative post date as the tooltip.' + ] 'Comment Expansion': [ true 'Add buttons to expand too long comments.' diff --git a/src/Miscellaneous/RelativeDates.coffee b/src/Miscellaneous/RelativeDates.coffee index 810c7bceb..699734aba 100755 --- a/src/Miscellaneous/RelativeDates.coffee +++ b/src/Miscellaneous/RelativeDates.coffee @@ -16,13 +16,19 @@ RelativeDates = Post.callbacks.push name: 'Relative Post Dates' cb: @node + node: -> + dateEl = @nodes.date + if Conf['Relative Date Title'] + $.on dateEl, 'mouseover', => + RelativeDates.hover @ + return + return if @isClone # Show original absolute time as tooltip so users can still know exact times # Since "Time Formatting" runs its `node` before us, the title tooltip will # pick up the user-formatted time instead of 4chan time when enabled. - dateEl = @nodes.date dateEl.title = dateEl.textContent RelativeDates.update @ @@ -82,6 +88,13 @@ RelativeDates = clearTimeout RelativeDates.timeout RelativeDates.timeout = setTimeout RelativeDates.flush, RelativeDates.INTERVAL + # Relative Date Title + hover: (post) -> + {date} = post.info + now = new Date() + diff = now - date + post.nodes.date.title = RelativeDates.relative diff, now, date + # `update()`, when called from `flush()`, updates the elements, # and re-calls `setOwnTimeout()` to re-add `data` to the stale list later. update: (data, now) ->