MediaWiki:Gadget-youtube.js
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));