User:K599/Vimeo.js

//Author: K599 / Kelvs599

//Code based on https://dev.fandom.com/wiki/MediaWiki:YoutubePlayer/code.js

//Loading this JavaScript allows Vimeo videos to be embedded. Go to your MediaWiki:Common.js, or wherever you're loading your JS, and either copy this page's code or insert the following line: //mw.loader.load('https://meta.miraheze.org/w/index.php?title=User:K599/Vimeo.js&action=raw&ctype=text/javascript');

//You embed by inserting the following code: // //The full list of parameters is as follows: // //Explanations for each parameter can be found on https://vimeo.zendesk.com/hc/en-us/articles/360001494447-Using-Player-Parameters //Default width and height is 640x360.

mw.hook('wikipage.content').add(function($content) {   $content.find('.vimeo:not(.loaded)').each(function { var $this = $(this), data = $this.data, uri = new mw.Uri('https://player.vimeo.com/video/'), width = typeof data.width === 'number' ? data.width + 'px' : String(data.width || '').trim, height = typeof data.height === 'number' ? data.height + 'px' : String(data.height || '').trim;

uri.path += String(data.id || '').trim; uri.query = { autoplay: String(data.autoplay ?? '').trim, loop: String(data.loop ?? '').trim, color: String(data.color || '').trim, portrait: String(data.portrait ?? '').trim, title: String(data.title ?? '').trim, byline: String(data.byline ?? '').trim, muted: String(data.muted ?? '').trim, autopause: String(data.autopause ?? '').trim };

$this.html(           $(' ', { src: uri.toString + '#t=' + encodeURIComponent(String(data.time || '').trim), style: 'width: ' + (width ? width : height ? 'calc(' + height + ' * 16 / 9)' : '640px') + '; height: ' + (height ? height : width ? 'calc(' + width + ' * 9 / 16)' : '360px') + ';', frameborder: '0', allowfullscreen: 'true', allow: 'autoplay; fullscreen; picture-in-picture;' })       ).addClass('loaded'); }); });