function search_autocomplete_init in Search Autocomplete 7.2
Same name and namespace in other branches
- 6.4 search_autocomplete.module \search_autocomplete_init()
- 6.2 search_autocomplete.module \search_autocomplete_init()
- 7.3 search_autocomplete.module \search_autocomplete_init()
HOOK OF INIT: add autocomplete.js on everypage
File
- ./
search_autocomplete.module, line 73
Code
function search_autocomplete_init() {
global $base_url;
// checkout if user have authorization to access the autocompleted form
if (user_access('use Search Autocomplete')) {
// init:
$settings = array();
// checkout if the db exists (it should)
if (db_table_exists('search_autocomplete_forms')) {
// get every form to autocomplete
$result = db_query('SELECT * FROM {search_autocomplete_forms} WHERE enabled=1');
// build the setting array to transfert to JS
foreach ($result as $match) {
$form_id = 'form' . $match->fid;
drupal_add_js(array(
'search_autocomplete' => array(
$form_id => array(
'selector' => $match->selector,
'minChars' => $match->min_char,
'max_sug' => $match->max_sug,
'url' => $base_url . '/search_autocomplete/' . $match->fid . '/autocomplete',
'fid' => $match->fid,
),
),
), 'setting');
}
// If there is some results: need to include the css and js....
if ($result) {
drupal_add_css(drupal_get_path('module', 'search_autocomplete') . '/css/jquery.autocomplete.css');
drupal_add_js(drupal_get_path('module', 'search_autocomplete') . '/js/jquery.autocomplete.js');
}
}
}
}