-
Notifications
You must be signed in to change notification settings - Fork 3
/
post.js
84 lines (70 loc) · 2.03 KB
/
post.js
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
81
82
83
84
function Post(data){
if(!data){
data = {};
}
//this.data = data
//done in fill_post
this.gui_post_id = gui_post_ids++
this.post_id = data.post_id;
this.fill_post = function(item, data){
//console.log('fill_post', item, data)
if(!item)
item = this.div;
if(typeof(data.avatar) === 'undefined'){
data.avatar = ''
}
this.data = data;
item.dataset.date = data.date;
//item.dataset.post_id = data.post_id;
//item.dataset.gui_post_id = this.gui_post_id;
//happens in display(need to run only once values should never change)
f(item,'screenname').textContent = data.screenname;
f(item,'fullname').textContent = data.fullname;
f(item,'text').textContent = data.text;
f(item,'created_at').textContent = (new Date(data.date)).toLocaleDateString();
f(item, 'avatar').src = data.avatar;
f(item, 'delete').onclick = function(){
delete_post(data);
}
f(item, 'syndicate').onclick = function(){
console.log('onclick : ',data.twitter_id)
if(!data.twitter_id && sockethubClient){
syndicate_to_twitter(data);
}
}
if(data.twitter_id){
add_class(item, 'syndicated')
}
}
this.display = function(){
var item = this.div
if(!item) {
console.log("creating new Post : ", this.gui_post_id)
item = blogpost_template.cloneNode(true);
item.id = "";
item.dataset.gui_post_id = this.gui_post_id;
item.dataset.post_id = data.post_id;
this.fill_post(item, data);
var next_element = feed_div.firstElementChild;
feed_div.insertBefore(item, next_element);
this.div = item;
}
return item;
}
this.to_atom = function(){
var feed = ""
feed += tag ( 'entry',
tag( 'author',
tag( 'name',this.fullname) +
tag( 'email', this.screenname )
) +
tag( 'updated', this.created_at) +
tag( 'summary', this.text )
);
return feed;
}
this.display();
}
function new_post(data){
posts.push(new Post(data));
}