Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 159: Line 159:
event.preventDefault();
event.preventDefault();
toggleClassCard(this);
toggleClassCard(this);
}
});
}() );
/* Mobile/tablet spellbook builder and collapse controls */
( function () {
var spellbookQuery = window.matchMedia('(max-width: 899px)');
var hasBuiltMobileSpellbooks = false;
var spellSummaries = {
'Arcane Weapon': 'Imbues a one-handed weapon with arcane energy, allowing it to strike with magical force.',
'Greater Arcane Weapon': 'Empowers a two-handed weapon with potent arcane magic, greatly enhancing its destructive power.',
'Arcane Armour': 'Wraps an ally in protective arcane energy, increasing their resilience against harm.',
'Arcane Ward': 'Enchants a shield with magical protection, allowing it to deflect hostile spells.',
'Arcane Bolt': 'Channels raw arcane energy into a magical projectile that blasts through enemy defences.',
'Arcane Force': 'Unleashes a burst of telekinetic power that hurls enemies away from the caster.',
'Nullify': 'Dispels magical effects within the surrounding area, disrupting spells and summoned creatures alike.',
'Mage Walk': 'Allows the caster to briefly walk across water as though it were solid ground.',
'Arcane Bridge': 'Creates a temporary bridge of magical energy, allowing allies to safely cross dangerous terrain.',
'Arcane Bridge Lv1': 'Creates a temporary bridge of magical energy, allowing allies to safely cross dangerous terrain.',
'Arcane Bridge Lv2': 'Creates a temporary bridge of magical energy, allowing allies to safely cross dangerous terrain.',
'Arcane Bind': 'Pins an enemy in place with invisible magical force, preventing them from escaping.',
'Summon Minor Arcane Servant - Defend': 'Summons a lesser arcane spirit that remains close to its master, defending them from nearby threats.',
'Summon Minor Arcane Servant - Attack': 'Summons a lesser arcane spirit that relentlessly pursues and attacks a chosen enemy.',
'Summon Arcane Servant - Defend': 'Calls forth a powerful guardian spirit dedicated to protecting its summoner.',
'Summon Arcane Servant - Attack': 'Summons a powerful arcane warrior that hunts down enemies with unwavering determination.',
'Summon Greater Arcane Servant': 'Calls forth a sentient arcane servant capable of acting independently on the battlefield.',
'Blessing': 'Fills an ally with divine favour, strengthening their body and shielding them from hostile magic.',
'Blessed Weapon': 'Consecrates a one-handed weapon so it strikes with holy power.',
'Greater Blessed Weapon': 'Infuses a two-handed weapon with divine might, allowing it to smite evil with every blow.',
'Holy Ward': 'Blesses a shield with sacred protection, turning aside magical attacks.',
'Sanctuary': 'Creates a holy sanctuary that wards away magical beings and protects the faithful.',
'Heal': 'Channels divine energy to mend wounds and restore an ally\'s vitality.',
'Full Heal': 'Completely restores a living ally, closing wounds and renewing their strength.',
'Mass Heal': 'Calls upon divine power to restore multiple wounded allies at once.',
'Resurrection': 'Returns a fallen ally to life through the power of divine intervention.',
'Bind Person': 'Calls upon divine authority to hold a mortal in place, preventing their escape.',
'Bind Person Lv1': 'Calls upon divine authority to hold a mortal in place, preventing their escape.',
'Bind Person Lv2': 'Calls upon divine authority to hold a mortal in place, preventing their escape.',
'Immobilise': 'Overwhelms a target with sacred power, leaving them completely unable to move or fight.',
'Taunt': 'Compels magical creatures to focus their attention upon the caster through divine command.',
'Taunt Lv1': 'Compels magical creatures to focus their attention upon the caster through divine command.',
'Taunt Lv2': 'Compels magical creatures to focus their attention upon the caster through divine command.',
'Banish': 'Drives magical creatures and summoned beings away with overwhelming divine authority.'
};
function getArcaneIcon() {
var $sourceIcon = $('.wizlords-magic-intro-icon img').first();
if (!$sourceIcon.length) {
return $('<span>').text('');
}
return $sourceIcon.clone()
.removeAttr('width')
.removeAttr('height')
.removeAttr('srcset')
.removeAttr('sizes')
.removeAttr('style')
.attr('alt', '');
}
function buildMobileSpellCard($sourceCard) {
var title = $.trim($sourceCard.children('.wizlords-spell-card-title').first().text());
var $card = $('<div>').addClass('wizlords-mobile-spell-card');
var $icon = $('<div>').addClass('wizlords-mobile-spell-card-icon').append(getArcaneIcon());
var $title = $('<div>').addClass('wizlords-mobile-spell-card-title').text(title);
var $summary = $('<div>').addClass('wizlords-mobile-spell-card-summary').text(spellSummaries[title] || '');
var $rules = $('<div>').addClass('wizlords-mobile-spell-card-rules');
$sourceCard.children().not('.wizlords-spell-card-title').each(function () {
$rules.append($(this).clone());
});
return $card
.append($icon)
.append($title)
.append($summary)
.append($rules);
}
function buildMobileSpellbook(sourceSelector, title, variantClass) {
var $source = $(sourceSelector);
var $content = $source.children('.mw-collapsible-content').first();
var $book = $('<div>').addClass('wizlords-mobile-spellbook ' + variantClass);
var $currentCategory = null;
$book.append($('<div>').addClass('wizlords-mobile-spellbook-title').text(title));
$content.children().each(function () {
var $node = $(this);
if ($node.hasClass('wizlords-spell-category-heading')) {
$currentCategory = $('<div>').addClass('wizlords-mobile-spell-category');
$currentCategory.append($('<div>').addClass('wizlords-mobile-spell-category-heading').text($.trim($node.text())));
$book.append($currentCategory);
return;
}
if ($node.hasClass('wizlords-spell-category-description') && $currentCategory) {
$currentCategory.append($node.clone().removeClass('wizlords-spell-category-description').addClass('wizlords-mobile-spell-category-description'));
return;
}
if ($node.hasClass('wizlords-spell-card-grid')) {
if (!$currentCategory) {
$currentCategory = $('<div>').addClass('wizlords-mobile-spell-category');
$book.append($currentCategory);
}
$node.children('.wizlords-spell-card').each(function () {
$currentCategory.append(buildMobileSpellCard($(this)));
});
}
});
return $book;
}
function buildMobileSpellbooks() {
var $target = $('.wizlords-spellbooks-mobile');
if (hasBuiltMobileSpellbooks || !$target.length) {
return;
}
$target
.empty()
.append(buildMobileSpellbook('#wizlords-arcane-spellbook', 'Arcane Spellbook', 'wizlords-mobile-spellbook-arcane'))
.append(buildMobileSpellbook('#wizlords-divine-spellbook', 'Divine Spellbook', 'wizlords-mobile-spellbook-divine'));
hasBuiltMobileSpellbooks = true;
}
function initialiseMobileSpellCards() {
buildMobileSpellbooks();
$('.wizlords-spellbooks-mobile').attr('aria-hidden', spellbookQuery.matches ? 'false' : 'true');
$('.wizlords-mobile-spell-card').each(function () {
var $card = $(this);
if (spellbookQuery.matches) {
if (!$card.attr('data-wizlords-mobile-spell-card')) {
$card
.attr('data-wizlords-mobile-spell-card', '1')
.attr('role', 'button')
.attr('tabindex', '0');
}
if (!$card.hasClass('is-open')) {
$card.attr('aria-expanded', 'false');
}
} else {
$card
.removeAttr('data-wizlords-mobile-spell-card')
.removeAttr('role')
.removeAttr('tabindex')
.removeAttr('aria-expanded')
.removeClass('is-open');
}
});
}
function toggleMobileSpellCard(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');
}
$(initialiseMobileSpellCards);
if (spellbookQuery.addEventListener) {
spellbookQuery.addEventListener('change', initialiseMobileSpellCards);
} else if (spellbookQuery.addListener) {
spellbookQuery.addListener(initialiseMobileSpellCards);
}
$(document).on('click', '.wizlords-mobile-spell-card', function (event) {
if ($(event.target).closest('a').length) {
return;
}
toggleMobileSpellCard(this);
});
$(document).on('keydown', '.wizlords-mobile-spell-card', function (event) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
toggleMobileSpellCard(this);
}
}
});
});
}() );
}() );