MediaWiki:Common.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
Line 354:
});
 
/* Collapsible inlineInline footnotes ({{footnote}}) need NO JavaScript: the note is click-triggeredshown card.by
the browser's native title tooltip on desktop and a CSS attr(title) bubble
Clicking the "note" chip toggles .ed-fn-open; ALL positioning/visibility
ison intouch (see MediaWiki:Common.css (a fixed bottom.ed-centrefn cardrules), so the JS just flips. the*/
class — there is nothing to mis-place, so the card can never open to
"nothing". One card open at a time; outside-click and Escape dismiss;
Enter/Space + aria-expanded for keyboard and screen readers. The note text
stays in the DOM at all times, so the bot reads it from the parsed HTML. */
$( function () {
$( '.ed-fn-chip' ).attr( { role: 'button', tabindex: 0, 'aria-expanded': 'false' } );
 
function closeAll( except ) {
$( '.ed-fn.ed-fn-open' ).each( function () {
if ( this !== except ) {
$( this ).removeClass( 'ed-fn-open' )
.children( '.ed-fn-chip' ).attr( 'aria-expanded', 'false' );
}
} );
}
 
$( document ).on( 'click keydown', '.ed-fn-chip', function ( e ) {
if ( e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ' ) {
return;
}
e.preventDefault();
var $fn = $( this ).closest( '.ed-fn' ),
willOpen = !$fn.hasClass( 'ed-fn-open' );
closeAll( $fn[ 0 ] );
$fn.toggleClass( 'ed-fn-open', willOpen );
$( this ).attr( 'aria-expanded', willOpen ? 'true' : 'false' );
} );
 
// click outside any .ed-fn, or press Escape, to dismiss
$( document ).on( 'click', function ( e ) {
if ( !$( e.target ).closest( '.ed-fn' ).length ) {
closeAll( null );
}
} );
$( document ).on( 'keydown', function ( e ) {
if ( e.key === 'Escape' ) {
closeAll( null );
}
} );
} );