You are here

function _pagerer_itemize_js_element in Pagerer 7

Return HTML to an active js element for page navigation.

Enables client side to directly enter a target page through a javascript enabled element.

Parameters

string $element_type: 'widget' for an active input box, 'slider' for a jquery ui slider, 'scrollpane' for a scrolling pager

array $variables: theme's variables

array $markers: precalculated markers for the pager

Return value

array pre-rendered items

2 calls to _pagerer_itemize_js_element()
_pagerer_itemize_page_links in ./pagerer.module
Return rendered items representing the links to 'page' elements in the pager.
_pagerer_theme_handler in ./pagerer.module
Pagerer's theme handler.

File

./pagerer.module, line 1777
Pagerer

Code

function _pagerer_itemize_js_element($element_type, $variables, $markers) {
  global $pager_page_array, $pager_limits;
  static $js_enabled;
  $c = $markers['pager_current'] - 1;
  $m = $markers['pager_max'] - 1;

  // Checks jQuery is available.
  if (!isset($js_enabled)) {

    // Requires 'jquery_update' module.
    if (module_exists('jquery_update')) {

      // Add pagerer js.
      $js_enabled = TRUE;
      drupal_add_js(drupal_get_path('module', 'pagerer') . '/pagerer.js');
    }
    else {

      // Degrade.
      $js_enabled = FALSE;
    }
  }

  // Slider and scrollpane will not work for Internet Explorer below version 9.
  // In such case, degrade to widget.
  if ($element_type == 'slider' or $element_type == 'scrollpane') {
    $browser_info = _pagerer_browser_info();
    if ($browser_info['browser'] == 'MSIE' and $browser_info['version_major'] < 9) {
      $element_type = 'slider_degraded';
    }
  }

  // Prepare query parameters.
  // 'page' querystring fragment, overriding current 'page' with a text
  // that the js widget will then replace with the content of HTML 'value'
  // attribute.
  $page_new = pager_load_array($c, $variables['element'], $pager_page_array);
  $page_new[$variables['element']] = 'pagererpage';
  ksort($page_new);
  $variables['parameters']['page'] = implode(',', $page_new);

  // Combine query parameters with those coming from the current request URL.
  $variables['parameters'] = array_merge(pager_get_query_parameters(), $variables['parameters']);

  // Are we displaying pages or items; 'value' HTML attribute will bear
  // the current $current value.
  if ($variables['display'] == 'pages') {
    $current = $markers['pager_current'];
    $interval = 1;
  }
  else {
    $current = $markers['pager_current_first_item'];
    $interval = $pager_limits[$variables['element']];
  }

  // Prepare path to the page.
  $query_parms = drupal_get_query_parameters(NULL, array());
  $path = $query_parms['q'] . '?' . drupal_http_build_query($variables['parameters']);

  // Prepare js widget state.
  $state = array(
    'path' => $path,
    'element' => $variables['element'],
    'quantity' => $variables['quantity'],
    'total' => $markers['pager_max'],
    'totalItems' => $markers['pager_item_max'],
    'current' => $markers['pager_current'] - 1,
    'interval' => $interval,
    'display' => $variables['display'],
    'pagerSeparator' => $variables['pager_separator'],
    'rangeSeparator' => $variables['range_separator'],
    'pageTag' => $variables['tags']['page'],
  );
  switch ($element_type) {
    case 'widget':
      $state['widgetResize'] = $variables['widget_resize'];
      break;
    case 'slider':
      $state['action'] = $variables['slider_action'];
      $state['timelapse'] = $variables['slider_action_timelapse'];
      $state['icons'] = $variables['slider_navigation_icons'];
      $state['tickmarkTitle'] = $variables['tags']['slider_tickmark_title'];
      break;
    case 'scrollpane':
      $state['pageTitle'] = $variables['tags']['page_title'];
      $state['firstTitle'] = $variables['tags']['first_title'];
      $state['lastTitle'] = $variables['tags']['last_title'];
      break;
  }
  $state_encoded = drupal_json_encode($state);

  // Create items.
  $items = array();
  if ($js_enabled) {
    switch ($element_type) {
      case 'widget':
        $title = $variables['tags']['widget_title'];
        $items[] = array(
          'class' => array(
            'pager-item',
            'widget',
            'active',
          ),
          'data' => "<input type=\"text\" class=\"pagerer-page\" name ='{$state_encoded}' title=\"{$title}\" value=\"{$current}\" />",
        );
        break;
      case 'scrollpane':

        // Add ui.button library.
        drupal_add_library('system', 'ui.button');

        // Left buttons.
        $items[] = _pagerer_itemize_link('first', $variables, $markers, 'button');
        $items[] = _pagerer_itemize_link('previous', $variables, $markers, 'button');

        // Scrollpane.
        $variables['label_display'] = 'none';
        $variables['current_display'] = 'normal';
        $variables['total_display'] = 'none';
        $variables['first_link'] = 'never';
        $variables['previous_link'] = 'never';
        $variables['next_link'] = 'never';
        $variables['last_link'] = 'never';
        $items[] = array(
          'class' => array(
            'pager-item',
            'pagerer-scrollpane',
          ),
          'id' => $state_encoded,
          'data' => theme('pagerer_standard', $variables),
        );

        // Right buttons.
        $items[] = _pagerer_itemize_link('next', $variables, $markers, 'button');
        $items[] = _pagerer_itemize_link('last', $variables, $markers, 'button');
        break;
      case 'slider':

        // Add ui.slider library.
        drupal_add_library('system', 'ui.slider');
        if ($variables['slider_navigation_icons'] != 'no') {
          $items[] = array(
            'class' => array(
              'pager-item',
              'widget',
              'active',
            ),
            'data' => "<div class='pagerer-slider-control-icon ui-icon ui-icon-circle-minus'/>",
          );
        }
        $title = $variables['tags']['slider_title'];
        $items[] = array(
          'class' => array(
            'pager-item',
            'widget',
          ),
          'data' => "<div class='pagerer-slider' id='{$state_encoded}' title='{$title}'/>",
        );
        if ($variables['slider_navigation_icons'] != 'no') {
          $items[] = array(
            'class' => array(
              'pager-item',
              'widget',
              'active',
            ),
            'data' => "<div class='pagerer-slider-control-icon ui-icon ui-icon-circle-plus'/>",
          );
        }
        break;
      case 'slider_degraded':

        // Basically, a widget with first/prev/next/last links.
        $items[] = _pagerer_itemize_link('first', $variables, $markers);
        $items[] = _pagerer_itemize_link('previous', $variables, $markers);
        $title = $variables['tags']['widget_title'];
        $items[] = array(
          'class' => array(
            'pager-current',
            'widget',
          ),
          'data' => "<input type=\"text\" class=\"pagerer-page\" name ='{$state_encoded}' title=\"{$title}\" value=\"{$current}\" />",
        );
        $items[] = _pagerer_itemize_link('next', $variables, $markers);
        $items[] = _pagerer_itemize_link('last', $variables, $markers);
        break;
    }
  }
  else {
    $items[] = array(
      'class' => array(
        'pager-current',
      ),
      'data' => $current,
    );
  }
  return $items;
}