From 6f682bc54bbe1d90fb8b33fe21317f3dc2085495 Mon Sep 17 00:00:00 2001 From: Niko Date: Mon, 14 Feb 2022 13:33:29 +0100 Subject: [PATCH] Added carousel.js for showing/hiding elements --- web/src/app/js/carousel.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 web/src/app/js/carousel.js diff --git a/web/src/app/js/carousel.js b/web/src/app/js/carousel.js new file mode 100644 index 0000000..8369db2 --- /dev/null +++ b/web/src/app/js/carousel.js @@ -0,0 +1,33 @@ +app.carousel = { + hasNext: function(mod, i) { + i = i || mod._current; + return i < mod._size() - 1; + }, + hasPrev: function(mod, i) { + i = i || mod._current; + return i > 0; + }, + next: function(mod) { + if (!app.carousel.hasNext(mod)) + return false; + return app.carousel.set(mod, mod._current+1); + }, + prev: function(mod) { + if (!app.carousel.hasPrev(mod)) + return false; + return app.carousel.set(mod, mod._current-1); + }, + set: function(mod, i) { + const elements = mod._elements(); + const current = elements[mod._current]; + const next = elements[i]; + if (mod._animation !== undefined) { + // TODO: animation run here + } + for (var j = 0; j < elements.length; j++) + elements[j].style = 'display: none'; + next.removeAttribute('style'); + mod._current = i; + return true; + }, +};