function search_api_ajax_preprocess_page in Search API ajax 7
Implementation of hook_preprocess_page().
Adds JavaScript files and settings. To successfully configure this module, another module must implement hook_search_api_ajax_settings(), which must return an array with the required keys "content", "blocks", "regions" and the optional key "spinner".
"content" must be the CSS selector for the HTML node in which the page content is displayed. In the Zen theme, this is '#content-area'.
"blocks" must be a map between the block keys and the CSS selectors for the blocks. Block keys follow the pattern: MODULE_DELTA. In the Zen theme, this may be: array('node_0' => '#block-node-0', ...). You need only do this for search-related blocks. If you don't know your blocks, run:
<pre> $modules = search_api_ajax_modules(); foreach ($modules as $module) { if (module_exists($module)) { if ($list = module_invoke($module, 'block', 'list')) { foreach (array_keys($list) as $delta) { print $module .'_'. $delta; } } } } </pre>
"regions" must be a map between the theme regions and the CSS selectors for the regions. In the Zen theme, this may be: array('content_top' => '.region-content-top'). If you don't know your theme's regions, run: <code>system_region_list('mytheme');</code>
(Optional) "spinner" is the path to an animated image to be displayed while content is loading via AJAX, e.g.: <code>base_path() . drupal_get_path('module', 'mymodule') .'/images/spinner.gif'</code>
See also
http://developer.yahoo.com/yui/history/
File
- ./
search_api_ajax.module, line 257 - AJAXifies the Search API search pages, links, ranges, sorts and forms.
Code
function search_api_ajax_preprocess_page(&$vars, $hook) {
$return = FALSE;
foreach (search_api_current_search() as $key => $search) {
if (strpos($key, 'facets_block') !== FALSE) {
continue;
}
$return = TRUE;
}
if (!$return) {
return;
}
// Configuration to enable/disable AJAX by path
$pages = variable_get('search_api_ajax_pages', '');
$visibility = variable_get('search_api_ajax_visibility', '');
if ($pages) {
// Convert path to lowercase. This allows comparison of the same path
// with different case. Ex: /Page, /page, /PAGE.
$pages = drupal_strtolower($pages);
// Convert the Drupal path to lowercase
$path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
// Compare the lowercase internal and lowercase path alias (if any).
$page_match = drupal_match_path($path, $pages);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $pages);
}
// When $pages has a value of 0 (VISIBILITY_NOTLISTED),
// the block is displayed on all pages except those listed in $pages.
// When set to 1 (VISIBILITY_LISTED), it is displayed only on those
// pages listed in $pages.
$page_match = !($visibility xor $page_match);
}
else {
$page_match = TRUE;
}
// No match
if (!$page_match) {
return;
}
// Loas CSS, JS and libraries
drupal_add_css(drupal_get_path('module', 'search_api_ajax') . '/search_api_ajax.css');
drupal_add_js(array(
'search_api_ajax' => module_invoke_all('search_api_ajax_settings'),
), 'setting');
drupal_add_library('system', 'jquery.bbq');
drupal_add_js(drupal_get_path('module', 'search_api_ajax') . '/search_api_ajax.js', array(
'scope' => 'footer',
));
}