MediaWiki:BackToTopButton/code.js

//A script that adds a "Back To Top" button in the footer of the Oasis theme. //I don't like scrolling back to top on long pages neither do you :) //Created by Noemon from Dead Space Wiki

(function(window, $, mw) {   'use strict';

var translations = { en: 'Back To Top', es: 'Volver Arriba', ja: 'ページ先頭へ戻る', nl: 'Terug naar boven', ru: 'Наверх', 'zh-hans': '回到页首', 'zh-hant': '回到頁首' },       buttonStart = typeof window.BackToTopStart === 'number' ? window.BackToTopStart : 800,       scrollSpeed = typeof window.BackToTopSpeed === 'number' ? window.BackToTopSpeed : 600,       fadeSwitch = typeof window.BackToTopFade === 'number' ? window.BackToTopFade : 600,

theText = (typeof window.BacktoTopText === 'string' && window.BacktoTopText) || translations[mw.config.get('wgContentLanguage')] || translations.en;

if (window.BackToTopLoaded) { return }

window.BackToTopLoaded = true;

$(addBackToTop);

function hideFade { $("#backtotop").hide;

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

$('#backtotop').click(function {       $('body,html').animate({ scrollTop: 0 }, scrollSpeed);       return false;    });

function addBackToTop { if (skin == 'oasis') { $button = $('') .attr('id', 'backtotop') .css({					'position': 'absolute',					'right': '20px',					'top': '1px'				}) .append(                   $(' ')                        .attr({ type: 'button', value: 'Back To Top' })                       .css('height','20px')                        .text(theText)				) .appendTo('#WikiaBarWrapper .toolbar > .tools'); hideFade; }   } }(this, jQuery, mediaWiki));