<modification>
    <code>iproductvideo</code>
    <name>iProductVideo by iSenseLabs</name>
    <version>5.4.4</version>
    <link>http://isenselabs.com</link>
    <author>iSenseLabs</author>

    <file path="catalog/view/theme/*/template/product/product.twig">
        <operation info="Video replace main image">
            <search><![CDATA[<ul class="thumbnails">]]></search>
            <add position="before"><![CDATA[
                {% if thumb and iproductvideo.main_thumb is not empty %}
                  <div class="thumbnail iproductvideo-wrapper">
                    {% if iproductvideo.main_source == 'local' %}
                      <video controls {{ iproductvideo.autoplay ? 'autoplay muted' }} preload="auto">
                        <source src="{{ popup }}" type="video/{{ iproductvideo.main_ext }}">
                        <i>Your browser does not support the video tag.</i>
                      </video>
                    {% elseif iproductvideo.main_source == 'youtube' %}
                        {% if iproductvideo.nocookie %}
                            <iframe src="//www.youtube-nocookie.com/embed/{{ iproductvideo.main_id }}?rel=0{{ iproductvideo.autoplay ? '&autoplay=1&mute=1' }}" frameborder="0" allowfullscreen="" allow="autoplay"></iframe>
                        {% else %}
                            <iframe src="//www.youtube.com/embed/{{ iproductvideo.main_id }}?rel=0{{ iproductvideo.autoplay ? '&autoplay=1&mute=1' }}" frameborder="0" allowfullscreen="" allow="autoplay"></iframe>
                        {% endif %}
                    {% elseif iproductvideo.main_source == 'vimeo' %}
                      <iframe src="https://player.vimeo.com/video/{{ iproductvideo.main_id }}{{ iproductvideo.autoplay ? '?autoplay=1&muted=1' }}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen allow="autoplay"></iframe>
                    {% endif %}
                  </div>
                {% endif %}
            ]]></add>
        </operation>
        <operation info="add iProductVideo setting as data attribute">
            <search><![CDATA[<ul class="thumbnails">]]></search>
            <add position="replace"><![CDATA[<ul class="thumbnails" data-ipvsetting='{"autoplay":{{ iproductvideo.autoplay ? '1' : '0' }},"nocookie":{{ iproductvideo.nocookie ? '1' : '0' }} }'>]]></add>
        </operation>
        <operation info="Hide main image if video set to replace it">
            <search><![CDATA[{% if thumb %}]]></search>
            <add position="replace"><![CDATA[{% if thumb and iproductvideo.main_thumb is empty %}]]></add>
        </operation>
    </file>

    <!-- Journal 2 -->
    <file path="catalog/view/theme/journal2/template/product/product.twig">
        <operation info="Video replace main image">
            <search><![CDATA[<div class="left">]]></search>
            <add position="after"><![CDATA[
                {% if thumb and iproductvideo.main_thumb is not empty %}
                  <div class="thumbnail iproductvideo-wrapper">
                    {% if iproductvideo.main_source == 'local' %}
                      <video controls {{ iproductvideo.autoplay ? 'autoplay muted' }} preload="auto">
                        <source src="{{ popup }}" type="video/{{ iproductvideo.main_ext }}">
                        <i>Your browser does not support the video tag.</i>
                      </video>
                    {% elseif iproductvideo.main_source == 'youtube' %}
                        {% if iproductvideo.nocookie %}
                            <iframe src="//www.youtube-nocookie.com/embed/{{ iproductvideo.main_id }}?rel=0{{ iproductvideo.autoplay ? '&autoplay=1&mute=1' }}" frameborder="0" allowfullscreen="" allow="autoplay"></iframe>
                        {% else %}
                            <iframe src="//www.youtube.com/embed/{{ iproductvideo.main_id }}?rel=0{{ iproductvideo.autoplay ? '&autoplay=1&mute=1' }}" frameborder="0" allowfullscreen="" allow="autoplay"></iframe>
                        {% endif %}
                    {% elseif iproductvideo.main_source == 'vimeo' %}
                      <iframe src="https://player.vimeo.com/video/{{ iproductvideo.main_id }}{{ iproductvideo.autoplay ? '?autoplay=1&muted=1' }}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen allow="autoplay"></iframe>
                    {% endif %}
                  </div>
                {% endif %}
            ]]></add>
        </operation>
        <operation info="Hide main image if video set to replace it">
            <search><![CDATA[{% if thumb %}]]></search>
            <add position="replace"><![CDATA[{% if thumb and iproductvideo.main_thumb is empty %}]]></add>
        </operation>
        <operation info="add iProductVideo setting as data attribute">
            <search><![CDATA[class="container]]></search>
            <add position="replace"><![CDATA[data-ipvsetting='{"autoplay":{{ iproductvideo.autoplay ? '1' : '0' }},"nocookie":{{ iproductvideo.nocookie ? '1' : '0' }} }' class="container]]></add>
        </operation>
        <operation>
            <search index="0"><![CDATA[<a class="swiper-slide"]]></search>
            <add position="replace"><![CDATA[<a class="swiper-slide" data-ipvitem='{"ipv":"{{ iproductvideo.main_thumb ? 'true' : 'false' }}","main":"{{ iproductvideo.main_thumb ? 'true' : 'false' }}","source":"{{ iproductvideo.main_source }}","id":"{{ iproductvideo.main_id }}","ext":"{{ iproductvideo.main_ext }}"}']]></add>
        </operation>
        <operation>
            <search index="1"><![CDATA[<a class="swiper-slide"]]></search>
            <add position="replace"><![CDATA[<a class="swiper-slide" data-ipvitem='{"ipv":"{{ image.iProductVideo is not empty ? 'true' : 'false' }}","main":"false","source":"{{ image.iProductVideo is not empty ? image.iProductVideo_source }}","id":"{{ image.iProductVideo is not empty ? image.iProductVideo_id }}","ext":"{{ image.iProductVideo is not empty ? image.iProductVideo_ext }}"}']]></add>
        </operation>
    </file>

    <!-- Journal 3-->
    <file path="catalog/view/theme/journal3/template/product/product.twig">
        <operation info="add iProductVideo setting as data attribute">
            <search><![CDATA[class="container]]></search>
            <add position="replace"><![CDATA[data-ipvsetting='{"autoplay":{{ iproductvideo.autoplay ? '1' : '0' }},"nocookie":{{ iproductvideo.nocookie ? '1' : '0' }} }' class="container]]></add>
        </operation>
        <operation>
            <search><![CDATA[<img src="{{ image.image }}" {% if image.image2x %}]]></search>
            <add position="before"><![CDATA[
              {% if image.ipv_journal3|default(false) and iproductvideo.main_thumb is not empty %}
                <div class="iproductvideo-wrapper ipv-journal3">
                  {% if iproductvideo.main_source == 'local' %}
                    <video controls {{ iproductvideo.autoplay ? 'autoplay muted' }} preload="auto">
                      <source src="{{ popup }}" type="video/{{ iproductvideo.main_ext }}">
                      <i>Your browser does not support the video tag.</i>
                    </video>
                  {% elseif iproductvideo.main_source == 'youtube' %}
                      {% if iproductvideo.nocookie %}
                          <iframe src="//www.youtube-nocookie.com/embed/{{ iproductvideo.main_id }}?rel=0{{ iproductvideo.autoplay ? '&autoplay=1&mute=1' }}" frameborder="0" allowfullscreen="" allow="autoplay"></iframe>
                      {% else %}
                          <iframe src="//www.youtube.com/embed/{{ iproductvideo.main_id }}?rel=0{{ iproductvideo.autoplay ? '&autoplay=1&mute=1' }}" frameborder="0" allowfullscreen="" allow="autoplay"></iframe>
                      {% endif %}
                  {% elseif iproductvideo.main_source == 'vimeo' %}
                    <iframe src="https://player.vimeo.com/video/{{ iproductvideo.main_id }}{{ iproductvideo.autoplay ? '?autoplay=1&muted=1' }}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen allow="autoplay"></iframe>
                  {% endif %}
                </div>
              {% endif %}
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[<div class="swiper-slide]]></search>
            <add position="replace"><![CDATA[<div data-ipvitem='{"ipv":"{{ image.iProductVideo is not empty ? 'true' : 'false' }}","main":"false","source":"{{ image.iProductVideo is not empty ? image.iProductVideo_source }}","id":"{{ image.iProductVideo is not empty ? image.iProductVideo_id }}","ext":"{{ image.iProductVideo is not empty ? image.iProductVideo_ext }}"}' class="swiper-slide]]></add>
        </operation>

        <!-- Quick view -->
        <operation info="add iProductVideo setting as data attribute">
            <search><![CDATA[<div class="additional-images">]]></search>
            <add position="replace"><![CDATA[<div class="additional-images" data-ipvsetting='{"autoplay":{{ iproductvideo.autoplay ? '1' : '0' }},"nocookie":{{ iproductvideo.nocookie ? '1' : '0' }} }'>]]></add>
        </operation>
        <operation>
            <search><![CDATA[<div class="additional-image" data-index="{{ loop.index0 }}">]]></search>
            <add position="replace"><![CDATA[<div class="additional-image" data-ipvitem='{"ipv":"{{ image.iProductVideo is not empty ? 'true' : 'false' }}","main":"false","source":"{{ image.iProductVideo is not empty ? image.iProductVideo_source }}","id":"{{ image.iProductVideo is not empty ? image.iProductVideo_id }}","ext":"{{ image.iProductVideo is not empty ? image.iProductVideo_ext }}"}' data-index="{{ loop.index0 }}">]]></add>
        </operation>
        <operation>
            <search><![CDATA[{% set gallery = gallery|merge([{src: image.popup, thumb: image.galleryThumb, subHtml: heading_title}]) %}]]></search>
            <add position="replace"><![CDATA[{% set html = '' %}
				  {% set source = [] %}
				  {% set video = {} %}
				  {% set srcs = image.popup %}
				  {% if image.iProductVideo is not empty %}
				  {% if image.iProductVideo_source == 'local' %}
				  {% set source = source|merge([{"src": image.popup | replace({'#iproductvideo_local': ''}), "type":"video/mp4"}]) %}
				  {% set video = {"source": source, "attributes": {"preload": false, "playsinline": true, "controls": true}} %}
				  {% set html = '#iproductvideo_local' ~ loop.index0 %}
				  {% set srcs = '' %}
				  {% endif %}
				  {% endif %}
                    {% set gallery = gallery|merge([{src: srcs, thumb: image.image, subHtml: heading_title, html: html}]) %}]]></add>
        </operation>
    </file>
    <file path="system/library/journal3/minifier.php">
        <operation info="Make minifier smarter">
            <search><![CDATA[$_content = file_get_contents($style['href']);]]></search>
            <add position="before"><![CDATA[
                $ipv_style = strstr($style['href'], '?v=', true);
                if ($ipv_style) {
                  $style['href'] = $ipv_style;
                }
            ]]></add>
        </operation>
        <operation info="Make minifier smarter">
            <search><![CDATA[$_content = file_get_contents($script);]]></search>
            <add position="before"><![CDATA[
                $ipv_script = strstr($script, '?v=', true);
                if ($ipv_script) {
                  $script = $ipv_script;
                }
            ]]></add>
        </operation>
    </file>
</modification>
