MediaWiki:Common.js: Difference between revisions

From [STAGING] Destiny Wiki
Jump to navigation Jump to search
(modifying JS for preload)
(Preload video fix. Fix for disappearing videos.)
Tag: Reverted
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
const observer = new MutationObserver((mutations) => {
mw.loader.using('mediawiki.util').then(function () {
     mutations.forEach((mutation) => {
     document.addEventListener('DOMContentLoaded', function () {
         mutation.addedNodes.forEach((node) => {
         // Select all video elements
             if (node.tagName === 'VIDEO') {
        var videos = document.querySelectorAll('video');
                node.setAttribute('preload', 'none');
 
             }
        videos.forEach(function (video) {
             // Set the preload attribute to 'metadata'
            // This loads only the metadata and ensures the placeholder is displayed
            video.setAttribute('preload', 'metadata');
 
            // Add event listener to ensure the video plays correctly on click
            video.addEventListener('click', function () {
                video.play();
             });
         });
         });
     });
     });
});
});
// Start observing the document for changes
observer.observe(document.body, { childList: true, subtree: true });

Revision as of 21:07, 10 December 2024

/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using('mediawiki.util').then(function () {
    document.addEventListener('DOMContentLoaded', function () {
        // Select all video elements
        var videos = document.querySelectorAll('video');

        videos.forEach(function (video) {
            // Set the preload attribute to 'metadata'
            // This loads only the metadata and ensures the placeholder is displayed
            video.setAttribute('preload', 'metadata');

            // Add event listener to ensure the video plays correctly on click
            video.addEventListener('click', function () {
                video.play();
            });
        });
    });
});