Okay
  Public Ticket #3752255
Communicating between two sliders on the same page
Open

Comments

  •  3
    David started the conversation

    Hi.

    Not sure if this is included in support, but...

    I'm trying to communicate between two popup sliders. When a button is clicked in one, the other closes:

    document.addEventListener('DOMContentLoaded', function() {               
        // Handle button click inside the 'christmas-sale' slider  
        const christmasButton = document.getElementById('view-christmas-sale')  
        christmasButton.addEventListener('click', () => {               
            const snowmanGlobeSlider = document.querySelector('[data-ls-slug=snowball-lightbulb]').layerSlider()  
            snowmanGlobeSlider.api('closePopup')  // Close popup in snowman-globe slider  
        })   
      
        // Handle button click inside the 'snowman-globe' slider  
        const snowmanButton = document.getElementById('view-christmas-ornaments')          
        snowmanButton.addEventListener('click', () => { ⌬ tabnine {}  
            const christmasSaleSlider = document.querySelector('[data-ls-slug=christmas-bottom-bar]').layerSlider()
            christmasSaleSlider.api('closePopup')  // Close popup in christmas-sale slider   
        })   
    })   

    I get the following error:


    Uncaught TypeError: document.querySelector(...).layerSlider is not a function
        at HTMLSpanElement.<anonymous> (layerslider.js?ver=1730035793:8:96)


  •  137
    George replied

    Hello David,

    I've modified the end of your code:

    snowmanButton.addEventListener('click', () => { ⌬ tabnine {}  
            const christmasSaleSlider = document.querySelector('[data-ls-slug=christmas-bottom-bar]')
            christmasSaleSlider.layerSlider('closePopup')  // Close popup in christmas-sale slider   
        })   

    I think, that should work.

    Best Regards,
    George | Kreatura Dev Team

  •  3
    David replied

    Unfortunately, this didn't work either. However, I came up up with an acceptable solution. I'll leave it here in case anybody else has the same problem.

    In the Project -> Event Callbacks list, I modified the "sliderDidLoad" function as such:

    function( event, slider ) {
      window.christmasSaleSlider = slider
    }

    Then in my javascript:

      window.cmcGoToOrnaments = () => {
        window.christmasSaleSlider.api('closePopup')  // Close popup in christmas-sale slider
        setTimeout(() => {
          window.location.href = "<forwarding-url>"
        }, 500)
      }

    A lot of global variables, but other than that, it seems to work well.

    Thanks for your help!

  •  137
    George replied

    Nice solution! Thank you for the feedback!

    Best Regards,
    George | Kreatura Dev Team