diff --git a/js/splashify_full_screen.js b/js/splashify_full_screen.js index ca787d70ac94433cca484d36dc52432d70f8d1c2..bd19925c5406109027fdef800c72df0f3d8724a4 100644 --- a/js/splashify_full_screen.js +++ b/js/splashify_full_screen.js @@ -1,54 +1,73 @@ (function ($) { - Drupal.behaviors.splashifyBehavior.full_screen = - function (context, settings) { - var splash_height = $(window).height(); + Drupal.behaviors.splashifyBehavior.full_screen = function ( + context, + settings, + ) { + const splashHeight = $(window).height(); - $('#splashify', context).once('splashify_open').each(function () { - var $splash = $(this); + // Open the splash div. + function openSplash($splash) { + const $body = $('body'); + $body.addClass('splash-active'); + + const originalHeight = $splash.attr('originalheight'); + + if (originalHeight) { + $body[0].style.marginTop = `${originalHeight}px`; + + const splashWrapper = document.querySelector('.splash-wrapper'); + if (splashWrapper) { + splashWrapper.style.height = `${originalHeight}px`; + } + } + + window.scrollTo(0, 0); + } + + $('#splashify', context) + .once('splashify_open') + .each(function () { + const $splash = $(this); // Get the height of the div. Set it as a custom attribute. // Update the height to 0 and then show the div. - $('body').css('margin-top', splash_height); - $splash.attr('originalheight', splash_height + 'px'); - $splash.css('position', 'absolute'); - $splash.css('display', 'block'); + document.body.style.marginTop = splashHeight; + $splash.setAttribute('originalheight', `${splashHeight}px`); + $splash.style.position = 'absolute'; + $splash.style.display = 'block'; // Open the splash. openSplash($splash); // Track scroll position to destroy splash - $(context).once('splashify_scroll').on('scroll.splash', function () { - var $object = $(this); - var scroll_position = $object.scrollTop(); - if (scroll_position >= splash_height) { - $object.scrollTop(0); - // Destroy the splash div...they scrolled passed it. - var $body = $('body'); - $body.removeClass('splash-active'); - $body.css('margin-top', 0); - $('#splashify', context).css('height', 0); - $object.off('scroll.splash'); - } - }); - }); + $(context) + .once('splashify_scroll') + .on('scroll.splash', function () { + const $object = $(this); + const scrollPosition = $object.scrollTop(); + if (scrollPosition >= splashHeight) { + $object.scrollTop(0); + // Destroy the splash div, they scrolled passed it. + const $body = $('body'); + $body.removeClass('splash-active'); + $body[0].style.marginTop = '0'; - // Open the splash div. - function openSplash($splash) { - var $body = $('body'); - $body.addClass('splash-active'); - $body.css('margin-top', $splash.attr('originalheight')); - $('.splash-wrapper').css('height', $splash.attr('originalheight')); - window.scrollTo(0, 0); - } + const splashify = document.getElementById('splashify'); + if (splashify) { + splashify.style.height = '0'; + } - // Close the splash div. - function closeSplash() { - var $body = $('body'); - $body.removeClass('splash-active'); - $body.css('margin-top', 0); - $('.splash-wrapper').css('height', 0); - } + $object.off('scroll.splash'); + } + }); + }); + // Close the splash div. + function closeSplash() { + const $body = $('body'); + $body.removeClass('splash-active'); + $body[0].style.marginTop = '0'; + document.querySelector('.splash-wrapper').style.height = '0'; } - + }; })(jQuery); diff --git a/js/splashify_init.js b/js/splashify_init.js index e129214650a59c69da18fd7098c97694820b465a..d12e8b02396b670f392326a4e574df4fcdadf101 100644 --- a/js/splashify_init.js +++ b/js/splashify_init.js @@ -1,27 +1,27 @@ (function ($) { Drupal.behaviors.splashifyBehavior = { - attach: function (context, settings) { - var jsmode = settings.splashify.mode, - referrer = document.referrer + '', - hostname = window.location.hostname + '', - referrer_check = settings.splashify.referrer_check; + attach(context, settings) { + const jsmode = settings.splashify.mode; + let referrer = `${document.referrer}`; + const hostname = `${window.location.hostname}`; + const referrerCheck = settings.splashify.referrer_check; - // This updates the referer string by taking out the url parameter from the - // url...which is included from google search results (as an example). - if (referrer.indexOf('?') != -1) { + // This updates the referer string by taking out the URL parameter from the + // URL, which is included from Google search results (as an example). + if (referrer.indexOf('?') !== -1) { referrer = referrer.substr(0, referrer.indexOf('?')); } - // Stop the splash page from show up if on the splash page. Also prevent + + // Stop the splash page from showing up if on the splash page. Also prevent // the splash from showing up from internal links (dependent on the // referrer check settings). - if ((referrer.search(hostname) != -1 && referrer_check)) { + if (referrer.search(hostname) !== -1 && referrerCheck) { return; } - if (typeof Drupal.behaviors.splashifyBehavior[jsmode] != 'undefined') { + if (typeof Drupal.behaviors.splashifyBehavior[jsmode] !== 'undefined') { Drupal.behaviors.splashifyBehavior[jsmode](context, settings); } - } - } - + }, + }; })(jQuery); diff --git a/js/splashify_lightbox.js b/js/splashify_lightbox.js index cd3c0a2b01154937ef601854dafa1802e798d658..6b7638b10f291e9788a8175aca2d223c2a32c2d8 100644 --- a/js/splashify_lightbox.js +++ b/js/splashify_lightbox.js @@ -1,15 +1,13 @@ (function ($) { - Drupal.behaviors.splashifyBehavior.lightbox = - function (context, settings) { - var url = settings.splashify.url; - - $.colorbox({ - transition: 'elastic', - iframe: true, - href: url, - width: settings.splashify.width, - height: settings.splashify.height - }); - } + Drupal.behaviors.splashifyBehavior.lightbox = function (context, settings) { + const url = settings.splashify.url; + $.colorbox({ + transition: 'elastic', + iframe: true, + href: url, + width: settings.splashify.width, + height: settings.splashify.height, + }); + }; })(jQuery); diff --git a/js/splashify_redirect.js b/js/splashify_redirect.js index de974bd701c83e56a012f011382cb16aad04bba5..93a8f611b6350844485630fe7d09aa015cae1fe7 100644 --- a/js/splashify_redirect.js +++ b/js/splashify_redirect.js @@ -1,9 +1,7 @@ (function ($) { - Drupal.behaviors.splashifyBehavior.redirect = - function (context, settings) { - var url = settings.splashify.url; - - window.location.replace(url); - } + Drupal.behaviors.splashifyBehavior.redirect = function (context, settings) { + const url = settings.splashify.url; + window.location.replace(url); + }; })(jQuery); diff --git a/js/splashify_window.js b/js/splashify_window.js index 1c97502b84fa9ca39929655148741eb7470754cc..cb8aa0711140ca02f6f689f26be366485b180b64 100644 --- a/js/splashify_window.js +++ b/js/splashify_window.js @@ -1,9 +1,7 @@ (function ($) { - Drupal.behaviors.splashifyBehavior.window = - function (context, settings) { - var url = settings.splashify.url; - - window.open(url, 'splash', settings.splashify.size); - } + Drupal.behaviors.splashifyBehavior.window = function (context, settings) { + const url = settings.splashify.url; + window.open(url, 'splash', settings.splashify.size); + }; })(jQuery);