MediaWiki:Gadget-youtube.js

From RuneRealm Wiki

This is the current revision of this page, as edited by Alex (talk | contribs) at 00:10, 17 October 2024 (Created page with "→‎* * YouTube video embedder * Injects an iframe, rather than uploading the video to Wikia's video library * See https://runescape.wiki/w/Template:Youtube for further documentation: ;(function ($, document) { 'use strict'; if ($('.youtube').length == 0) { return; } function injectVideo() { var tags = $('.youtube'), i, contents, iframe; if (tags.length === 0) { return; }..."). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

After saving, you may need to bypass your browser's cache to see the changes. For further information, see Wikipedia:Bypass your cache.

  • In most Windows and Linux browsers: Hold down Ctrl and press F5.
  • In Safari: Hold down ⇧ Shift and click the Reload button.
  • In Chrome and Firefox for Mac: Hold down both ⌘ Cmd+⇧ Shift and press R.
/**
 * YouTube video embedder
 * Injects an iframe, rather than uploading the video to Wikia's video library
 * See https://runescape.wiki/w/Template:Youtube for further documentation
 */

;(function ($, document) {
    'use strict';
    if ($('.youtube').length == 0) {
    	return;
    }

    function injectVideo() {
        var tags = $('.youtube'),
            i,
            contents,
            iframe;

        if (tags.length === 0) {
            return;
        }

        for (i = 0; i < tags.length; i += 1) {
            contents = $(tags[i]).html().split('|');

            // for no arguments in template use
            if (contents[0] === 'ERROR') {
                return;
            }
            
            iframe = document.createElement('iframe');
            iframe.src = 'https://www.youtube.com/embed/' + contents[0];
            iframe.height = contents[1];
            iframe.width = contents[2];
            
            $(tags[i]).html(iframe);
            // reverse the display:none; set in the template
            $(tags[i]).show();
        }

        // hide the original link as there's already one in the player
        $('.original-link').hide();
    }
    
    $(function () {
        injectVideo();
    });

}(this.jQuery, this.document));