0
|
1
|
|
2 /**
|
|
3 * Adds the custom autocomplete widget behavior.
|
|
4 */
|
|
5 Drupal.behaviors.solrsearch_autocomplete = {
|
|
6 attach: function(context) {
|
|
7
|
|
8 jQuery(".solrsearch-autocomplete.unprocessed", context).add(".solrsearch-autocomplete.unprocessed input", context).autocomplete(Drupal.settings.solrsearch_autocomplete.path,
|
|
9 {
|
|
10 // Classnames for the widget.
|
|
11 extraParams : {fieldName:function(){
|
|
12 classes = document.activeElement.getAttribute("class");
|
|
13 splitted =classes.split(" ");
|
|
14 for (var i=0; i <splitted.length; i++){
|
|
15 if (splitted[i].match("^solrsearch-autocomplete.field.")){
|
|
16 return splitted[i].replace("solrsearch-autocomplete.field.","");
|
|
17 }
|
|
18 };
|
|
19 return "IM_author";
|
|
20 }},
|
|
21 inputClass: "",
|
|
22 loadingClass: "throbbing",
|
|
23 // Do not select first suggestion by default.
|
|
24 selectFirst: false,
|
|
25 // Specify no matching as it wil be done on server-side.
|
|
26 matchContains: false,
|
|
27 matchSubset: false,
|
|
28 // Maximum number of items to show in widget.
|
|
29 max: 50,
|
|
30 scroll: true,
|
|
31 scrollHeight: 360,
|
|
32 // Data returned from server is JSON-encoded.
|
|
33 dataType: "json",
|
|
34 // Function to parse returned json into elements.
|
|
35 parse: function(data) {
|
|
36 return jQuery.map(data, function(item) {
|
|
37 return {
|
|
38 data: item, // Echo the input data.
|
|
39 value: item.display, // This will be shown in the options widget.
|
|
40 result: item.key // The actual value to put into the form element.
|
|
41 }
|
|
42 });
|
|
43 },
|
|
44 // Return the HTML to display in the options widget.
|
|
45 formatItem: function(item) {
|
|
46 return item.display;
|
|
47 }
|
|
48 }).result(function(item, element) {
|
|
49 // Handle selection of an element in the autocomplete widget.
|
|
50 // We should submit the widget's parent form.
|
|
51 jQuery(this).get(0).form.submit();
|
|
52 }).addClass('form-autocomplete'); // Add Drupal autocomplete widget's style.
|
|
53 }
|
|
54 };
|