No edit summary |
No edit summary |
||
| Line 12: | Line 12: | ||
var audioId = audioElement.attr('id'); | var audioId = audioElement.attr('id'); | ||
console.log('Audio element found with ID:', audioId); | console.log('Audio element found with ID:', audioId); | ||
var originalLocation = $(this).closest('p'); | |||
setTimeout(function () { | setTimeout(function () { | ||
// Stop and remove any currently playing video-js in footer | // Stop and remove any currently playing video-js in footer | ||
var existingPlayer = $(targetDivSelector).find('.video-js'); | var existingPlayer = $(targetDivSelector).find('.video-js'); | ||
if (existingPlayer.length) { | if (existingPlayer.length) { | ||
console.log('Existing player found in footer. Stopping and removing.'); | console.log('Existing player found in footer. Stopping and removing.'); | ||
existingPlayer.find('video, audio').each(function () { | var media = existingPlayer.find('video, audio'); | ||
media.each(function () { | |||
this.pause(); | this.pause(); | ||
this.currentTime = 0; | this.currentTime = 0; | ||
| Line 25: | Line 29: | ||
} | } | ||
var vjsElement = $('.video-js.mwe_player_' + audioId.split('_').pop() + '-dimensions'); | var vjsElement = $('.video-js.mwe_player_' + audioId.split('_').pop() + '-dimensions'); | ||
| Line 41: | Line 44: | ||
console.log('Found video-js element:', vjsElement.attr('class')); | console.log('Found video-js element:', vjsElement.attr('class')); | ||
var originalParent = vjsElement.parent(); | |||
var | |||
vjsElement.appendTo(targetDivSelector); | |||
console.log('Moved video-js player to target div'); | |||
vjsElement.find('video, audio').on('ended', function () { | |||
vjsElement.appendTo(originalParent); | |||
console.log('Moved video-js player back to original position'); | |||
console.log(' | |||
}); | }); | ||
} else { | } else { | ||
| Line 66: | Line 61: | ||
} | } | ||
}); | }); | ||
}); | }); | ||
Revision as of 21:47, 4 May 2025
$(document).ready(function () {
var targetDivSelector = '#footer';
$('.mw-default-size').on('click', function () {
var audioElement = $(this).find('audio').first();
if (!audioElement.length) {
audioElement = $(this).closest('p').find('audio').first();
}
if (audioElement.length) {
var audioId = audioElement.attr('id');
console.log('Audio element found with ID:', audioId);
var originalLocation = $(this).closest('p');
setTimeout(function () {
// Stop and remove any currently playing video-js in footer
var existingPlayer = $(targetDivSelector).find('.video-js');
if (existingPlayer.length) {
console.log('Existing player found in footer. Stopping and removing.');
var media = existingPlayer.find('video, audio');
media.each(function () {
this.pause();
this.currentTime = 0;
});
existingPlayer.remove();
}
var vjsElement = $('.video-js.mwe_player_' + audioId.split('_').pop() + '-dimensions');
if (!vjsElement.length) {
vjsElement = $('.video-js.' + audioId + '-dimensions');
}
if (!vjsElement.length) {
vjsElement = $('.video-js').filter(function () {
return $(this).hasClass('vjs-has-started');
}).first();
}
if (vjsElement.length > 0 && $(targetDivSelector).length > 0) {
console.log('Found video-js element:', vjsElement.attr('class'));
var originalParent = vjsElement.parent();
vjsElement.appendTo(targetDivSelector);
console.log('Moved video-js player to target div');
vjsElement.find('video, audio').on('ended', function () {
vjsElement.appendTo(originalParent);
console.log('Moved video-js player back to original position');
});
} else {
console.log('Could not find video-js element or target div');
}
}, 500);
} else {
console.log('No audio element found near the clicked element');
}
});
});
/* 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();
});
