Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Grav-plugin-sharer does not fire anything

Started by Junillon 5 years ago · 7 replies · 537 views
5 years ago

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 ?

5 years ago

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 ?

last edited 02/27/21 by Junillon
5 years ago

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...

5 years ago

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

5 years ago

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 🙂
thanks for answering

5 years ago

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

JS
$('[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.:

JS
$('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
5 years ago

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 🙂

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 43 1 week ago
Plugins · by Xavier, 4 weeks ago
2 53 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1179 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 47 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 72 2 months ago