• Resolved cicolino

    (@cicolino)


    Hi. I really like your plugin, and I will definitely buy some addons. I’ve been trying to achieve something, but without success.
    I’ve built an overlay element (.my-hidden-bewertungen) for the entire screen size (something like lightbox). This element opens on button click with the class: .my-bewertungen-button. Inside the overlay element, there is a review form shortcode. I can close this element with the close button: .close-bewertungen. Everything is working fine, but I would like to have it automatically close with a delay after the review is sent. This is my current java script code:

    (function() {
      var buttons = document.querySelectorAll('.my-bewertungen-button');
      var elements = document.querySelectorAll('.my-hidden-bewertungen');
      var backButton = document.querySelectorAll('.close-bewertungen');
      var visibleIndex = null;
    
      for (var i = 0; i < buttons.length; i++) {
        (function(i) {
          var button = buttons[i];
          var element = elements[i];
          var backBtn = backButton[i];
    
          button.addEventListener('click', function(event) {
            event.preventDefault();
    
            // überprüfe, ob ein Element bereits sichtbar ist
            if (visibleIndex !== null) {
              elements[visibleIndex].style.opacity = 0; // Setze die Deckkraft des sichtbaren Elements auf 0
            }
    
            if (element.style.display === 'block') {
              element.style.display = 'none';
              visibleIndex = null; // Setze den Index des sichtbaren Elements auf null
            } else {
              element.style.display = 'block';
              visibleIndex = i; // Setze den Index des sichtbaren Elements auf den aktuellen Index
    
              // Füge die Einblendanimation hinzu
              element.style.opacity = 0;
              setTimeout(function() {
                element.style.opacity = 1;
              }, 100); // ?ndern Sie die Zeit nach Bedarf, um die Geschwindigkeit der Animation anzupassen
            }
          });
    
          backBtn.addEventListener('click', function(event) {
            event.preventDefault();
    
            // Füge die Ausblendanimation hinzu
            element.style.opacity = 0;
            setTimeout(function() {
              element.style.display = 'none';
              visibleIndex = null; // Setze den Index des sichtbaren Elements auf null
            }, 500); // ?ndern Sie die Zeit nach Bedarf, um die Geschwindigkeit der Animation anzupassen
          });
        })(i);
      }
    })();
    

    I’ve tried with a hook:

    add_action('site-reviews/review/created', function ($review, $command) {
        sleep(1.5); // Verz?gerung in Sekunden anpassen
        echo '<script type="text/javascript">
            var element = document.querySelector(".my-hidden-bewertungen");
            element.style.opacity = 0;
            setTimeout(function() {
                element.style.display = "none";
            }, 500);
        </script>';
    }, 10, 2);

    but I have a spinning wheel when sending a review. I’ve tried many options with Chat GPT, but without success.

    Maybe you can give me some help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    Have you looked at the FAQ? There is a section there that explains how to hide the review form after submitting a review. Use that code snippet as a starting point.

    Thread Starter cicolino

    (@cicolino)

    Yes. I made this (or better Chat GPT made this for me because I’m not coding guy ), and this is working well for me

    /**
     * Hides the review form after a review has been submitted with a delay
     * Paste this in your active theme's functions.php file
     *
     * @param string $script
     * @return string
     */
    add_filter('site-reviews/enqueue/public/inline-script/after', function ($javascript) {
        return $javascript . "
        document.addEventListener('DOMContentLoaded', function () {
            GLSR.Event.on('site-reviews/form/handle', function (response, form) {
                if (false !== response.errors) return;
                form.classList.add('glsr-hide-form');
                form.insertAdjacentHTML('afterend', '<p class=\"my-bewertung-message\">' + response.message + '</p>');
    
                // Add a delay before closing the element
                setTimeout(function() {
                    var buttons = document.querySelectorAll('.my-bewertungen-button');
                    var elements = document.querySelectorAll('.my-hidden-bewertungen');
                    var visibleIndex = null;
    
                    for (var i = 0; i < buttons.length; i++) {
                        var element = elements[i];
    
                        element.style.opacity = 0;
                        setTimeout(function() {
                            element.style.display = 'none';
                            var responseMessage = document.querySelector('.my-bewertung-message');
                            responseMessage.parentNode.removeChild(responseMessage);
                        }, 500); // Adjust the delay time as needed
                    }
                }, 3000); // Adjust the delay time as needed
            });
        });";
    });
    

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Action after submitting’ is closed to new replies.