-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutocomplete.php
56 lines (38 loc) · 1.19 KB
/
Autocomplete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Automad\Bootstrap;
defined('AUTOMAD') or die('Direct access not permitted!');
class Autocomplete {
/**
* The main autocomplete function.
*
* @param array $options
* @param object $Automad
* @return string The autocomplete markup
*/
public function Autocomplete($options, $Automad) {
// Define some defaults.
$defaults = array(
'inputSelector' => '#search',
'treshold' => 3,
'highlightClass' => 'text-primary',
'maximumItems' => 10
);
// Merge defaults with options.
$options = array_merge($defaults, $options);
$data = array();
$Pagelist = $Automad->getPagelist();
$n = 1;
foreach ($Pagelist->getPages() as $Page) {
$data[$Page->get(AM_KEY_TITLE)] = $n++;
}
foreach ($Pagelist->getTags() as $tag) {
$data[$tag] = $n++;
}
$options['data'] = $data;
$str = '<script>var autocomplete = ' . json_encode($options) . '</script>';
$file = '/packages/automad/bootstrap-autocomplete/bootstrap-4-autocomplete/dist/bootstrap-4-autocomplete.min.js';
$str .= '<script src="' . $file . '"></script>';
$str .= '<script src="/packages/automad/bootstrap-autocomplete/js/script.js"></script>';
return $str;
}
}