MediaWiki:Featured-video.js: Difference between revisions
From PC Gaming Shelter
Created page with "(function () { 'use strict'; var observedWrappers = new WeakSet(); var resizeObserver = 'ResizeObserver' in window ? new ResizeObserver(function (entries) { entries.forEach(function (entry) { resizeWrapper(entry.target); }); }) : null; var mutationObserver = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { resizeWrapper(mutation.target.closest('.embedvideo-wrapper')); });..." |
No edit summary |
||
| Line 2: | Line 2: | ||
'use strict'; | 'use strict'; | ||
function resizeVideo(figure) { | |||
var wrapper = figure.querySelector('.embedvideo-wrapper'); | |||
var config; | |||
if (!wrapper) { | if (!wrapper) { | ||
return; | return; | ||
} | } | ||
try { | |||
config = JSON.parse(figure.getAttribute('data-iframeconfig') || '{}'); | |||
} catch (error) { | |||
return; | return; | ||
} | } | ||
if (!(config.width > 0 && config.height > 0)) { | |||
if ( | return; | ||
} | } | ||
wrapper | wrapper.style.height = | ||
(figure.clientWidth * config.height / config.width) + 'px'; | |||
} | } | ||
function | function resizeVideos(root) { | ||
root.querySelectorAll(' | root.querySelectorAll('figure.embedvideo').forEach(resizeVideo); | ||
} | } | ||
mw.hook('wikipage.content').add(function ($content) { | mw.hook('wikipage.content').add(function ($content) { | ||
resizeVideos($content[0]); | |||
}); | }); | ||
window.addEventListener('resize', function () { | |||
resizeVideos(document); | |||
}); | |||
}()); | }()); | ||
Latest revision as of 19:47, 6 June 2026
(function () {
'use strict';
function resizeVideo(figure) {
var wrapper = figure.querySelector('.embedvideo-wrapper');
var config;
if (!wrapper) {
return;
}
try {
config = JSON.parse(figure.getAttribute('data-iframeconfig') || '{}');
} catch (error) {
return;
}
if (!(config.width > 0 && config.height > 0)) {
return;
}
wrapper.style.height =
(figure.clientWidth * config.height / config.width) + 'px';
}
function resizeVideos(root) {
root.querySelectorAll('figure.embedvideo').forEach(resizeVideo);
}
mw.hook('wikipage.content').add(function ($content) {
resizeVideos($content[0]);
});
window.addEventListener('resize', function () {
resizeVideos(document);
});
}());
