-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
82 lines (66 loc) · 2.13 KB
/
Copy pathmain.js
File metadata and controls
82 lines (66 loc) · 2.13 KB
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
$(function() {
var entry_template = Handlebars.compile($("#entry-template").html());
var feed = $("#feed");
function refresh_content() {
feed.html("<div class=\"d-flex justify-content-center\"><div class=\"spinner-border\" role=\"status\"><span class=\"sr-only\">Loading...</span></div></div>");
$.ajax({
method: "GET",
url: "/api/rss.php",
dataType: "json"
}).done(function(result) {
if (result.success) {
$.ajax({
method: "GET",
url: "/api/content.php",
dataType: "json"
}).done(function(data) {
if (data && data.articles) {
feed.html("");
$.each(data.articles, function(i, article) {
feed.append(entry_template(article));
});
}
});
}
})
}
$("#refresh-feed").on("click", function(e) {
e.preventDefault();
refresh_content();
});
var feed_template = Handlebars.compile($("#feed-template").html());
var feeds = $("#feeds");
function refresh_feeds() {
feeds.html("");
$.ajax({
method: "GET",
url: "/api/feeds.php",
dataType: "json"
}).done(function(data) {
if (data && data.feeds) {
$.each(data.feeds, function(i, feed) {
feeds.append(feed_template(feed));
});
}
});
}
$("#show-feeds").on("click", function(e) {
e.preventDefault();
refresh_feeds();
$("#feed-modal").modal("show");
});
$("#new-feed-form").on("submit", function(e) {
e.preventDefault();
$.ajax({
method: "POST",
url: "/api/feeds.php",
data: $("#new-feed-form").serializeArray(),
dataType: "json"
}).done(function(result) {
if (result && result.success) {
refresh_feeds();
}
});
})
refresh_content();
});