autocomplete.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Displays an autocomplete text input.
  4. *
  5. * @package Elgg
  6. * @subpackage Core
  7. *
  8. * @todo This currently only works for ONE AUTOCOMPLETE TEXT FIELD on a page.
  9. *
  10. * @uses $vars['value'] Current value for the text input
  11. * @uses $vars['match_on'] Array | str What to match on. all|array(groups|users|friends)
  12. * @uses $vars['match_owner'] Bool. Match only entities that are owned by logged in user.
  13. * @uses $vars['class'] Additional CSS class
  14. */
  15. if (isset($vars['class'])) {
  16. $vars['class'] = "elgg-input-autocomplete {$vars['class']}";
  17. } else {
  18. $vars['class'] = "elgg-input-autocomplete";
  19. }
  20. $defaults = array(
  21. 'value' => '',
  22. 'disabled' => false,
  23. );
  24. $vars = array_merge($defaults, $vars);
  25. $params = array();
  26. if (isset($vars['match_on'])) {
  27. $params['match_on'] = $vars['match_on'];
  28. unset($vars['match_on']);
  29. }
  30. if (isset($vars['match_owner'])) {
  31. $params['match_owner'] = $vars['match_owner'];
  32. unset($vars['match_owner']);
  33. }
  34. $ac_url_params = http_build_query($params);
  35. elgg_load_js('elgg.autocomplete');
  36. elgg_load_js('jquery.ui.autocomplete.html');
  37. ?>
  38. <script type="text/javascript">
  39. elgg.provide('elgg.autocomplete');
  40. elgg.autocomplete.url = "<?php echo elgg_get_site_url() . 'livesearch?' . $ac_url_params; ?>";
  41. </script>
  42. <input type="text" <?php echo elgg_format_attributes($vars); ?> />