-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
215 lines (185 loc) · 6.53 KB
/
index.html
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!DOCTYPE html>
<html>
<head>
<meta content='text/html;charset=UTF-8' http-equiv='content-type' />
<title>Read Share Thumbs Up</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script type="text/javascript" src="./js/jquery.tmpl.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script id="articleTemplate" type="text/x-jquery-tmpl">
<div class='articleContainer' style='display: none;'> <!-- display none cause we jqueryUI toggle them into view -->
<div class='articleContent'></div>
<div class='articleControls'>
<div class='commentControls'>
<div>
<textarea class='commentBox' type='textarea'></textarea>
</div>
<div>
<input type='button' value='add comment' />
</div>
</div>
<input type='button' value='like' />
<input type='button' value='share' />
</div>
</div>
</script>
<script type="text/javascript">
var RSTUModule = (function() {
var feedUrls = [];
var myModule = {};
var cookies;
// Thanks http://stackoverflow.com/questions/5639346/shortest-function-for-reading-a-cookie-in-javascript
// for this solution
myModule.readCookie = function(name,c,C,i){
if(cookies){ return cookies[name]; }
c = document.cookie.split('; ');
cookies = {};
for(i=c.length-1; i>=0; i--){
C = c[i].split('=');
cookies[C[0]] = C[1];
}
return cookies[name];
}
myModule.readCookie = readCookie;
myModule.AddFeed = function(feedUrl) {
// Notify the srevice that you're adding a feed
$.ajax({
url:'http://readsharethumbsupservice.apphb.com/Feed/AddFeed',
dataType: 'jsonp',
data: {
'userName': 'mlang',
'feedUrl': feedUrl
},
success: function(data) {
alert('Service AddFeed method said: ' + data.response);
// add it to the page if it succeeds
addFeedToPage(feedUrl);
}
});
};
var addFeedToPage = function(feedUrl) {
feedUrls.push(feedUrl);
var feed = new google.feeds.Feed(feedUrl);
feed.load(function(result) {
if (!result.error) {
var feedsContainer = document.getElementById("feedList");
var feedElement = document.createElement("li");
var feedTitleElement = document.createElement("span");
feedTitleElement.className = "feedTitle";
feedTitleElement.appendChild(document.createTextNode(result.feed.title));
feedElement.appendChild(feedTitleElement);
feedsContainer.appendChild(feedElement);
$(feedElement).data('feedUrl', feedUrl);
}
});
}
var showFeedArticles = function(feedTitleElement) {
var feedRootElement = feedTitleElement.parentNode;
var feedUrl = $(feedRootElement).data('feedUrl');
var feed = new google.feeds.Feed(feedUrl);
feed.load(function(result) {
if (!result.error) {
var entryListElement = document.createElement("ul");
entryListElement.className = "articleList";
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var entryElement = document.createElement("li");
entryElement.className = "entryRoot";
var entryTitleElement = document.createElement("span");
entryTitleElement.className = "articleTitle";
entryTitleElement.appendChild(document.createTextNode(entry.title));
$(entryElement).data('articleIndex', i);
entryElement.appendChild(entryTitleElement);
entryListElement.appendChild(entryElement);
}
entryListElement.setAttribute('style', 'display: none;');
feedRootElement.appendChild(entryListElement);
$(entryListElement).toggle('blind', {}, 500);
$(feedRootElement).data('loaded', true);
}
});
};
var loadAndShowArticleContent = function(articleTitleElement) {
var articleRootElement = articleTitleElement.parentNode;
var feedUrl = $(articleRootElement).parent().parent().data('feedUrl');
var i = $(articleRootElement).data('articleIndex');
var feed = new google.feeds.Feed(feedUrl);
feed.load(function(result) {
if (!result.error) {
$('#articleTemplate').tmpl().appendTo(articleRootElement);
$(articleRootElement).find('.articleContent').html(result.feed.entries[i].content);
$(articleRootElement).find('.articleContainer').toggle('blind', {}, 500);
$(articleRootElement).data('loaded', true);
}
});
};
myModule.Initialize = function() {
$(document).ready(function() {
$.ajax({
url: 'http://readsharethumbsupservice.apphb.com/Feed/GetFeeds',
dataType: 'jsonp',
data: { userName: 'mlang' },
success: function(data) {
for (var i=0; i<data.length; i++) {
addFeedToPage(data[i]);
}
return;
}
});
$(document).on('click','.articleTitle', function() {
var articleRoot = this.parentNode;
var loaded = $(articleRoot).data('loaded');
if (loaded) {
$(articleRoot).find('.articleContainer').toggle('blind', {}, 500);
} else {
loadAndShowArticleContent(this);
}
});
$(document).on('click', '.feedTitle', function() {
var feedRoot = this.parentNode;
var loaded = $(feedRoot).data('loaded');
if (loaded) {
$(feedRoot).find('.articleList').toggle('blind', {}, 500);
} else {
showFeedArticles(this);
}
});
});
};
return myModule;
}());
</script>
<script type="text/javascript">
google.load("feeds", "1");
function initialize() {
RSTUModule.Initialize();
}
google.setOnLoadCallback(initialize);
$(document).ready(function() {
$('#loginButton').click(function() {
RSTUModule.Login($('#
});
$('#addButton').click(function() {
RSTUModule.AddFeed($('#addBox').val());
});
});
</script>
<link href="./css/styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>Read Share Thumbs Up v0.0</h1>
<h2>The Minimalist Social RSS Reader</h2>
<div id="loginControls">
<label for="userNameBox">Username:</label>
<input id="userNameBox" type="text" />
<input id="addButton" type="button" value="Login"/>
</div>
<div id="controls" class="notLoggedIn">
<input id="addBox" type="text" />
<input id="addButton" type="button" value="Add Feed" />
</div>
<ul id="feedList">
</ul>
</body>
</html>