reformat and cleanup js code

git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@221 a672b425-5310-4d7a-af5c-997e18724b81
This commit is contained in:
bevilj 2018-11-15 20:54:09 +00:00
parent 2351af8a62
commit ff4d47d64c
2 changed files with 113 additions and 100 deletions

View File

@ -38,60 +38,63 @@
{{ content }} {{ content }}
</main> </main>
{% include footer.html %} {% include footer.html %}
<script src="https://cdn.rawgit.com/christian-fei/Simple-Jekyll-Search/master/dest/simple-jekyll-search.min.js"></script> <script src="https://cdn.rawgit.com/christian-fei/Simple-Jekyll-Search/master/dest/simple-jekyll-search.min.js"></script>
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
var searchBar = document.getElementById('search-bar'); var searchBar = document.getElementById('search-bar');
var results = document.getElementById('search-results'); var results = document.getElementById('search-results');
var sjs = SimpleJekyllSearch({ var sjs = SimpleJekyllSearch({
searchInput: searchBar, searchInput: searchBar,
resultsContainer: results, resultsContainer: results,
json: '/search.json', json: '/search.json',
searchResultTemplate: searchResultTemplate:
'<li><a href="{url}"><h3>{title}</h3><h4>{category}</h4></a></li>', '<li><a href="{url}"><h3>{title}</h3><h4>{category}</h4></a></li>',
success: function(sr) { success: function(sr) {
results.setAttribute("class", sr.length <= 1 ? "" : "show"); results.setAttribute("class", sr.length <= 1 ? "" : "show");
} }
}); });
searchBar.addEventListener('keypress', function () { searchBar.addEventListener('keypress', function () {
sjs.search(); sjs.search();
}); });
}); });
var sentence =["<span class='NotoSansLight'>t", "h", "e</span>", "<span class='NotoSansBold'>s", "h", "e", "l", "l</span>"]; // Animated logo
var shell = ""; var sentence = ["<span class='NotoSansLight'>t", "h", "e</span>",
var counter = 0; "<span class='NotoSansBold'>s", "h", "e", "l", "l</span>"];
var shell = "";
var counter = 0;
function typing_shell(){ function typing_shell() {
if(counter < 8){ if (counter < 8){
write(counter); write(counter);
counter++; counter++;
}else{ } else {
document.getElementById("blikli").classList.add("bli"); document.getElementById("blikli").classList.add("bli");
} }
}
} setInterval(typing_shell, 200);
setInterval( function write(position){
typing_shell shell = shell + sentence[position];
, 200); document.getElementById("title-home").innerHTML = shell;
}
function write(position){ var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
shell = shell + sentence[position]; if (!isChrome) {
document.getElementById("title-home").innerHTML = shell; document.getElementById('foolChrome').remove();
} var homeVideo = document.getElementById('videoHome');
// Try and see if we can play with audio, otherwise mute the video
var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor); try {
if (!isChrome) { homeVideo.play();
document.getElementById('foolChrome').remove(); } catch (err) {
homeVideo.muted = true;
// Mute and play
var homeVideo = document.getElementById('videoHome');
homeVideo.play(); homeVideo.play();
} }
}
</script> </script>
</body> </body>

View File

@ -9,63 +9,73 @@
{{ content }} {{ content }}
</main> </main>
{% include footer.html %} {% include footer.html %}
<script src="https://cdn.rawgit.com/christian-fei/Simple-Jekyll-Search/master/dest/simple-jekyll-search.min.js"></script> <script src="https://cdn.rawgit.com/christian-fei/Simple-Jekyll-Search/master/dest/simple-jekyll-search.min.js"></script>
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
var searchBar = document.getElementById('search-bar'); var searchBar = document.getElementById('search-bar');
var results = document.getElementById('search-results'); var results = document.getElementById('search-results');
var sjs = SimpleJekyllSearch({ var sjs = SimpleJekyllSearch({
searchInput: searchBar, searchInput: searchBar,
resultsContainer: results, resultsContainer: results,
json: '/search.json', json: '/search.json',
searchResultTemplate: searchResultTemplate:
'<li><a href="{url}"><h3>{title}</h3><h4>{category}</h4></a></li>', '<li><a href="{url}"><h3>{title}</h3><h4>{category}</h4></a></li>',
success: function(sr) { success: function(sr) {
results.setAttribute("class", sr.length <= 1 ? "" : "show"); results.setAttribute("class", sr.length <= 1 ? "" : "show");
} }
}); });
searchBar.addEventListener('keypress', function () { searchBar.addEventListener('keypress', function () {
sjs.search(); sjs.search();
}); });
}); });
var bdy = document.getElementById("bdy"); document.addEventListener("keypress", function(event) {
document.addEventListener("keypress", function(event){ switch (event.key) {
if(event.key == "w" || event.key == "k"){ case "w":
window.scrollTo (0,0); case "k":
}else if(event.key == "~"){ window.scrollTo (0,0);
location.href = "{{ site.baseurl }}/"; break;
}else if(event.key == "a" || event.key == "h"){ case "a":
var previous = "{{ site.baseurl }}/{{ page.previous-page }}"; case "h":
if(previous){ var previous = "{{ page.previous-page }}";
location.href = previous; if (previous) {
} location.href = "{{ site.baseurl }}/" + previous;
}else if(event.key == "d" || event.key == "l"){ }
var next = "{{ site.baseurl }}/{{ page.next-page }}"; break;
if(next){ case "d":
location.href = next; case "l":
} var next = "{{ page.next-page }}";
}else if(event.key == "s" || event.key == "j"){ if (next) {
var topic; location.href = "{{ site.baseurl }}/" + next;
switch("{{ page.category-page }}"){ }
case "basic": break;
topic = "{{ site.baseurl }}/pages/topic/cmd/basic.html"; case "s":
case "intermediate": case "j":
topic = "{{ site.baseurl }}/pages/topic/cmd/intermediate.html"; var topicPage;
case "advanced": var topic = "{{ page.category-page }}";
topic = "{{ site.baseurl }}/pages/topic/cmd/advanced.html"; switch (topic) {
case "fs": case "basic":
topic = "{{ site.baseurl }}/pages/topic/fs.html"; case "intermediate":
case "scripts": case "advanced":
topic = "{{ site.baseurl }}/pages/topic/scripts.html"; topicPage = "{{ site.baseurl }}/pages/topic/cmd/" + topic + ".html";
}; break;
if (topic){ case "fs":
location.href = topic; case "scripts":
} topicPage = "{{ site.baseurl }}/pages/topic/" + topic + ".html";
} break;
}); }
</script>
if (topicPage) {
location.href = topicPage;
}
break;
case "~":
location.href = "{{ site.baseurl }}/";
break;
}
});
</script>
</body> </body>
</html> </html>