// source --> https://saasenheim.fr/wp-content/plugins/document-emberdder/build/public.js?ver=2.1.0 
(()=>{"use strict";document.addEventListener("DOMContentLoaded",function(){const e=document.querySelectorAll(".ppv_container");function t(e){if(!e)return!1;const n=e.querySelector("iframe:not(.pdfp_library)"),o=e.querySelector(".ppv-lightbox-loading"),l=e.querySelector(".ppv-loading");if(n&&null!==n.contentDocument){const o=n.src;n.src=o,setTimeout(()=>{t(e)},1200)}else o&&(o.style.display="none"),l&&(l.style.display="none")}Object.values(e).map(e=>{const n=Boolean(e.dataset.lightbox),o=document.querySelector(".ppv-lightbox-overlay"),l=e.querySelector(".bplde-lightbox-close");if(n){const n=e.querySelector(".ppv-lightbox-btn");n&&n.addEventListener("click",function(){o.classList.add("open"),t(e)}),l&&l.addEventListener("click",function(){o.classList.remove("open")})}else t(e)}),document.querySelectorAll(".ppv-email-gate-btn").forEach(e=>{e.addEventListener("click",function(e){e.preventDefault();const t=this.dataset.docId,n=document.getElementById("ppv-gate-modal-"+t);n&&(n.style.display="flex")})}),document.querySelectorAll(".ppv-close-modal").forEach(e=>{e.addEventListener("click",function(e){e.preventDefault(),this.closest(".ppv-email-gate-modal-wrapper").style.display="none"})}),document.querySelectorAll(".ppv-email-gate-form").forEach(e=>{e.addEventListener("submit",function(e){e.preventDefault();const t=this.querySelector('button[type="submit"]'),n=t.innerText;t.innerText="Processing...",t.disabled=!0;const o=new FormData(this),l={name:o.get("name"),email:o.get("email"),document_id:o.get("document_id")};fetch(bplde_obj.rest_url+"gate-download",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}).then(e=>e.json()).then(e=>{e.success&&e.url?(this.closest(".ppv-email-gate-modal-wrapper").style.display="none",window.location.href=e.url):alert(e.message||"Error processing request")}).catch(e=>{alert("Error connecting to server.")}).finally(()=>{t.innerText=n,t.disabled=!1})})}),document.querySelectorAll(".ppv-direct-download").forEach(e=>{e.addEventListener("click",function(e){if("undefined"==typeof bplde_obj)return;e.preventDefault();const t=this.dataset.docId,n=this,o=n.innerHTML;n.innerHTML="Downloading...";let l=null;"newtab"===n.dataset.behavior&&(l=window.open("about:blank","_blank")),jQuery.ajax({url:bplde_obj.ajax_url,type:"POST",data:{action:"de_track_download",nonce:bplde_obj.track_nonce,document_id:t},success:function(e){if(e.success){const r=n.closest("p, div").querySelector(".ppv-download-count");r&&(r.innerText=e.data.count+" downloads");const a=bplde_obj.rest_url+"download/"+t+"?de_nonce="+e.data.nonce;"newtab"===n.dataset.behavior&&l?l.location.href=a:window.location.href=a,setTimeout(()=>{n.innerHTML=o},1e3)}else alert("Tracking error: "+(e.data||"Unknown error")),n.innerHTML=o,l&&l.close()},error:function(){n.innerHTML=o,l&&l.close()}})})})})})();
// source --> https://saasenheim.fr/wp-content/plugins/email-encoder-bundle/assets/js/custom.js?ver=2c542c9989f589cd5318f5cef6a9ecd7 
/* Email Encoder */
/*global jQuery, window*/
jQuery(function ($) {

    'use strict';

    // encoding method
    function rot13(s) {
        // source: http://jsfromhell.com/string/rot13
        return s.replace(/[a-zA-Z]/g, function (c) {
            return String.fromCharCode((c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
        });
    }

    /**
     * EMAIL RELATED LOGIC
     */

    // fetch email from data attribute
    function fetchEmail(el) {
        var email = el.getAttribute('data-enc-email');

        if (!email) {
            return null;
        }

        // replace [at] sign
        email = email.replace(/\[at\]/g, '@');

        // encode
        email = rot13(email);

        return email;
    }

    // replace email in title attribute
    function parseTitle(el) {
        var title = el.getAttribute('title');
        var email = fetchEmail(el);

        if (title && email) {
            title = title.replace('{{email}}', email);
            el.setAttribute('title', title);
        }
    }

    // set input value attribute
    function setInputValue(el) {
        var email = fetchEmail(el);

        if (email) {
            el.setAttribute('value', email);
        }
    }

    // open mailto link
    function mailto(el) {
        var email = fetchEmail(el);

        if (email) {
            window.location.href = 'mailto:' + email;
        }
    }
    
    // revert
    function revert(el, rtl) {
        var email = fetchEmail(el);

        if (email) {
           rtl.text(email);
           rtl.removeClass('eeb-rtl');
        }
    }

    // prepare for copying email
    document.addEventListener('copy', function(e){
        $('a[data-enc-email]').each(function () {
            var rtl = $(this).find('.eeb-rtl');

            if (rtl.text()) {
                revert(this, rtl);
            }
        });
        console.log('copy');
    });

    // set mailto click
    $('body').on('click', 'a[data-enc-email]', function () {
        mailto(this);
    });

    // parse title attirbute
    $('a[data-enc-email]').each(function () {
        parseTitle(this);
    });

    // parse input fields
    $('input[data-enc-email]').each(function () {
        setInputValue(this);
    });

});