Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
1d1b4133
Commit
1d1b4133
authored
May 15, 2012
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add missing handlebars helpers js
parent
1b1e571a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
helpers.js
hypothesis/js/helpers.js
+48
-0
No files found.
hypothesis/js/helpers.js
0 → 100644
View file @
1d1b4133
/*
* 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>'
))
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment