1

I've designed a calendar of events. It uses a Next and Previous pager. With the theme I am using, the top of the calendar displays part way down the screen when first viewed. The user typically scrolls the screen using the mouse to bring the entire calendar into view. This is problematic if the user needs to page to the next or prior month because he needs to once again use the mouse to position the entire calendar on the screen.

I'm not exactly clear on the best approach to resolve this. I thought about looking into the theme code but wasn't sure if that's a good place to start. I thought about trapping the display of each page of the calendar and trying to reposition (scroll) the page programmatically, but, that seemed like unnecessary code.

Can anyone advise me on a proper approach to solve this issue? Ideally, I'd like the user to not have to scroll each page of the calendar when he uses the Next or Prior button. It seems like there should be a way to ensure the entire calendar is visible.

1 Answer 1

0

One solution that comes to mind is to use hook_pager_link() to modify your view's pager links to include fragment/anchor that is in your view's header. This would work on the assumptions:

  1. You have custom unique text for previous/next pager links (e.g. "previous month"/"next month").
  2. You placed an anchor link in your view header (e.g. <a name="calendar"></a>).

In your theme's template.php you could override like so:

function MYTHEME_pager_link($variables) {

  // If we are looking at pager links with our custom title 
  // use our modified theme_pager_link code:
  if (in_array($variables['text'], array('previous month', 'next month'))) {
    $text = $variables['text'];
    $page_new = $variables['page_new'];
    $element = $variables['element'];
    $parameters = $variables['parameters'];
    $attributes = $variables['attributes'];

    $page = isset($_GET['page']) ? $_GET['page'] : '';
    if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
      $parameters['page'] = $new_page;
    }

    $query = array();
    if (count($parameters)) {
      $query = drupal_get_query_parameters($parameters, array());
    }
    if ($query_pager = pager_get_query_parameters()) {
      $query = array_merge($query, $query_pager);
    }

    // Add our custom #calendar fragment
    $attributes['href'] = url($_GET['q'], array('query' => $query, 'fragment' => 'calendar'));
    return '<a' . drupal_attributes($attributes) . '>' . check_plain($text) . '</a>';
  }
  else { // Otherwise fall back to core theme pager.
    return theme_pager_link($variables);
  }
}
1
  • Thanks for the advice. I'll give it a shot and report back.
    – rrirower
    Commented Jun 20, 2016 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.