-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
124 lines (99 loc) · 2.75 KB
/
main.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var feed_div;
var profile_div;
var blogpost_template;
var keys;
var sockethubClient;
var dove_it;
var options;
var url;
var gui_post_ids;
var posts = [];
function init(){
remoteStorage.enableLog();
console.log("Welcome in the microblogging app")
options = args_to_object(document.location.search);
feed_div = document.getElementById('feed');
profile_div = document.getElementById('profile');
gui_post_ids = 0;
blogpost_template = document.getElementById('blogpost_template');
// if(options.keys) {
// registration_init(options)
// }
if(options.me == 'true'){
init_remotestorage();
} else {
var base_url = options.base_url;
if(base_url) {
aggregate(base_url+'/microblog/microposts_list');
get_profile(base_url+'/profile/me');
}
}
if(options.syndicate == 'true'){
remoteStorage.on('ready', rs_init_syndication);
}
var twitter_cfg
if( options.twitter )
if ( twitter_cfg = objectify_arguments(options.twitter)) {
store_twitter_credentials(twitter_cfg);
}
var sh_cfg
if(options.sockethub && ( sh_cfg = objectify_arguments(options.sockethub) )){
store_sh_credentials(sh_cfg);
}
if( !( options.me || options.syndicate
|| options.twitter || options.sockethub
|| options.base_url) ){
document.getElementById('help').style.display = 'block'
}
f(profile_div,'edit').onclick = edit_profile_callback.bind(
{'screenname' : '',
'name' : '',
'description' : '',
'location' : '',
'homepage' : '',
'profile_image_url' : ''}
);
}
function clear_all_posts(){
while(posts.length > 0){
posts.pop().div.remove();
}
}
function get_items (items) {
console.log("post of this user : ", items);
var max_items;
if(max_items = options.max_items){
items = items.slice(0,max_items)
}
items.forEach(aggregate_item);
}
function aggregate(url){
get_url(url, get_items);
}
function aggregate_item(url){
get_url(url, new_post);
}
function get_profile(url){
try {
get_url( url, set_profile );
} catch (e){
console.error("retriving Profile failed : ", e)
}
}
function set_profile(profile){
//console.log("Setting Profile : ",profile);
if(!profile){
console.log("no profile in set_profile")
return;
}
if(!profile.homepage){
profile.homepage = window.location.origin+window.location.pathname+"?base_url="+options.base_url
}
const profile_keys = ['screenname','name','description','location'];
fill_div(profile_div, profile_keys, profile);
f(profile_div,'profile_img').src = profile.profile_image_url;
f(profile_div, 'homepage').href = profile.homepage;
f(profile_div,'edit').onclick = edit_profile_callback.bind(profile);
return profile;
}
window.onload = init;