MediaWiki:Common.js: различия между версиями
реанимация вк Метка: отменено |
Возврат рабочей версии вк Метка: ручная отмена |
||
| Строка 68: | Строка 68: | ||
/* Вставка VK-видео на страницу для шаблона {{VKVideo}} */ | /* Вставка VK-видео на страницу для шаблона {{VKVideo}} */ | ||
(function() { | (function() { | ||
'use strict'; | 'use strict'; | ||
function initVKVideo() { | function initVKVideo() { | ||
var containers = document.querySelectorAll('.vk-video-js'); | var containers = document.querySelectorAll('.vk-video-js'); | ||
for (var i = 0; i < containers.length; i++) { | for (var i = 0; i < containers.length; i++) { | ||
var container = containers[i]; | var container = containers[i]; | ||
var oid = container.getAttribute('data-oid'); | var oid = container.getAttribute('data-oid'); | ||
var id = container.getAttribute('data-id'); | var id = container.getAttribute('data-id'); | ||
var width = container.getAttribute('data-width') || '560'; | var width = container.getAttribute('data-width') || '560'; | ||
var height = container.getAttribute('data-height') || '315'; | var height = container.getAttribute('data-height') || '315'; | ||
width = parseInt(width) || 560; | width = parseInt(width) || 560; | ||
height = parseInt(height) || 315; | height = parseInt(height) || 315; | ||
if (width > 2000) width = 2000; | |||
if (height < 100) height = 100; | |||
if (height > 2000) height = 2000; | |||
if (oid && id && oid !== 'null' && id !== 'null' && /^[-_a-zA-Z0-9]+$/.test(oid) && /^[-_a-zA-Z0-9]+$/.test(id)) { | |||
var iframe = document.createElement('iframe'); | |||
iframe.src = 'https://vk.com/video_ext.php?oid=' + encodeURIComponent(oid) + '&id=' + encodeURIComponent(id); | |||
iframe.width = width; | |||
if (oid && id && oid !== 'null' && id !== 'null' && /^[-_a-zA-Z0-9]+$/.test(oid) && /^[-_a-zA-Z0-9]+$/.test(id)) { | iframe.height = height; | ||
var iframe = document.createElement('iframe'); | iframe.frameBorder = '0'; | ||
iframe.src = 'https://vk.com/video_ext.php?oid=' + encodeURIComponent(oid) + '&id=' + encodeURIComponent(id); | iframe.allowFullscreen = true; | ||
iframe.width = width; | |||
iframe.height = height; | |||
iframe.frameBorder = '0'; | |||
iframe.allowFullscreen = true; | |||
iframe.sandbox = 'allow-scripts allow-same-origin allow-presentation allow-fullscreen'; | iframe.sandbox = 'allow-scripts allow-same-origin allow-presentation allow-fullscreen'; | ||
iframe.allow = 'fullscreen'; | iframe.allow = 'fullscreen'; | ||
iframe.style.border = 'none'; | |||
while (container.firstChild) { | |||
container.removeChild(container.firstChild); | |||
} | |||
container.appendChild(iframe); | |||
} else { | |||
var errorDiv = document.createElement('div'); | |||
errorDiv.style.cssText = 'color: red; padding: 10px; text-align: center; border: 1px solid red;'; | |||
errorDiv.textContent = 'Ошибка: неверные параметры видео'; | |||
while (container.firstChild) { | |||
container.removeChild(container.firstChild); | |||
} | |||
container.appendChild(errorDiv); | |||
} | |||
} | |||
} | |||
while (container.firstChild) { | |||
container.removeChild(container.firstChild); | |||
} | |||
container.appendChild(errorDiv); | |||
} | |||
} | |||
} | |||
if (document.readyState === 'loading') { | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', initVKVideo); | document.addEventListener('DOMContentLoaded', initVKVideo); | ||
} else { | } else { | ||
initVKVideo(); | initVKVideo(); | ||
} | } | ||
})(); | })(); | ||