Grav-plugin-sharer does not fire anything

Hi all

I installed the very promising sharer plugin, and … all the buttons are displayed, the config is ok, but no clicks works !
Even in debug, there is no event launched. Nothing is happening, no popup or else. Can’t even trace in JS as there is no call. any idea anyone ?

Does console show any JS error?

absolutely nothing.
The JS is loaded.
As the surprise comes from the fact clicking the button doesn’t call anything, I atually, debug something. Here is what I have :
function (p, r) is called, but the line
var t = r.querySelectorAll("[data-sharer]"), e, a = t.length;
seems to have a missing “)” … I’m right ?

ok, I made a very little modification to
var t = r.querySelectorAll("[data-sharer]");
var e =0;
var a = t.length;

so it does not fail anymore and work in global page.

But I found another thing. It’s not working when loading from jscript.
In my code, part of the page is loaded with $(".globalInfos").load(st, function( response, status, xhr )
and then, the queryselector doesn’t catch “data-sharer” for some strange reason…

The reason isn’t strange at all, if click listener is defined before your part of the page is loaded. After the content is loaded dynamically, you have to add click listeners to these newly loaded elements

I think “strange” because the init part is called when dynamically load, but failed to find anything.
ok, so all I have to do is to try calling the init part again after loading. I’ll do that and come back to tell the result :slight_smile:
thanks for answering

I’m not familiar with the plugin, but I see you use jQuery. So this might come handy some time in the future maybe.

If you add listeners like

$('[data-sharer]').on('click', function(e) {});

Then you have to do this every time dynamic content, which contains such elements, is loaded, but if you add like this for eg.:

$('body').on('click', '[data-sharer]', function(e) {});

Then the event listener is added actually to the body itself and clicks are checked for '[data-sharer]' inside body no matter when elements were loaded. So in this case you wouldn’t need to add listeners every time dynamic content is loaded.

Not sure how you can achieve same with vanilla JS

1 Like

Actually, a “dirty” way to do it, is to reload the script through $.getScript.
It automatically rebinds event.
That’s worth it in my case. User click one image, script backload a page and show it in a div, then the getscript binds everyting correctly.
In some futur days, I’ll have more times and try some script modifications.
Anyway, thanks for you help :slight_smile: