Skip to content
This repository has been archived by the owner on May 12, 2019. It is now read-only.

Commit

Permalink
Fix timeAgo function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Dec 22, 2015
1 parent 161bd5c commit 398e691
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
29 changes: 12 additions & 17 deletions assets/js/src/__init.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,18 @@ $ ->

is: (property, value) -> this.app.dataset[property] is value

readTime: ->
DateInDays = (selector, cb) ->
$(selector).each ->
postDate = $(this).html()
postDateNow = new Date(Date.now())
postDateInDays = Math.floor((postDateNow - new Date(postDate)) / 86400000)

if postDateInDays is 0 then postDateInDays = 'today'
else if postDateInDays is 1 then postDateInDays = 'yesterday'
else postDateInDays = "#{postDateInDays} days ago"

$(this).html(postDateInDays)
$(this).mouseover -> $(this).html postDate
$(this).mouseout -> $(this).html postDateInDays

selectorDate = if Uno.is 'home' then '#posts-list time' else '.post.meta > time'
DateInDays selectorDate
timeAgo: (selector) ->
$(selector).each ->
postDate = $(this).html()
postDateInDays = Math.floor((Date.now() - new Date(postDate)) / 86400000)

if postDateInDays is 0 then postDateInDays = 'today'
else if postDateInDays is 1 then postDateInDays = 'yesterday'
else postDateInDays = "#{postDateInDays} days ago"

$(this).html(postDateInDays)
$(this).mouseover -> $(this).html postDate
$(this).mouseout -> $(this).html postDateInDays

device: ->
w = window.innerWidth
Expand Down
15 changes: 9 additions & 6 deletions assets/js/src/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@

$ ->

$('#profile-title').text window.profile_title if window.profile_title
$('#profile-resume').text window.profile_resume if window.profile_resume

el = Uno.app
el.dataset.page = Uno.context()
el.dataset.device = Uno.device()

Uno.readTime()
FastClick.attach el unless Uno.is 'device', 'desktop'

$('#profile-title').text window.profile_title if window.profile_title
$('#profile-resume').text window.profile_resume if window.profile_resume

if Uno.is 'device', 'desktop'
$('a').not('[href*="mailto:"]').click ->
if this.href.indexOf(location.hostname) is -1
window.open $(this).attr 'href'
false
else
FastClick.attach el

if Uno.is 'page', 'home'
Uno.timeAgo '#posts-list time'

if Uno.is 'page', 'post'
Uno.timeAgo '.post.meta > time'
$('main').readingTime readingTimeTarget: '.post.reading-time > span'
$('.content').fitVids()

Expand Down

0 comments on commit 398e691

Please sign in to comment.