Use Drupal.behaviors, not jQuery(document).ready()

Created on 21 April 2019, over 5 years ago
Updated 15 August 2024, 3 months ago
πŸ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡·πŸ‡ΈSerbia gnikolovski Subotica, Serbia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States aaronpinero

    I visited this issue because I am experiencing inconsistent results with the module. Sometimes the JavaScript for the hierarchical taxonomy menu will load properly and sometimes it will not. That is, the JavaScript appears in the HTML in a script tag but none of the code inside is being executed. This makes me think that because Drupal behaviors are not being used, the JS is running before the menu block is fully rendered and none of the event handlers for opening and closing submenus are being applied.

    I added the attached patch against the 2.0.x branch (created a new one since the last one is quite old) and it seems like the issue has been resolved.

  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States aaronpinero

    I am adding an updated patch. I encountered a situation where, as described in one of the earlier comments, the submenus open and then immediately close. I believe this is because the JavaScript is not using core/once as a dependency. Inspecting the menu in the browser showed that the event handler for toggling open the submenus was being added multiple times.

    The updated patch uses 'once' to make sure this doesn't happen. I added a relationship to another old issue that also suggested using 'once' in the JavaScript.

    I am marking this now as Needs Review.

Production build 0.71.5 2024