annotate sites/all/modules/custom/solrsearch_autocomplete/solrsearch_autocomplete.js @ 0:015d06b10d37 default tip

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