No edit summary |
No edit summary |
||
(114 intermediate revisions by 3 users not shown) | |||
Line 9: | Line 9: | ||
var username = data.query.userinfo.name; | var username = data.query.userinfo.name; | ||
var userLink = mw.util.getUrl('User:' + username); | var userLink = mw.util.getUrl('User:' + username); | ||
$('#user-info').html('<a href="' + userLink + '" class="text-white">' + username + '</a>'); | var logoutLink = mw.util.getUrl('Special:Logout'); | ||
$('#user-info').html('<a href="' + userLink + '" class="text-white">' + username + '</a>' + | |||
' | <a href="' + logoutLink + '" class="text-white">Logout</a>'); | |||
} | } | ||
}); | }); | ||
}); | }); | ||
document.getElementById('offcanvas-toggler').addEventListener('click', function() { | document.getElementById('offcanvas-toggler').addEventListener('click', function() { | ||
var sidebar = document.getElementById('offcanvas-menu'); | var sidebar = document.getElementById('offcanvas-menu'); | ||
Line 25: | Line 27: | ||
function toggleSection( | |||
var submenu = header. | |||
if ( | $(document).ready(function() { | ||
$('#offcanvas-close').on('click', function() { | |||
$('#offcanvas-menu').removeClass('show'); | |||
}); | |||
}); | |||
document.addEventListener('DOMContentLoaded', function() { | |||
var form = document.querySelector('.namespace-search-form'); | |||
if (form) { | |||
form.addEventListener('submit', function(e) { | |||
var input = form.querySelector('#bs-extendedsearch-input'); | |||
if (input) { | |||
var namespace = mw.config.get('wgCanonicalNamespace'); | |||
if (namespace && namespace.length > 0) { | |||
input.value = namespace + ": " + input.value; | |||
} | |||
} | |||
}); | |||
} | |||
}); | |||
(function($) { | |||
'use strict'; | |||
var css = [ | |||
'#suggestion-container {', | |||
' position: relative;', | |||
' width: 100%;', | |||
'}', | |||
'#suggestion-box {', | |||
' position: absolute;', | |||
' top: 100%;', | |||
' left: 0;', | |||
' width: 100%;', | |||
' margin-top: 5px;', | |||
' background-color: #fff;', | |||
' z-index: 1000;', | |||
'}', | |||
'.suggestion-item {', | |||
' padding: 8px;', | |||
' cursor: pointer;', | |||
'}', | |||
'.suggestion-item:hover {', | |||
' background-color: #e0e0e0;', | |||
'}' | |||
].join('\n'); | |||
$('head').append('<style type="text/css">' + css + '</style>'); | |||
$('#suggestion-container').append('<div id="suggestion-box"></div>'); | |||
function showSuggestions() { | |||
var query = $(this).val(); | |||
if (query.length > 0) { | |||
var apiUrl = "https://wiki.mdriven.net/api.php"; | |||
var requestData = { | |||
action: "bs-extendedsearch-autocomplete", | |||
format: "json", | |||
q: JSON.stringify({ | |||
query: { | |||
bool: { | |||
must: { | |||
match: { | |||
ac_ngram: { | |||
query: query | |||
} | |||
} | |||
} | |||
} | |||
}, | |||
size: 8 | |||
}), | |||
searchData: JSON.stringify({ | |||
namespace: 0, | |||
value: query, | |||
mainpage: "" | |||
}) | |||
}; | |||
$.ajax({ | |||
url: apiUrl, | |||
data: requestData, | |||
dataType: "json", | |||
method: "GET", | |||
success: function(data) { | |||
var suggestions = data.suggestions || []; | |||
$('#suggestion-box').empty(); | |||
$.each(suggestions, function(index, suggestion) { | |||
var item = $('<div class="suggestion-item"></div>').text(suggestion.basename); | |||
$('#suggestion-box').append(item); | |||
}); | |||
}, | |||
error: function(jqxhr, textStatus, error) { | |||
console.error('Error fetching suggestions:', error); | |||
} | |||
}); | |||
} | |||
} | |||
function hideSuggestions(event) { | |||
if (!$(event.target).closest('#suggestion-container').length) { | |||
$('#suggestion-box').empty(); | |||
} | |||
} | |||
function selectSuggestion(event) { | |||
event.preventDefault(); // Prevent the mousedown event from triggering blur on the search input | |||
var selectedText = $(this).text(); | |||
window.location.href = '/index.php?title=' + encodeURIComponent(selectedText); | |||
} | |||
$('.search-input').on('input', showSuggestions); | |||
$(document).on('click', hideSuggestions); | |||
$('#suggestion-box').on('mousedown', '.suggestion-item', selectSuggestion); | |||
})(jQuery); | |||
$(document).ready(function() { | |||
// Function to toggle a section open or closed | |||
function toggleSection(element) { | |||
var submenu = $(element).next('.submenu'); | |||
submenu.toggle(); | |||
} | |||
// Function to open the submenu containing the current page link and scroll to it | |||
function openCurrentPageSubmenuAndScroll() { | |||
var currentPageLink = $('#navMenu .current-page'); | |||
if (currentPageLink.length) { | |||
// Open the parent submenu(s) of the current page link | |||
currentPageLink.parents('.submenu').show(); | |||
// Delay the scrolling to allow for any dynamic layout changes | |||
setTimeout(function() { | |||
// Calculate the position of the current page link | |||
var position = currentPageLink.offset().top - $('#navMenu').offset().top + $('#navMenu').scrollTop(); | |||
// Scroll the menu to the active item | |||
$('#navMenu').animate({ | |||
scrollTop: position | |||
}, 500); | |||
}, 100); // Delay of 100 milliseconds | |||
} | |||
} | |||
// Event delegation for dynamically loaded content | |||
$('#navMenu').on('click', '.menu-header', function() { | |||
toggleSection(this); | |||
}); | |||
// Open the submenu containing the current page link and scroll to it | |||
openCurrentPageSubmenuAndScroll(); | |||
}); | |||
document.getElementById('menu-toggle').addEventListener('click', function() { | |||
var navMenu = document.getElementById('navMenu'); | |||
var bodyContent = document.getElementById('bodyContent'); | |||
if (navMenu.style.display === 'none' || navMenu.style.display === '') { | |||
navMenu.style.display = 'block'; | |||
bodyContent.style.display = 'none'; // Hide body content when nav menu is displayed | |||
} else { | } else { | ||
navMenu.style.display = 'none'; | |||
bodyContent.style.display = 'block'; // Show body content when nav menu is hidden | |||
} | } | ||
} | }); | ||
$(document).ready(function() { | |||
$('.video__navigation .navigation-item').click(function() { | |||
var videoID = $(this).data('video'); | |||
var startTime = $(this).data('start'); | |||
var newSrc = 'https://www.youtube.com/embed/' + videoID + '?start=' + startTime + '&autoplay=1'; | |||
$('.video__wrapper iframe').attr('src', newSrc); | |||
}); | |||
}); | |||
$(document).ready(function() { | |||
$('.bs-extendedsearch-filter-button-button').each(function() { | |||
$(this).append('<span class="fa fa-chevron-down"></span>'); | |||
}); | |||
}); | |||
document.addEventListener("scroll", function() { | |||
var sidebar = document.getElementById("navMenu"); | |||
var footerHeight = 100; | |||
var windowHeight = window.innerHeight; | |||
var scrollBottomPosition = window.scrollY + windowHeight; | |||
var footerTopPosition = document.documentElement.offsetHeight - footerHeight; | |||
if (scrollBottomPosition <= footerTopPosition) { | |||
sidebar.style.height = "100vh"; | |||
} else { | |||
sidebar.style.height = "calc(100vh - 110px)"; | |||
} | |||
}); | |||
mw.loader.using('jquery', function() { | |||
$(document).ready(function() { | |||
var $toc = $('#toc').clone(); | |||
$('#toc').remove(); | |||
$('#tocContainer').html($toc); | |||
$('#tocContainer').css({ | |||
position: '-webkit-sticky', | |||
position: 'sticky', | |||
top: '0', | |||
padding: '15px', | |||
margin: '0 auto', | |||
borderRadius: '5px', | |||
maxWidth: '280px', | |||
maxHeight: 'max-content', | |||
overflowY: 'auto', | |||
height: '90vh', | |||
zIndex: 1000 | |||
}); | |||
$('#tocContainer .toctitle').css({ | |||
fontSize: '16px', | |||
fontWeight: '600', | |||
color: '#555', | |||
borderBottom: '1px solid #ccc', | |||
paddingBottom: '10px', | |||
marginBottom: '10px' | |||
}); | |||
$('#tocContainer ul').css({ | |||
margin: 0, | |||
padding: '0 0 0 20px', | |||
listStyleType: 'none', | |||
fontSize: '14px', | |||
lineHeight: '1.6' | |||
}); | |||
$('#tocContainer li').css({ | |||
marginBottom: '5px', | |||
}); | |||
$('#tocContainer a').css({ | |||
color: '#555', | |||
textDecoration: 'none', | |||
}).hover( | |||
function() { $(this).css({textDecoration: 'underline', color: '#000'}); }, | |||
function() { $(this).css({textDecoration: 'none', color: '#555'}); } | |||
); | |||
}); | |||
}); | |||
$(document).ready(function() { | |||
var $inputElement = $('.oo-ui-textInputWidget-type-search .oo-ui-inputWidget-input'); | |||
if ($inputElement.length) { | |||
$inputElement.on('keydown', function(event) { | |||
if (event.key === 'Enter') { | |||
event.preventDefault(); | |||
$inputElement.addClass('search-input'); | |||
} | |||
}); | |||
} | |||
}); | |||
$(document).ready(function() { | |||
var $inputElement = $('.oo-ui-textInputWidget-type-search .oo-ui-inputWidget-input'); | |||
if ($inputElement.length) { | |||
$inputElement.addClass('search-input'); | |||
console.log('Class "search-input" added to the input element.'); | |||
} else { | |||
console.log('Input element not found.'); | |||
} | |||
}); | |||
$(document).ready(function() { | |||
function applyChanges() { | |||
console.log('applyChanges function called'); | |||
var $searchInput = $('input[type="search"].oo-ui-inputWidget-input'); | |||
var $searchWidgetResults = $('.oo-ui-searchWidget-results'); | |||
if ($searchInput.length && $searchWidgetResults.length) { | |||
console.log('Input element found:', $searchInput); | |||
$searchInput.addClass('search-input-edit'); | |||
console.log('Class "search-input" added to input element'); | |||
if ($searchWidgetResults.next('#suggestion-container-edit').length === 0) { | |||
$('<div id="suggestion-container-edit"></div>').insertAfter($searchWidgetResults); | |||
console.log('Suggestion container added after .oo-ui-searchWidget-results element'); | |||
} | |||
$searchInput.on('input', showSuggestions); | |||
$('#suggestion-container').css('width', $searchInput.outerWidth()); | |||
} else { | |||
console.log('Input element or .oo-ui-searchWidget-results not found, retrying...'); | |||
setTimeout(applyChanges, 100); | |||
} | |||
} | |||
function checkVeActiveClass() { | |||
console.log('Checking for ve-active class'); | |||
var $htmlTag = $('html'); | |||
if ($htmlTag.hasClass('ve-active')) { | |||
console.log('ve-active class detected on HTML tag'); | |||
applyChanges(); | |||
} else { | |||
console.log('ve-active class not yet detected, retrying...'); | |||
setTimeout(checkVeActiveClass, 100); | |||
} | |||
} | |||
function showSuggestions() { | |||
var query = $(this).val(); | |||
if (query.length > 0) { | |||
var apiUrl = "https://wiki.mdriven.net/api.php"; | |||
var requestData = { | |||
action: "bs-extendedsearch-autocomplete", | |||
format: "json", | |||
q: JSON.stringify({ | |||
query: { | |||
bool: { | |||
must: { | |||
match: { | |||
ac_ngram: { | |||
query: query | |||
} | |||
} | |||
} | |||
} | |||
}, | |||
size: 8 | |||
}), | |||
searchData: JSON.stringify({ | |||
namespace: 0, | |||
value: query, | |||
mainpage: "" | |||
}) | |||
}; | |||
$.ajax({ | |||
url: apiUrl, | |||
data: requestData, | |||
dataType: "json", | |||
method: "GET", | |||
success: function(data) { | |||
var suggestions = data.suggestions || []; | |||
$('#suggestion-container-edit').empty(); | |||
$.each(suggestions, function(index, suggestion) { | |||
var displayText = suggestion.namespace_text === 'Pages' ? suggestion.basename : suggestion.namespace_text + ':' + suggestion.basename; | |||
var item = $('<div class="suggestion-item-edit"></div>').text(displayText); | |||
item.on('click', function() { | |||
$('input[type="search"].oo-ui-inputWidget-input').val(displayText); | |||
$('#suggestion-container-edit').empty(); | |||
}); | |||
$('#suggestion-container-edit').append(item); | |||
}); | |||
}, | |||
error: function(jqxhr, textStatus, error) { | |||
console.error('Error fetching suggestions:', error); | |||
} | |||
}); | |||
} else { | |||
$('#suggestion-container-edit').empty(); // Clear suggestions if query is empty | |||
} | |||
} | |||
console.log('Starting to check for ve-active class'); | |||
checkVeActiveClass(); | |||
}); | |||
$('<style type="text/css">#suggestion-container-edit { position: static; border: 1px solid #ccc; background: white; z-index: 10000; width: 100%; overflow-y: auto; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); } .suggestion-item-edit { padding: 8px; cursor: pointer; } .suggestion-item-edit:hover { background: #f0f0f0; }</style>').appendTo('head'); | |||
$(document).ready(function() { | |||
var signInLink = $('#user-info a'); | |||
var currentUrl = encodeURIComponent(window.location.pathname + window.location.search + window.location.hash); | |||
signInLink.attr('href', signInLink.attr('href').replace('<CURRENT_URL>', currentUrl)); | |||
}); |
Latest revision as of 20:39, 23 May 2024
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function () {
$.get(mw.util.wikiScript('api'), {
action: 'query',
meta: 'userinfo',
format: 'json'
}).done(function (data) {
if (data.query.userinfo.id !== 0) {
var username = data.query.userinfo.name;
var userLink = mw.util.getUrl('User:' + username);
var logoutLink = mw.util.getUrl('Special:Logout');
$('#user-info').html('<a href="' + userLink + '" class="text-white">' + username + '</a>' +
' | <a href="' + logoutLink + '" class="text-white">Logout</a>');
}
});
});
document.getElementById('offcanvas-toggler').addEventListener('click', function() {
var sidebar = document.getElementById('offcanvas-menu');
if (sidebar.classList.contains('show')) {
sidebar.classList.remove('show');
} else {
sidebar.classList.add('show');
}
});
$(document).ready(function() {
$('#offcanvas-close').on('click', function() {
$('#offcanvas-menu').removeClass('show');
});
});
document.addEventListener('DOMContentLoaded', function() {
var form = document.querySelector('.namespace-search-form');
if (form) {
form.addEventListener('submit', function(e) {
var input = form.querySelector('#bs-extendedsearch-input');
if (input) {
var namespace = mw.config.get('wgCanonicalNamespace');
if (namespace && namespace.length > 0) {
input.value = namespace + ": " + input.value;
}
}
});
}
});
(function($) {
'use strict';
var css = [
'#suggestion-container {',
' position: relative;',
' width: 100%;',
'}',
'#suggestion-box {',
' position: absolute;',
' top: 100%;',
' left: 0;',
' width: 100%;',
' margin-top: 5px;',
' background-color: #fff;',
' z-index: 1000;',
'}',
'.suggestion-item {',
' padding: 8px;',
' cursor: pointer;',
'}',
'.suggestion-item:hover {',
' background-color: #e0e0e0;',
'}'
].join('\n');
$('head').append('<style type="text/css">' + css + '</style>');
$('#suggestion-container').append('<div id="suggestion-box"></div>');
function showSuggestions() {
var query = $(this).val();
if (query.length > 0) {
var apiUrl = "https://wiki.mdriven.net/api.php";
var requestData = {
action: "bs-extendedsearch-autocomplete",
format: "json",
q: JSON.stringify({
query: {
bool: {
must: {
match: {
ac_ngram: {
query: query
}
}
}
}
},
size: 8
}),
searchData: JSON.stringify({
namespace: 0,
value: query,
mainpage: ""
})
};
$.ajax({
url: apiUrl,
data: requestData,
dataType: "json",
method: "GET",
success: function(data) {
var suggestions = data.suggestions || [];
$('#suggestion-box').empty();
$.each(suggestions, function(index, suggestion) {
var item = $('<div class="suggestion-item"></div>').text(suggestion.basename);
$('#suggestion-box').append(item);
});
},
error: function(jqxhr, textStatus, error) {
console.error('Error fetching suggestions:', error);
}
});
}
}
function hideSuggestions(event) {
if (!$(event.target).closest('#suggestion-container').length) {
$('#suggestion-box').empty();
}
}
function selectSuggestion(event) {
event.preventDefault(); // Prevent the mousedown event from triggering blur on the search input
var selectedText = $(this).text();
window.location.href = '/index.php?title=' + encodeURIComponent(selectedText);
}
$('.search-input').on('input', showSuggestions);
$(document).on('click', hideSuggestions);
$('#suggestion-box').on('mousedown', '.suggestion-item', selectSuggestion);
})(jQuery);
$(document).ready(function() {
// Function to toggle a section open or closed
function toggleSection(element) {
var submenu = $(element).next('.submenu');
submenu.toggle();
}
// Function to open the submenu containing the current page link and scroll to it
function openCurrentPageSubmenuAndScroll() {
var currentPageLink = $('#navMenu .current-page');
if (currentPageLink.length) {
// Open the parent submenu(s) of the current page link
currentPageLink.parents('.submenu').show();
// Delay the scrolling to allow for any dynamic layout changes
setTimeout(function() {
// Calculate the position of the current page link
var position = currentPageLink.offset().top - $('#navMenu').offset().top + $('#navMenu').scrollTop();
// Scroll the menu to the active item
$('#navMenu').animate({
scrollTop: position
}, 500);
}, 100); // Delay of 100 milliseconds
}
}
// Event delegation for dynamically loaded content
$('#navMenu').on('click', '.menu-header', function() {
toggleSection(this);
});
// Open the submenu containing the current page link and scroll to it
openCurrentPageSubmenuAndScroll();
});
document.getElementById('menu-toggle').addEventListener('click', function() {
var navMenu = document.getElementById('navMenu');
var bodyContent = document.getElementById('bodyContent');
if (navMenu.style.display === 'none' || navMenu.style.display === '') {
navMenu.style.display = 'block';
bodyContent.style.display = 'none'; // Hide body content when nav menu is displayed
} else {
navMenu.style.display = 'none';
bodyContent.style.display = 'block'; // Show body content when nav menu is hidden
}
});
$(document).ready(function() {
$('.video__navigation .navigation-item').click(function() {
var videoID = $(this).data('video');
var startTime = $(this).data('start');
var newSrc = 'https://www.youtube.com/embed/' + videoID + '?start=' + startTime + '&autoplay=1';
$('.video__wrapper iframe').attr('src', newSrc);
});
});
$(document).ready(function() {
$('.bs-extendedsearch-filter-button-button').each(function() {
$(this).append('<span class="fa fa-chevron-down"></span>');
});
});
document.addEventListener("scroll", function() {
var sidebar = document.getElementById("navMenu");
var footerHeight = 100;
var windowHeight = window.innerHeight;
var scrollBottomPosition = window.scrollY + windowHeight;
var footerTopPosition = document.documentElement.offsetHeight - footerHeight;
if (scrollBottomPosition <= footerTopPosition) {
sidebar.style.height = "100vh";
} else {
sidebar.style.height = "calc(100vh - 110px)";
}
});
mw.loader.using('jquery', function() {
$(document).ready(function() {
var $toc = $('#toc').clone();
$('#toc').remove();
$('#tocContainer').html($toc);
$('#tocContainer').css({
position: '-webkit-sticky',
position: 'sticky',
top: '0',
padding: '15px',
margin: '0 auto',
borderRadius: '5px',
maxWidth: '280px',
maxHeight: 'max-content',
overflowY: 'auto',
height: '90vh',
zIndex: 1000
});
$('#tocContainer .toctitle').css({
fontSize: '16px',
fontWeight: '600',
color: '#555',
borderBottom: '1px solid #ccc',
paddingBottom: '10px',
marginBottom: '10px'
});
$('#tocContainer ul').css({
margin: 0,
padding: '0 0 0 20px',
listStyleType: 'none',
fontSize: '14px',
lineHeight: '1.6'
});
$('#tocContainer li').css({
marginBottom: '5px',
});
$('#tocContainer a').css({
color: '#555',
textDecoration: 'none',
}).hover(
function() { $(this).css({textDecoration: 'underline', color: '#000'}); },
function() { $(this).css({textDecoration: 'none', color: '#555'}); }
);
});
});
$(document).ready(function() {
var $inputElement = $('.oo-ui-textInputWidget-type-search .oo-ui-inputWidget-input');
if ($inputElement.length) {
$inputElement.on('keydown', function(event) {
if (event.key === 'Enter') {
event.preventDefault();
$inputElement.addClass('search-input');
}
});
}
});
$(document).ready(function() {
var $inputElement = $('.oo-ui-textInputWidget-type-search .oo-ui-inputWidget-input');
if ($inputElement.length) {
$inputElement.addClass('search-input');
console.log('Class "search-input" added to the input element.');
} else {
console.log('Input element not found.');
}
});
$(document).ready(function() {
function applyChanges() {
console.log('applyChanges function called');
var $searchInput = $('input[type="search"].oo-ui-inputWidget-input');
var $searchWidgetResults = $('.oo-ui-searchWidget-results');
if ($searchInput.length && $searchWidgetResults.length) {
console.log('Input element found:', $searchInput);
$searchInput.addClass('search-input-edit');
console.log('Class "search-input" added to input element');
if ($searchWidgetResults.next('#suggestion-container-edit').length === 0) {
$('<div id="suggestion-container-edit"></div>').insertAfter($searchWidgetResults);
console.log('Suggestion container added after .oo-ui-searchWidget-results element');
}
$searchInput.on('input', showSuggestions);
$('#suggestion-container').css('width', $searchInput.outerWidth());
} else {
console.log('Input element or .oo-ui-searchWidget-results not found, retrying...');
setTimeout(applyChanges, 100);
}
}
function checkVeActiveClass() {
console.log('Checking for ve-active class');
var $htmlTag = $('html');
if ($htmlTag.hasClass('ve-active')) {
console.log('ve-active class detected on HTML tag');
applyChanges();
} else {
console.log('ve-active class not yet detected, retrying...');
setTimeout(checkVeActiveClass, 100);
}
}
function showSuggestions() {
var query = $(this).val();
if (query.length > 0) {
var apiUrl = "https://wiki.mdriven.net/api.php";
var requestData = {
action: "bs-extendedsearch-autocomplete",
format: "json",
q: JSON.stringify({
query: {
bool: {
must: {
match: {
ac_ngram: {
query: query
}
}
}
}
},
size: 8
}),
searchData: JSON.stringify({
namespace: 0,
value: query,
mainpage: ""
})
};
$.ajax({
url: apiUrl,
data: requestData,
dataType: "json",
method: "GET",
success: function(data) {
var suggestions = data.suggestions || [];
$('#suggestion-container-edit').empty();
$.each(suggestions, function(index, suggestion) {
var displayText = suggestion.namespace_text === 'Pages' ? suggestion.basename : suggestion.namespace_text + ':' + suggestion.basename;
var item = $('<div class="suggestion-item-edit"></div>').text(displayText);
item.on('click', function() {
$('input[type="search"].oo-ui-inputWidget-input').val(displayText);
$('#suggestion-container-edit').empty();
});
$('#suggestion-container-edit').append(item);
});
},
error: function(jqxhr, textStatus, error) {
console.error('Error fetching suggestions:', error);
}
});
} else {
$('#suggestion-container-edit').empty(); // Clear suggestions if query is empty
}
}
console.log('Starting to check for ve-active class');
checkVeActiveClass();
});
$('<style type="text/css">#suggestion-container-edit { position: static; border: 1px solid #ccc; background: white; z-index: 10000; width: 100%; overflow-y: auto; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); } .suggestion-item-edit { padding: 8px; cursor: pointer; } .suggestion-item-edit:hover { background: #f0f0f0; }</style>').appendTo('head');
$(document).ready(function() {
var signInLink = $('#user-info a');
var currentUrl = encodeURIComponent(window.location.pathname + window.location.search + window.location.hash);
signInLink.attr('href', signInLink.attr('href').replace('<CURRENT_URL>', currentUrl));
});
This page was edited 10 days ago on 05/23/2024. What links here