Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
// MediaWiki Audio Player Controller
// Add this to your MediaWiki common.js or custom JavaScript file
$(document).ready(function() {
// Function to stop and reset all other audio players
function stopAndResetOtherPlayers(currentPlayerId) {
// Find all audio elements that are not the current one
$('audio[id^="mwe_player_"]:not(#' + currentPlayerId + ')').each(function() {
var audioElement = this;
// Pause the audio if it's playing
if (!audioElement.paused) {
audioElement.pause();
audioElement.currentTime = 0;
}
// Find the corresponding player container
var playerId = audioElement.id;
var playerContainer = $('.mw-tmh-player').has('#' + playerId);
// Check if this player has been activated (has video-js class)
var videoJsPlayer = playerContainer.find('.video-js');
if (videoJsPlayer.length > 0) {
// This player has been activated, we need to reset it
resetPlayerToInitialState(playerId, playerContainer);
}
});
}
// Function to reset a player to its initial state
function resetPlayerToInitialState(playerId, playerContainer) {
// Extract the placeholder ID and media info
var placeholderId = playerId + '_placeholder';
var audioElement = $('#' + playerId)[0];
if (audioElement) {
// Get original attributes
var durationHint = audioElement.dataset.durationhint;
var mwTitle = audioElement.dataset.mwtitle;
var mwProvider = audioElement.dataset.mwprovider;
var width = audioElement.style.width || '300px';
// Create the original placeholder structure
var originalHTML = `
<audio id="${placeholderId}" preload="none" width="300" style="width:${width};"
data-durationhint="${durationHint}" data-mwtitle="${mwTitle}"
data-mwprovider="${mwProvider}" disabled="disabled" tabindex="-1"></audio>
<a class="mw-tmh-play" href="/index.php?title=File:${mwTitle}"
title="Play media" role="button">
<span class="mw-tmh-play-icon"></span>
</a>
<span class="mw-tmh-duration mw-tmh-label" aria-label="${formatDuration(durationHint)}">
${formatDuration(durationHint)}
</span>
`;
// Replace the video-js player with the original structure
playerContainer.html(originalHTML);
// Re-initialize the click handler for the new play button
initializePlayButton(playerContainer.find('.mw-tmh-play'));
}
}
// Function to format duration from seconds to MM:SS
function formatDuration(seconds) {
var minutes = Math.floor(seconds / 60);
var remainingSeconds = seconds % 60;
return minutes + ':' + (remainingSeconds < 10 ? '0' : '') + remainingSeconds;
}
// Function to initialize play button click handler
function initializePlayButton(playButton) {
playButton.off('click.audioController').on('click.audioController', function(e) {
e.preventDefault();
// Find the placeholder audio element
var playerContainer = $(this).closest('.mw-tmh-player');
var placeholderAudio = playerContainer.find('audio[id$="_placeholder"]');
if (placeholderAudio.length > 0) {
var currentPlayerId = placeholderAudio[0].id.replace('_placeholder', '');
// Stop and reset all other players before starting this one
stopAndResetOtherPlayers(currentPlayerId);
// Let MediaWiki handle the rest (converting to full player)
// We need to remove our custom handler temporarily to avoid infinite recursion
$(this).off('click.audioController');
$(this)[0].click();
}
});
}
// Initialize all existing play buttons
$('.mw-tmh-play').each(function() {
initializePlayButton($(this));
});
// Also monitor for play events on activated players
$(document).on('play', 'audio[id^="mwe_player_"]:not([id$="_placeholder"])', function() {
var currentPlayerId = this.id;
stopAndResetOtherPlayers(currentPlayerId);
});
// Handle the case where MediaWiki dynamically creates new players
// We'll use a MutationObserver to watch for new video-js elements
if (window.MutationObserver) {
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === 1) { // Element node
var $node = $(node);
// Check if the added node contains new play buttons
var newPlayButtons = $node.find('.mw-tmh-play').addBack('.mw-tmh-play');
newPlayButtons.each(function() {
initializePlayButton($(this));
});
}
});
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
});
$(document).ready(function () {
$('.contact-form-container').each(function() {
// Create the form HTML
var formHTML = '<form method="POST" action="https://script.google.com/macros/s/AKfycbzGYYHbCtVTjXPjTcYKA3wuK6ZAfKIiluw6sZKuWTZzVFnlnl-V9UYsVEroi1MzyIoUhg/exec">' +
'<input name="Email" type="email" placeholder="Email" required>' +
'<input name="Name" type="text" placeholder="Name" required>' +
'<button type="submit">Send</button>' +
'</form>';
// Insert the form HTML into the div
$(this).html(formHTML);
// Optional: Add event listener for form submission if you want to handle it with JS
$(this).find('form').on('submit', function(e) {
// You can add custom submission handling here if needed
console.log('Form submitted');
// If you want to handle the submission yourself, uncomment the next line
// e.preventDefault();
});
});
/* IFRAME COMMUNICATION */
(function() {
'use strict';
// Only run if we're in an iframe
if (window.parent !== window) {
// Wait for the page to load
$(function() {
// Configuration
var PARENT_ORIGIN = 'http://127.0.0.1:5500/wiki/index.html';
var CLICKABLE_ELEMENTS = [
'a', // Category links
'.audio-ref'
];
// Add click handlers to the specified elements
$(CLICKABLE_ELEMENTS.join(', ')).on('click', function(e) {
// Get element information
var elementInfo = {
type: 'elementClicked',
elementId: this.id || 'unnamed-element',
elementTag: this.tagName.toLowerCase(),
elementClass: this.className,
elementText: $(this).text().trim(),
timestamp: Date.now()
};
// Send message to parent React app
window.parent.postMessage(elementInfo, PARENT_ORIGIN);
console.log('Click detected and reported:', elementInfo);
});
console.log('Click detection initialized for iframe communication');
});
}
})();
/* SIDEBAR CUSTOMIZATION */
$(document).ready(function() {
// Get element's position relative to the viewport
function getElementTopPosition(selector) {
var element = $(selector);
if (element.length) {
var elementPosition = element.offset().top;
var scrollTop = $(window).scrollTop();
var positionInViewport = elementPosition - scrollTop;
// Store the position for later use
var storedPosition = elementPosition;
console.log('Element position stored:', storedPosition);
return storedPosition;
}
return 0;
}
// Store positions when page loads
var onePosition = getElementTopPosition('.sidebar-heading.one');
var twoPosition = getElementTopPosition('.sidebar-heading.two');
var threePosition = getElementTopPosition('.sidebar-heading.three');
// Select elements with the scroll-trigger class
$('.sidebar-heading.one').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: onePosition - 202
}, 300); // 300ms animation duration
});
$('.sidebar-heading.two').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: twoPosition - 240
}, 300); // 300ms
});
// Select elements with the scroll-trigger class
$('.sidebar-heading.three').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: threePosition - 275
}, 300); // 300ms animation duration
});
});
mw.hook('wikipage.content').add(function ($content) {
// Find all links in the content
var links = $content.find('a');
// Iterate through each link
links.each(function() {
var $link = $(this);
var html = $link.html();
// Check if the link contains the symbol (including variant selectors)
if (html && html.indexOf('▶') !== -1) {
// Replace the symbol with a span that has white color
var newHtml = html.replace(/▶[\uFE0E\uFE0F]?/g, '<span class="symbol-container" style="color: white;">▶</span>');
$link.html(newHtml);
}
});
});
function initializeAllVideoJS() {
var players = document.querySelectorAll('audio.video-js, video.video-js');
players.forEach(function(player) {
if (!player.player) { // Prevent double init
videojs(player);
}
});
}
$(document).ready(function() {
initializeAllVideoJS();
});
