No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
// Wait for document ready | // Wait for document ready | ||
$(document).ready(function() { | $(document).ready(function() { | ||
// Target div where you want the player to appear | // Target div where you want the player to appear | ||
var targetDivSelector = '#top'; | |||
// Use MutationObserver to detect when video-js elements are created | // Use MutationObserver to detect when video-js elements are created | ||
var observer = new MutationObserver(function(mutations) { | |||
mutations.forEach(function(mutation) { | mutations.forEach(function(mutation) { | ||
if (mutation.addedNodes && mutation.addedNodes.length > 0) { | if (mutation.addedNodes && mutation.addedNodes.length > 0) { | ||
for ( | for (var i = 0; i < mutation.addedNodes.length; i++) { | ||
var node = mutation.addedNodes[i]; | |||
// Check if the added node is a video-js element or contains one | // Check if the added node is a video-js element or contains one | ||
if ($(node).hasClass('video-js') || $(node).find('.video-js').length > 0) { | if ($(node).hasClass('video-js') || $(node).find('.video-js').length > 0) { | ||
var vjsElement = $(node).hasClass('video-js') ? $(node) : $(node).find('.video-js'); | |||
// Store the original position for reference | // Store the original position for reference | ||
var originalParent = vjsElement.parent(); | |||
// Move the video-js player to the target div | // Move the video-js player to the target div | ||
| Line 41: | Line 40: | ||
}); | }); | ||
}); | }); | ||
// Add play buttons to spans with a specific class | // Add play buttons to spans with a specific class | ||
| Line 52: | Line 47: | ||
var $span = $(this); | var $span = $(this); | ||
$span.css({ | |||
'display': 'inline-flex', | 'display': 'inline-flex', | ||
'align-items': 'center' | 'align-items': 'center' | ||
| Line 63: | Line 58: | ||
.css({ | .css({ | ||
'margin-left': '10px', | 'margin-left': '10px', | ||
'cursor': 'pointer', | 'cursor': 'pointer', | ||
'background': 'transparent', | 'background': 'transparent', | ||
'color':'white' | 'color': 'white' | ||
}) | }) | ||
.click(function (e) { | .click(function (e) { | ||
| Line 91: | Line 85: | ||
/* IFRAME COMMUNICATION */ | /* IFRAME COMMUNICATION */ | ||
(function() { | (function() { | ||
'use strict'; | 'use strict'; | ||
| Line 104: | Line 96: | ||
var CLICKABLE_ELEMENTS = [ | var CLICKABLE_ELEMENTS = [ | ||
'a', // Category links | 'a', // Category links | ||
'.audio-ref' | '.audio-ref' | ||
]; | ]; | ||
| Line 124: | Line 115: | ||
console.log('Click detected and reported:', elementInfo); | console.log('Click detected and reported:', elementInfo); | ||
}); | }); | ||
| Line 131: | Line 121: | ||
} | } | ||
})(); | })(); | ||
/* SIDEBAR CUSTOMIZATION */ | /* SIDEBAR CUSTOMIZATION */ | ||
$(document).ready(function() { | $(document).ready(function() { | ||
// Get element's position relative to the viewport | // Get element's position relative to the viewport | ||
| Line 169: | Line 157: | ||
}); | }); | ||
$('.sidebar-heading.two').click(function() { | $('.sidebar-heading.two').click(function() { | ||
// Find the scrollable container | // Find the scrollable container | ||
var container = $('#topbar'); | var container = $('#topbar'); | ||
| Line 179: | Line 167: | ||
}); | }); | ||
// Select elements with the scroll-trigger class | |||
$('.sidebar-heading.three').click(function() { | $('.sidebar-heading.three').click(function() { | ||
// Find the scrollable container | // Find the scrollable container | ||
| Line 189: | Line 177: | ||
}, 300); // 300ms animation duration | }, 300); // 300ms animation duration | ||
}); | }); | ||
}); | }); | ||
| Line 218: | Line 205: | ||
}); | }); | ||
} | } | ||
$(document).ready(function() { | $(document).ready(function() { | ||
initializeAllVideoJS(); | initializeAllVideoJS(); | ||
}); | }); | ||
Revision as of 20:47, 4 May 2025
// Wait for document ready
$(document).ready(function() {
// Target div where you want the player to appear
var targetDivSelector = '#top';
// Use MutationObserver to detect when video-js elements are created
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes && mutation.addedNodes.length > 0) {
for (var i = 0; i < mutation.addedNodes.length; i++) {
var node = mutation.addedNodes[i];
// Check if the added node is a video-js element or contains one
if ($(node).hasClass('video-js') || $(node).find('.video-js').length > 0) {
var vjsElement = $(node).hasClass('video-js') ? $(node) : $(node).find('.video-js');
// Store the original position for reference
var originalParent = vjsElement.parent();
// Move the video-js player to the target div
if ($(targetDivSelector).length > 0) {
vjsElement.appendTo(targetDivSelector);
console.log('Moved video-js player to target div');
// Optional: Add logic to move it back when playback ends
vjsElement.find('video, audio').on('ended', function() {
vjsElement.appendTo(originalParent);
console.log('Moved video-js player back to original position');
});
}
}
}
}
});
});
// Start observing the document body for added video-js elements
observer.observe(document.body, {
childList: true,
subtree: true
});
});
// Add play buttons to spans with a specific class
mw.hook('wikipage.content').add(function ($content) {
// Target spans with your specific class, e.g., 'audio-text'
$content.find('span.audio-text').each(function () {
var $span = $(this);
$span.css({
'display': 'inline-flex',
'align-items': 'center'
});
// Create the play button
var $playButton = $('<button>')
.addClass('play-button')
.text('')
.css({
'margin-left': '10px',
'cursor': 'pointer',
'background': 'transparent',
'color': 'white'
})
.click(function (e) {
e.preventDefault();
// Add your play functionality here
// For example, read the text aloud or play an associated audio file
var textToSpeak = $span.text();
console.log('Playing:', textToSpeak);
// Example: Use the Web Speech API for text-to-speech
// Uncomment if you want to use this functionality
/*
if ('speechSynthesis' in window) {
var utterance = new SpeechSynthesisUtterance(textToSpeak);
speechSynthesis.speak(utterance);
}
*/
});
// Insert the play button after the span
$span.append($playButton);
});
});
/* 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();
});
