Commit 74323c51 authored by Ian Dennis Miller's avatar Ian Dennis Miller

split js into several files

parent 769d6dbe
var handler = function(e) {
var charCode = (typeof e.which == "number") ? e.which : e.keyCode;
// console.log(charCode);
if (e.ctrlKey && charCode == '65') {
// a: all
e.preventDefault();
e.stopPropagation();
toggle_appearances();
}
else if (e.ctrlKey && charCode == '83') {
// s: search
e.preventDefault();
e.stopPropagation();
toggle_search();
}
else if (e.ctrlKey && charCode == '90') {
// z: zoom
e.preventDefault();
e.stopPropagation();
toggle_focus();
}
else if (charCode == '37') {
// left arrow
show_previous();
}
else if (charCode == '39') {
// right arrow
show_next();
}
else if (charCode == '27') {
// escape
toggle_ui();
}
else if (e.ctrlKey && charCode == '68') {
// d: dark
e.preventDefault();
e.stopPropagation();
toggle_dark_mode();
}
else if (e.ctrlKey && charCode == '72') {
// h: help
e.preventDefault();
e.stopPropagation();
toggle_help();
}
}
......@@ -56,6 +56,8 @@
<script>
{% include 'swiper.js' %}
{% include 'pager.js' %}
{% include 'keyboard.js' %}
{% include 'main.js' %}
</script>
</body>
</html>
var divs = document.getElementsByClassName("card");
var counter = 0;
var filtered = false;
var focused = true;
var filter_id = "";
var appearances = "visible";
function main() {
show_all();
swiper.onLeft(show_next);
swiper.onRight(show_previous);
swiper.run();
}
var swiper = new Swipe(document.getElementsByTagName('body')[0]);
document.onkeydown = handler;
main();
var divs = document.getElementsByClassName("card");
var counter = 0;
var filtered = false;
var focused = true;
var filter_id = "";
var appearances = "visible";
/* focus */
var toggle_focus = function() {
if (focused) {
......@@ -55,6 +49,15 @@ var show_all = function() {
el.classList.remove('focused');
}
var refresh = function(els) {
for (var i = 0; i < els.length; i++){
els[i].style.display = "none";
}
els[counter].style.display = "block";
}
/* focus: previous/next */
var show_next = function() {
if (!focused) { return; }
......@@ -73,13 +76,6 @@ var show_next = function() {
refresh(els);
}
var refresh = function(els) {
for (var i = 0; i < els.length; i++){
els[i].style.display = "none";
}
els[counter].style.display = "block";
}
var show_previous = function() {
if (!focused) { return; }
......@@ -98,6 +94,8 @@ var show_previous = function() {
refresh(els);
}
/* filter by article */
var toggle_article = function(id) {
// find the article button
var button = document.getElementById(id + "-button");
......@@ -221,6 +219,8 @@ var toggle_ui = function() {
}
}
/* help */
var toggle_help = function() {
var el = document.getElementById("ui-help");
if (el.classList.contains("expanded")) {
......@@ -231,6 +231,8 @@ var toggle_help = function() {
}
}
/* dark mode */
var toggle_dark_mode = function() {
var el = document.getElementsByTagName("body")[0];
if (el.classList.contains("dark")) {
......@@ -240,63 +242,3 @@ var toggle_dark_mode = function() {
el.classList.add('dark');
}
}
var handler = function(e) {
var charCode = (typeof e.which == "number") ? e.which : e.keyCode;
// console.log(charCode);
if (e.ctrlKey && charCode == '65') {
// a: all
e.preventDefault();
e.stopPropagation();
toggle_appearances();
}
else if (e.ctrlKey && charCode == '83') {
// s: search
e.preventDefault();
e.stopPropagation();
toggle_search();
}
else if (e.ctrlKey && charCode == '90') {
// z: zoom
e.preventDefault();
e.stopPropagation();
toggle_focus();
}
else if (charCode == '37') {
// left arrow
show_previous();
}
else if (charCode == '39') {
// right arrow
show_next();
}
else if (charCode == '27') {
// escape
toggle_ui();
}
else if (e.ctrlKey && charCode == '68') {
// d: dark
e.preventDefault();
e.stopPropagation();
toggle_dark_mode();
}
else if (e.ctrlKey && charCode == '72') {
// h: help
e.preventDefault();
e.stopPropagation();
toggle_help();
}
}
function main() {
show_all();
swiper.onLeft(show_next);
swiper.onRight(show_previous);
swiper.run();
}
var swiper = new Swipe(document.getElementsByTagName('body')[0]);
document.onkeydown = handler;
main();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment