For one of my clients, I needed the opposite feature, ie give the possibility to scroll to the bottom of the page from the top of the page. I decided to implement it as a patch to this module, which I'm going to provide in this issue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

guillaumev’s picture

Status: Active » Needs review
FileSize
355 bytes
6.91 KB

Here is the patch, along with the image.

guillaumev’s picture

New version of the patch for latest 2.x version... Would love to see this committed :-)

dddave’s picture

FileSize
17.25 KB

Basically works fine but the arrow downwards isn't showing...
scrollbottom

fadgadget’s picture

Hello does this patch allow folks to move to bottom and the top if they wish? Thanks

tarekdj’s picture

+++ b/scroll_to_top.js
@@ -5,11 +5,16 @@
+        if (bottom_enabled) {
+          // append scroll to bottom link
+          $("body").append("<p id='scroll-bottom'><a href='#scroll_bottom'><span id='bottom-button'></span><span id='bottom-link'>" + settings.scroll_to_top.bottom_label + "</span></a></p>");
+        }
 	// Preview function

It would be better to check if the #scroll-bottom exists. This will avoid a bug with ajax requests.
Fix would be something like :

var bottom_exist= jQuery('#scroll-bottom').length; // bottom_exist = 0 if element doesn't exist
if (bottom_enabled && bottom_exist == 0) {
  // Do the stuff...
}
tarekdj’s picture

Issue summary: View changes
Status: Needs review » Needs work
baso’s picture

Thanks tarekdj for the quick help. I tested your suggestion by changing contents of file 'scroll_to_top.js' as follows:

Drupal.behaviors.scroll_to_top = {
  attach: function (context, settings) {
        var bottom_enabled = settings.scroll_to_top.enable_scroll_bottom;
	
	// Append back-to-top link to body.
	var exist= jQuery('#back-top').length; // Perform exist test to work around AJAX bug.
	if(exist == 0){ 
		$("body").append("<p id='back-top'><a href='#top'><span id='button'></span><span id='link'>" + settings.scroll_to_top.label + "</span></a></p>");
	}
	
  // Append scroll-to-bottom link to body.
	var bottom_exist= jQuery('#scroll-bottom').length; // Perform exist test to work around AJAX bug.
  if (bottom_enabled && bottom_exist == 0) {
    $("body").append("<p id='scroll-bottom'><a href='#scroll_bottom'><span id='bottom-button'></span><span id='bottom-link'>" + settings.scroll_to_top.bottom_label + "</span></a></p>");
  }
  
  // Preview function

I then tested the changes on regular pages and views with exposed filters on the view itself and on blocks in different regions. And on my site it works. So in my opinion time has come for patch #3 :-).

Kind regards,
baso.

tarekdj’s picture

Status: Needs work » Closed (won't fix)