You are here

function fac_page_build in Fast Autocomplete 7

Implements hook_page_build().

Add the Fast Autocomplete javaScript.

File

./fac.module, line 152
This file contains the main functions of the Fast Autocomplete module.

Code

function fac_page_build(&$page) {
  global $language;

  // Add the Fast Autcomplete jQuery plugin to the output.
  $page['content']['#attached']['library'][] = array(
    'fac',
    'fastautocomplete',
  );
  $highlight_enabled = FALSE;
  if (($library_check = libraries_detect('highlight')) && !empty($library_check['installed'])) {
    $highlight_enabled = TRUE;

    // Add the Highlight jQuery plugin to the output.
    $page['content']['#attached']['libraries_load'][] = array(
      'highlight',
    );
  }
  $empty_result = variable_get('fac_empty_result', '');

  // Allow other modules to modify the empty result.
  drupal_alter('fac_empty_result', $empty_result);
  $account = variable_get('fac_anonymous_search', TRUE) ? drupal_anonymous_user() : $GLOBALS['user'];

  // Add the Fast Autocomplete settings to the output.
  $fac_settings = array(
    'jsonFilesPath' => base_path() . variable_get('file_public_path', conf_path() . '/files') . '/fac-json/' . $language->language . '/' . _fac_get_role_hmac($account) . '/',
    'inputSelectors' => variable_get('fac_input_selectors', ''),
    'keyMinLength' => variable_get('fac_key_min_length', 1),
    'keyMaxLength' => variable_get('fac_key_max_length', 5),
    'breakpoint' => variable_get('fac_breakpoint', 0),
    'emptyResult' => $empty_result,
    'allResultsLink' => variable_get('fac_all_results_link', TRUE),
    'allResultsLinkThreshold' => variable_get('fac_all_results_link_threshold', -1),
    'highlightEnabled' => $highlight_enabled,
    'resultLocation' => variable_get('fac_result_location', FALSE),
  );
  $page['content']['#attached']['js'][] = array(
    'data' => array(
      'fac' => $fac_settings,
    ),
    'type' => 'setting',
  );

  // Add the Fast Autocomplete JavaScript to the output.
  $page['content']['#attached']['js'][] = array(
    'data' => drupal_get_path('module', 'fac') . '/js/fac.js',
    'type' => 'file',
  );
  if (variable_get('fac_use_module_css', TRUE)) {

    // Add the Fast Autocomplete CSS to the output.
    $page['content']['#attached']['css'][] = drupal_get_path('module', 'fac') . '/css/fac.css';
  }
}