Skip to content

Commit

Permalink
ci: 👷 lint code to MediaWiki standards
Browse files Browse the repository at this point in the history
Check commit and GitHub actions for more details
  • Loading branch information
github-actions committed Dec 31, 2022
1 parent 782d9fb commit 70f030c
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 124 deletions.
246 changes: 123 additions & 123 deletions resources/skins.citizen.scripts/skin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const checkboxHack = require('./checkboxHack.js'),
CHECKBOX_HACK_CONTAINER_SELECTOR = '.mw-checkbox-hack-container',
CHECKBOX_HACK_CHECKBOX_SELECTOR = '.mw-checkbox-hack-checkbox',
CHECKBOX_HACK_BUTTON_SELECTOR = '.mw-checkbox-hack-button',
CHECKBOX_HACK_TARGET_SELECTOR = '.mw-checkbox-hack-target'
const checkboxHack = require( './checkboxHack.js' ),
CHECKBOX_HACK_CONTAINER_SELECTOR = '.mw-checkbox-hack-container',
CHECKBOX_HACK_CHECKBOX_SELECTOR = '.mw-checkbox-hack-checkbox',
CHECKBOX_HACK_BUTTON_SELECTOR = '.mw-checkbox-hack-button',
CHECKBOX_HACK_TARGET_SELECTOR = '.mw-checkbox-hack-target';

