MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* Bottom collapse controls */ | /* Bottom collapse controls */ | ||
mw.loader.using('jquery.makeCollapsible').then(function () { | mw.loader.using('jquery.makeCollapsible').then(function () { | ||
var exampleTableQuery = window.matchMedia('(max-width: 899px)'); | |||
function updateExampleTableState($table) { | function updateExampleTableState($table) { | ||
$table | $table | ||
| Line 7: | Line 9: | ||
} | } | ||
$('.wizlords-example-table.mw-collapsible').each(function () { | function initialiseExampleTables() { | ||
$('.wizlords-example-table.mw-collapsible').each(function () { | |||
var $table = $(this); | |||
var $caption = $table.children('caption'); | |||
if (exampleTableQuery.matches) { | |||
$caption | |||
.attr('role', 'button') | |||
.attr('tabindex', '0'); | |||
updateExampleTableState($table); | |||
} else { | |||
$caption | |||
.removeAttr('role') | |||
.removeAttr('tabindex') | |||
.removeAttr('aria-expanded'); | |||
} | |||
}); | |||
} | |||
$(initialiseExampleTables); | |||
if (exampleTableQuery.addEventListener) { | |||
}); | exampleTableQuery.addEventListener('change', initialiseExampleTables); | ||
} else if (exampleTableQuery.addListener) { | |||
exampleTableQuery.addListener(initialiseExampleTables); | |||
} | |||
$(document).on('click', '.wizlords-example-table.mw-collapsible > caption', function (event) { | $(document).on('click', '.wizlords-example-table.mw-collapsible > caption', function (event) { | ||
if (!exampleTableQuery.matches) { | |||
return; | |||
} | |||
if ($(event.target).closest('.mw-collapsible-toggle').length) { | if ($(event.target).closest('.mw-collapsible-toggle').length) { | ||
return; | return; | ||
| Line 35: | Line 58: | ||
$(document).on('keydown', '.wizlords-example-table.mw-collapsible > caption', function (event) { | $(document).on('keydown', '.wizlords-example-table.mw-collapsible > caption', function (event) { | ||
if (!exampleTableQuery.matches) { | |||
return; | |||
} | |||
if (event.key === 'Enter' || event.key === ' ') { | if (event.key === 'Enter' || event.key === ' ') { | ||
event.preventDefault(); | event.preventDefault(); | ||