-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
276 lines (232 loc) · 10.1 KB
/
script.js
File metadata and controls
276 lines (232 loc) · 10.1 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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/* ---------------------------------------------------------------------------- */
/* -- Document ---------------------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
function writeHeader() {
document.write("<div id='header'>");
document.write("<a href='https://collicalex.github.io/' id='header-logo'>Collicalex</a> <span id='header-logo-tooltip'>← take a look at my other projects made with <span class='heart'>♥</span></span>");
document.write("<a href='https://www.instagram.com/collicalex'/' id='header-avatar'></a><span id='header-avatar-tooltip2'>See my photo on Instagram →</span>");
document.write("</div>");
}
function writeProjectCover() {
var projectName = document.title;
document.write("<div id='project-cover'>");
document.write("<div id='project-title'>"+projectName+"</div>");
document.write("<div id='project-description'></div>");
document.write("<div>");
document.write("<a class='project-button' href='https://github.com/collicalex/"+projectName+"'>View source</a>");
document.write("<a class='project-button' href='https://github.com/collicalex/"+projectName+"/releases/latest'>Download</a>");
document.write("</div>");
document.write("<div id='project-version'>");
document.write("<span id='projectLastVersionNumber'></span><span id='projectLastVersionDate'></span>");
document.write("</div>");
document.write("</div>");
}
function writeDownloadSection() {
var projectName = document.title;
document.write("<h2>Download</h2>");
document.write("<p>You can download the latest version of "+projectName+" in the dedicated <a href='https://github.com/collicalex/"+projectName+"/releases/latest'>releases page</a>.");
}
function writeJavaPreRequirementSection() {
var projectName = document.title;
document.write("<h2>Pre Requirement</h2>");
document.write("<p>"+projectName+" is written in JAVA. So it's natively executable on all Operating System (Windows, OsX, Unix/Linux,...). You just need to have a JRE (Java Runtime Environement) installed on your system. Download it <a href='https://www.java.com/download'>here</a>.</p>");
}
function writePreFooter() {
var projectName = document.title;
document.write("<h2>Want to contribute?</h2>");
if (projectName.indexOf('Collicalex') == -1) {
document.write("<p>You can contribute with "+projectName+" by <a href='https://github.com/collicalex/"+projectName+"/releases'>installing it</a>, using it, take a look at its <a href='https://github.com/collicalex/"+projectName+"'>source code</a> and <a href='https://github.com/collicalex/"+projectName+"/issues'>submitting issues</a> and <a href='https://github.com/collicalex/"+projectName+"/pulls'>pull requests</a> :)</p>");
} else {
document.write("<p>You can contribute to any of my project by installing them, using them, take a look at their source code and submitting issues and pull requests on their dedicated page.</p>");
}
document.write("<h2>Follow me</h2>");
document.write("<p>You can follow me:");
document.write("<ul>");
document.write("<li>as photographer on <a href='https://www.instagram.com/collicalex'>Instagram</a> and <a href='https://www.flickr.com/photos/colliculus'>Flickr</a></li>");
document.write("<li>as developer on <a href='https://github.com/collicalex'>GitHub</a></li>");
document.write("</ul>");
document.write("</p>");
}
function writeFooter() {
var projectName = document.title;
document.write("<div id='footer'>");
if (projectName.indexOf('Collicalex') == -1) {
document.write("<div id='footer-title'>"+projectName+"</div>");
}
document.write("<div id='footer-author'>Made with <span class='heart'>♥</span> by <a href='https://collicalex.github.io/'>Alexandre Bargeton</a>.</div>");
document.write("</div>");
}
window.onload = function(e){
var projectName = document.title;
if (projectName.indexOf('Collicalex') == -1) {
getGitHubProject();
} else {
getGitHubProjects();
}
onloadSlides();
}
/* ---------------------------------------------------------------------------- */
/* -- GitHub API -------------------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
function ajax_getJSON(url, callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
try {
var data = JSON.parse(xmlhttp.responseText);
} catch(err) {
console.log(err.message + " in " + xmlhttp.responseText);
return;
}
callback(data);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function getGitHubProjectDescription(userName, projectName) {
var jsonurl = "https://api.github.com/repos/" + userName + "/" + projectName;
ajax_getJSON(jsonurl, function(data) {
document.getElementById("project-description").innerHTML = data.description;
});
}
function grabDateFromISO8601(datetime) {
return datetime.split("T")[0];
}
function getGitHubProjectLastVersion(userName, projectName) {
var jsonurl = "https://api.github.com/repos/" + userName + "/" + projectName + "/releases";
ajax_getJSON(jsonurl, function(data) {
var lastVersionIndex = -1;
var lastVersionId = 0;
for (i = 0; i < data.length; ++i) {
if (data[i].prerelease == false) {
if (data[i].id > lastVersionId) {
lastVersionIndex = i;
lastVersionId = data[i].id;
}
}
}
if (i > -1) {
document.getElementById("projectLastVersionNumber").innerHTML = data[lastVersionIndex].name + " (" + data[lastVersionIndex].tag_name + ")";
document.getElementById("projectLastVersionDate").innerHTML = grabDateFromISO8601(data[lastVersionIndex].published_at);
}
});
}
function getGitHubProject() {
var userName = "collicalex";
var projectName = document.title;
getGitHubProjectDescription(userName, projectName);
getGitHubProjectLastVersion(userName, projectName);
}
function getGitHubProjects() {
var userName = "collicalex";
var jsonurl = "https://api.github.com/users/"+userName+"/repos";
ajax_getJSON(jsonurl, function(data) {
var html = "";
for (i = 0; i < data.length; ++i) {
if ((data[i].name.indexOf('collicalex.github.io') == -1) && (data[i].fork == false)) {
var projectName = document.createElement("div");
projectName.classList.add('projectName');
projectName.appendChild(document.createTextNode(data[i].name));
var projectDescription = document.createElement("div");
projectDescription.classList.add('projectDescription');
projectDescription.appendChild(document.createTextNode(data[i].description));
var homepage = null;
if (data[i].homepage != null) {
homepage = document.createElement("a");
homepage.classList.add('projectButton');
homepage.title = "Homepage";
homepage.href = data[i].homepage;
homepage.appendChild(document.createTextNode("Homepage"));
}
var source = document.createElement("a");
source.classList.add('projectButton');
source.title = "View source";
source.href = data[i].html_url;
source.appendChild(document.createTextNode("View source"));
var release = document.createElement("a");
release.classList.add('projectButton');
release.title = "Latest Release";
release.href = "https://github.com/collicalex/"+data[i].name+"/releases/latest";
release.appendChild(document.createTextNode("Download"));
var buttons = document.createElement("div");
buttons.classList.add('projectButtons');
if (homepage != null) {
buttons.appendChild(homepage);
}
buttons.appendChild(source);
buttons.appendChild(release);
var project = document.createElement("div");
project.classList.add('project');
project.appendChild(projectName);
project.appendChild(projectDescription);
project.appendChild(buttons);
document.getElementById('projects').appendChild(project);
}
}
});
}
/* ---------------------------------------------------------------------------- */
/* -- Slideshow --------------------------------------------------------------- */
/* ---------------------------------------------------------------------------- */
function onloadSlides() {
var slideshow = document.getElementsByClassName("slideshow-container");
for (var i = 0; i < slideshow.length; ++i) {
addArrowsToSlideShow(slideshow[i]);
addDotsToSlideshow(slideshow[i]);
showSlide(slideshow[i], 0);
}
}
function previousSlide(elt) {
showSlide(elt, getSlideId(elt)-1);
}
function nextSlide(elt) {
showSlide(elt, getSlideId(elt)+1);
}
function getSlideId(elt) {
while (elt.className != "slideshow-container") {
elt = elt.parentElement;
}
var dots = elt.getElementsByClassName("slide-dot");
for (i = 0; i < dots.length; i++) {
if (dots[i].className.indexOf("active") !== -1) {
return i;
}
}
return 0;
}
function showSlide(elt, n) {
while (elt.className != "slideshow-container") {
elt = elt.parentElement;
}
var i;
var slides = elt.getElementsByClassName("slide");
var dots = elt.getElementsByClassName("slide-dot");
if (n >= slides.length) {n = slides.length-1;}
if (n < 0) {n=0;}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
dots[i].className = dots[i].className.replace(" active", "");
}
slides[n].style.display = "block";
dots[n].className += " active";
}
function addArrowsToSlideShow(elt) {
var slides = elt.getElementsByClassName("slideshow-images");
slides = slides[0];
slides.innerHTML += "<a class='prev' onclick='previousSlide(this)'>❮</a><a class='next' onclick='nextSlide(this)'>❯</a>";
}
function addDotsToSlideshow(elt) {
var slides = elt.getElementsByClassName("slide");
var dotsTxt = "<div style='text-align:center; position:relative; top:-135px'>";
for (var i = 0; i < slides.length; ++i) {
dotsTxt += "<span class='slide-dot' onclick='showSlide(this, "+i+")'></span>\r\n";
}
dotsTxt += "</div>";
elt.innerHTML += dotsTxt;
var slidesTxt = elt.getElementsByClassName("slide-text");
for (var i = 0; i < slidesTxt.length; ++i) {
slidesTxt[i].style.position = 'relative';
slidesTxt[i].style.top = '45px';
}
}