Relative Date Title #161

This commit is contained in:
ccd0 2014-12-18 18:57:57 -08:00
parent c5c6896c53
commit ca4339a57d
2 changed files with 19 additions and 2 deletions

View File

@ -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.'

View File

@ -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) ->