PageSourceSearch

https://librivox.org/js/common/autocomplete.js?v=1710057521

js librivox.org collected 2026-09-27 21:08:30 UTC 2,750 bytes, 77 lines download raw bytes

1set_autocomplete();
2
3/**
4 * Set up auto-complete boxes using jQuery Autocomplete.
5 *
6 * Input elements need to define the following attributes:
7 *
8 *   - data-search_func - The backend ajax function to call
9 *   - data-search_field - The name of the field
10 *   - data-search_area - Which area on the page is being auto-completed
11 *   - data-array_index - Used when you've got multiple inputs in one area (e.g. multiple authors)
12 *
13 * In the pages where this script is included, you'll also need to define two
14 * functions:
15 *
16 *   - autocomplete_assign_vars - Maps backend results to values to show in the drop-down
17 *   - autocomplete_assign_elements - Handles updating inputs when a value is selected
18 *
19 * See also: https://api.jqueryui.com/autocomplete/
20 */
21
22function set_autocomplete() {
23	var search_area;
24    	var array_index;
25
26	$( ".autocomplete" ).autocomplete({
27        source: function(request, response) {
28
29			var element = this.element;
30			var search_func = element.attr('data-search_func');
31			var search_field = element.attr('data-search_field');
32            		array_index = element.attr('data-array_index');
33			search_area = element.attr('data-search_area');
34
35            var filter_element_id = element.attr('data-filter_element');
36            if (filter_element_id) {
37                var filter_element_obj = $('input[id^="' + filter_element_id + '"]')[0];
38                var filter_field = filter_element_obj.attributes['data-search_field'].value;
39                var filter_term = filter_element_obj.value;
40            }
41
42            $.ajax({ url: CI_ROOT + 'public/public_ajax/' + search_func,
43                data: { 'term': element.val(), 'search_field': search_field,
44                    'filter_field': filter_field, 'filter_term':  filter_term},
45                dataType: "json",
46                type: "POST",
47		global: false, // prevent modal loader dialog
48                success: function (data) {
49                    if (data != null) {
50                        response($.map(data, function (item) {
51								return autocomplete_assign_vars(item);				
52                        }))	
53                    } else $(".ui-autocomplete").css({
54                        "display": "none"
55                    });
56                },
57                error: function (data) {
58                    alert('Error: ' + data.errorThrown);
59                }
60            });
61        },
62        minLength: 1,
63        select: function (event, ui) {
64			autocomplete_assign_elements(search_area, ui, array_index);
65            return false;
66        }
67	});
68	
69}
70	
71
72	/*
73	.data('autocomplete')._renderItem() = function (ul, item) { 
74				return $("<li></li>
74").data("item.autocomplete", item).prepend("<a>" + item.label + "</a>").appendTo(ul);
75			}
76	*/
77

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.