convert into ES6

Signed-off-by: WaitSpring <me@waitspring.com>
这个提交包含在:
WaitSpring 2023-11-19 11:04:16 +08:00
父节点 13258a1576
当前提交 f363b8f6b4
找不到此签名对应的密钥
共有 4 个文件被更改,包括 52 次插入63 次删除

查看文件

@ -3,12 +3,10 @@
* © 2015-2021 Isarra
* © 2021-2023 WaitSpring
*/
'use strict';
$( function () {
$( () => {
// sidebar-inner only applies to desktop-small, but the toggles are hidden at
// other resolutions regardless and the css overrides any visible effects.
var $dropdowns = $( '#personal, #p-variants-desktop, .sidebar-inner' );
const $dropdowns = $( '#personal, #p-variants-desktop, .sidebar-inner' );
/**
* Desktop menu click-toggling
@ -16,13 +14,12 @@ $( function () {
* We're not even checking if it's desktop because the classes in play have no effect
* on mobile regardless... this may break things at some point, though.
*/
/**
* Close all dropdowns
*/
function closeOpen() {
const closeOpen = () => {
$dropdowns.removeClass( 'dropdown-active' );
}
};
/**
* Click behaviour
@ -42,8 +39,8 @@ $( function () {
$( this ).addClass( 'dropdown-active' );
}
} );
$( document ).on( 'click', function ( e ) {
if ( $( e.target ).closest( $dropdowns ).length > 0 ) {
$( document ).on( 'click', ( { target } ) => {
if ( $( target ).closest( $dropdowns ).length > 0 ) {
// Clicked inside an open menu; don't close anything
} else {
closeOpen();

查看文件

@ -17,16 +17,14 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
'use strict';
/* Popout menus (header) */
/* eslint-disable no-jquery/no-fade */
$( function () {
var toggleTime = 150;
$( () => {
const toggleTime = 150;
// Open the various menus
$( '#user-tools h2' ).on( 'click', function () {
$( '#user-tools h2' ).on( 'click', () => {
if ( $( window ).width() < 851 ) {
$( '#personal-inner' ).css(
'left',
@ -40,7 +38,7 @@ $( function () {
$( '#personal .mobile-close-button' ).fadeToggle( toggleTime );
}
} );
$( '#sidebar-tools h2' ).on( 'click', function () {
$( '#sidebar-tools h2' ).on( 'click', () => {
if ( $( window ).width() < 851 ) {
$( '#site-navigation .sidebar-inner' ).css(
'left',
@ -54,7 +52,7 @@ $( function () {
$( '#site-navigation .mobile-close-button' ).fadeToggle( toggleTime );
}
} );
$( '#search-button h2' ).on( 'click', function () {
$( '#search-button h2' ).on( 'click', () => {
if ( $( window ).width() < 851 ) {
$( '#p-search .mobile-close-button' )
.css( 'top', $( '#search-button h2' ).offset().top - 4 )
@ -64,7 +62,7 @@ $( function () {
$( '#p-search .mobile-close-button' ).fadeToggle( toggleTime );
}
} );
$( '#ca-more' ).on( 'click', function () {
$( '#ca-more' ).on( 'click', () => {
$( '#page-more .sidebar-inner' ).css( 'top', $( '#ca-more' ).offset().top + 25 );
$( '#page-more .mobile-close-button' )
.css( 'top', $( '#ca-more' ).offset().top - 4 )
@ -75,7 +73,7 @@ $( function () {
$( '#page-more .mobile-close-button' ).fadeToggle( toggleTime );
}
} );
$( '#ca-tools' ).on( 'click', function () {
$( '#ca-tools' ).on( 'click', () => {
$( '#page-tools .sidebar-inner' ).css(
'top',
$( '#ca-tools' ).offset().top + 25
@ -89,7 +87,7 @@ $( function () {
$( '#page-tools .mobile-close-button' ).fadeToggle( toggleTime );
}
} );
$( '#ca-languages' ).on( 'click', function () {
$( '#ca-languages' ).on( 'click', () => {
$( '#other-languages .sidebar-inner' ).css(
'top',
$( '#ca-languages' ).offset().top + 25
@ -105,10 +103,10 @@ $( function () {
} );
// Close menus on click outside
$( document ).on( 'click touchstart', function ( e ) {
$( document ).on( 'click touchstart', ( { target } ) => {
if (
$( e.target ).closest( '#menus-cover' ).length > 0 ||
$( e.target ).closest( '.mobile-close-button' ).length > 0
$( target ).closest( '#menus-cover' ).length > 0 ||
$( target ).closest( '.mobile-close-button' ).length > 0
) {
$( '#personal-inner' ).fadeOut( toggleTime );
$( '.sidebar-inner' ).fadeOut( toggleTime );

查看文件

@ -17,9 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
'use strict';
mw.hook( 'wikipage.content' ).add( function ( $content ) {
mw.hook( 'wikipage.content' ).add( ( $content ) => {
// Skip on Special:Recentchanges
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Recentchanges' ) {
return;
@ -44,11 +42,11 @@ mw.hook( 'wikipage.content' ).add( function ( $content ) {
*
* @param {jQuery} $table
*/
function setScrollClass( $table ) {
var $tableWrapper = $table.parent(),
$wrapper = $tableWrapper.parent(),
// wtf browser rtl implementations
scroll = Math.abs( $tableWrapper.scrollLeft() );
const setScrollClass = ( $table ) => {
const $tableWrapper = $table.parent();
const $wrapper = $tableWrapper.parent();
const scroll = Math.abs( $tableWrapper.scrollLeft() ); // wtf browser rtl implementations
// 1 instead of 0 because of weird rtl rounding errors or something
if ( scroll > 1 ) {
@ -61,27 +59,27 @@ mw.hook( 'wikipage.content' ).add( function ( $content ) {
} else {
$wrapper.removeClass( 'scroll-right' );
}
}
};
$content.find( '.content-table' ).on( 'scroll', function () {
setScrollClass( $( this ).children( 'table' ).first() );
if ( $content.attr( 'dir' ) === 'rtl' ) {
$( this )
.find( 'caption' )
.css( 'margin-right', Math.abs( $( this ).scrollLeft() ) + 'px' );
.css( 'margin-right', `${Math.abs( $( this ).scrollLeft() )}px` );
} else {
$( this )
.find( 'caption' )
.css( 'margin-left', $( this ).scrollLeft() + 'px' );
.css( 'margin-left', `${$( this ).scrollLeft()}px` );
}
} );
/**
* Mark overflowed tables for scrolling
*/
function unOverflowTables() {
const unOverflowTables = () => {
$content.find( '.content-table > table' ).each( function () {
var $table = $( this ),
$wrapper = $table.parent().parent();
const $table = $( this );
const $wrapper = $table.parent().parent();
if ( $table.outerWidth() > $wrapper.outerWidth() ) {
$wrapper.addClass( 'overflowed' );
setScrollClass( $table );
@ -94,10 +92,10 @@ mw.hook( 'wikipage.content' ).add( function ( $content ) {
// Set up sticky captions
$content.find( '.content-table > table > caption' ).each( function () {
var $container,
tableHeight,
$table = $( this ).parent(),
$wrapper = $table.parent().parent();
let $container;
let tableHeight;
const $table = $( this ).parent();
const $wrapper = $table.parent().parent();
if ( $table.outerWidth() > $wrapper.outerWidth() ) {
$container = $( this ).parents( '.content-table-wrapper' );
$( this ).width( $content.width() );
@ -106,7 +104,7 @@ mw.hook( 'wikipage.content' ).add( function ( $content ) {
$container.find( '.content-table-right' ).height( tableHeight );
}
} );
}
};
unOverflowTables();
$( window ).on( 'resize', unOverflowTables );
@ -114,15 +112,14 @@ mw.hook( 'wikipage.content' ).add( function ( $content ) {
* Sticky scrollbars maybe?!
*/
$content.find( '.content-table' ).each( function () {
var $table, $tableWrapper, $spoof, $scrollbar;
$tableWrapper = $( this );
$table = $tableWrapper.children( 'table' ).first();
const $tableWrapper = $( this );
const $table = $tableWrapper.children( 'table' ).first();
// Assemble our silly crap and add to page
$scrollbar = $( '<div>' )
const $scrollbar = $( '<div>' )
.addClass( 'content-table-scrollbar inactive' )
.width( $content.width() );
$spoof = $( '<div>' )
const $spoof = $( '<div>' )
.addClass( 'content-table-spoof' )
.width( $table.outerWidth() );
$tableWrapper.parent().prepend( $scrollbar.prepend( $spoof ) );
@ -133,11 +130,11 @@ mw.hook( 'wikipage.content' ).add( function ( $content ) {
*/
$content.find( '.content-table' ).on( 'scroll', function () {
// Only do this here if we're not already mirroring the spoof
var $mirror = $( this ).siblings( '.inactive' ).first();
const $mirror = $( this ).siblings( '.inactive' ).first();
$mirror.scrollLeft( $( this ).scrollLeft() );
} );
$content.find( '.content-table-scrollbar' ).on( 'scroll', function () {
var $mirror = $( this ).siblings( '.content-table' ).first();
const $mirror = $( this ).siblings( '.content-table' ).first();
// Only do this here if we're not already mirroring the table
// eslint-disable-next-line no-jquery/no-class-state
@ -149,13 +146,10 @@ mw.hook( 'wikipage.content' ).add( function ( $content ) {
/**
* Set active when actually over the table it applies to...
*/
function determineActiveSpoofScrollbars() {
const determineActiveSpoofScrollbars = () => {
$content.find( '.overflowed .content-table' ).each( function () {
var $scrollbar = $( this ).siblings( '.content-table-scrollbar' ).first(),
tableTop,
tableBottom,
viewBottom,
captionHeight;
const $scrollbar = $( this ).siblings( '.content-table-scrollbar' ).first();
let captionHeight;
// Skip caption
captionHeight = $( this ).find( 'caption' ).outerHeight();
@ -165,25 +159,25 @@ mw.hook( 'wikipage.content' ).add( function ( $content ) {
// Pad slightly for reasons
captionHeight += 8;
}
tableTop = $( this ).offset().top;
tableBottom = tableTop + $( this ).outerHeight();
viewBottom = window.scrollY + document.documentElement.clientHeight;
const tableTop = $( this ).offset().top;
const tableBottom = tableTop + $( this ).outerHeight();
const viewBottom = window.scrollY + document.documentElement.clientHeight;
if ( tableTop + captionHeight < viewBottom && tableBottom > viewBottom ) {
$scrollbar.removeClass( 'inactive' );
} else {
$scrollbar.addClass( 'inactive' );
}
} );
}
};
determineActiveSpoofScrollbars();
$( window ).on( 'scroll resize', determineActiveSpoofScrollbars );
/**
* Make sure tablespoofs remain correctly-sized?
*/
$( window ).on( 'resize', function () {
$( window ).on( 'resize', () => {
$content.find( '.content-table-scrollbar' ).each( function () {
var width = $( this ).siblings().first().find( 'table' ).first().width();
const width = $( this ).siblings().first().find( 'table' ).first().width();
$( this ).find( '.content-table-spoof' ).first().width( width );
$( this ).width( $content.width() );
} );

查看文件

@ -18,10 +18,10 @@
*/
'use strict';
$( function () {
$( () => {
if ( $( '#toc>ul' ).length !== 0 ) {
/* TOC (Left) */
var $div = $( '<div>' ).attr( 'id', 'site-toc' ).addClass( 'sidebar-chunk' ),
const $div = $( '<div>' ).attr( 'id', 'site-toc' ).addClass( 'sidebar-chunk' ),
$title = $( '#mw-toc-heading' ).html(),
$titleH2 = $( '<h2>' ).append( $( '<span>' ).text( $title ) ),
$titleH3 = $( '<h3>' ).attr( 'id', 'p-toc-label' ).text( $title ),
@ -44,7 +44,7 @@ $( function () {
.appendTo( $( '#mw-site-navigation' ) );
/* TOC (Right) */
var $divNavi = $( '<div>' ).attr( 'id', 'mw-toc-navigation' ),
const $divNavi = $( '<div>' ).attr( 'id', 'mw-toc-navigation' ),
$divRight = $( '<div>' )
.attr( 'id', 'site-toc-right' )
.addClass( 'sidebar-chunk' ),