{"version":3,"sources":["aheto/video-btn/assets/js/cs_layout2.js"],"names":["document","setupVideo","video","link","querySelector","id","getAttribute","addEventListener","setAttribute","createElement","classList","iframe","generateURL","add","remove","removeAttribute","videos","querySelectorAll","findVideos","i","length","jQuery","window"],"mappings":"cAAC,SAAsBA,GAqBnB,SAASC,EAAWC,GAChB,IAAIC,EAAOD,EAAME,cAAc,YAD1BH,EAATC,EAAAE,cAA2B,cAKnBC,EAAKH,EAAMI,aAAa,WAE5BJ,EAAMK,iBAAiB,QAAS,WAF1B,IAuCcF,EACbG,EAxCEN,GAuCWG,EAvCQA,GAwCrBG,EAAAA,EAAaC,cAApB,WAEOC,aAAc,kBAArB,IAEAC,EAAOA,aAAP,QAAA,YACHA,EAAAH,aAAA,MAUD,SAAqBH,GAGjB,MAAO,iCAAmCA,EAGpC,+BAhBTO,CAAAP,IAEDM,EAAAD,UAAAG,IAAA,sBAHWF,GAzCCA,EAAMG,SAELA,EAALA,SACMZ,EAACY,YAAPH,KAIAR,EAACY,gBAAgB,QACrBb,EAAMQ,UAAcG,IAAA,mBA9BxB,WAAA,IACI,IAAIG,EAAShB,EAASiB,iBAAiB,aADlCC,EAAT,EAAsBC,EAAAH,EAAAI,OAAAD,IACdH,EAAShB,EAASiB,IA+E1BC,GAvFH,EAyFEG,OAAQC,OAAQtB","file":"cs_layout2.min.js","sourcesContent":[";(function ($, window, document, undefined) {\n \"use strict\";\n \n /**\n * find all videos\n */\n\n function findVideos() {\n let videos = document.querySelectorAll('.js-video');\n\n for (let i = 0; i < videos.length; i++) {\n setupVideo(videos[i]);\n }\n }\n\n /**\n * Setup video after click on box\n * \n * @param video \n */\n\n function setupVideo(video) {\n let link = video.querySelector('.js-link');\n // let media = video.querySelector('.js-media');\n let button = video.querySelector('.js-button');\n // let id = parseMediaURL(media);\n let id = video.getAttribute('data-id');\n\n video.addEventListener('click', () => {\n let iframe = createIframe(id);\n\n link.remove();\n button.remove();\n video.appendChild(iframe);\n });\n\n link.removeAttribute('href');\n video.classList.add('video--enabled');\n }\n\n /**\n * Parse ID from URL\n * \n * @param media Link with video ID(youtube poster src)\n */\n\n // function parseMediaURL(media) {\n // \tlet regexp = /https:\\/\\/i\\.ytimg\\.com\\/vi\\/([a-zA-Z0-9_-]+)\\/maxresdefault\\.jpg/i;\n // \tlet url = media.src;\n // \tlet match = url.match(regexp);\n\n // \treturn match[1];\n // }\n\n /**\n * Create Iframe\n * \n * @param id Video ID\n * \n * @returns iframe objects\n */\n\n function createIframe(id) {\n let iframe = document.createElement('iframe');\n\n iframe.setAttribute('allowfullscreen', '');\n iframe.setAttribute('allow', 'autoplay');\n iframe.setAttribute('src', generateURL(id));\n iframe.classList.add('aheto-video__media');\n\n return iframe;\n }\n\n /**\n * Generate full video URL\n * \n * @param id Video ID\n * \n * @returns full video url\n */\n\n function generateURL(id) {\n let query = '?rel=0&showinfo=0&autoplay=1';\n\n return 'https://www.youtube.com/embed/' + id + query;\n }\n\n findVideos();\t\n\n})(jQuery, window, document);"]}