I'm running Drupal 8 with an off-canvas menu supported by mmenu (http://mmenu.frebsite.nl/). When I enabled the menu, the Disqus comments disappeared. The Disqus comments were running on the same theme without this menu library. So I can confirm that my setup is configured correctly. Also, when I switch to Drupal's default themes,
Here is an example page with Disqus comments enabled, but nothing is showing:
https://swingtx7left.org/blog/house-party-alex-triantaphyllis
The disqus_thread div is being generated, but the disqus comments box are not displaying. It seems that settings.disqus is undefined when Drupal.behaviors.drupal is called, and thus, the code to embed disqus is never executed in disqus.js.
Update:
I have a theory of what might be happening. None of the javascript is being loaded from the disqus module. This might be due to a conflict between the call to Dupal.behaviors.disqus and the call to $(document).ready()
to initialize the off-canvas menu.
The mmenu tutorial provides that the off-canvas menu can be initialized using $(document).ready()
:
$(document).ready(function() {
$("#my-menu").mmenu({});
});
See http://mmenu.frebsite.nl/tutorials/off-canvas/the-page.html
I'll see if I can tweak how the off-canvas menu is initialized.
Update 2:
So it seems that settings.disqus is no longer defined when Drupal.behaviors.drupal is attached.
In my personal virtual server, I changed how the off-canvass menu is loaded using another Drupal.behaviors function. And I can see the disqus behaviors when I setup a breakpoint inside the Drupal.attachBehavoirs function. So in all there doesn't seem to be a conflict with the behaviors, but instead the settings.disqus is undefined.
Comments
Comment #2
orange-wedge CreditAttribution: orange-wedge commentedComment #3
orange-wedge CreditAttribution: orange-wedge commentedComment #4
orange-wedge CreditAttribution: orange-wedge commentedComment #5
orange-wedge CreditAttribution: orange-wedge as a volunteer commentedI tried adding a dependency to the drupalSettings in
disqus.libraries.yml
to force the drupalSettings to load before the disqus javascript library is loaded, but that did not work.E.g.:
Both settings and drupalSettings remained undefined in disqus.js regardless of the dependency.
But I stumbled on this change record for Drupal core: https://www.drupal.org/node/2513818
Fabianx suggests using the following code in the rare event drupalSettings is not being loaded in time.
As a proposed patch for the disqus module, I've added an if-statement to check if settings.disqus is undefined, and if settings.disqus is undefined then force settings to be loaded using the JSON.parse statement above.
E.g.:
Comment #6
gaurav.kapoor CreditAttribution: gaurav.kapoor at Axelerant for Drupal India Association commentedThere are already issues open up for improvement related to JS optimization and this issue will be fixed under those. Check https://www.drupal.org/project/disqus/issues/3212045 and https://www.drupal.org/project/disqus/issues/1508786.