MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
No edit summary |
No edit summary |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
/* Return to a box header after using its bottom collapse control. */ | |||
function wizlordsScrollToCollapsedHeader($box) { | |||
if (!$box.length) { return; } | |||
$box.children('.mw-collapsible-content').promise().done(function () { | |||
window.requestAnimationFrame(function () { | |||
window.requestAnimationFrame(function () { | |||
if (!document.documentElement.contains($box[0])) { return; } | |||
var offset = 16; | |||
document.querySelectorAll('.citizen-header, .vector-sticky-header').forEach(function (header) { | |||
var style = window.getComputedStyle(header); | |||
var rect = header.getBoundingClientRect(); | |||
if ((style.position === 'fixed' || style.position === 'sticky') && | |||
rect.height > 0 && rect.top <= 0 && rect.bottom > 0) { | |||
offset = Math.max(offset, rect.bottom + 16); | |||
} | |||
}); | |||
$box.children('[aria-expanded]').addBack('[aria-expanded]').attr('aria-expanded', 'false'); | |||
var previousMargin = $box[0].style.scrollMarginTop; | |||
$box[0].style.scrollMarginTop = offset + 'px'; | |||
$box[0].scrollIntoView({ block: 'start', inline: 'nearest', behavior: 'instant' }); | |||
$box[0].style.scrollMarginTop = previousMargin; | |||
}); | |||
}); | |||
}); | |||
} | |||
/* Bottom collapse controls */ | /* Bottom collapse controls */ | ||
mw.loader.using('jquery.makeCollapsible').then(function () { | mw.loader.using('jquery.makeCollapsible').then(function () { | ||
| Line 77: | Line 102: | ||
if ($topToggle.length) { | if ($topToggle.length) { | ||
$topToggle.trigger('click'); | $topToggle.trigger('click'); | ||
wizlordsScrollToCollapsedHeader($collapsible); | |||
} | } | ||
}); | }); | ||
| Line 92: | Line 118: | ||
if ($topToggle.length) { | if ($topToggle.length) { | ||
$topToggle.trigger('click'); | $topToggle.trigger('click'); | ||
wizlordsScrollToCollapsedHeader($collapsible); | |||
} | } | ||
}); | }); | ||
| Line 137: | Line 164: | ||
.toggleClass('is-open', !isOpen) | .toggleClass('is-open', !isOpen) | ||
.attr('aria-expanded', isOpen ? 'false' : 'true'); | .attr('aria-expanded', isOpen ? 'false' : 'true'); | ||
if (isOpen) { wizlordsScrollToCollapsedHeader($card); } | |||
} | } | ||
| Line 671: | Line 699: | ||
.toggleClass('is-open', !isOpen) | .toggleClass('is-open', !isOpen) | ||
.attr('aria-expanded', isOpen ? 'false' : 'true'); | .attr('aria-expanded', isOpen ? 'false' : 'true'); | ||
if (isOpen) { wizlordsScrollToCollapsedHeader($card); } | |||
} | } | ||
| Line 730: | Line 759: | ||
$(document).on('click', '.wizlords-mobile-spellbook-collapse', function () { | $(document).on('click', '.wizlords-mobile-spellbook-collapse', function () { | ||
var $book = $(this).closest('.wizlords-mobile-spellbook'); | |||
toggleMobileSpellbook($book.children('.wizlords-mobile-spellbook-header').first()); | |||
wizlordsScrollToCollapsedHeader($book); | |||
}); | }); | ||
| Line 778: | Line 809: | ||
$(prepareLoreProfiles); | $(prepareLoreProfiles); | ||
if (query.addEventListener) { query.addEventListener('change', prepareLoreProfiles); } | if (query.addEventListener) { query.addEventListener('change', prepareLoreProfiles); } | ||
$(document).on('click', '.wizlords-lore-profile > .wizlords-collapsible-section-title', function () { | $(document).on('click', '.wizlords-lore-profile > .wizlords-collapsible-section-title, .wizlords-lore-profile > .wizlords-lore-profile-mobile-icon', function () { | ||
if (!query.matches) { return; } | if (!query.matches) { return; } | ||
$(this).parent().children('.mw-collapsible-toggle').first().trigger('click'); | var $profile = $(this).parent(); | ||
var wasOpen = !$profile.hasClass('mw-collapsed'); | |||
$profile.children('.mw-collapsible-toggle').first().trigger('click'); | |||
prepareLoreProfiles(); | prepareLoreProfiles(); | ||
if (wasOpen) { wizlordsScrollToCollapsedHeader($profile); } | |||
}); | }); | ||
$(document).on('keydown', '.wizlords-lore-profile > .wizlords-collapsible-section-title', function (event) { | $(document).on('keydown', '.wizlords-lore-profile > .wizlords-collapsible-section-title, .wizlords-lore-profile > .wizlords-lore-profile-mobile-icon', function (event) { | ||
if (query.matches && (event.key === 'Enter' || event.key === ' ')) { | if (query.matches && (event.key === 'Enter' || event.key === ' ')) { | ||
event.preventDefault(); | event.preventDefault(); | ||
| Line 789: | Line 823: | ||
} | } | ||
}); | }); | ||
}); | |||
$(document).on('keydown', '.wizlords-lore-collapse', function (event) { | |||
if (event.key === 'Enter' || event.key === ' ') { | |||
event.preventDefault(); | |||
$(this).trigger('click'); | |||
} | |||
}); | }); | ||