-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmicroblog.js
83 lines (73 loc) · 2.66 KB
/
microblog.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
var article = {};
var articles = [];
// Use some nice scrollbars for in-page independent scrolling
$("#scrollContainer").overlayScrollbars({
className: "os-theme-dark",
resize: "none",
autoHide: "move"
})
//Gets all of the articles and loads their titles, locations and synopses
function getArticles() {
$("#dynamicContainer").empty();
$.getJSON("/articles/articleListing.json")
.done(function(data) {
$.each(data.archives, function(i, archive) {
article = {
_url: archive.url,
_title: archive.title,
_synopsis: archive.synopsis
}
articles.push(article);
});
articles.reverse();
displayHome();
});
}
//Displays articles as listing boxes
function displayHome() {
$("#dynamicContainer").empty();
var appender = "";
var i;
for (i = 0; i < articles.length; ++i) {
appender += "<div class=\"catalogmember\" articleurl=\"" + articles[i]._url + "\" articletitle=\"" + articles[i]._title + "\"><div class=\"blurcontainer\"><div class=\"blur\"></div></div><div class=\"membertitle\">" + articles[i]._title + "</div><div class=\"memberdetails\"><span>" + articles[i]._synopsis + "</span></div></div>";
}
$("#dynamicContainer").append("<div class=\"articleListing\">" + appender + "</div>");
}
//Empties the main container and loads an article
function displayArticle(articleURL) {
$("#dynamicContainer").empty();
if (articleURL.length == 0) {
displayHome()
} else {
$("#dynamicContainer").load("articles/" + articleURL);
if ($("#dynamicContainer").is(":empty")) {
displayHome();
doPushState("", "");
}
}
}
//Supposed to push history states. WIP
function doPushState(articleURL, articleTitle) {
var state = { selectedArticle: articleURL },
title = articleTitle,
path = "/";
history.pushState(state, title, path);
}
//Checks for a direct link to an article. Dismisses other variables for now
function checkURL() {
var url = window.location.search.substring(1);
var urlvars = url.split('&');
var articlevar = urlvars[0].split('=');
if (articlevar[0] == "a") {
displayArticle(articlevar[1]);
}
}
$("#dynamicContainer").on("click", ".catalogmember", function() {
displayArticle($(this).attr("articleurl"));
doPushState($(this).attr("articleurl"), $(this).attr("articletitle"))
});
$("#dynamicContainer").on("click", ".return", function() {
displayHome();
});
getArticles();
checkURL();