forked from buddycloud/buddycloud-webclient-discontinuted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.coffee
80 lines (71 loc) · 2.85 KB
/
post.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
unless process.title is 'browser'
return module.exports =
src: "streams.html"
select: () ->
el = @select "article.topic:first section.opener" , "p *"
el.find('p, span').text("")
return el
{ Template } = require 'dynamictemplate'
jqueryify = require 'dt-jquery'
design = require '../../_design/channel/post'
module.exports = design (view) ->
return jqueryify new Template schema:5, ->
@$section ->
@attr class:"#{view.type}"
avatar = @img class:'avatar'
@$div class:'postmeta', ->
@$span class:'time', ->
update_time = =>
# FIXME: single tick bug
setTimeout =>
date = view.model.get('updated') or
view.model.get('published')
@attr "data-date":date
@_jquery?.formatdate update:off
, 1
view.model.bind 'change:updated', update_time
view.model.bind 'change:published', update_time
update_time()
name = @span class:'name'
update_author = ->
author = app.users.get_or_create id:(view.model.get('author')?.jid)
avatar.attr src:"#{author?.avatar or " "}"
# FIXME: single tick bug
setTimeout ->
name.text(author?.get('name') or
author?.get('jid') or
"???")
, 1
view.model.bind 'change:author', update_author
do update_author
# this saves us some jquery roundtrips when updating
# the tags for the first time
avatar.end()
name.end()
@$span class:'location', ->
@remove() # FIXME not implemented yet :(
@$p ->
update_text = =>
@text(view.model.get('content')?.value or "")
render_previews.call(this, view)
view.model.bind 'change:content', update_text
update_text()
render_previews = (view) ->
urls = @text?().match /(https?:\/\/[^\s]+)/g
return unless urls?
(urls ? []).forEach (url) =>
div = @div()
for url in urls
do (url) =>
view.load_url_preview url, (data) =>
if data.html?
@$div ->
@raw data.html
else if data.type is 'photo' and data.url?
@$img
src: data.url
style: "max-width: 100%"
else if data.thumbnail_url
@$img
src: data.thumbnail_url
style: "max-width: 100%"