MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
No edit summary |
No edit summary |
||
| Line 257: | Line 257: | ||
function buildMobileServantRulesCard($sourceRules) { | function buildMobileServantRulesCard($sourceRules) { | ||
var title = $.trim($sourceRules.children('.wizlords-servant-rules-title').first().text()); | var title = $.trim($sourceRules.children('.wizlords-servant-rules-title').first().text()); | ||
var $card = $('<div>').addClass('wizlords-mobile-servant-rules-card'); | var $card = $('<div>') | ||
.addClass('wizlords-mobile-servant-rules-card') | |||
.attr('role', 'button') | |||
.attr('tabindex', '0') | |||
.attr('aria-expanded', 'false'); | |||
var $title = $('<div>').addClass('wizlords-mobile-servant-rules-title').text(title); | var $title = $('<div>').addClass('wizlords-mobile-servant-rules-title').text(title); | ||
var $rules = $('<div>').addClass('wizlords-mobile-servant-rules-content'); | var $rules = $('<div>').addClass('wizlords-mobile-servant-rules-content'); | ||
| Line 395: | Line 399: | ||
$card | $card | ||
.removeAttr('data-wizlords-mobile-spell-card') | .removeAttr('data-wizlords-mobile-spell-card') | ||
.removeAttr('role') | |||
.removeAttr('tabindex') | |||
.removeAttr('aria-expanded') | |||
.removeClass('is-open'); | |||
} | |||
}); | |||
$('.wizlords-mobile-servant-rules-card').each(function () { | |||
var $card = $(this); | |||
if (spellbookQuery.matches) { | |||
$card | |||
.attr('role', 'button') | |||
.attr('tabindex', '0'); | |||
if (!$card.hasClass('is-open')) { | |||
$card.attr('aria-expanded', 'false'); | |||
} | |||
} else { | |||
$card | |||
.removeAttr('role') | .removeAttr('role') | ||
.removeAttr('tabindex') | .removeAttr('tabindex') | ||
| Line 428: | Line 452: | ||
$book | $book | ||
.find('.wizlords-mobile-spellbook-header, .wizlords-mobile-spellbook-collapse') | .find('.wizlords-mobile-spellbook-header, .wizlords-mobile-spellbook-collapse') | ||
.attr('aria-expanded', isOpen ? 'false' : 'true'); | |||
} | |||
function toggleMobileServantRulesCard(card) { | |||
if (!spellbookQuery.matches) { | |||
return; | |||
} | |||
var $card = $(card); | |||
var isOpen = $card.hasClass('is-open'); | |||
$card | |||
.toggleClass('is-open', !isOpen) | |||
.attr('aria-expanded', isOpen ? 'false' : 'true'); | .attr('aria-expanded', isOpen ? 'false' : 'true'); | ||
} | } | ||
| Line 445: | Line 482: | ||
toggleMobileSpellCard(this); | toggleMobileSpellCard(this); | ||
}); | |||
$(document).on('click', '.wizlords-mobile-servant-rules-card', function (event) { | |||
if ($(event.target).closest('a').length) { | |||
return; | |||
} | |||
toggleMobileServantRulesCard(this); | |||
}); | }); | ||
| Line 459: | Line 504: | ||
event.preventDefault(); | event.preventDefault(); | ||
toggleMobileSpellCard(this); | toggleMobileSpellCard(this); | ||
} | |||
}); | |||
$(document).on('keydown', '.wizlords-mobile-servant-rules-card', function (event) { | |||
if (event.key === 'Enter' || event.key === ' ') { | |||
event.preventDefault(); | |||
toggleMobileServantRulesCard(this); | |||
} | } | ||
}); | }); | ||