//noinspection BadExpressionStatementJS
(function(window){
var replaceUrl = false;
var url = new URL(window.location.href);
var searchParams = new URLSearchParams(url.search);
if ('undefined' === typeof window.kuuid) {
setUuidParam();
}
if ('undefined' === typeof window.kll) {
setKllParam();
}
if ('undefined' === typeof window.kref) {
setKrefParam();
}
setKaffParam();
if (replaceUrl) {
window.history.replaceState(
null,
null,
url.toString()
);
}
function getCookie(name) {
var cookieRegex = '(?:(?:^|.*; *)' + name + ' *= *([^;]*).*$)|^.*$';
var cookie = document.cookie.match(cookieRegex)[1];
if (cookie) {
return decodeURIComponent(cookie);
}
}
function setCookie(name, value, options) {
options = options || {};
// If 'days' is provided, calculate max-age in seconds
if (options.days) {
options['max-age'] = options.days * 60 * 60 * 24;
delete options.days;
}
// Build the options string from the options object
var optionsStr = Object.keys(options).reduce(
function(acc, key) {
return acc + '; ' + key + '=' + options[key];
},
''
);
// Get the current document domain and split it by '.'
var domain = document.domain;
var parts = domain.split('.');
// Build an array of all possible domain variants
// For example, for "subdomain.abc.co.uk" this will yield:
// ["subdomain.abc.co.uk", "abc.co.uk", "co.uk"]
var domains = [];
if (parts.length > 1) {
for (var i = 0; i < parts.length - 1; i++) {
domains.push(parts.slice(i).join('.'));
}
} else {
domains = [domain];
}
// Set the cookie for each domain variant
for (var j = 0; j < domains.length; j++) {
document.cookie = name + '=' + encodeURIComponent(value) + optionsStr + '; path=/; domain=' + domains[j];
}
}
function generateUUID() {
var d = new Date().getTime();
var d2 = (
'undefined' !== typeof performance
&& performance.now
&& (performance.now() * 1000)
)
|| 0;
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16;
if (d > 0) {
r = (d + r) % 16 | 0;
d = Math.floor(d / 16);
} else {
r = (d2 + r) % 16 | 0;
d2 = Math.floor(d2 / 16);
}
return (
c === 'x'
? r
: (r & 0x3 | 0x8)
).toString(16);
});
}
function generateKuuid() {
var uuid = generateUUID();
var currentUnixTimestamp = Math.floor(Date.now() / 1000);
return uuid + '-' + currentUnixTimestamp;
}
function isInIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
function validateKuuid(uuid) {
// Explode the string by the dash
var segments = uuid.split('-');
// Check if the 6th segment exists & is a valid UNIX timestamp
if (
segments.length >= 6
&& segments[5]
) {
return isValidUnixTimestamp(segments[5]);
}
// If no 6th segment, check the current time against the threshold
var currentTimestamp = Math.floor(Date.now() / 1000); // Current UNIX timestamp in seconds
var thresholdTimestamp = 1728950400; // 15 Oct 2024 00:00:00 UNIX timestamp
// Validate if the current timestamp is before the threshold
return currentTimestamp < thresholdTimestamp;
}
function setUuidParam() {
var inIframe = isInIframe();
var uuid;
if (inIframe) {
if (searchParams.has('kuid')) {
uuid = searchParams.get('kuid');
} else {
uuid = getCookie('kuuid');
}
} else {
uuid = getCookie('kuuid');
if (!uuid) {
var kartraReferrer = searchParams.get('kref');
var kartraLid = searchParams.get('lid');
if (
searchParams.has('kuid')
&& kartraReferrer
&& (
document.referrer
|| kartraLid
)
) {
uuid = searchParams.get('kuid');
}
}
}
if (
!uuid
|| !validateKuuid(uuid)
) {
uuid = generateKuuid();
}
window.kuuid = uuid;
if (searchParams.has('kuid')) {
url.searchParams.delete('kuid');
replaceUrl = true;
}
}
function setKllParam() {
var kll = getCookie('kll');
if (!kll) {
if (searchParams.has('kll')) {
kll = searchParams.get('kll');
}
}
window.kll = kll;
if (searchParams.has('kll')) {
url.searchParams.delete('kll');
replaceUrl = true;
}
}
function setKrefParam() {
var referrer;
var inIframe = isInIframe();
if (inIframe) {
if (searchParams.has('referrer')) {
referrer = searchParams.get('referrer');
}
} else {
referrer = (document.referrer && document.referrer.split('?')[0]) || '';
}
if (searchParams.has('kref')) {
referrer = searchParams.get('kref');
replaceUrl = true;
url.searchParams.delete('kref');
}
window.kref = referrer;
}
function setKaffParam() {
if (
searchParams.has('kaff')
&& searchParams.has('kmid')
) {
var affiliateHash = searchParams.get('kaff');
var memberHash = searchParams.get('kmid');
var cookieName = 'kaff_' + memberHash;
url.searchParams.delete('kaff');
url.searchParams.delete('kmid');
setCookie(
cookieName,
affiliateHash,
{
path: '/',
days: 30,
secure: true,
samesite: 'none',
}
);
replaceUrl = true;
}
}
function isValidUnixTimestamp(timestamp) {
var timestampInteger = parseInt(timestamp, 10);
return !isNaN(timestampInteger)
&& timestampInteger > 0
&& timestamp.length === 10;
}
}(window));
;(function(window) {
'use strict';
window['kartra'] = 'undefined' === typeof window['kartra']
? []
: window['kartra'];
window['kartra']['video-embeds'] = 'undefined' === typeof window['kartra']['video-embeds']
? []
: window['kartra']['video-embeds'];
window['kartra']['pages'] = 'undefined' === typeof window['kartra']['pages']
? []
: window['kartra']['pages'];
window['kartra']['pages']['init'] = 'undefined' === typeof window['kartra']['pages']['init']
? []
: window['kartra']['pages']['init'];
var stickySensitivity = 80,
jQ;
loadCss();
jQuery(document).ready(function() {
jQ = jQuery.noConflict();
var $playlistContainers = jQ('[id="kartra_playlist_containeruWnBSN9ygaCp?autoplay=true&mute_on_start=true&show_controls=true"]').not('iframe');
$playlistContainers.each(function(i, el) {
var $playlistContainer = jQ(el);
if ($playlistContainer.parents('[data-delay-duration]').not('.js_delay_loaded').length < 1) {
initEmbeduWnBSN9ygaCp();
} else {
// works with delay code in pages-skeleton.js
$playlistContainer
.attr('data-playlist-hashed', 'uWnBSN9ygaCp')
.attr('data-delayed-type', 'playlist')
.addClass('js_delayed');
window['kartra']['pages']['init']['playlist'] = function($container) {
window['kartra']['video-embeds'][$container.attr('data-playlist-hashed')]();
jQ(window).trigger('resize');
}
}
});
initEvents();
});
function loadCss() {
var cssPath = 'https://app.kartra.com/css/new/css/v5/stylesheets_frontend/video/video_wrapper/styles.css',
existingCssScript = document.querySelector('link[href="' + cssPath + '"]');
if (!existingCssScript) {
var cssLink = document.createElement('link');
cssLink.type = 'text/css';
cssLink.rel = 'stylesheet';
cssLink.href = cssPath;
document.head.appendChild(cssLink);
}
}
function initEmbeduWnBSN9ygaCp() {
var styleString = '\
',
$playlistContainers = jQ('[id="kartra_playlist_containeruWnBSN9ygaCp?autoplay=true&mute_on_start=true&show_controls=true"]').not('iframe');
$playlistContainers.each(function(i, el) {
var $container = jQ(el);
var $playlistOuterWrapper = jQ('');
var $playlistEmbedWrapper = jQ('');
var $playlistPlaceholder = jQ('');
var $videoShadow = jQ('');
var memberHash = $container.attr('data-kt-owner') || '';
var $iframe = generateIframe(memberHash);
$container.empty();
// For the same playlist, embed styling only once in page
if (0 === i) {
$container.append(styleString);
}
$playlistEmbedWrapper.append($iframe);
$playlistOuterWrapper.append($playlistEmbedWrapper);
$container
.addClass('js_kartra_playlist_container kartra_playlist_containeruWnBSN9ygaCp')
.append($playlistOuterWrapper)
.append($playlistPlaceholder)
.append($videoShadow);
$iframe.on('load', function() {
var playlistHeight = $container.outerHeight(),
position = playlistHeight/2 + $container.offset().top + stickySensitivity;
position = Math.round(position);
// Make it from the bottom half of the video
$container.attr('data-original-position', position);
$container.addClass('js_video_embed_loaded');
});
});
}
function initEvents() {
jQ(window).on('message', function(event) {
var messageData = event.originalEvent.data;
if ('undefined' !== typeof(messageData)) {
if (
'kt-video-play-uWnBSN9ygaCp' === messageData['message']
|| 'kt-video-play-sticky-uWnBSN9ygaCp' === messageData['message']
|| 'kt-video-pause-uWnBSN9ygaCp' === messageData['message']
|| 'kt-video-complete-uWnBSN9ygaCp' === messageData['message']
|| 'kt-video-loaded' === messageData['message']
) {
if (
'undefined' === typeof messageData['payload']
|| 'undefined' === typeof messageData['payload']['frame']
) {
return false;
}
var $playlistIframe = jQ('.js_kartra_playlist_container iframe[name="' + messageData['payload']['frame'] + '"]');
if ($playlistIframe.length) {
var $playlistContainer = $playlistIframe.closest('.js_kartra_playlist_container'),
$stickyPlaylist = jQ('.js_kartra_video_container.kartra-video-sticky-top, .js_kartra_playlist_container.kartra-video-sticky-top'),
frameWindow = $playlistIframe[0].contentWindow ?
$playlistIframe[0].contentWindow : $playlistIframe[0].contentDocument.defaultView;
switch(messageData['message']) {
case 'kt-video-play-sticky-uWnBSN9ygaCp':
$playlistContainer.addClass('js_video_enable_sticky');
if (
$stickyPlaylist.length
&& !$stickyPlaylist.is($playlistContainer)
) {
closeStickyPlaylist($stickyPlaylist, true);
}
break;
case 'kt-video-pause-uWnBSN9ygaCp':
case 'kt-video-complete-uWnBSN9ygaCp':
$playlistContainer.removeClass('js_video_enable_sticky');
break;
case 'kt-video-loaded':
frameWindow.postMessage({
message: 'kt-video-embed-domain',
payload: {
location: window.location.href
}
}, '*');
break;
default:
if ($stickyPlaylist.length) {
closeStickyPlaylist($stickyPlaylist, true);
}
}
}
}
}
});
}
function generateIframe(memberHash) {
var iframeSrc = 'https://app.kartra.com/video_front/pages_playlist_preview/uWnBSN9ygaCp?autoplay=true&mute_on_start=true&show_controls=true';
var urlParams = getUrlParams();
var kartraPage = getKartraPage();
var referrer = '';
var uuid = window.kuuid;
var affiliateData = memberHash && checkForAffiliate(memberHash);
if (kartraPage) {
referrer = kartraPage;
} else {
referrer = window.location.href.split('?')[0];
}
for (var param of urlParams) {
iframeSrc += '&' + param.key + '=' + encodeURIComponent(param.value);
}
iframeSrc += '&referrer=' + encodeURIComponent(referrer);
iframeSrc += '&kuid=' + encodeURIComponent(uuid);
if (affiliateData) {
iframeSrc += '&kaff=' + encodeURIComponent(affiliateData);
}
return jQ('