app/template/plugin/ApgVideoInsert42/front/render_product_detail_js.twig line 1

Open in your IDE?
  1. {% if youtubeVideoId is defined and youtubeVideoId %}
  2.     <script>
  3.         $(function () {
  4.             const tag = document.createElement('script');
  5.             tag.src = "https://www.youtube.com/iframe_api";
  6.             const firstScriptTag = document.getElementsByTagName('script')[0];
  7.             firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  8.         });
  9.         {% if videoInsertType is  defined and videoInsertType == constant('Plugin\\ApgVideoInsert42\\Domain\\VideoInsertType::SLIDE') %}
  10.         $(function () {
  11.             $(".item_visual").on("beforeChange", function (event, slick) {
  12.                 slick = $(slick.$slider);
  13.                 playPauseVideo(slick, "pause");
  14.             });
  15.             $(".item_visual").on("afterChange", function (event, slick) {
  16.                 slick = $(slick.$slider);
  17.                 playPauseVideo(slick, "play");
  18.             });
  19.             $(".item_visual").on('init', function (slick) {
  20.                 $('.slick-dots .apg_video_youtube_player_image').show();
  21.             });
  22.         });
  23.         {% endif %}
  24.         let player;
  25.         function onYouTubeIframeAPIReady() {
  26.             $('.apg_video_youtube_player_image').hide();
  27.             $('.slick-dots .apg_video_youtube_player_image').show();
  28.             {% if videoInsertType is  defined and videoInsertType == constant('Plugin\\ApgVideoInsert42\\Domain\\VideoInsertType::SLIDE') %}
  29.             let ifram_height = $('.apg_video_youtube_player_image:first').height();
  30.             if (!ifram_height || ifram_height < 360) {
  31.                 if (window.matchMedia('(max-width: 767px)').matches) {
  32.                     ifram_height = '360';
  33.                 } else {
  34.                     ifram_height = '480';
  35.                 }
  36.             }
  37.             {% else %}
  38.             ifram_height = '480';
  39.             if (window.matchMedia('(max-width: 767px)').matches) {
  40.                 ifram_height = '360';
  41.             }
  42.             {% endif %}
  43.             $('.apg_video_youtube').height(ifram_height);
  44.             let targetDom = null;
  45.             if($('#apg_video_youtube_player').length > 0){
  46.                 targetDom = $('#apg_video_youtube_player')[0]
  47.             } else if($('.apg_video_youtube_player').length > 0) {
  48.                 targetDom = $('.apg_video_youtube_player')[0]
  49.             }
  50.             if(targetDom !== null){
  51.                 player = new YT.Player(targetDom, {
  52.                     height: ifram_height,
  53.                     width: '1000',
  54.                     videoId: '{{ youtubeVideoId }}',
  55.                     events: {
  56.                         'onReady': onPlayerReady,
  57.                         'onStateChange': onPlayerStateChange
  58.                     },
  59.                     playerVars: {}
  60.                 });
  61.             }
  62.         }
  63.         function onPlayerReady(event) {
  64.             {% if videoInsertType is  defined and videoInsertType == constant('Plugin\\ApgVideoInsert42\\Domain\\VideoInsertType::SLIDE') %}
  65.             event.target.playVideo();
  66.             {% endif %}
  67.             event.target.mute();
  68.         }
  69.         function onPlayerStateChange(event) {
  70.         }
  71.         function playVideo(time) {
  72.             player.seekTo(time);
  73.             player.playVideo();
  74.         }
  75.         function stopVideo() {
  76.             player.stopVideo();
  77.         }
  78.         function playPauseVideo(slick, control) {
  79.             const currentSlide = slick.find(".slick-active");
  80.             const player = currentSlide.find("iframe").get(0);
  81.             switch (control) {
  82.                 case "play":
  83.                     if (player) {
  84.                         playVideo(0);
  85.                     }
  86.                     break;
  87.                 case "pause":
  88.                     if (player) {
  89.                         stopVideo();
  90.                     }
  91.                     break;
  92.             }
  93.         }
  94.     </script>
  95. {% endif %}