1. PROMO Get 60% OFF Lifetime Pro Membership & access all our Pro Divi Extensions, Divi Layouts, Divi AI Generator, Divi Block, etc.VIEW PRICING
BEST Divi Block - A revolutionary drag & drop tool to easily mix & match 960+ premade blocks (Light & Dark) to kick start your Divi site design. Special module designs are included as well. Also newly added AI generator & color.
Learn More About Divi BlockFree Version ~ 340+ Free Blocks

Solved Code to hide elements in frontend, hide them also in backend.

Discussion in 'Free Divi Community Forum' started by Arunki, Jun 3, 2024.

  1. Arunki

    Arunki New Member

    Hi, Friends

    I need a hand to solve this.

    I found the right code for synchronizing elements with the timing of video, however, to edit the sections on this page I have to temporarily delete the code module, edit everytinhg and then call it back again when my edition is finished, because the code hide the sections, elements also in the backend.

    The code I am talking about is:

    Code:
    <style>.delay { display: none }</style>
    
    <script type="text/javascript">
    document.addEventListener("DOMContentLoaded", function() {
    /* Change the value 10 for the seconds where the sections will appear */
    var SECONDS_TO_DISPLAY = 10;
    var CLASS_TO_DISPLAY = ".delay";
    /* From now on don't have to change */
    var attempts = 0;
    var elsHiddenList = [];
    var elsDisplayed = false;
    var elsHidden = document.querySelectorAll(CLASS_TO_DISPLAY);
    var alreadyDisplayedKey = "alreadyElsDisplayed" + SECONDS_TO_DISPLAY;
    var alreadyElsDisplayed = null;
    try {
        alreadyElsDisplayed = localStorage.getItem(alreadyDisplayedKey);
    } catch(e) {
        console.warn('Failed to read data from localStorage: ', e);
    }
    setTimeout(function () { elsHiddenList = Array.prototype.slice.call(elsHidden); }, 0);
    var showHiddenElements = function () {
    elsDisplayed = true;
    elsHiddenList.forEach((e) => e.style.display = "block");
    try {
      localStorage.setItem(alreadyDisplayedKey, true);
    } catch (e) {
      console.warn('Failed to save data in localStorage: ', e);
    }
    }
    var startWatchVideoProgress = function () {
    if (typeof smartplayer === 'undefined' || !(smartplayer.instances && smartplayer.instances.length)) {
    if (attempts >= 10) return;
    attempts += 1;
    return setTimeout(function () { startWatchVideoProgress() }, 1000);
    }
    smartplayer.instances[0].on('timeupdate', () => {
    if (elsDisplayed || smartplayer.instances[0].smartAutoPlay) return;
    if (smartplayer.instances[0].video.currentTime < SECONDS_TO_DISPLAY) return;
    showHiddenElements();
    })
    }
    if (alreadyElsDisplayed === 'true') {
    setTimeout(function () { showHiddenElements(); }, 100);
    } else {
    startWatchVideoProgress()
    }
    });
    </script>
    
     
    1. PRO MEMBER PERKS Divi Ultimate Header Plugin - Custom Divi Builder header on desktop + default slide in / fullscreen menu on mobile:Learn More
  2. Divi Booster

    Divi Booster Divi Expert

    Hey Arunki, nice work on getting this far with it.

    Divi adds the class "et-fb" to the body tag when the visual builder is active, so you can usually stop CSS / selectors from applying in the visual builder by adding "body:not(.et-fb)" at the start. In your case, I think changing the start of the code to this should do the trick:

    Code:
    <style>body:not(.et-fb) .delay { display: none }</style>
    
    <script type="text/javascript">
    document.addEventListener("DOMContentLoaded", function() {
    /* Change the value 10 for the seconds where the sections will appear */
    var SECONDS_TO_DISPLAY = 10;
    var CLASS_TO_DISPLAY = "body:not(.et-fb) .delay";
    I haven't tested it, but if that doesn't work let me know and I'll do a proper test of it.
     
  3. Arunki

    Arunki New Member


    Fantastic!! Perfect!

    Thank you, my friend.
     
    1. PRO MEMBER PERKS Divi Cart Count Plugin - Easily add cart count to your Divi cart icon. 6 different styles to choose from:Learn More
  4. Divi Booster

    Divi Booster Divi Expert

    You're welcome, Arunki. I'm glad that helped :)