Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Drupal.behaviors is used in the JavaScript file to setup the callbacks but it does not respect the context parameter, so it is run every time any other module calls attachBehaviors (i.e. whenever another module changes the DOM). This causes multiple scroll to top divs to be added to the same page, all with the same HTML ID. As well, the scroll callback gets attached many times resulting in a very bizarre effect when attempting to scroll to top (the page locks up and keep pushing upwards for several seconds until all of the scroll callbacks get a chance to finish in sequence).
Comment | File | Size | Author |
---|---|---|---|
#1 | scroll_to_top-respect_behaviors_context-1879202-1.patch | 1.07 KB | stewart.adam |
Comments
Comment #1
stewart.adam CreditAttribution: stewart.adam commentedAttached patch resolves the problem by inspecting only the context for matching elements, not the entire page. The scroll callback is only added when context == document (i.e. when the page first loads), and is equivalent to $(document).ready().
Comment #2
tarekdj CreditAttribution: tarekdj commentedThanks stewart.adam for the patch, status changed for review
Comment #3
R2-D8 CreditAttribution: R2-D8 commentedIt seems to me the 7.x versions are having the same problem.
Of course the 6.x-patch doesn't match on 7.x, and I'm not a JavaScript expert.
But after some analysis and testing the only modifications I needed are:
Maybe someone can provide a better solution.
Comment #4
tarekdj CreditAttribution: tarekdj commentedFix commited to dev branch. Thanks stewart.adam.
Comment #5
tarekdj CreditAttribution: tarekdj commented