From 7341b0f478dd3d4a25a1d59609cf723ef3777bb2 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Sat, 14 Apr 2018 09:30:40 +0100 Subject: [PATCH] Comment js, check before setup --- html/main.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/html/main.js b/html/main.js index ad804d96..9aeb2357 100644 --- a/html/main.js +++ b/html/main.js @@ -1,6 +1,14 @@ - -carousel = (function(){ +/** + * Simple carousel + * + * Based on example code by Christian Heilmann + * http://christianheilmann.com/2015/04/08/keeping-it-simple-coding-a-carousel/ + */ +carousel = function(){ var box = document.querySelector('.carousel'); + if (!box) { + return + } var next = box.querySelector('.next'); var prev = box.querySelector('.back'); // Define the global counter, the items and the @@ -33,4 +41,12 @@ carousel = (function(){ // show the first element // (when direction is 0 counter doesn't change) navigate(0); -})(); +} + +/** + * "Cut the mustard" and setup page + */ +if('querySelector' in document + && 'addEventListener' in window) { + carousel(); +}