From 19a8a9d91eca3f79e7ed3cf89abf065c7517eba3 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 16 Feb 2020 00:20:20 +0000 Subject: [PATCH] Github CI lint - eslint/stylelint --- resources/scripts/header.js | 36 ++++++++++----------- resources/scripts/lazyload.js | 46 +++++++++++++-------------- resources/scripts/toc.js | 60 +++++++++++++++++------------------ 3 files changed, 71 insertions(+), 71 deletions(-) diff --git a/resources/scripts/header.js b/resources/scripts/header.js index 6b9b0763..c5554b4d 100644 --- a/resources/scripts/header.js +++ b/resources/scripts/header.js @@ -3,22 +3,22 @@ * Modified from https://codepen.io/sajjad/pen/vgEZNy */ -(function() { +( function () { // Hide header on scroll down var didScroll, lastScrollTop = 0, navbarHeight = 0, delta = 0, - header = document.getElementsByTagName('header')[0], - headerContainer = document.querySelector('.mw-header-container'); + header = document.getElementsByTagName( 'header' )[ 0 ], + headerContainer = document.querySelector( '.mw-header-container' ); - if (headerContainer !== null) { + if ( headerContainer !== null ) { navbarHeight = headerContainer.offsetHeight; } - window.addEventListener('scroll', function() { + window.addEventListener( 'scroll', function () { didScroll = true; - }); + } ); function hasScrolled() { var st = window.scrollY, @@ -26,34 +26,34 @@ html, documentHeight; - if (Math.abs(lastScrollTop - st) <= delta) { + if ( Math.abs( lastScrollTop - st ) <= delta ) { return; } - if (st > lastScrollTop && st > navbarHeight) { + if ( st > lastScrollTop && st > navbarHeight ) { // If scrolled down and past the navbar, add class .nav-up. // Scroll Down - header.classList.remove('nav-down'); - header.classList.add('nav-up'); + header.classList.remove( 'nav-down' ); + header.classList.add( 'nav-up' ); } else { // Scroll Up body = document.body; html = document.documentElement; - documentHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight); + documentHeight = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); - if (st + window.innerHeight < documentHeight) { - header.classList.remove('nav-up'); - header.classList.add('nav-down'); + if ( st + window.innerHeight < documentHeight ) { + header.classList.remove( 'nav-up' ); + header.classList.add( 'nav-down' ); } } lastScrollTop = st; } - setInterval(function() { - if (didScroll) { + setInterval( function () { + if ( didScroll ) { hasScrolled(); didScroll = false; } - }, 250); -})(); \ No newline at end of file + }, 250 ); +}() ); diff --git a/resources/scripts/lazyload.js b/resources/scripts/lazyload.js index 108d0a3a..c5099211 100644 --- a/resources/scripts/lazyload.js +++ b/resources/scripts/lazyload.js @@ -8,39 +8,39 @@ var observer; // Native API -if ('loading' in HTMLImageElement.prototype) { - document.querySelectorAll('img.lazy').forEach(function(img) { - img.setAttribute('src', img.getAttribute('data-src')); +if ( 'loading' in HTMLImageElement.prototype ) { + document.querySelectorAll( 'img.lazy' ).forEach( function ( img ) { + img.setAttribute( 'src', img.getAttribute( 'data-src' ) ); - if (img.hasAttribute('data-srcset')) { - img.setAttribute('srcset', img.getAttribute('data-srcset')); + if ( img.hasAttribute( 'data-srcset' ) ) { + img.setAttribute( 'srcset', img.getAttribute( 'data-srcset' ) ); } - img.classList.remove('lazy'); - }); + img.classList.remove( 'lazy' ); + } ); } else { // IntersectionObserver API - if (typeof IntersectionObserver !== 'undefined' && 'forEach' in NodeList.prototype) { - observer = new IntersectionObserver(function(changes) { - if ('connection' in navigator && navigator.connection.saveData === true) { + if ( typeof IntersectionObserver !== 'undefined' && 'forEach' in NodeList.prototype ) { + observer = new IntersectionObserver( function ( changes ) { + if ( 'connection' in navigator && navigator.connection.saveData === true ) { return; } - changes.forEach(function(change) { - if (change.isIntersecting) { - change.target.setAttribute('src', change.target.getAttribute('data-src')); + changes.forEach( function ( change ) { + if ( change.isIntersecting ) { + change.target.setAttribute( 'src', change.target.getAttribute( 'data-src' ) ); - if (change.target.hasAttribute('data-srcset')) { - change.target.setAttribute('srcset', change.target.getAttribute('data-srcset')); + if ( change.target.hasAttribute( 'data-srcset' ) ) { + change.target.setAttribute( 'srcset', change.target.getAttribute( 'data-srcset' ) ); } - change.target.classList.remove('lazy'); - observer.unobserve(change.target); + change.target.classList.remove( 'lazy' ); + observer.unobserve( change.target ); } - }); - }); - document.querySelectorAll('img.lazy').forEach(function(img) { - observer.observe(img); - }); + } ); + } ); + document.querySelectorAll( 'img.lazy' ).forEach( function ( img ) { + observer.observe( img ); + } ); } -} \ No newline at end of file +} diff --git a/resources/scripts/toc.js b/resources/scripts/toc.js index 7bba9c2e..1e6a54b6 100644 --- a/resources/scripts/toc.js +++ b/resources/scripts/toc.js @@ -7,65 +7,65 @@ function SmoothScroll() { var navLinks, eventListener, link; - if (!("scrollBehavior" in document.documentElement.style)) { - navLinks = document.querySelectorAll("#toc a"); - eventListener = function eventListener(e) { + if ( !( 'scrollBehavior' in document.documentElement.style ) ) { + navLinks = document.querySelectorAll( '#toc a' ); + eventListener = function eventListener( e ) { e.preventDefault(); - e.target.scrollIntoView({ - behavior: "smooth" - }); + e.target.scrollIntoView( { + behavior: 'smooth' + } ); }; - for (link in navLinks) { - if (Object.prototype.hasOwnProperty.call(navLinks, link)) { - navLinks[link].addEventListener("click", eventListener); + for ( link in navLinks ) { + if ( Object.prototype.hasOwnProperty.call( navLinks, link ) ) { + navLinks[ link ].addEventListener( 'click', eventListener ); } } } } function ScrollSpy() { - var sections = document.querySelectorAll(".mw-headline"); - window.addEventListener("scroll", function() { + var sections = document.querySelectorAll( '.mw-headline' ); + window.addEventListener( 'scroll', function () { var scrollPos = document.documentElement.scrollTop || document.body.scrollTop, section, id, node, active; - for (section in sections) { + for ( section in sections ) { if ( - Object.prototype.hasOwnProperty.call(sections, section) && - sections[section].offsetTop <= scrollPos + Object.prototype.hasOwnProperty.call( sections, section ) && + sections[ section ].offsetTop <= scrollPos ) { - id = mw.util.escapeIdForAttribute(sections[section].id); - node = document.querySelector("a[href='#" + id + "']").parentNode; - active = document.querySelector(".active"); - if (active !== null) { - active.classList.remove("active"); + id = mw.util.escapeIdForAttribute( sections[ section ].id ); + node = document.querySelector( "a[href='#" + id + "']" ).parentNode; + active = document.querySelector( '.active' ); + if ( active !== null ) { + active.classList.remove( 'active' ); } - if (node !== null) { - node.classList.add("active"); + if ( node !== null ) { + node.classList.add( 'active' ); } } } - }); + } ); } function CheckToC() { - if (document.getElementById("toc")) { + if ( document.getElementById( 'toc' ) ) { SmoothScroll(); ScrollSpy(); } } -if (document.readyState !== "loading") { +if ( document.readyState !== 'loading' ) { CheckToC(); -} else if (document.addEventListener) { +} else if ( document.addEventListener ) { // All modern browsers to register DOMContentLoaded - document.addEventListener("DOMContentLoaded", CheckToC); + document.addEventListener( 'DOMContentLoaded', CheckToC ); } else { // Old IE browsers - document.attachEvent("onreadystatechange", function() { - if (document.readyState === "complete") { + document.attachEvent( 'onreadystatechange', function () { + if ( document.readyState === 'complete' ) { CheckToC(); } - }); -} \ No newline at end of file + } ); +}