PC Gaming Shelter
An archive dedicated to preserving PC Gaming history and more

MediaWiki:Featured-video.js

From PC Gaming Shelter

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
(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);
  });
}());