MediaWiki:Common.js: Difference between revisions
From The Seven Sages of Rome
No edit summary |
No edit summary |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 63: | Line 63: | ||
} ); | } ); | ||
}) | }) | ||
$(document).ready(function() { | |||
$('[data-toggle="tooltip"]').tooltip(); | |||
}); | |||
$(document).ready(function () { | |||
$('#tree-filter').on('input', function () { | |||
const query = $(this).val().toLowerCase(); | |||
$('#motif-tree li').each(function () { | |||
const $li = $(this); | |||
const $link = $li.children('a'); | |||
const text = $link.text().toLowerCase(); | |||
const matches = text.includes(query); | |||
// Initially hide everything | |||
$li.data('match', matches).hide(); | |||
}); | |||
// Show matching items and their ancestors | |||
$('#motif-tree li').each(function () { | |||
const $li = $(this); | |||
if ($li.data('match')) { | |||
$li.show(); | |||
$li.parentsUntil('#motif-tree', 'li').show(); | |||
} | |||
}); | |||
// If input is empty, show all | |||
if (query === '') { | |||
$('#motif-tree li').show(); | |||
} | |||
}); | |||
}); | |||
function toggleTreeNode(element) { | |||
var childrenDiv = element.parentElement.nextElementSibling; | |||
if (childrenDiv && childrenDiv.classList.contains('smw-tree-children')) { | |||
if (childrenDiv.style.display === 'none') { | |||
childrenDiv.style.display = 'block'; | |||
element.classList.add('expanded'); | |||
} else { | |||
childrenDiv.style.display = 'none'; | |||
element.classList.remove('expanded'); | |||
} | |||
} | |||
} | |||
// Optional: Add expand/collapse all functionality | |||
function expandAllTreeNodes() { | |||
document.querySelectorAll('.smw-tree-toggle').forEach(function(toggle) { | |||
var childrenDiv = toggle.parentElement.nextElementSibling; | |||
if (childrenDiv && childrenDiv.classList.contains('smw-tree-children')) { | |||
childrenDiv.style.display = 'block'; | |||
toggle.classList.add('expanded'); | |||
} | |||
}); | |||
} | |||
function collapseAllTreeNodes() { | |||
document.querySelectorAll('.smw-tree-toggle').forEach(function(toggle) { | |||
var childrenDiv = toggle.parentElement.nextElementSibling; | |||
if (childrenDiv && childrenDiv.classList.contains('smw-tree-children')) { | |||
childrenDiv.style.display = 'none'; | |||
toggle.classList.remove('expanded'); | |||
} | |||
}); | |||
} | |||
$(document).ready(function () { | |||
$('.collapsible-tree').each(function () { | |||
const $tree = $(this); | |||
const expandLevel = $tree.data('expand-level'); // 'all', 'none', or a number (1, 2, etc.) | |||
// Iterate each LI that contains a UL as immediate child | |||
$tree.find('ul li:has(> ul)').each(function () { | |||
const $parentLi = $(this); | |||
const $subUl = $parentLi.children('ul'); | |||
const $toggleIcon = $('<i class="js-toggle-icon">+</i>'); | |||
// Calculate the depth level of this item (1 = first level, 2 = second level, etc.) | |||
const depth = $parentLi.parents('ul').length; | |||
// Add class for styling and prepend toggle icon | |||
$parentLi.addClass('has-children').prepend($toggleIcon); | |||
// Determine if this item should be expanded based on expand-level | |||
let shouldExpand = false; | |||
if (expandLevel === 'all') { | |||
shouldExpand = true; | |||
} else if (expandLevel === 'none' || expandLevel === undefined) { | |||
shouldExpand = false; | |||
} else if (typeof expandLevel === 'number' || !isNaN(expandLevel)) { | |||
// Expand if current depth is less than or equal to the specified level | |||
shouldExpand = depth <= parseInt(expandLevel); | |||
} | |||
// Set initial state | |||
if (shouldExpand) { | |||
$toggleIcon.text('−'); | |||
$subUl.show(); | |||
} else { | |||
$toggleIcon.text('+'); | |||
$subUl.hide(); | |||
} | |||
// Attach event handler to the toggle icon | |||
$toggleIcon.on('click', function (e) { | |||
e.stopPropagation(); | |||
const isCollapsed = $(this).text() === '+'; | |||
$(this).text(isCollapsed ? '−' : '+'); | |||
$subUl.slideToggle(200); | |||
}); | |||
}); | |||
}); | |||
}); | |||
// Copy permalink to clipboard | |||
function copyPermalinkToClipboard() { | |||
var revisionId = mw.config.get('wgRevisionId'); | |||
var pageTitle = mw.config.get('wgPageName'); | |||
var permalink = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + encodeURIComponent(pageTitle) + '&oldid=' + revisionId; | |||
navigator.clipboard.writeText(permalink).then(function() { | |||
mw.notify('Permalink copied to clipboard!', { type: 'success' }); | |||
}).catch(function(err) { | |||
mw.notify('Failed to copy permalink', { type: 'error' }); | |||
}); | |||
} | |||
// Attach to elements with class 'copy-permalink' | |||
$(document).ready(function() { | |||
$(document).on('click', '.copy-permalink', function(e) { | |||
e.preventDefault(); | |||
copyPermalinkToClipboard(); | |||
}); | |||
}); | |||
Latest revision as of 08:45, 5 February 2026
mw.loader.load('/index.php?title=MediaWiki:CopyEmbeddedStory.js&action=raw&ctype=text/javascript');
window.addEventListener('scroll', function() {
const navbar = document.getElementById('mw-navigation');
if (window.scrollY > 0) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
function scrollToAnchor(anchorId) {
const element = document.getElementById(anchorId);
const navbarHeight = 50;
if (element) {
// Calculate the adjusted scroll position
const elementPosition = element.getBoundingClientRect().top + window.pageYOffset;
const offsetPosition = elementPosition - navbarHeight;
// Scroll to the adjusted position
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
}
function drilldownswitcher() {
$('#drilldown-switch:contains("Show all filters")').length ? ($(".drilldown-filter-values:has(a)").css("display", "block"),
$(".drilldown-values-toggle").each(function () {
$("img").each(function () {
$(this).attr("src", $(this).attr("src").replace("right-arrow.png", "down-arrow.png"));
});
}),
(document.getElementById("drilldown-switch").innerHTML = 'Hide all filters <i class="fa fa-minus"></i>'))
: $('#drilldown-switch:contains("Hide all filters")').length &&
($(".drilldown-filter-values:has(a)").css("display", "none"),
$(".drilldown-values-toggle").each(function () {
$("img").each(function () {
$(this).attr("src", $(this).attr("src").replace("down-arrow.png", "right-arrow.png"));
});
}),
(document.getElementById("drilldown-switch").innerHTML = 'Show all filters <i class="fa fa-plus"></i>'));
}
$(document).ready(function () {
$(".drilldown-results").css({ "-webkit-filter": "blur(0)", "-moz-filter": "blur(0)", "-o-filter": "blur(0)", "-ms-filter": "blur(0)", filter: "blur(0)" }), $(".drilldown-filter-values:has(a)").css("display", "none");
$('<br /><h3 class="drilldown-pre-header">1. Selected Filters</h3>').insertBefore("#drilldown-applied-filters"),
$('<h3 class="drilldown-pre-filters">2. Available Filters</h3>').insertBefore("#drilldown-applicable-filters"),
$('<h3 class="drilldown-post-filters">3. Filtered Results</h3>').insertAfter("#drilldown-applicable-filters"),
$('<html><div class="drilldown-btn-wrapper"><a class="btn primary-btn" href="javascript:;" onclick="drilldownswitcher()" id="drilldown-switch">Show all filters <i class="fa fa-plus"></i></a></div></html>').insertBefore("#drilldown-filters");
$(".drilldown-values-toggle").each(function () {
$("img").each(function () {
$(this).attr("src", $(this).attr("src").replace("down-arrow.png", "right-arrow.png"));
});
});
if( mw.storage.get( "wip-dismissed" ) === null || JSON.parse(mw.storage.get( "wip-dismissed" )) === false){
$( ".wip-alert" ).fadeIn( "slow", function() {});
}
$( "#close-wip" ).on( "click", function() {
mw.storage.set( "wip-dismissed", true );
$( ".wip-alert" ).fadeOut( "slow", function() {});
} );
})
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
});
$(document).ready(function () {
$('#tree-filter').on('input', function () {
const query = $(this).val().toLowerCase();
$('#motif-tree li').each(function () {
const $li = $(this);
const $link = $li.children('a');
const text = $link.text().toLowerCase();
const matches = text.includes(query);
// Initially hide everything
$li.data('match', matches).hide();
});
// Show matching items and their ancestors
$('#motif-tree li').each(function () {
const $li = $(this);
if ($li.data('match')) {
$li.show();
$li.parentsUntil('#motif-tree', 'li').show();
}
});
// If input is empty, show all
if (query === '') {
$('#motif-tree li').show();
}
});
});
function toggleTreeNode(element) {
var childrenDiv = element.parentElement.nextElementSibling;
if (childrenDiv && childrenDiv.classList.contains('smw-tree-children')) {
if (childrenDiv.style.display === 'none') {
childrenDiv.style.display = 'block';
element.classList.add('expanded');
} else {
childrenDiv.style.display = 'none';
element.classList.remove('expanded');
}
}
}
// Optional: Add expand/collapse all functionality
function expandAllTreeNodes() {
document.querySelectorAll('.smw-tree-toggle').forEach(function(toggle) {
var childrenDiv = toggle.parentElement.nextElementSibling;
if (childrenDiv && childrenDiv.classList.contains('smw-tree-children')) {
childrenDiv.style.display = 'block';
toggle.classList.add('expanded');
}
});
}
function collapseAllTreeNodes() {
document.querySelectorAll('.smw-tree-toggle').forEach(function(toggle) {
var childrenDiv = toggle.parentElement.nextElementSibling;
if (childrenDiv && childrenDiv.classList.contains('smw-tree-children')) {
childrenDiv.style.display = 'none';
toggle.classList.remove('expanded');
}
});
}
$(document).ready(function () {
$('.collapsible-tree').each(function () {
const $tree = $(this);
const expandLevel = $tree.data('expand-level'); // 'all', 'none', or a number (1, 2, etc.)
// Iterate each LI that contains a UL as immediate child
$tree.find('ul li:has(> ul)').each(function () {
const $parentLi = $(this);
const $subUl = $parentLi.children('ul');
const $toggleIcon = $('<i class="js-toggle-icon">+</i>');
// Calculate the depth level of this item (1 = first level, 2 = second level, etc.)
const depth = $parentLi.parents('ul').length;
// Add class for styling and prepend toggle icon
$parentLi.addClass('has-children').prepend($toggleIcon);
// Determine if this item should be expanded based on expand-level
let shouldExpand = false;
if (expandLevel === 'all') {
shouldExpand = true;
} else if (expandLevel === 'none' || expandLevel === undefined) {
shouldExpand = false;
} else if (typeof expandLevel === 'number' || !isNaN(expandLevel)) {
// Expand if current depth is less than or equal to the specified level
shouldExpand = depth <= parseInt(expandLevel);
}
// Set initial state
if (shouldExpand) {
$toggleIcon.text('−');
$subUl.show();
} else {
$toggleIcon.text('+');
$subUl.hide();
}
// Attach event handler to the toggle icon
$toggleIcon.on('click', function (e) {
e.stopPropagation();
const isCollapsed = $(this).text() === '+';
$(this).text(isCollapsed ? '−' : '+');
$subUl.slideToggle(200);
});
});
});
});
// Copy permalink to clipboard
function copyPermalinkToClipboard() {
var revisionId = mw.config.get('wgRevisionId');
var pageTitle = mw.config.get('wgPageName');
var permalink = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + encodeURIComponent(pageTitle) + '&oldid=' + revisionId;
navigator.clipboard.writeText(permalink).then(function() {
mw.notify('Permalink copied to clipboard!', { type: 'success' });
}).catch(function(err) {
mw.notify('Failed to copy permalink', { type: 'error' });
});
}
// Attach to elements with class 'copy-permalink'
$(document).ready(function() {
$(document).on('click', '.copy-permalink', function(e) {
e.preventDefault();
copyPermalinkToClipboard();
});
});