(function(){"use strict";var iframe, wrapper, isFloating, floatingTimeout, floatingAnimation;var host = "https://delivery.youplay.se/api";var debounce = function(func, wait){var timeout;timeout = void 0;return function(){var args, context, later;context = this;args = arguments;later = function(){timeout = null;func.apply(context, args);};clearTimeout(timeout);timeout = setTimeout(later, wait);};};var helpers ={isFloating: function(){return isFloating;},openLink: function(link){window.location = link;},visible: false,setHeight: function(id, height){var iframe = document.getElementById(id);if(iframe){iframe.style.height = height + "px";iframe.height = height;}},setWidth: function(id, width){var iframe = document.getElementById(id);if(iframe){iframe.style.width = width + "px";iframe.width = width;}},addEvent: function(elem, type, eventHandle){if(!elem){return;} if(elem.addEventListener){elem.addEventListener(type, eventHandle, false);} else if(elem.attachEvent){elem.attachEvent("on" + type, eventHandle);} else{elem["on" + type] = eventHandle;}},onMessage: function(message){message = message.data;if(typeof message === "string" && message.indexOf("yp") > -1){message = message.split("|");var key = message[1];var value = message[2];switch(key){case "height": iframe.height = value;iframe.style.height = value + "px";break;}}},floatingEnabled: function(frame){function isValidFrame(){return frame &&frame.contentWindow &&frame.contentWindow.youplay;} function getVideo(){return frame && frame.contentWindow && frame.contentWindow.video;} function isFloatingEnabled(){var v = getVideo();return v && v.isFloatingEnabled && v.isFloatingEnabled();} function hasVideoStarted(){var v = getVideo();return v && v.player && v.player.hasStarted &&(v.player.hasStarted() || v.isAdPlaying());} return isValidFrame() && isFloatingEnabled() && hasVideoStarted();},scroll: function(id){var iframe = document.getElementById(id);if(this.floatingEnabled(iframe)){this.makeFloating(id, this.isWrapperVisible(iframe));} if(iframe && iframe.contentWindow && iframe.contentWindow.video){var s = this.isVisible(iframe);if(this.visible !== s){this.visible = s;iframe.contentWindow.video.setOnScreen(this.visible);setTimeout(function(){if(helpers.isVisible(iframe)){iframe.contentWindow.video.tracker.onScreen();}}, 1000);}}},isVisible: function(iframe){if(iframe && iframe.contentWindow && iframe.contentWindow){var elemTop = iframe.getBoundingClientRect().top;var elemBottom = iframe.getBoundingClientRect().bottom;if(!elemBottom){return false;} return(elemTop >= -(iframe.contentWindow.innerHeight / 2)) &&(elemBottom <=(window.innerHeight +(iframe.contentWindow.innerHeight / 2)));}},isWrapperVisible: function(iframe){if(iframe && iframe.contentWindow){var elemTop = wrapper.getBoundingClientRect().top;var elemBottom = wrapper.getBoundingClientRect().bottom;return(elemTop >= -(wrapper.clientHeight / 2)) &&(elemBottom <=(window.innerHeight +(wrapper.clientHeight / 2)));}},removeFormat: function(id){var el = document.querySelector("iframe#" + id);var container;if(el && el.parentNode){container = el.parentNode;container.removeChild(el);} if(container && container.parentNode){container.parentNode.removeChild(container);}},setupPassbackIframe: function(iframe, passback_url){const doc = iframe.contentDocument || iframe.contentWindow.document;const script = doc.createElement('script');script.src = passback_url + '?rand=' + Math.random();doc.head.appendChild(script);const resize = function(){if(doc.body){const bw = doc.body.scrollWidth;const bh = doc.body.scrollHeight;if(bw && iframe.width !== bw.toString()){iframe.width = bw;} if(bh && iframe.height !== bh.toString()){iframe.height = bh;}}};const rzIval = setInterval(resize, 200);setTimeout(function(){clearInterval(rzIval);}, 10000);},createPassbackIframe: function(id){const iframe = document.createElement("iframe");iframe.id = id + '-pb';iframe.width = 0;iframe.height = 0;iframe.style.border = "none";iframe.style.width = "100%";iframe.style.maxWidth = "100%";iframe.style.padding = "0";iframe.style.margin = "0";iframe.scrolling = "no";iframe.setAttribute("webkitallowfullscreen", "true");iframe.setAttribute("mozallowfullscreen", "true");iframe.setAttribute("allowfullscreen", "true");iframe.setAttribute("allow", "autoplay");iframe.style.position = "relative";iframe.style.backgroundColor = "transparent";iframe.className = "yp-iframe-passback";iframe.name = "yp-iframe-passback";return iframe;},replaceWithPassback: function(id, passback_url){const el = document.querySelector("iframe#" + id);let container;if(el && el.parentNode){container = el.parentNode;container.removeChild(el);} if(container && container.parentNode){const pbFrame = this.createPassbackIframe(id);const setup = this.setupPassbackIframe.bind(this);pbFrame.onload = function(){ setup(pbFrame, passback_url)};pbFrame.className = "yp-injected-passback";container.parentNode.replaceChild(pbFrame, container);}},runMainPlayer: function(partId, zoneId, overlay){var check = document.querySelector(".yp-main-player-iframe");if(check){return;} var div = document.createElement("div");div.style.width = "100%";div.style.maxWidth = "100%";div.style.height = "100%";div.style.position = "fixed";div.style.top = 0;div.style.left = 0;div.style.right = 0;div.style.bottom = 0;div.style.overflow = "auto";div.style.backgroundColor = "rgba(0, 0, 0, 0.7)";div.style.zIndex = 2147483647;var script = document.createElement("script");script.setAttribute("type", "text/javascript");script.setAttribute("charset", "utf-8");script.setAttribute("async", true);script.setAttribute("defer", true);script.setAttribute("class", "yp-main-player");var url = "https://main-player.youplay.se/bootstrap.js";url += "?zone_id=" + zoneId + "&part_id=" + partId;if(overlay){url += "&overlay=true";} script.setAttribute("src", url);document.body.appendChild(div);div.appendChild(script);},makeFloating: function(id, revert){if(window.youplay &&window.youplay.floating &&window.youplay.floating !== id){return;} var iframe = document.getElementById(id);var video = iframe.contentWindow.video;var adPlaying = video.isAdPlaying();if(video &&!(adPlaying || !video.player.paused()) &&!revert){return;} window.youplay = window.youplay ||{};window.youplay.floating = id;var transition = shouldStickOnTop ? 'none' : 'all .5s';var wrapper = iframe.parentNode;var youplayConfig = iframe.contentWindow.youplay.config;var pos = youplayConfig.floating;var floating_offset_options = youplayConfig.floating_offset_options;/* Number indicating selected position(corner); increasing clockwise ie. 1 => top right, 2 => bottom right, 3 => bottom left, 4 => top left */ if(!revert){if(!isFloating){iframe.style.transition = 'none';iframe.style.opacity = 0;window.removeEventListener("resize", helpers.resizeAll);var w = window.innerWidth < 640 ? Math.round(window.innerWidth / 2) : 320;wrapper.style.height = wrapper.offsetHeight + "px";iframe.style.zIndex = 9999;iframe.style.position = "fixed";var playerWidth = w;var heightBase = shouldStickOnTop ? window.innerWidth : w;var playerHeight = Math.round(heightBase * 9 / 16);if(youplayConfig.player_size && youplayConfig.player_size == 'custom' && youplayConfig.player_size_percentage > 100){var updatedPlayerWidth = playerWidth*youplayConfig.player_size_percentage/100;var updatedPlayerHeight = playerHeight*youplayConfig.player_size_percentage/100;if(updatedPlayerWidth < window.innerWidth && updatedPlayerHeight < window.innerHeight){playerWidth = updatedPlayerWidth;playerHeight = updatedPlayerHeight;}} iframe.style.width = playerWidth + "px";iframe.style.height = playerHeight + 'px';if(pos === 1 || pos === 4 || shouldStickOnTop){iframe.style.top = 0;} else{iframe.style.bottom = 0;} if(pos > 2){iframe.style.left = 0;} else{iframe.style.right = 0;} isFloating = true;this.applyOffsetOptionForIframe(iframe, floating_offset_options);iframe.classList.add('floating');if(!shouldStickOnTop){iframe.style.minWidth = 'auto';} iframe.style.transition = 'opacity 0.5s';setTimeout(function(){iframe.style.opacity = 1;}, 1);}} else if(revert && isFloating){iframe.style.transition = 'none';iframe.style.opacity = 0;iframe.style.position = "initial";if(pos === 1 || pos === 4){iframe.style.top = wrapper.getBoundingClientRect().top + "px";} else{iframe.style.bottom = document.documentElement.clientHeight - wrapper.getBoundingClientRect().bottom + "px";} if(pos > 2){iframe.style.left = wrapper.getBoundingClientRect().left + "px";} else{iframe.style.right = document.documentElement.clientWidth - wrapper.getBoundingClientRect().right + "px";} iframe.style.width = '100%';if(wrapper.offsetHeight === 0){iframe.style.height = Math.round(wrapper.offsetWidth * 0.5625) + 'px';} else{iframe.style.height = wrapper.offsetHeight + 'px';} isFloating = false;iframe.classList.remove('floating');iframe.style.transition = 'opacity 0.5s';setTimeout(function(){iframe.style.opacity = 1;window.addEventListener('resize', helpers.resizeAll);}, 1);}},ajax: function(url, params, method, callback, error, withCredentials){var xmlhttp = new XMLHttpRequest();var lastStatus = 0;if("withCredentials" in xmlhttp){} else if(typeof XDomainRequest != "undefined"){xmlhttp = new XDomainRequest();} else{xmlhttp = null;} if(!xmlhttp){if(typeof error === 'function'){error("Can't create http request.");} return;} var parameters =[];xmlhttp.onprogress = function(){return;};xmlhttp.onload = function(){if(typeof XDomainRequest != "undefined"){return callback(xmlhttp.responseText);} if(typeof xmlhttp.status !== "undefined" &&["4", "5"].indexOf(xmlhttp.status.toString()[0]) === -1){return callback(xmlhttp.responseText);} else if(typeof error == "function"){return error(xmlhttp.responseText);}};xmlhttp.onreadystatechange = function(){if(xmlhttp.status === 0 || xmlhttp.status === lastStatus){return;} lastStatus = xmlhttp.status;};if(typeof error === 'function'){xmlhttp.onerror = function(){error();};} xmlhttp.open(method, url, true);for(var i = 0; i < params.length; i++){params[i][1] = encodeURIComponent(params[i][1]);parameters.push(params[i][0] + "=" + params[i][1]);} parameters = parameters.join("&");if(withCredentials){xmlhttp.withCredentials = true;} xmlhttp.send(parameters);},resizeAll: debounce((function(_this){return function(){var iframes = document.querySelectorAll(".yp-iframe");for(var i = 0; i < iframes.length; i++){var el = iframes[i];if(el.className.indexOf('floating') > -1){return;} var wrapper = el.contentWindow.document.querySelector(".container");if(wrapper){var height = Math.max(wrapper.scrollHeight, wrapper.offsetHeight, wrapper.clientHeight);el.height = height;el.style.height = height + "px";el.parentNode.height = height;el.parentNode.style.height = height + "px";}}};})(this), 250),resize: function(id){var el = document.querySelector("#" + id);if(!el || isFloating){return;} var wrapper = el.contentWindow.document.querySelector(".container");var height = Math.max(wrapper.scrollHeight, wrapper.offsetHeight, wrapper.clientHeight);el.height = height;el.style.height = height + "px";},resizeResponsive: function(id){var el = document.querySelector("#" + id);if(!el){return;} el.style.width = "100%";el.style.height = "100%";el.style.position = "absolute";var wrapper = el.parentNode;wrapper.style.position = "relative";wrapper.style.width = "100%";wrapper.style.height = "0";wrapper.style.paddingBottom = "56%";},parseQueryString: function(url){if(!url){return{};} var vars =[];var hashes, hash;var url = url.split("?");if(url.length === 1){return{};} url = url[1];if(url === ""){return{};} if(url.indexOf("&") > -1){hashes = url.split("&");} else{hashes = url.split("&");} for(var i = 0; i < hashes.length; i++){hashes[i] = hashes[i].replace("?", "");hash = hashes[i].split('=');vars[hash[0]] = hash[1];} return vars;},scrollIntoView: function(id){var el = document.querySelector("#" + id);if(!el || !el.scrollIntoView){return;} el.scrollIntoView();},resizePopup: function(id, popupWidth, popupHeight){var popupWidth = popupWidth || "142px";var popupHeight = popupHeight || "151px";var el = document.getElementById(id);if(el){el.style.width = popupWidth;el.style.height = popupHeight;}},closePopup: function(id, remember){if(remember){document.cookie = "yp-popup-closed=1;max-age=86400";} document.getElementById(id).remove();},getPlayerBase: function(){var queryParams = this.parseQueryString(window.location.href);if(queryParams.yp_player_base){return "https://" + queryParams.yp_player_base;} else{return "https://player.youplay.se/assets/formats/0.0.467";}},increaseAutoplayCount: function(){window.youplay = window.youplay ||{};if(typeof window.youplay.autoplayCount === 'number'){window.youplay.autoplayCount += 1;} else{window.youplay.autoplayCount = 1;}},isAutoplayAllowed: function(){return(!window.youplay || !window.youplay.autoplayCount || window.youplay.autoplayCount < 2);},getTrackingParams: function(c){c = c ||{};var trackingParamsList =[ 'zone_id=' + c.zone_id,'endpoint=loadjs','format=' + c.player,'url=' + window.location.hostname];if(c.part_id){trackingParamsList.push('id=' + c.part_id);trackingParamsList.push('type=part');} else if(c.live_stream_id){trackingParamsList.push('id=' + c.live_stream_id);trackingParamsList.push('type=live_stream');} else if(c.program_id){trackingParamsList.push('id=' + c.program_id);trackingParamsList.push('type=program');} return trackingParamsList.join('&');},applyOffsetOptionForIframe(iframe, floating_offset_options){if(floating_offset_options && floating_offset_options.length > 0){floating_offset_options.forEach((option) =>{if((option['on_device'] === 'desktop' && shouldStickOnTop) ||(option['on_device'] === 'mobile' && !shouldStickOnTop)){return;} var unit_type = option['unit_type'];switch(option['direction']){case 'top': iframe.style.top = option['unit_value']+unit_type;break;case 'right': iframe.style.right = option['unit_value']+unit_type;break;case 'bottom': iframe.style.bottom = option['unit_value']+unit_type;break;case 'left': iframe.style.left = option['unit_value']+unit_type;break;}});}}};var shouldStickOnTop = isMobile() && !isTablet();function isSafari(){return /^((?!chrome).)*safari/i.test(navigator.userAgent);} function isMobile(){return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);} function isTablet(){var ua = navigator.userAgent.toLowerCase();return /(ipad|tablet|(android(?!.*mobile))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(ua);} function isIOS(){return !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);} function isFirefox(){return(typeof InstallTrigger !== "undefined");} function getScriptTag(config){var el;var playersPath ={'cd': 'displays/responsive','sd': 'displays/single','mp': 'displays/mobile','ld': 'displays/video_link','trd': 'displays/triple','tid': 'displays/ticker','pp': 'players/playlist','sp': 'players/single','up': 'players/single'} el = document.getElementById(config.id); return el;} function createIframe(config){var el, src;el = getScriptTag(config);if(!el){return;} src = el.src;wrapper = document.createElement("div");wrapper.style.position = "relative";wrapper.style.width = "100%";wrapper.style.textAlign = "left";el.parentNode.insertBefore(wrapper, el.nextSibling);var id = "id-" + Math.round((Math.random(1000) * 1000)).toString();iframe = document.createElement("iframe");iframe.id = id;iframe.style.border = "none";iframe.style.width = "100%";iframe.style.maxWidth = "100%";iframe.scrolling = "no";iframe.setAttribute("webkitallowfullscreen", "true");iframe.setAttribute("mozallowfullscreen", "true");iframe.setAttribute("allowfullscreen", "true");iframe.setAttribute("allow", "autoplay");iframe.style.height = "100%";iframe.style.position = "relative";iframe.style.backgroundColor = "transparent";iframe.className = "yp-iframe yp-single-iframe";iframe.name = "yp-iframe";function setupIframe(){iframe.onload = null;if(config.player === "popup" &&(document.cookie.search('yp-popup-closed=1') > -1 || isMobile())){return helpers.closePopup(id);} var playerBase = helpers.getPlayerBase();var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;var environment = "production";var youplay ={session_id: Math.floor(Math.random() * 2147483647),metrics_enabled:(Math.random() * 100) < 10,article_extract_enabled:(Math.random() * 100) < 1,initialized_at: new Date(),config: config,helpers: helpers,iframe: iframe,id: id,env: environment,parent_window: window,api:{host: host,version: "v2",delivery_host: "https://delivery.youplay.se",player_base: playerBase}};if(isSafari()){iframe.contentWindow.youplay = youplay;} if(['sp', 'lp', 'pp'].indexOf(config.player) > -1){config.player = 'up';} var trackingParams = helpers.getTrackingParams(config);var cssPath = playerBase + "/css/" + config.player;var jsPath = playerBase + "/js/" + config.player; cssPath += '.min';jsPath += '.min'; cssPath += '.css?' + trackingParams;jsPath += '.js?rand=' + Math.random() + '&' + trackingParams;iframeDoc.write("" + "
" + "" + "" + "" + "" + "" + "" + "" + "" + "");iframeDoc.close();if(!isSafari()){iframe.contentWindow.youplay = youplay;} if(config.player === "popup"){iframe.className = 'yp-popup';var popupDelay = config.popupDelay || 10;iframe.style.position = 'fixed';iframe.style.right = 0;iframe.style.bottom = '-9999em';helpers.resizePopup(youplay.id);iframe.style.bottom = '-160px';iframe.style.transition = "all .4s";setTimeout(function(){iframe.style.bottom = 0;}, popupDelay * 1000);}} function waitForIframe(){var iframeReadyInterval = window.setInterval(function(){if(iframe.contentWindow && iframe.contentWindow.document &&iframe.contentWindow.document.readyState === "complete"){clearInterval(iframeReadyInterval);setupIframe();}}, 100);setTimeout( function(){clearInterval(iframeReadyInterval);}, 5000);} if(isMobile()){iframe.style.minWidth = "100%";} if(isIOS()){iframe.style.width = "1px";if(config && config.phonegap){waitForIframe();} else if(/^http/.test(window.location.protocol)){iframe.onload = setupIframe;} else{waitForIframe();}} else if(isFirefox()){waitForIframe();} else{iframe.onload = setupIframe;} wrapper.appendChild(iframe);window.addEventListener("message", helpers.onMessage);window.addEventListener("resize", helpers.resizeAll);window.addEventListener("scroll", function(){helpers.scroll(id);});el.className = "yp-injected";} var sharing =(function(){return{updateConfig: function(config, queryParams){if(queryParams.yp_part_id &&queryParams.yp_zone_id &&queryParams.yp_format &&queryParams.yp_zone_id == config.zone_id &&queryParams.yp_format == config.player &&!config.manual){config.part_id = queryParams.yp_part_id;config.zone_id = queryParams.yp_zone_id;config.player = queryParams.yp_format;config.autoplay = true;if(queryParams.yp_time){config.time = parseInt(queryParams.yp_time);} config.isShared = true;} return config;}};})();function generateConfigFromEl(el){var config = JSON.parse(el.getAttribute("data-config"));config.auth = el.getAttribute("data-auth");var exp = config.experiments;var exp_zone = exp && parseInt(exp.zone_id);var exp_perc = exp && parseFloat(exp.percent);if(exp_zone && exp_perc && Math.random() * 100 < exp_perc){config.zone_id = exp_zone;} config.origin = encodeURIComponent(window.location.origin);if(config.url){try{var origin =(new URL(config.url)).origin;} catch(err){var arr = config.url.split("/");var origin = arr[0] + "//" + arr[2];} config.origin = encodeURIComponent(origin);} else{config.url = encodeURIComponent(window.location.href);} var queryParams = helpers.parseQueryString(window.location.href);config = sharing.updateConfig(config, queryParams);return config;} function generateConfigFromParams(){var config = {"player":"up","addons":"000"};config.url = encodeURIComponent(window.location.href);config.origin = encodeURIComponent(window.location.origin);var queryParams = helpers.parseQueryString(window.location.href);config = sharing.updateConfig(config, queryParams);return config;} function getScriptTagById(scriptTags, id){var tag;for(var i = 0; i < scriptTags.length; i++){tag = scriptTags[i];if(tag.src !== "undefined" && tag.src && tag.src.indexOf("load.js?id=" + id) > -1){return tag;}} return;} function getScriptTagsWithoutIds(scriptTags){var tag;var tags =[];for(var i = 0; i < scriptTags.length; i++){tag = scriptTags[i];if(tag && tag.src && tag.src.indexOf("load.js") > -1 && tag.src.indexOf("load.js?id=") < 0){tags.push(tag);}} return tags;} var config ={}; var scriptTags = document.querySelectorAll("script[src*='youplay'][data-config]") var scriptTagsWithoutIds = getScriptTagsWithoutIds(scriptTags);var el;if(scriptTags.length === 0){return;} el = getScriptTagById(scriptTags, "784827"); if(!el){return;} el.className = "yp-injected";config = generateConfigFromEl(el);var scriptId = "yp-script-" + Math.round((Math.random(999999) * 999999)).toString();config.id = scriptId;el.id = scriptId; if(config && config.player && config.zone_id){setTimeout( function(){createIframe(config);}, 0);}})();