MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
No edit summary |
No edit summary |
||
| Line 215: | Line 215: | ||
function getSpellIcon(iconType) { | function getSpellIcon(iconType) { | ||
var fileName = iconType === 'divine' ? 'DivineIcon.png' : 'ArcaneIcon.png'; | var fileName = iconType === 'divine' ? 'DivineIcon.png' : 'ArcaneIcon.png'; | ||
var scriptPath = mw.config.get('wgScriptPath') || ''; | |||
return $('<img>') | |||
.attr('src', scriptPath + '/index.php/Special:FilePath/' + encodeURIComponent(fileName)) | |||
.attr('alt', '') | |||
.attr('loading', 'lazy') | |||
.attr('decoding', 'async'); | |||
} | |||
function getSpellbookIcon(iconType) { | |||
var fileName = iconType === 'divine' ? 'DivineSpellbookIcon.png' : 'ArcaneSpellbookIcon.png'; | |||
var scriptPath = mw.config.get('wgScriptPath') || ''; | var scriptPath = mw.config.get('wgScriptPath') || ''; | ||
| Line 247: | Line 258: | ||
var $source = $(sourceSelector); | var $source = $(sourceSelector); | ||
var $content = $source.children('.mw-collapsible-content').first(); | var $content = $source.children('.mw-collapsible-content').first(); | ||
var $book = $('<div>').addClass('wizlords-mobile-spellbook ' + variantClass); | var $book = $('<div>').addClass('wizlords-mobile-spellbook is-open ' + variantClass); | ||
var $header = $('<div>') | |||
.addClass('wizlords-mobile-spellbook-header') | |||
.attr('role', 'button') | |||
.attr('tabindex', '0') | |||
.attr('aria-expanded', 'true'); | |||
var $body = $('<div>').addClass('wizlords-mobile-spellbook-body'); | |||
var $currentCategory = null; | var $currentCategory = null; | ||
$ | $header | ||
.append($('<span>').addClass('wizlords-mobile-spellbook-title').text(title)) | |||
.append($('<span>').addClass('wizlords-mobile-spellbook-icon').append(getSpellbookIcon(iconType))); | |||
$book.append($header).append($body); | |||
$content.children().each(function () { | $content.children().each(function () { | ||
| Line 258: | Line 279: | ||
$currentCategory = $('<div>').addClass('wizlords-mobile-spell-category'); | $currentCategory = $('<div>').addClass('wizlords-mobile-spell-category'); | ||
$currentCategory.append($('<div>').addClass('wizlords-mobile-spell-category-heading').text($.trim($node.text()))); | $currentCategory.append($('<div>').addClass('wizlords-mobile-spell-category-heading').text($.trim($node.text()))); | ||
$ | $body.append($currentCategory); | ||
return; | return; | ||
} | } | ||
| Line 270: | Line 291: | ||
if (!$currentCategory) { | if (!$currentCategory) { | ||
$currentCategory = $('<div>').addClass('wizlords-mobile-spell-category'); | $currentCategory = $('<div>').addClass('wizlords-mobile-spell-category'); | ||
$ | $body.append($currentCategory); | ||
} | } | ||
| Line 301: | Line 322: | ||
$('.wizlords-spellbooks-mobile').attr('aria-hidden', spellbookQuery.matches ? 'false' : 'true'); | $('.wizlords-spellbooks-mobile').attr('aria-hidden', spellbookQuery.matches ? 'false' : 'true'); | ||
$('.wizlords-mobile-spellbook-header').each(function () { | |||
var $header = $(this); | |||
var isOpen = $header.closest('.wizlords-mobile-spellbook').hasClass('is-open'); | |||
if (spellbookQuery.matches) { | |||
$header.attr('aria-expanded', isOpen ? 'true' : 'false'); | |||
} else { | |||
$header.removeAttr('aria-expanded'); | |||
} | |||
}); | |||
$('.wizlords-mobile-spell-card').each(function () { | $('.wizlords-mobile-spell-card').each(function () { | ||
| Line 338: | Line 370: | ||
.toggleClass('is-open', !isOpen) | .toggleClass('is-open', !isOpen) | ||
.attr('aria-expanded', isOpen ? 'false' : 'true'); | .attr('aria-expanded', isOpen ? 'false' : 'true'); | ||
} | |||
function toggleMobileSpellbook(header) { | |||
if (!spellbookQuery.matches) { | |||
return; | |||
} | |||
var $header = $(header); | |||
var $book = $header.closest('.wizlords-mobile-spellbook'); | |||
var isOpen = $book.hasClass('is-open'); | |||
$book.toggleClass('is-open', !isOpen); | |||
$header.attr('aria-expanded', isOpen ? 'false' : 'true'); | |||
} | } | ||
| Line 354: | Line 399: | ||
toggleMobileSpellCard(this); | toggleMobileSpellCard(this); | ||
}); | |||
$(document).on('click', '.wizlords-mobile-spellbook-header', function () { | |||
toggleMobileSpellbook(this); | |||
}); | }); | ||
| Line 360: | Line 409: | ||
event.preventDefault(); | event.preventDefault(); | ||
toggleMobileSpellCard(this); | toggleMobileSpellCard(this); | ||
} | |||
}); | |||
$(document).on('keydown', '.wizlords-mobile-spellbook-header', function (event) { | |||
if (event.key === 'Enter' || event.key === ' ') { | |||
event.preventDefault(); | |||
toggleMobileSpellbook(this); | |||
} | } | ||
}); | }); | ||
}() ); | }() ); | ||