function t937_init(recid, styles) {
var rec = document.getElementById('rec' + recid);
if (!rec) return;
var windowWidth = window.innerWidth;
var screenMin = rec.getAttribute('data-screen-min');
var screenMax = rec.getAttribute('data-screen-max');
if (screenMin && windowWidth < parseInt(screenMin, 10)) return false;
if (screenMax && windowWidth > parseInt(screenMax, 10)) return false;
var playlist = rec.querySelector('.t937__playlist-wrap');
var videoColumn = rec.querySelector('.t937__col_video');
var videoData = t937_parseData(recid);
var params = t937_getUrlParametrs(recid);
var activeVideoId = params.activeVideoId;
t937_setSizes(recid, styles);
t937_renderVideoCount(videoData, recid, styles);
t937_renderPlaylist(videoData, activeVideoId, recid, styles);
t937_renderVideoFrame(videoData, activeVideoId, recid, styles);
if (videoColumn) videoColumn.style.height = '';
if (playlist) playlist.style.visibility = 'visible';
t937_addEvents(recid, styles);
}
function t937_getUrlParametrs(recid) {
var activeRecId;
var activeVideoId;
var hash = window.location.hash;
if (hash && hash.indexOf('#tlection=') === -1) {
activeRecId = recid;
activeVideoId = 1;
} else {
var params = hash.replace('#tlection=', '').split('_');
activeRecId = params[0];
activeVideoId = +recid === +activeRecId ? params[1] : 1;
}
return {
activeRecId: activeRecId,
activeVideoId: activeVideoId,
};
}
function t937_parseData(recid) {
var rec = document.getElementById('rec' + recid);
if (!rec) return;
var recData = rec ? rec.querySelector('.t937__data') : null;
var data = recData ? recData.innerHTML : '';
var videos = [];
if (data) {
data = data.replace(/&/gi, '&');
var segments = data.split('\n');
for (var i = 0; i < segments.length; i++) {
/* url; title; time; description */
var segment = segments[i];
var parts = segment.split(';');
var video = t937_getVideoData(parts);
if (video.url || video.section) {
videos.push(video);
}
}
}
return videos;
}
function t937_getVideoData(data) {
/* If string contains '[...]', return as not a video data but section */
var first = data[0].trim();
if (first.indexOf('[') === 0 && first.indexOf(']') === first.length - 1) {
return {
section: first.slice(1, -1),
};
}
var url = data[0] && data[0].length ? data[0].trim() : null;
var title = data[1] ? data[1].trim() : null;
var time = data[2] ? data[2].trim() : null;
var description = data[3] ? data[3].trim() : null;
var type = null;
if (/youtube.com|youtu.be/gi.test(url)) {
type = 'youtube';
} else if (/vimeo.com/gi.test(url)) {
type = 'vimeo';
} else if (/rutube.ru/gi.test(url)) {
type = 'rutube';
} else if (/kinescope.io/gi.test(url)) {
type = 'kinescope';
} else if (/vk.com|vk.ru|vkvideo.ru/gi.test(url)) {
type = 'vkvideo';
// В сервисе boomstream есть ссылки формата .mp4
// Их лучше загружать в тег video, чтобы применялись все настройки видео
} else if (/boomstream.com/gi.test(url) && !/.mp4/gi.test(url)) {
type = 'boomstream';
} else if (/.mp4/gi.test(url)) {
type = 'mp4';
} else if (/.webm/gi.test(url)) {
type = 'webm';
} else {
type = 'iframe';
}
return {
url: url,
title: title,
time: time,
description: description,
type: type,
};
}
function t937_renderPlaylist(videoData, activeVideoId, recid, styles) {
var rec = document.getElementById('rec' + recid);
var container = rec.querySelector('.t937__playlist');
if (container) container.dataVideoContent = videoData;
if (container) container.dataPlaylistStyles = styles;
var videoCount = 1;
t937_setSizes(recid, styles);
if (container) container.innerHTML = '';
/* Define styles */
var mainColor = styles.mainColor.length ? 'color: ' + styles.mainColor + ';' : '';
var secondaryColor = styles.secondaryColor.length ? 'color: ' + styles.secondaryColor + ';' : '';
var border = styles.borderColor.length ? 'border-bottom: 1px solid ' + styles.borderColor + ';' : '';
t937_renderFade(recid, styles.bgColor);
for (var i = 0; i < videoData.length; i++) {
var data = videoData[i];
var id = i + 1;
var isActive = Number(id) === Number(activeVideoId);
var item;
if (Object.prototype.hasOwnProperty.call(data, 'section')) {
item = document.createElement('div');
item.classList.add('t937__playlist-item');
item.classList.add('t937__playlist-item_section');
item.setAttribute('style', border);
var itemChild = document.createElement('div');
itemChild.classList.add('t937__playlist-section');
itemChild.classList.add('t-name');
itemChild.classList.add('t-name_xs');
itemChild.setAttribute('style', mainColor);
itemChild.textContent = data.section;
item.insertAdjacentElement('beforeend', itemChild);
} else {
var title = data.title && data.title.length ? data.title : t937_translate('videoTitle');
var time = data.time ? data.time : '';
var linkBgColor = isActive && styles.linkBgColor.length ? 'background-color: ' + styles.linkBgColor + ';' : '';
item = document.createElement('div');
item.classList.add('t937__playlist-item');
item.setAttribute('data-video-id', id.toString());
item.setAttribute('style', border);
item.setAttribute('onclick', 'window.t937_onVideoClick(' + id + ', ' + recid + ')');
var playlistLink = document.createElement('div');
if (isActive) {
playlistLink.classList.add('t937__playlist-link');
playlistLink.classList.add('t-text');
playlistLink.classList.add('t-text_xs');
playlistLink.classList.add('t937__playlist-link_active');
} else {
playlistLink.classList.add('t937__playlist-link');
playlistLink.classList.add('t-text');
playlistLink.classList.add('t-text_xs');
}
playlistLink.setAttribute('style', linkBgColor);
var playlistNumber = document.createElement('div');
playlistNumber.classList.add('t937__playlist-number');
playlistNumber.setAttribute('style', secondaryColor);
playlistNumber.textContent = videoCount.toString();
var playlistTitle = document.createElement('div');
playlistTitle.classList.add('t937__playlist-title');
playlistTitle.setAttribute('style', mainColor);
playlistTitle.innerHTML = title;
/*var titleArray = title.split('
');
titleArray.forEach(function (title, i) {
var span = document.createElement('span');
span.textContent = title.toString();
var br = document.createElement('br');
playlistTitle.appendChild(span);
if (i !== titleArray.length - 1) {
playlistTitle.appendChild(br);
}
});*/
var playlistTime = document.createElement('div');
playlistTime.classList.add('t937__playlist-time');
playlistTime.setAttribute('style', secondaryColor);
playlistTime.textContent = time;
playlistLink.insertAdjacentElement('beforeend', playlistNumber);
playlistLink.insertAdjacentElement('beforeend', playlistTitle);
playlistLink.insertAdjacentElement('beforeend', playlistTime);
item.insertAdjacentElement('beforeend', playlistLink);
item.addEventListener('mousemove', function (e) {
var currentItem = e.target.closest('.t937__playlist-item');
currentItem.style.backgroundColor = styles.linkBgColor.length ? styles.linkBgColor : '#F0F0F0';
});
item.addEventListener('mouseout', function (e) {
var currentItem = e.target.closest('.t937__playlist-item');
currentItem.style.backgroundColor = '';
});
videoCount++;
}
if (container) container.insertAdjacentElement('beforeend', item);
}
}
function t937_renderVideoFrame(data, activeVideoId, recid) {
var rec = document.getElementById('rec' + recid);
var frame;
var video;
var container = rec ? rec.querySelector('.t937__video') : null;
var height = container ? container.offsetWidth * 0.5625 : 0;
if (container) container.classList.remove('t937__video_empty');
var id;
/* check that data[activeVideoId] is video, not a section */
for (var i = activeVideoId - 1; i < data.length; i++) {
if (data[i].url) {
video = data[i];
t937_renderDescription(video, recid);
break;
}
}
var optionsIframe = {
height: height,
type: video ? video.type : '',
};
if (!data.length || !video || !video.type) {
if (container) container.classList.add('t937__video_empty');
frame = document.createElement('div');
frame.classList.add('t937__system-message');
frame.textContent = !data.length ? t937_translate('noData') : t937_translate('wrongFormat');
} else if (video.type === 'youtube') {
var regex = /youtu(?:.*\/v\/|.*v=|\.be\/)([A-Za-z0-9_-]{11})/;
id = video.url.match(regex);
if (id !== null) id = id[1];
optionsIframe.src = 'https://www.youtube.com/embed/' + id + '?rel=0&fmt=18&html5=1&enablejsapi=1';
frame = t937_createIframe(optionsIframe);
} else if (video.type === 'vimeo') {
var idMatch = /vimeo[^/]*\/(\d+)\/?(\w*)\/?/i.exec(video.url);
id = idMatch ? idMatch[1] : null;
var hash = idMatch ? '?h=' + idMatch[2] : null;
var timecodeMatch = /#t=(\d*h)?(\d*m)?\d*s$/i.exec(video.url);
var timecode = timecodeMatch ? '/' + timecodeMatch[0] : '';
if (!id) {
if (container) container.classList.add('t937__video_empty');
frame = document.createElement('div');
frame.classList.add('t937__system-message');
frame.textContent = t937_translate('wrongFormat');
} else {
optionsIframe.src = 'https://player.vimeo.com/video/' + id + hash + timecode;
frame = t937_createIframe(optionsIframe);
}
} else if (video.type === 'kinescope') {
var regExp = /kinescope\.io\/(?:embed\/|pl\/)?([a-zA-Z0-9-]+)/;
var match = video.url.match(regExp);
var videoId = match ? match[1] : false;
optionsIframe.src = 'https://kinescope.io/embed/' + videoId;
frame = t937_createIframe(optionsIframe);
} else if (video.type === 'rutube') {
var regExp = /(?:https?:\/\/)?(?:www\.)?(?:rutube\.ru\/(?:shorts|video|play\/embed|embed|video\/private)\/)([a-f0-9]{32})(?:\/\?p=([a-zA-Z0-9_-]+))?/;
var match = video.url.match(regExp);
var videoId = match ? match[1] : false;
var videoHash = match ? match[2] : false;
optionsIframe.src = 'https://rutube.ru/embed/' + videoId + (videoHash ? '?p=' + videoHash : '');
frame = t937_createIframe(optionsIframe);
} else if (video.type === 'vkvideo') {
var regExp = /(?:video|video_ext\.php\?oid=|clip=?|)(-?\d+)_(\d+)|oid=(-?\d+)&id=(\d+)(?:.*?hash=([a-f0-9]+))?/;
var match = video.url.match(regExp);
var oid = '';
var id = '';
var videoHash = '';
if (match) {
oid = match[1] || match[3];
id = match[2] || match[4];
if (!videoHash && match[5]) videoHash = match[5];
}
optionsIframe.src = 'https://vkvideo.ru/video_ext.php?oid=' + oid + '&id=' + id + '&hd=2' + (videoHash ? '&hash=' + videoHash : '');
frame = t937_createIframe(optionsIframe);
} else if (video.type === 'boomstream') {
optionsIframe.src = video.url;
frame = t937_createIframe(optionsIframe);
} else if (video.type === 'iframe') {
optionsIframe.src = video.url;
frame = t937_createIframe(optionsIframe);
} else if (video.type === 'mp4' || video.type === 'webm') {
frame = document.createElement('video');
frame.classList.add('t937__video-frame');
frame.classList.add('t937__video-frame_html5');
frame.controls = true;
frame.title = 'html5-player';
frame.style.width = '100%';
frame.height = height;
var source = document.createElement('source');
var sourceType = 'video/' + video.type;
source.src = video.url;
source.setAttribute('type', sourceType);
frame.insertAdjacentElement('afterbegin', source);
}
if (container) {
container.innerHTML = '';
container.insertAdjacentElement('beforeend', frame);
}
}
function t937_createIframe(options) {
var frame = document.createElement('iframe');
var videoClass = 't937__video-frame_' + options.type;
frame.classList.add('t937__video-frame');
frame.classList.add(videoClass);
frame.width = '100%';
frame.height = options.height;
frame.src = options.src;
frame.frameBorder = '0';
frame.setAttribute('allowfullscreen', '');
frame.setAttribute('allow', 'autoplay; fullscreen; picture-in-picture; encrypted-media; gyroscope; accelerometer; clipboard-write;');
return frame;
}
function t937_renderDescription(videoData, recid) {
var rec = document.getElementById('rec' + recid);
var wrapper = rec ? rec.querySelector('.t937__col_description') : null;
var titleContainer = wrapper ? wrapper.querySelector('.t937__video-title') : null;
var descriptionContainer = wrapper ? wrapper.querySelector('.t937__video-description') : null;
if (wrapper) wrapper.classList.add('t937__col_hidden');
if (titleContainer) titleContainer.innerHTML = '';
if (descriptionContainer) descriptionContainer.innerHTML = '';
if (!videoData.description) return;
if (wrapper) wrapper.classList.remove('t937__col_hidden');
var title = videoData.title && videoData.title.length ? videoData.title : t937_translate('videoTitle');
descriptionContainer.innerHTML = videoData.description;
titleContainer.innerHTML = title;
/* var descriptionContent = t937_parseDescription(videoData.description);
var titleArray = title.split('
');
titleArray.forEach(function (title, i) {
var span = document.createElement('span');
span.textContent = title.toString();
var br = document.createElement('br');
titleContainer.appendChild(span);
if (i !== titleArray.length - 1) {
titleContainer.appendChild(br);
}
});
Array.prototype.forEach.call(descriptionContent, function (content) {
if (descriptionContainer) descriptionContainer.insertAdjacentElement('beforeend', content);
});*/
}
function t937_renderVideoCount(data, recid, styles) {
var rec = document.getElementById('rec' + recid);
var subheading = rec ? rec.querySelector('.t937__subheading-title') : null;
var icon = rec ? rec.querySelector('.t937__subheading-icon') : null;
var size = 0;
var color = styles.secondaryColor.length ? styles.secondaryColor.replace('#', '%23') : '%23111111';
if (icon) icon.style.backgroundImage = 'url("data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 16 16\' width=\'16\' height=\'16\'%3E%3Ctitle%3Evideo playlist%3C/title%3E%3Cg class=\'nc-icon-wrapper\' stroke-width=\'1\' fill=' +
'\'' + color + '\'' + ' stroke=' + '\'' + color + '\'' +
'%3E%3Crect x=\'0.5\' y=\'2.5\' width=\'15\' height=\'12\' rx=\'1\' fill=\'none\' stroke=' + '\'' + color + '\'' +
' stroke-linecap=\'round\' stroke-linejoin=\'round\'/%3E%3Cpolygon points=\'6.5 5.5 11.5 8.5 6.5 11.5 6.5 5.5\' fill=\'none\' stroke-linecap=\'round\' stroke-linejoin=\'round\' data-color=\'color-2\'/%3E%3Cline x1=\'3.5\' y1=\'0.5\' x2=\'12.5\' y2=\'0.5\' fill=\'none\' stroke=' +
'\'' + color + '\'' + ' stroke-linecap=\'round\' stroke-linejoin=\'round\'/%3E%3C/g%3E%3C/svg%3E"';
for (var item in data) {
if (!data[item].section) {
size++;
}
}
var videoPart = t937_translate('videoPart');
if (subheading) subheading.textContent = size + ' ' + videoPart;
}
function t937_renderFade(recid, color) {
color = color.length ? color : '#ffffff';
var rec = document.getElementById('rec' + recid);
var playlistFade = rec ? rec.querySelector('.t937__playlist-fade') : null;
var colorFrom = t937_hex2rgb(color, 0);
var colorTo = t937_hex2rgb(color, 1);
if (playlistFade) playlistFade.style.backgroundImage = 'linear-gradient(' + colorFrom + ' 0%, ' + colorTo + ' 90%)';
}
/*function t937_parseDescription(string) {
var result = [];
var parts = string.split('
');
var res;
parts.forEach(function (part) {
if (!part.length) {
res = document.createElement('br');
result.push(res);
} else {
res = document.createElement('p');
res.classList.add('t937__paragraph');
res.textContent = part;
result.push(res);
}
});
return result;
}*/
function t937_setSizes(recid, styles) {
var rec = document.getElementById('rec' + recid);
var playlistWrapper = rec ? rec.querySelector('.t937__playlist-wrap') : null;
var iframe = rec ? rec.querySelector('.t937__video-frame') : null;
var playlistCol = rec ? rec.querySelector('.t937__col_playlist') : null;
var description = rec ? rec.querySelector('.t937__description') : null;
var videoCol = rec ? rec.querySelector('.t937__video') : null;
var videoColWidth = videoCol ? videoCol.offsetWidth : 0;
/* Set 9:16 player sides */
var height = videoColWidth * 0.5625;
if (iframe) iframe.setAttribute('height', height.toString());
if (window.innerWidth >= 960) {
if (description) description.style.width = videoColWidth + 'px';
if (playlistWrapper) playlistWrapper.style.height = height + 'px';
if (playlistWrapper) playlistWrapper.style.maxHeight = '';
if (styles.playlistWidth.length) {
if (playlistCol) playlistCol.style.width = parseInt(styles.playlistWidth, 10) + 'px';
}
} else {
if (playlistWrapper) playlistWrapper.style.maxHeight = height + 'px';
if (playlistWrapper) playlistWrapper.style.height = '';
if (playlistCol) playlistCol.style.width = '';
if (description) description.style.width = '';
}
}
function t937_translate(keyword) {
var dict = [];
dict['videoTitle'] = {
RU: 'Без названия',
EN: 'Untitled video',
FR: 'Vidéo sans titre',
DE: 'Video ohne Titel',
ES: 'Video sin título',
PT: 'Bez tytułu wideo',
UK: 'Відео без назви',
JA: '無題の動画',
ZH: '无标题的视频',
PL: 'Bez tytułu',
};
dict['videoPart'] = {
RU: 'видео',
EN: 'videos',
FR: 'vidéos',
DE: 'videos',
ES: 'videos',
PT: 'filmy',
UK: 'відео',
JA: 'ビデオ',
ZH: '影片',
PL: 'video',
};
dict['noData'] = {
RU: 'Пожалуйста, добавьте хотя бы одно видео в плейлист',
EN: 'Please add at least one video to the playlist',
UK: 'Будь ласка, додайте хоча б одне відео в плейлист',
PL: 'Proszę dodać jeden filmik do listy',
};
dict['wrongFormat'] = {
RU: 'Пожалуйста, проверьте корректность заполненных данных',
EN: 'Please check that the data is filled in correctly',
UK: 'Будь ласка, перевірте коректність заповнених даних',
PL: 'Sprawdź poprawność danych',
};
var lang = (window.navigator.userLanguage || window.navigator.language).toUpperCase().slice(0, 2);
// Language override based on attribute
var allrecords = document.getElementById('allrecords');
if (allrecords) {
var projectLang = allrecords.getAttribute('data-tilda-project-lang');
if (projectLang) {
lang = projectLang;
}
}
if (dict[keyword] !== undefined) {
if (dict[keyword][lang] !== undefined && dict[keyword][lang] !== '') {
return dict[keyword][lang];
} else {
return dict[keyword]['EN'];
}
}
return 'Text not found #' + keyword;
}
function t937_hex2rgb(color, opacity) {
// Парсинг глобального стиля цвета
const varRegexp = /var\((--uc-color-color-[a-zA-Z0-9]+),\s*([a-fA-F0-9#]+)\)/;
const varMatch = varRegexp.exec(color);
let hex = color;
if (varMatch && varMatch[1]) {
const varName = varMatch[1];
const bodyStyle = window.getComputedStyle(document.body);
hex = bodyStyle.getPropertyValue(varName) || varMatch[2];
}
const components = /^#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})$/i.exec(hex);
if (!components) return `rgba(0,0,0,${opacity})`;
const rgb = components.slice(1).map(comp => parseInt(comp, 16) || 0);
return `rgba(${rgb.join(',')},${opacity})`;
}
function t937_addEvents(recid, styles) {
window.addEventListener('resize', t_throttle(function () {
t937_setSizes(recid, styles);
}));
if (typeof jQuery !== 'undefined') {
$('.t937').bind('displayChanged', function () {
t937_setSizes(recid, styles);
});
} else {
var currentBlocks = document.querySelectorAll('.t937');
Array.prototype.forEach.call(currentBlocks, function (block) {
block.addEventListener('displayChanged', function () {
t937_setSizes(recid, styles);
});
});
}
/* Render/Remove playlist borrom fade */
var rec = document.getElementById('rec' + recid);
var playlistWrap = rec ? rec.querySelector('.t937__playlist-wrap') : null;
var playlistFade = rec ? rec.querySelector('.t937__playlist-fade') : null;
if (playlistWrap) {
playlistWrap.addEventListener('scroll', function () {
var currentHeight = playlistWrap.offsetHeight;
var scrollTop = playlistWrap.scrollTop;
var scrollHeight = playlistWrap.scrollHeight;
var marginBottom = 30;
if (currentHeight + scrollTop >= scrollHeight - marginBottom) {
if (playlistFade) playlistFade.style.backgroundImage = '';
} else {
t937_renderFade(recid, styles.bgColor);
}
});
}
}
function t937_onVideoClick(id, recid) {
var rec = document.getElementById('rec' + recid);
var container = rec ? rec.querySelector('.t937__playlist') : null;
var videoData = container ? container.dataVideoContent : null;
var styles = container ? container.dataPlaylistStyles : null;
window.location.hash = 'tlection=' + recid + '_' + id;
t937_renderPlaylist(videoData, id, recid, styles);
t937_renderVideoFrame(videoData, id, recid, styles);
t937_playVideo(recid);
}
function t937_playVideo(recid) {
var rec = document.getElementById('rec' + recid);
var videoFrame = rec ? rec.querySelector('.t937__video-frame') : null;
if (videoFrame && videoFrame.classList.contains('t937__video-frame_youtube')) {
videoFrame.addEventListener('load', function () {
var command = 'playVideo';
videoFrame.contentWindow.postMessage('{"event":"command","func":"' + command + '","args":""}', '*');
});
}
}
if (document.readyState !== 'loading') {
if (document.body) {
document.body.style['-webkit-text-size-adjust'] = '100%';
}
} else {
document.addEventListener('DOMContentLoaded', function () {
if (document.body) {
document.body.style['-webkit-text-size-adjust'] = '100%';
}
});
}