Commit 1d1b4133 authored by Randall Leeds's avatar Randall Leeds

add missing handlebars helpers js

parent 1b1e571a
/*
* http://stackoverflow.com/a/7641812
*/
var Handlebars
Handlebars.registerHelper('fuzzyTime', function (date) {
var delta = Math.round((+new Date - new Date(date)) / 1000)
var minute = 60,
hour = minute * 60,
day = hour * 24,
week = day * 7
var fuzzy
if (delta < 30) {
fuzzy = 'moments ago.'
} else if (delta < minute) {
fuzzy = delta + ' seconds ago.'
} else if (delta < 2 * minute) {
fuzzy = 'a minute ago.'
} else if (delta < hour) {
fuzzy = Math.floor(delta / minute) + ' minutes ago.'
} else if (Math.floor(delta / hour) == 1) {
fuzzy = '1 hour ago.'
} else if (delta < day) {
fuzzy = Math.floor(delta / hour) + ' hours ago.'
} else if (delta < day * 2) {
fuzzy = 'yesterday'
}
return fuzzy
})
Handlebars.registerHelper('splitUser', function (user, options) {
var parts = this.user.split(/(?:acct:)|@/);
return options.fn({
name: parts[1],
provider: parts[2]
})
})
Handlebars.registerHelper('formatUser', function (user) {
return new Handlebars.SafeString(
user.replace(
/^acct:([^@]+)@(.+)$/,
'$1 <span class="hyp-provider">on $2</span>'))
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment