From 40813f606ec67dc40e556942358d4e8963c20ffe Mon Sep 17 00:00:00 2001 From: Wruczek Date: Sun, 4 Dec 2016 17:28:54 +0100 Subject: [PATCH] Added a option to disable snow effect --- css/christmas-theme.css | 5 +++++ include/footer.php | 1 + js/christmas.js | 47 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/css/christmas-theme.css b/css/christmas-theme.css index 463630c..ca33342 100644 --- a/css/christmas-theme.css +++ b/css/christmas-theme.css @@ -9,6 +9,11 @@ body { background-image: url(../img/christmas-bg.jpg); } +.disableSnowLink { + position: fixed; + bottom: 0; +} + .panel { background-color: #410b13; } diff --git a/include/footer.php b/include/footer.php index f6a9971..d297730 100644 --- a/include/footer.php +++ b/include/footer.php @@ -54,6 +54,7 @@ + diff --git a/js/christmas.js b/js/christmas.js index 3801814..747eda9 100644 --- a/js/christmas.js +++ b/js/christmas.js @@ -16,6 +16,18 @@ if (new Date().getMonth() === 11) { document.head.appendChild(script); window.addEventListener('load', function () { + // Change background artist in the footer + document.getElementById('background-artist').innerHTML = 'Debi Geroux - Public Domain'; + + if(getCookie('snoweffect') === 'false') { + document.getElementsByTagName('body')[0].innerHTML += 'Enable snow effect'; + return; + } + + // Add a link to disable the effect + document.getElementsByTagName('body')[0].innerHTML += 'Disable snow effect'; + + // Add the snow effect snowFall.snow(document.body, { flakeCount: (document.body.clientWidth > 992 ? 500 : 100), flakeIndex: -1, @@ -26,8 +38,37 @@ if (new Date().getMonth() === 11) { round: true, shadow: true }); - - // Change background artist in the footer - document.getElementById('background-artist').innerHTML = 'Debi Geroux - Public Domain'; }); } + +function disableSnowEffect() { + setCookie('snoweffect', 'false', 30); + location.reload(); +} + +function enableSnowEffect() { + setCookie('snoweffect', 'true', 30); + location.reload(); +} + +function setCookie(cname,cvalue,exdays) { + var d = new Date(); + d.setTime(d.getTime() + (exdays*24*60*60*1000)); + var expires = "expires=" + d.toGMTString(); + document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; +} + +function getCookie(cname) { + var name = cname + "="; + var ca = document.cookie.split(';'); + for(var i = 0; i < ca.length; i++) { + var c = ca[i]; + while (c.charAt(0) == ' ') { + c = c.substring(1); + } + if (c.indexOf(name) == 0) { + return c.substring(name.length, c.length); + } + } + return ""; +}