MediaWiki:Common.js: различия между версиями
м В принципе лишние комменты |
Добавим тогда и Vimeo как представителя большой четвёрки видеохостингов в России Метка: отменено |
||
| Строка 160: | Строка 160: | ||
} | } | ||
})(); | |||
/* Функция для вставки Vimeo-видео на страницу для шаблона Vimeo, простая версия */ | |||
(function() { | |||
'use strict'; | |||
function initVimeoPlayers() { | |||
var containers = document.querySelectorAll('.vimeo-player-container'); | |||
if (containers.length === 0) return; | |||
if (typeof Vimeo === 'undefined') { | |||
var script = document.createElement('script'); | |||
script.src = 'https://player.vimeo.com/api/player.js'; | |||
script.onload = function() { | |||
setTimeout(createVimeoPlayers, 100); | |||
}; | |||
document.head.appendChild(script); | |||
} else { | |||
createVimeoPlayers(); | |||
} | |||
function createVimeoPlayers() { | |||
containers.forEach(function(container) { | |||
var videoId = container.getAttribute('data-vimeo-id'); | |||
var placeholder = container.querySelector('.vimeo-placeholder'); | |||
if (!videoId || !placeholder) return; | |||
var iframe = document.createElement('iframe'); | |||
iframe.src = 'https://player.vimeo.com/video/' + videoId + | |||
'?autoplay=0&title=0&byline=0&portrait=0&dnt=1'; | |||
iframe.width = '560'; | |||
iframe.height = '315'; | |||
iframe.frameBorder = '0'; | |||
iframe.allow = 'autoplay; fullscreen; picture-in-picture'; | |||
iframe.allowFullscreen = true; | |||
placeholder.parentNode.replaceChild(iframe, placeholder); | |||
}); | |||
} | |||
} | |||
if (document.readyState === 'loading') { | |||
document.addEventListener('DOMContentLoaded', initVimeoPlayers); | |||
} else { | |||
initVimeoPlayers(); | |||
} | |||
mw.hook('wikipage.content').add(initVimeoPlayers); | |||
})(); | })(); | ||