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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stewart.adam’s picture

Attached 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().

tarekdj’s picture

Status: Active » Needs review

Thanks stewart.adam for the patch, status changed for review

R2-D8’s picture

It 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:

--- a/scroll_to_top.js
+++ b/scroll_to_top.js

-		$("#back-top").hide();
+		$("#back-top", context).hide();

-		$('#back-top a').click(function () {
+		$('#back-top a', context).click(function () {

Maybe someone can provide a better solution.

tarekdj’s picture

Fix commited to dev branch. Thanks stewart.adam.

tarekdj’s picture

Issue summary: View changes
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.