{"version":3,"sources":["webpack:///./Flugger.Web/Scripts/Flugger/components/youtube.js","webpack:///./node_modules/youtube-google-analytics/lunametrics-youtube.gtm.js"],"names":["_jquery","_interopRequireDefault","require","_lunametricsYoutubeGtm","obj","__esModule","default","externalVideos","$","videoOnPage","loadExternalVideos","videos","getScript","count","each","$currentElement","this","ytId","attr","ytVideo","currCount","playYtVideo","playVideo","after","YT","Player","width","height","videoId","playerVars","autoplay","controls","rel","showinfo","modestbranding","wmode","events","onStateChange","event","data","stopYtVideo","onReady","target","f","ytTracker","init","console","log","initYtVideo","parent","addClass","window","trigger","pauseVideo","removeClass","on","e","id","exports","length","hasVideo","stopAllVideo","document","config","navigator","userAgent","match","firstScriptTag","tag","key","o","_config","forceSyntax","dataLayerName","eventsFired","hasOwnProperty","createElement","src","getElementsByTagName","parentNode","insertBefore","onYouTubeIframeAPIReady","apply","arguments","readyState","bind","addEvent","potentialVideos","i","checkIfYouTubeVideo","addYouTubeEvents","normalizeYouTubeIframe","digestPotentialVideos","getTagsAsArr_","concat","addEventListener","bindToNewVideos_","potentialYouTubeVideo","potentialYouTubeVideoSrc","dataSrc","getAttribute","indexOf","jsApiEnabled","url","originEnabled","youTubeVideo","loc","location","a","href","tmpPathname","pathname","charAt","search","hostname","port","origin","protocol","type","newIframe","replace","replaceChild","hash","youTubeIframe","player","get","pauseFlag","evt","stateIndex","targetVideoId","getVideoUrl","playerState","getPlayerState","marks","duration","Math","min","floor","percentageTracking","points","every","parseInt","num","push","_point","_time","getMarks","getDuration","state","playTracker","timer","clearInterval","setInterval","currentTime","getCurrentTime","fireAnalyticsEvent","checkCompletion","onStateChangeHandler","videoUrl","_ga","GoogleAnalyticsObject","getAll","_gaq","el","name","fn","attachEvent","srcElement","call","tagName","slice","isYT"],"mappings":"6JAAA,IAAAA,EAAAC,EAAAC,EAAA,IACAC,EAAAF,EAAAC,EAAA,MAA4E,SAAAD,EAAAG,GAAA,OAAAA,KAAAC,WAAAD,EAAA,CAAAE,QAAAF,GA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,EAAIpC,WAIsB,IAApBoC,EAAG,KAAOC,IAA6C,OAApBD,EAAG,KAAOC,KAG7DD,EAAG,KAAOC,GAAQ,SAASrC,GAEzBA,EAAIrF,OAASqF,EAAIrF,QAAUqF,EAAIwC,WAE/BF,EAAGG,KAAKL,EAAIpC,KASlB,SAASlC,EAAc4E,GAErB,MAAO,GAAGC,MAAMF,KAAK1G,EAASgB,qBAAqB2F,IAIrD,SAASzE,EAAiB+B,GAExB,IAAIoC,EAAKpC,EAAIrF,QAAUqF,EAAIwC,WACvBI,EAAOlF,EAAoB0E,GAIZ,WAAfA,EAAGM,SAAwBE,GAAQrE,EAAa6D,EAAGtF,MAAQ2B,EAAc2D,EAAGtF,MAE9Ea,EAAiByE,IA9bvB,CAocGrG,SAAUX","file":"11.325caa4e69ee70d18c40.chunk.js","sourcesContent":["import $ from 'jquery';\r\nimport ytTracker from 'youtube-google-analytics/lunametrics-youtube.gtm.js';\r\n\r\nconst externalVideos = $('[src-yt]');\r\nlet videoOnPage = false;\r\n\r\nfunction callYtTracker() {\r\n if (typeof ytTracker !== 'undefined') {\r\n if (typeof ytTracker.init === 'function') {\r\n ytTracker.init();\r\n }\r\n } else {\r\n console.log('no ytTracker found'); // eslint-disable-line no-console\r\n }\r\n}\r\n\r\nfunction loadExternalVideos(videos) {\r\n $.getScript('https://www.youtube.com/iframe_api', function() {\r\n let count = 0;\r\n videos.each(function() {\r\n const $currentElement = $(this);\r\n const ytId = $currentElement.attr('src-yt');\r\n let ytVideo = null;\r\n const currCount = count;\r\n\r\n function playYtVideo() {\r\n if (ytVideo !== null) {\r\n ytVideo.playVideo();\r\n } else {\r\n initYtVideo();\r\n }\r\n $currentElement.parent().addClass('playing');\r\n $(window).trigger('videoPlaying', [currCount]);\r\n }\r\n\r\n function stopYtVideo() {\r\n if (ytVideo !== null) {\r\n ytVideo.pauseVideo();\r\n $currentElement.parent().removeClass('playing');\r\n $(window).trigger('videoStopped', [currCount]);\r\n }\r\n }\r\n\r\n function showMedia($element) {\r\n /*\r\n if (!$element.is('iframe')) {\r\n $currentElement.after($element);\r\n }\r\n */\r\n callYtTracker();\r\n }\r\n\r\n function initYtVideo() {\r\n $currentElement.after($('
'));\r\n\r\n const playerVars = {\r\n autoplay: 1,\r\n controls: 1,\r\n rel: 0,\r\n showinfo: 0,\r\n modestbranding: 1,\r\n wmode: 'transparent'\r\n };\r\n\r\n ytVideo = new YT.Player('yt' + currCount, {\r\n width: 1280,\r\n height: 720,\r\n videoId: ytId,\r\n playerVars: playerVars,\r\n events: {\r\n onStateChange: function(event) {\r\n if (event.data === 1) {\r\n playYtVideo();\r\n }\r\n if (event.data === 2) {\r\n stopYtVideo();\r\n }\r\n },\r\n onReady: function(event) {\r\n showMedia($(event.target.f));\r\n }\r\n }\r\n });\r\n }\r\n\r\n $currentElement.parent().on('click', playYtVideo);\r\n\r\n $(window).on('videoStop', function(e, id) {\r\n stopYtVideo();\r\n });\r\n\r\n $(window).on('videoPlaying', function(e, id) {\r\n if (id !== currCount) {\r\n stopYtVideo();\r\n }\r\n });\r\n\r\n count++;\r\n });\r\n });\r\n}\r\n\r\nfunction playExternalBackgroundVideos(videos) {\r\n videos.each(function(index, element) {\r\n element.playVideo();\r\n });\r\n}\r\n\r\nfunction stopAllVideo() {\r\n $(window).trigger('videoStop');\r\n}\r\n\r\nfunction hasVideo() {\r\n return videoOnPage;\r\n}\r\n\r\nfunction init() {\r\n if (externalVideos.length < 1) return false;\r\n videoOnPage = true;\r\n loadExternalVideos(externalVideos);\r\n}\r\n\r\nexport default {\r\n init: init,\r\n hasVideo: hasVideo,\r\n stopAllVideo: stopAllVideo\r\n};\r\n","(function(document, window, config) {\r\n\r\n 'use strict';\r\n\t// This script won't work on IE 6 or 7, so we bail at this point if we detect that UA\r\n\tif (navigator.userAgent.match(/MSIE [67]\\./gi)) return;\r\n\r\n var _config = config || {};\r\n var forceSyntax = _config.forceSyntax || 0;\r\n var dataLayerName = _config.dataLayerName || 'dataLayer';\r\n // Default configuration for events\r\n var eventsFired = {\r\n 'Play': true,\r\n 'Pause': true,\r\n 'Watch to End': true\r\n };\r\n\tvar firstScriptTag;\r\n\tvar tag;\r\n var key;\r\n\r\n for (key in _config.events) {\r\n\r\n if (_config.events.hasOwnProperty(key)) {\r\n\r\n eventsFired[key] = _config.events[key];\r\n\r\n }\r\n\r\n }\r\n\r\n\tif (window.YT) {\r\n\r\n\t\tinit();\t\r\n\r\n\t} else {\r\n\r\n\t\t// Fetches YouTube JS API\r\n\t\ttag = document.createElement('script');\r\n\t\ttag.src = '//www.youtube.com/iframe_api';\r\n\t\tfirstScriptTag = document.getElementsByTagName('script')[0];\r\n\t\tfirstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\r\n\r\n\t\twindow.onYouTubeIframeAPIReady = (function(o) {\r\n\r\n\t\t\treturn function() {\r\n\r\n\t\t\t\tif (o) o.apply(this, arguments);\r\n\r\n\t\t\t\tinit();\r\n\r\n\t\t\t};\t\r\n\r\n\t\t})(window.onYouTubeIframeAPIReady);\r\n\r\n\t}\r\n\r\n // Invoked by the YouTube API when it's ready\r\n function init() {\r\n\r\n\t\tif (document.readyState !== 'loading') {\r\n\r\n\t\t\tbind();\r\n\r\n\t\t} else {\r\n\r\n\t\t\t// On IE8 this fires on window.load, all other browsers will fire when DOM ready\r\n\t\t\tif ('addEventListener' in document) {\r\n\r\n\t\t\t\taddEvent(document, 'DOMContentLoaded', bind);\r\n\r\n\t\t\t} else {\r\n\r\n\t\t\t\taddEvent(window, 'load', bind);\r\n\r\n\t\t\t}\r\n\r\n\t\t}\r\n\r\n }\r\n\r\n\tfunction bind() {\r\n\r\n var potentialVideos = getTagsAsArr_('iframe').concat(getTagsAsArr_('embed'));\r\n digestPotentialVideos(potentialVideos);\r\n\r\n // Will bind to dynamically added videos\r\n if ('addEventListener' in document) { \r\n document.addEventListener('load', bindToNewVideos_, true);\r\n }\r\n\r\n\t}\r\n\r\n // Take our videos and turn them into trackable videos with events\r\n function digestPotentialVideos(potentialVideos) {\r\n\r\n var i;\r\n\r\n for (i = 0; i < potentialVideos.length; i++) {\r\n\r\n var isYouTubeVideo = checkIfYouTubeVideo(potentialVideos[i]);\r\n\r\n if (isYouTubeVideo) {\r\n\r\n var normalizedYouTubeIframe = normalizeYouTubeIframe(potentialVideos[i]);\r\n addYouTubeEvents(normalizedYouTubeIframe);\r\n\r\n }\r\n\r\n }\r\n\r\n }\r\n\r\n // Determine if the element is a YouTube video or not\r\n function checkIfYouTubeVideo(potentialYouTubeVideo) {\r\n\r\n var potentialYouTubeVideoSrc = potentialYouTubeVideo.src || '';\r\n var dataSrc = potentialYouTubeVideo.getAttribute('data-src') || '';\r\n\r\n if (potentialYouTubeVideoSrc.indexOf('youtube.com/embed/') > -1 ||\r\n potentialYouTubeVideoSrc.indexOf('youtube.com/v/') > -1 ||\r\n dataSrc.indexOf('youtube.com/embed/') > -1 ||\r\n dataSrc.indexOf('youtube.com/v/') > -1) {\r\n\r\n return true;\r\n\r\n }\r\n\r\n return false;\r\n\r\n }\r\n\r\n function jsApiEnabled(url) {\r\n\r\n return url.indexOf('enablejsapi') > -1;\r\n\r\n }\r\n\r\n function originEnabled(url) {\r\n\r\n return url.indexOf('origin') > -1;\r\n\r\n }\r\n\r\n // Turn embed objects into iframe objects and ensure they have the right parameters\r\n function normalizeYouTubeIframe(youTubeVideo) {\r\n\r\n var loc = window.location;\r\n var a = document.createElement('a');\r\n a.href = youTubeVideo.getAttribute('data-src') || youTubeVideo.src;\r\n var tmpPathname = a.pathname.charAt(0) === '/' ? a.pathname : '/' + a.pathname; // IE10 shim\r\n\r\n // For security reasons, YouTube wants an origin parameter set that matches our hostname\r\n\r\n if (!jsApiEnabled(a.search)) {\r\n\r\n a.search = (a.search.length > 0 ? a.search + '&' : '') + 'enablejsapi=1';\r\n\r\n }\r\n\r\n if (!originEnabled(a.search) && loc.hostname.indexOf('localhost') === -1) {\r\n \r\n var port = loc.port ? ':' + loc.port : '';\r\n var origin = loc.protocol + '%2F%2F' + loc.hostname + port;\r\n\r\n a.search = a.search + '&origin=' + origin;\r\n\r\n }\r\n\r\n if (youTubeVideo.type === 'application/x-shockwave-flash') {\r\n\r\n var newIframe = document.createElement('iframe');\r\n newIframe.height = youTubeVideo.height;\r\n newIframe.width = youTubeVideo.width;\r\n tmpPathname = tmpPathname.replace('/v/', '/embed/');\r\n\r\n youTubeVideo.parentNode.parentNode.replaceChild(newIframe, youTubeVideo.parentNode);\r\n\r\n youTubeVideo = newIframe;\r\n\r\n }\r\n\r\n a.pathname = tmpPathname;\r\n\r\n if (youTubeVideo.src !== a.href + a.hash) {\r\n\r\n youTubeVideo.src = a.href + a.hash;\r\n\r\n }\r\n\r\n return youTubeVideo;\r\n\r\n }\r\n\r\n // Add event handlers for events emitted by the YouTube API\r\n function addYouTubeEvents(youTubeIframe) {\r\n\r\n var player = YT.get(youTubeIframe.id);\r\n\r\n if (!player) {\r\n\r\n player = new YT.Player(youTubeIframe, {}); \r\n\r\n }\r\n\r\n if (typeof youTubeIframe.pauseFlag === 'undefined') { \r\n\r\n youTubeIframe.pauseFlag = false;\r\n player.addEventListener('onStateChange', function(evt) {\r\n\r\n onStateChangeHandler(evt, youTubeIframe);\r\n\r\n });\r\n\r\n }\r\n\r\n }\r\n\r\n // Returns key/value pairs of percentages: number of seconds to achieve\r\n function getMarks(duration) {\r\n\r\n var marks = {};\r\n\r\n // For full support, we're handling Watch to End with percentage viewed\r\n if (_config.events['Watch to End']) {\r\n\r\n marks['Watch to End'] = Math.min(duration - 3, Math.floor(duration * 0.99));\r\n\r\n }\r\n\r\n if (_config.percentageTracking) {\r\n\r\n var points = [];\r\n var i;\r\n\r\n if (_config.percentageTracking.each) {\r\n\r\n points = points.concat(_config.percentageTracking.each);\r\n\r\n }\r\n\r\n if (_config.percentageTracking.every) {\r\n\r\n var every = parseInt(_config.percentageTracking.every, 10);\r\n var num = 100 / every;\r\n\r\n for (i = 1; i < num; i++) {\r\n\r\n points.push(i * every);\r\n\r\n }\r\n\r\n }\r\n\r\n for (i = 0; i < points.length; i++) {\r\n\r\n var _point = points[i];\r\n var _mark = _point + '%';\r\n var _time = duration * _point / 100;\r\n\r\n marks[_mark] = Math.floor(_time);\r\n\r\n }\r\n\r\n }\r\n\r\n return marks;\r\n\r\n }\r\n\r\n function checkCompletion(player, marks, videoId) {\r\n\r\n var currentTime = player.getCurrentTime();\r\n var key;\r\n\r\n player[videoId] = player[videoId] || {};\r\n\r\n for (key in marks) {\r\n\r\n if (marks[key] <= currentTime && !player[videoId][key]) {\r\n\r\n player[videoId][key] = true;\r\n fireAnalyticsEvent(videoId, key);\r\n\r\n }\r\n\r\n }\r\n\r\n }\r\n\r\n // Event handler for events emitted from the YouTube API\r\n function onStateChangeHandler(evt, youTubeIframe) {\r\n\r\n var stateIndex = evt.data;\r\n var player = evt.target;\r\n var targetVideoUrl = player.getVideoUrl();\r\n var targetVideoId = targetVideoUrl.match(/[?&]v=([^]*)/)[1]; // Extract the ID \r\n var playerState = player.getPlayerState();\r\n var duration = Math.floor(player.getDuration());\r\n var marks = getMarks(duration);\r\n var playerStatesIndex = {\r\n '1': 'Play',\r\n '2': 'Pause'\r\n };\r\n var state = playerStatesIndex[stateIndex];\r\n\r\n youTubeIframe.playTracker = youTubeIframe.playTracker || {};\r\n\r\n if (playerState === 1 && !youTubeIframe.timer) {\r\n\r\n clearInterval(youTubeIframe.timer);\r\n\r\n youTubeIframe.timer = setInterval(function() {\r\n\r\n // Check every second to see if we've hit any of our percentage viewed marks\r\n checkCompletion(player, marks, youTubeIframe.videoId);\r\n\r\n }, 1000);\r\n\r\n } else {\r\n\r\n clearInterval(youTubeIframe.timer);\r\n youTubeIframe.timer = false;\r\n\r\n }\r\n\r\n // Playlist edge-case handler\r\n if (stateIndex === 1) {\r\n\r\n youTubeIframe.playTracker[targetVideoId] = true;\r\n youTubeIframe.videoId = targetVideoId;\r\n youTubeIframe.pauseFlag = false;\r\n\r\n }\r\n\r\n if (!youTubeIframe.playTracker[youTubeIframe.videoId]) {\r\n\r\n // This video hasn't started yet, so this is spam\r\n return false;\r\n\r\n }\r\n\r\n if (stateIndex === 2) {\r\n\r\n if (!youTubeIframe.pauseFlag) {\r\n\r\n youTubeIframe.pauseFlag = true;\r\n\r\n } else {\r\n\r\n // We don't want to fire consecutive pause events\r\n return false;\r\n\r\n }\r\n\r\n }\r\n\r\n // If we're meant to track this event, fire it\r\n if (eventsFired[state]) {\r\n\r\n fireAnalyticsEvent(youTubeIframe.videoId, state);\r\n\r\n }\r\n\r\n }\r\n\r\n // Fire an event to Google Analytics or Google Tag Manager\r\n function fireAnalyticsEvent(videoId, state) {\r\n\r\n var videoUrl = 'https://www.youtube.com/watch?v=' + videoId;\r\n var _ga = window.GoogleAnalyticsObject;\r\n\r\n if (typeof window[dataLayerName] !== 'undefined' && !_config.forceSyntax) {\r\n\r\n window[dataLayerName].push({\r\n\r\n 'event': 'youTubeTrack',\r\n 'attributes': {\r\n\r\n 'videoUrl': videoUrl,\r\n 'videoAction': state\r\n\r\n }\r\n\r\n });\r\n\r\n } else if (typeof window[_ga] === 'function' &&\r\n typeof window[_ga].getAll === 'function' &&\r\n _config.forceSyntax !== 2) {\r\n\r\n window[_ga]('send', 'event', 'Videos', state, videoUrl);\r\n\r\n } else if (typeof window._gaq !== 'undefined' && forceSyntax !== 1) {\r\n\r\n window._gaq.push(['_trackEvent', 'Videos', state, videoUrl]);\r\n\r\n }\r\n\r\n }\r\n\r\n // Simple cross-browser event listener\r\n function addEvent(el, name, fn) {\r\n\r\n if (el.addEventListener) {\r\n\r\n el.addEventListener(name, fn);\r\n\r\n } else if (el.attachEvent) {\r\n\r\n el.attachEvent('on' + name, function(evt) {\r\n\r\n evt.target = evt.target || evt.srcElement;\r\n // Call the event to ensure uniform 'this' handling, pass it event\r\n fn.call(el, evt);\r\n\r\n });\r\n\r\n } else if (typeof el['on' + name] === 'undefined' || el['on' + name] === null) {\r\n\r\n\r\n el['on' + name] = function(evt) {\r\n\r\n evt.target = evt.target || evt.srcElement;\r\n // Call the event to ensure uniform 'this' handling, pass it event\r\n fn.call(el, evt);\r\n\r\n };\r\n\r\n }\r\n\r\n }\r\n\r\n // Returns array of elements with given tag name\r\n function getTagsAsArr_(tagName) {\r\n\r\n return [].slice.call(document.getElementsByTagName(tagName));\r\n\r\n }\r\n\r\n function bindToNewVideos_(evt) {\r\n\r\n var el = evt.target || evt.srcElement;\r\n var isYT = checkIfYouTubeVideo(el);\r\n\r\n // We only bind to iframes with a YouTube URL with the enablejsapi=1 and \r\n // origin=<