MediaWiki:Gadget-ScrollUpButton.js:修订间差异

删除的内容 添加的内容
创建页面,内容为“* * Copyright (c) 2021-present, 安忆. * * @author 安忆 [[zh:U:安忆]] * @file scrollUpButton.js * @license GPL v3:​ $(function scrollUpButton() { var $window = $(window); var scrollButtonIcon = '//zybkcn.com/w/images/5/59/Font_Awesome_5_regular_arrow-circle-up_blue.svg'; if (!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1')) { scrollButtonIcon = '//zybkcn.com/w/images/5/59/Font_Awesome_5_regular_arrow…”
 
重构:节流优化、移除 dead code、修复动画堆积
第8行:
$(function scrollUpButton() {
var $window = $(window);
var scrollButtonIconicon = '//zybkcnmw.comconfig.get('wgServer') + '/w/images/5/59/Font_Awesome_5_regular_arrow-circle-up_blue.svg';
var visible = false;
if (!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1')) {
 
scrollButtonIcon = '//zybkcn.com/w/images/5/59/Font_Awesome_5_regular_arrow-circle-up_blue.svg/32px-Font_Awesome_5_regular_arrow-circle-up_blue.svg.png';
function scrollTo(h) {
$('html, body').stop(true, true).animate({ scrollTop: h }, 500);
}
 
var changeOpacity = function changeOpacity(event) {
function makeBtn(id, onClick, extraCss) {
event.currentTarget.style.opacity = event.type === 'mouseenter' ? '1' : '0.7';
return $('<img>')
};
.addClass('noprint')
var scrollTop = function scrollTop(height) {
.attr({ id: id, src: icon, draggable: 'false' })
$('html, body').animate({
scrollTop: height.css({
display: 'none',
}, 660);
position: 'fixed',
};
right: '18px',
var $scrollButton = $('<img>').addClass('noprint').attr({
draggable cursor: 'falsepointer',
opacity: '0.7',
src: scrollButtonIcon
width: '40px',
}).css({
display zIndex: 'none'9999,
position '-moz-user-select': 'fixednone',
right '-webkit-user-select': '18pxnone',
cursor 'user-select': 'pointernone',
opacity transition: 'opacity 0.72s',
...extraCss
'-moz-user-select': 'none',
})
'-webkit-user-select': 'none',
.on('mouseenter', function () { this.style.opacity = '1'; })
'user-select': 'none'
.on('mouseleave', function () { this.style.opacity = '0.7'; })
});
.on('click', onClick)
var $scrollDownButton = $scrollButton.clone().attr('id', 'scrollDownButton-zhwiki').css('transform', 'rotate(180deg)').on('click', function () {
.appendTo(document.body);
scrollTop(($(document).height() || 0) - ($window.height() || 0));
});
 
var $scrollUpButton = $scrollButton.clone().attr('id', 'scrollUpButton-zhwiki').on('click', function () {
var $up = makeBtn('scrollUpBtn', function () { scrollTo(0); }, { bottom: '85px' });
scrollTop(0);
var $down = makeBtn('scrollDownBtn', function () {
});
scrollTo(($(document).height() || 0) - ($window.height() || 0));
var $elements = [$scrollDownButton, $scrollUpButton];
}, { bottom: '45px', transform: 'rotate(180deg)' });
$elements.forEach(function ($element) {
 
$element.on('mouseenter mouseleave', changeOpacity).appendTo(document.body);
var $elements = $up.add($down);
});
 
var fadeIn = function fadeIn() {
$elements.forEach(function setLeft($elementpx) {
$elements.css('left', px ? px + 'px' : 'unset');
$element.fadeIn('slow');
});
 
};
var fadeOut = function fadeOutsetRight(px) {
$elements.forEachcss(function'right', ($element)px {? px + 'px' : 'unset');
}
$element.fadeOut('slow');
 
});
var isVector2022 = mw.config.get('skin') === 'vector-2022';
};
var leftmql = function leftwindow.matchMedia(px)'(min-width: {1400px)');
 
$elements.forEach(function ($element) {
function onWidthChange(e) {
$element.css('left', px ? px + 'px' : 'unset');
}if (isVector2022); {
setRight(e.matches ? 8 : 18);
};
}
var right = function right(px) {
}
$elements.forEach(function ($element) {
 
$element.css('right', px ? px + 'px' : 'unset');
if (isVector2022) {
});
};
var mediaQueryList = window.matchMedia('(min-width: 1400px)');
var isVector2022Match = false;
if (mw.config.get('skin') === 'vector-2022') {
var mediaQueryHandler = function mediaQueryHandler(event) {
if (event.matches) {
isVector2022Match = true;
right(8);
} else {
isVector2022Match = false;
right(18);
}
};
// Check mediaQueryList as Safari doesn't have support for mediaQueryList.addEventListener
try {
mediaQueryListmql.addEventListener('change', mediaQueryHandleronWidthChange);
} catch (e_) {
mediaQueryListmql.addListener(mediaQueryHandleronWidthChange);
}
if (mediaQueryList.matches) {
isVector2022Match = true;
right(8);
}
onWidthChange(mql);
}
 
var scrollButtonTimer;
$window.on('scroll selectionchange', function onScroll() {
var dingHeighty = $('#bluedeck_ding>div')window.heightscrollTop() || 0;
 
var vector2022Height = isVector2022Match ? 24 : 0;
if (y > 200 && !visible) {
$scrollDownButton.css('bottom', dingHeight + vector2022Height + 24 + 'px');
visible = true;
$scrollUpButton.css('bottom', dingHeight + vector2022Height + 65 + 'px');
$elements.fadeIn(300);
if (mw.config.get('wgGEHelpPanelEnabled') && $('#mw-ge-help-panel-cta-button').length || $('#cat_a_lot').length || $('#proveit').length || $('.wordcount').length) {
} else if (y <= 200 && visible) {
left(10);
} else {visible = false;
left$elements.fadeOut(300);
}
 
var windowScrollTop = $window.scrollTop() || 0;
if (windowScrollTop > 60) {
(mw.config.get('wgGEHelpPanelEnabled') && $('#mw-ge-help-panel-cta-button').length) ||
fadeIn();
$('#cat_a_lot').length ||
$('#proveit').length ||
$('.wordcount').length
) {
setLeft(10);
} else {
fadeOutsetLeft();
}
}
 
var ticking = false;
$window.on('scroll', function () {
if (!ticking) {
requestAnimationFrame(function () {
onScroll();
ticking = false;
});
ticking = true;
}
clearTimeout(scrollButtonTimer);
scrollButtonTimer = setTimeout(fadeOut, 2000);
});
$elements.forEach(function ($element) {
$element.on('mouseenter', function () {
clearTimeout(scrollButtonTimer);
});
});
 
onScroll();
});