MediaWiki:ModernBackToTopButton/code.js

(function(window, $, mw) {   'use strict';    var buttonStart = typeof window.BackToTopStart === 'number' ? window.BackToTopStart: 800,    scrollSpeed = typeof window.BackToTopSpeed === 'number' ? window.BackToTopSpeed: 600,    fadeSwitch = typeof window.BackToTopFade === 'number' ? window.BackToTopFade: 600;    if (window.BackToTopLoaded) {         return;    }

window.BackToTopLoaded = true; init; function init { addBackToTop; CSS; }   function hideFade { var Button = $('#BackToTopBtn'); Button.hide;

$(window).scroll(function {           if ($(this).scrollTop > buttonStart) {                switch (fadeSwitch) {                    case 0:                        Button.show;                        break;                    default:                        Button.fadeIn;                        break;                }            } else {                switch (fadeSwitch) {                    case 0:                        Button.hide;                        break;                    default:                        Button.fadeOut;                        break;                }            }        }); }

$('#BackToTopBtn').click(function {       $('body, html').animate({ scrollTop: 0 }, scrollSpeed);       return false;    }); function CSS { var BackgroundColor = $('.wds-community-header').css('background-color'); $('#BackToTopBtn div').css('background', BackgroundColor); }   function addBackToTop { $('body').append($(' ', { id: 'BackToTopBtn', append: [ $(' ', {                   append: [                        $('  ')                    ]                }) ]       }));        hideFade; } } (this, jQuery, mediaWiki));