/**
* Wait for first paint before calling this function.
Expand All @@ -11,8 +11,8 @@ const checkboxHack = require('./checkboxHack.js'),
* @param {Document} document
* @return {void}
*/
function enableCssAnimations(document) {
document.documentElement.classList.add('citizen-animations-ready')
function enableCssAnimations( document ) {
document.documentElement.classList.add( 'citizen-animations-ready' );
}

/**
Expand All @@ -24,20 +24,20 @@ function enableCssAnimations(document) {
* @return {void}
*/
function bind() {
// Search for all dropdown containers using the CHECKBOX_HACK_CONTAINER_SELECTOR.
const containers = document.querySelectorAll(CHECKBOX_HACK_CONTAINER_SELECTOR)
// Search for all dropdown containers using the CHECKBOX_HACK_CONTAINER_SELECTOR.
const containers = document.querySelectorAll( CHECKBOX_HACK_CONTAINER_SELECTOR );

containers.forEach((container) => {
const checkbox = container.querySelector(CHECKBOX_HACK_CHECKBOX_SELECTOR),
button = container.querySelector(CHECKBOX_HACK_BUTTON_SELECTOR),
target = container.querySelector(CHECKBOX_HACK_TARGET_SELECTOR)
containers.forEach( ( container ) => {
const checkbox = container.querySelector( CHECKBOX_HACK_CHECKBOX_SELECTOR ),
button = container.querySelector( CHECKBOX_HACK_BUTTON_SELECTOR ),
target = container.querySelector( CHECKBOX_HACK_TARGET_SELECTOR );

if (!(checkbox && button && target)) {
return
}
if ( !( checkbox && button && target ) ) {
return;
}

checkboxHack.bind(window, checkbox, button, target)
})
checkboxHack.bind( window, checkbox, button, target );
} );
}

/**
Expand All @@ -46,13 +46,13 @@ function bind() {
* @return {void}
*/
function uncheckCheckboxHacks() {
const checkboxes = document.querySelectorAll(
CHECKBOX_HACK_CHECKBOX_SELECTOR + ':checked'
)
const checkboxes = document.querySelectorAll(
CHECKBOX_HACK_CHECKBOX_SELECTOR + ':checked'
);

checkboxes.forEach((checkbox) => {
/** @type {HTMLInputElement} */ ;(checkbox).checked = false
})
checkboxes.forEach( ( checkbox ) => {
/** @type {HTMLInputElement} */ ( checkbox ).checked = false;
} );
}

/**
Expand All @@ -61,43 +61,43 @@ function uncheckCheckboxHacks() {
* @param {Document} document
* @return {void}
*/
function initStickyHeader(document) {
const scrollObserver = require('./scrollObserver.js')

// Detect scroll direction and add the right class
scrollObserver.initDirectionObserver(
() => {
document.body.classList.remove('citizen-scroll--up')
document.body.classList.add('citizen-scroll--down')
},
() => {
document.body.classList.remove('citizen-scroll--down')
document.body.classList.add('citizen-scroll--up')
},
10
)

const sentinel = document.getElementById(
'citizen-body-header-sticky-sentinel'
)

// In some pages we use display:none to disable the sticky header
// Do not start observer if it is set to display:none
if (
sentinel &&
getComputedStyle(sentinel).getPropertyValue('display') !== 'none'
) {
const observer = scrollObserver.initIntersectionObserver(
() => {
document.body.classList.add('citizen-body-header--sticky')
},
() => {
document.body.classList.remove('citizen-body-header--sticky')
}
)

observer.observe(sentinel)
}
function initStickyHeader( document ) {
const scrollObserver = require( './scrollObserver.js' );

// Detect scroll direction and add the right class
scrollObserver.initDirectionObserver(
() => {
document.body.classList.remove( 'citizen-scroll--up' );
document.body.classList.add( 'citizen-scroll--down' );
},
() => {
document.body.classList.remove( 'citizen-scroll--down' );
document.body.classList.add( 'citizen-scroll--up' );
},
10
);

const sentinel = document.getElementById(
'citizen-body-header-sticky-sentinel'
);

// In some pages we use display:none to disable the sticky header
// Do not start observer if it is set to display:none
if (
sentinel &&
getComputedStyle( sentinel ).getPropertyValue( 'display' ) !== 'none'
) {
const observer = scrollObserver.initIntersectionObserver(
() => {
document.body.classList.add( 'citizen-body-header--sticky' );
},
() => {
document.body.classList.remove( 'citizen-body-header--sticky' );
}
);

observer.observe( sentinel );
}
}

/**
Expand All @@ -106,83 +106,83 @@ function initStickyHeader(document) {
* @return {void}
*/
function registerServiceWorker() {
const scriptPath = mw.config.get('wgScriptPath')

// Only allow serviceWorker when the scriptPath is at root because of its scope
// I can't figure out how to add the Service-Worker-Allowed HTTP header
// to change the default scope
if (scriptPath === '') {
if ('serviceWorker' in navigator) {
const SW_MODULE_NAME = 'skins.citizen.serviceWorker',
version = mw.loader.moduleRegistry[SW_MODULE_NAME].version,
// HACK: Faking a RL link
swUrl =
const scriptPath = mw.config.get( 'wgScriptPath' );

// Only allow serviceWorker when the scriptPath is at root because of its scope
// I can't figure out how to add the Service-Worker-Allowed HTTP header
// to change the default scope
if ( scriptPath === '' ) {
if ( 'serviceWorker' in navigator ) {
const SW_MODULE_NAME = 'skins.citizen.serviceWorker',
version = mw.loader.moduleRegistry[ SW_MODULE_NAME ].version,
// HACK: Faking a RL link
swUrl =
scriptPath +
'/load.php?modules=' +
SW_MODULE_NAME +
'&only=scripts&raw=true&skin=citizen&version=' +
version
version;

navigator.serviceWorker.register(swUrl, { scope: '/' })
}
}
navigator.serviceWorker.register( swUrl, { scope: '/' } );
}
}
}

/**
* @param {Window} window
* @return {void}
*/
function main(window) {
const search = require('./search.js')

enableCssAnimations(window.document)
search.init(window)
initStickyHeader(window.document)

// Set up checkbox hacks
bind()

// Table of Contents
const tocContainer = document.getElementById('mw-panel-toc')
if (tocContainer) {
const toc = require('./tableOfContents.js')
toc.init()
}

// Collapsible sections
if (document.body.classList.contains('citizen-sections-enabled')) {
const sections = require('./sections.js')
sections.init()
}

mw.loader.load('skins.citizen.preferences')
mw.loader.load('https://story-cdn.teahouse.team/t-footer/assets/index.js')
mw.loader.load(
'https://story-cdn.teahouse.team/t-footer/assets/index.css',
'text/css'
)
registerServiceWorker()

window.addEventListener(
'beforeunload',
() => {
// T295085: Close all dropdown menus when page is unloaded to prevent them
// from being open when navigating back to a page.
uncheckCheckboxHacks()
// Set up loading indicator
document.documentElement.classList.add('citizen-loading')
},
false
)
function main( window ) {
const search = require( './search.js' );

enableCssAnimations( window.document );
search.init( window );
initStickyHeader( window.document );

// Set up checkbox hacks
bind();

// Table of Contents
const tocContainer = document.getElementById( 'mw-panel-toc' );
if ( tocContainer ) {
const toc = require( './tableOfContents.js' );
toc.init();
}

// Collapsible sections
if ( document.body.classList.contains( 'citizen-sections-enabled' ) ) {
const sections = require( './sections.js' );
sections.init();
}

mw.loader.load( 'skins.citizen.preferences' );
mw.loader.load( 'https://story-cdn.teahouse.team/t-footer/assets/index.js' );
mw.loader.load(
'https://story-cdn.teahouse.team/t-footer/assets/index.css',
'text/css'
);
registerServiceWorker();

window.addEventListener(
'beforeunload',
() => {
// T295085: Close all dropdown menus when page is unloaded to prevent them
// from being open when navigating back to a page.
uncheckCheckboxHacks();
// Set up loading indicator
document.documentElement.classList.add( 'citizen-loading' );
},
false
);
}

if (
document.readyState === 'interactive' ||
document.readyState === 'interactive' ||
document.readyState === 'complete'
) {
main(window)
main( window );
} else {
document.addEventListener('DOMContentLoaded', function () {
main(window)
})
document.addEventListener( 'DOMContentLoaded', function () {
main( window );
} );
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
.portable-infobox {
/* In case if tooltips go out of boundary */
overflow: visible;
border-radius: var( --border-radius--medium );
/* @noflip */
margin-left: 1.4rem;
border-radius: var( --border-radius--medium );
font-size: 0.875rem;
.boxshadow( 2 );

Expand Down

0 comments on commit 70f030c

Please sign in to comment.