Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ws:init not working #159

Open
pjebs opened this issue Apr 28, 2020 · 13 comments
Open

ws:init not working #159

pjebs opened this issue Apr 28, 2020 · 13 comments

Comments

@pjebs
Copy link

pjebs commented Apr 28, 2020

It appears that ws:init event is not working

@pjebs
Copy link
Author

pjebs commented Apr 28, 2020

     window.ws = new WebSlides({
        changeOnClick: true,
        loop: false,
      });

      window.ws.el.addEventListener('ws:init', function (e) {
                console.log("ws:init");
      });

@pjebs
Copy link
Author

pjebs commented Apr 29, 2020

@Antonio-Laguna @jlantunez Is this possibly a regression?

@Antonio-Laguna
Copy link
Member

I don't think so since this hasn't changed. I think the event has fired by the time you're attaching the event listener.

Do it like this:

document.body.addEventListener('ws:init', function (e) {
    console.log("ws:init");
});

window.ws = new WebSlides({
    changeOnClick: true,
    loop: false,
});

@pjebs
Copy link
Author

pjebs commented Apr 29, 2020

Can you update docs? (in repo's wiki)

@Antonio-Laguna
Copy link
Member

Added a note there.

@pjebs
Copy link
Author

pjebs commented Apr 29, 2020

Thanks

@pjebs
Copy link
Author

pjebs commented Apr 29, 2020

@Antonio-Laguna your suggestion doesn't work.

@pjebs
Copy link
Author

pjebs commented Apr 29, 2020

The docs state: WebSlides fires events on the WebSlide's element.

So I tried your suggestion on the element too and still didn't work. (window.ws doesn't exist at this point.)

      window.ws.el.addEventListener('ws:init', function (e) {
                console.log("ws:init");
      }); // window.ws doesn't exist at this point.
     window.ws = new WebSlides({
        changeOnClick: true,
        loop: false,
      });

@Antonio-Laguna
Copy link
Member

Needs to go as I wrote above. The event bubbles so it'll reach the body.

@pjebs
Copy link
Author

pjebs commented Apr 29, 2020

@Antonio-Laguna I tried what you wrote:

document.body.addEventListener('ws:init', function (e) {
    console.log("ws:init");
});

window.ws = new WebSlides({
    changeOnClick: true,
    loop: false,
});

It doesn't work.

@pjebs
Copy link
Author

pjebs commented Apr 29, 2020

Can we reopen this?

@pjebs
Copy link
Author

pjebs commented Apr 29, 2020

For future readers, here is my work-around. It's a dirty hack but works.

Add this after your code.

<script type="text/javascript" defer>document.body.dispatchEvent(new Event('ws:init'));</script>

@Antonio-Laguna
Copy link
Member

Sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants