From 98c5e85be6f75db99c51be15cd6a0f881abbb329 Mon Sep 17 00:00:00 2001 From: Wruczek Date: Fri, 2 Dec 2016 05:14:19 +0100 Subject: [PATCH] Fixed a issue when script was loaded before jquery --- js/christmas.js | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/js/christmas.js b/js/christmas.js index 4d975f3..8c27804 100644 --- a/js/christmas.js +++ b/js/christmas.js @@ -17,18 +17,29 @@ if (new Date().getMonth() === 11) { // Wait for the snowfall script and jQuery to load window.addEventListener('load', function () { - $(document).snowfall({ - flakeCount: ($(document).width() > 992 ? 500 : 100), - flakeIndex: -1, - minSize: 4, - maxSize: 5, - minSpeed: 1, - maxSpeed: 2, - round: true, - shadow: true - }); + defer(proceedWithJquery); + }); +} - // Change background artist in the footer - $('#background-artist').html('Debi Geroux - Public Domain'); +function defer(method) { + if (window.jQuery) + method(); + else + setTimeout(function() { defer(method) }, 50); +} + +function proceedWithJquery() { + $(document).snowfall({ + flakeCount: ($(document).width() > 992 ? 500 : 100), + flakeIndex: -1, + minSize: 4, + maxSize: 5, + minSpeed: 1, + maxSpeed: 2, + round: true, + shadow: true }); + + // Change background artist in the footer + $('#background-artist').html('Debi Geroux - Public Domain'); }