MediaWiki:Common.js: Difference between revisions
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. */ | ||
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(); | |||
}); | |||
}); | }); | ||
}); | }); | ||
}); | }); | ||
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(); }); }); }); });