1
1
( function ( $ ) {
2
- /**
2
+
3
+ /**
4
+ * Hides the autocomplete suggestions, original function.
5
+ */
6
+ Drupal . jsAC . prototype . hidePopupOrig = function ( keycode ) {
7
+ // Select item if the right key or mousebutton was pressed.
8
+ if ( this . selected && ( ( keycode && keycode != 46 && keycode != 8 && keycode != 27 ) || ! keycode ) ) {
9
+ this . input . value = $ ( this . selected ) . data ( 'autocompleteValue' ) ;
10
+ }
11
+ // Hide popup.
12
+ var popup = this . popup ;
13
+ if ( popup ) {
14
+ this . popup = null ;
15
+ $ ( popup ) . fadeOut ( 'fast' , function ( ) { $ ( popup ) . remove ( ) ; } ) ;
16
+ }
17
+ this . selected = false ;
18
+ $ ( this . ariaLive ) . empty ( ) ;
19
+ } ;
20
+
21
+ /**
3
22
* Hides the autocomplete suggestions.
4
23
*/
5
- Drupal . jsAC . prototype . hidePopup = function ( keycode ) {
6
- // Select item if the right key or mousebutton was pressed.
7
- if ( this . selected && ( ( keycode && keycode != 46 && keycode != 8 && keycode != 27 ) || ! keycode ) ) {
8
- this . input . value = $ ( 'a' , this . selected ) . attr ( "href" ) ;
9
- return $ ( 'a' , this . selected ) . attr ( "href" ) ;
10
- }
24
+ Drupal . jsAC . prototype . hidePopup = function ( keycode , event ) {
25
+ if ( $ ( this . input ) . attr ( 'elasticsearch-autocomplete' ) ) {
26
+ // Select item if the right key or mousebutton was pressed.
27
+ if ( this . selected && ( ( keycode && keycode != 46 && keycode != 8 && keycode != 27 ) || ! keycode ) ) {
28
+ this . input . value = $ ( 'a' , this . selected ) . text ( ) ;
29
+ if ( typeof event != 'undefined' ) {
30
+ event . preventDefault ( ) ;
31
+ }
32
+
33
+ window . location = $ ( 'a' , this . selected ) . attr ( "href" ) ;
34
+ }
11
35
12
- // Hide popup.
13
- var popup = this . popup ;
14
- if ( popup ) {
15
- this . popup = null ;
16
- $ ( popup ) . fadeOut ( 'fast' , function ( ) { $ ( popup ) . remove ( ) ; } ) ;
36
+ // Hide popup.
37
+ var popup = this . popup ;
38
+ if ( popup ) {
39
+ this . popup = null ;
40
+ $ ( popup ) . fadeOut ( 'fast' , function ( ) { $ ( popup ) . remove ( ) ; } ) ;
41
+ }
42
+ this . selected = false ;
43
+ $ ( this . ariaLive ) . empty ( ) ;
44
+ }
45
+ else {
46
+ this . hidePopupOrig ( keycode ) ;
17
47
}
18
- this . selected = false ;
19
- $ ( this . ariaLive ) . empty ( ) ;
20
48
} ;
21
49
22
50
/**
@@ -33,6 +61,7 @@ Drupal.behaviors.elasticsearch_autocomplete = {
33
61
}
34
62
var $input = $ ( this )
35
63
. attr ( 'autocomplete' , 'OFF' )
64
+ . attr ( 'elasticsearch-autocomplete' , true )
36
65
. attr ( 'aria-autocomplete' , 'list' ) ;
37
66
$ ( $input [ 0 ] . form ) . unbind ( ) ;
38
67
$ ( $input [ 0 ] . form ) . submit ( Drupal . ELAutocompleteSubmit ) ;
@@ -52,20 +81,13 @@ Drupal.behaviors.elasticsearch_autocomplete = {
52
81
* Prevents the form from submitting if the suggestions popup is open
53
82
* and closes the suggestions popup when doing so.
54
83
*/
55
- Drupal . ELAutocompleteSubmit = function ( ) {
84
+ Drupal . ELAutocompleteSubmit = function ( e ) {
56
85
var href = '' ;
57
86
$ ( '#autocomplete' ) . each ( function ( ) {
58
- href = this . owner . hidePopup ( ) ;
87
+ this . owner . hidePopup ( null , e ) ;
59
88
} ) ;
60
89
61
- if ( href == '' || typeof href == 'undefined' ) {
62
- return false ; ;
63
- }
64
- else {
65
- window . location = href ;
66
- }
67
-
68
- return false ;
90
+ return true ;
69
91
} ;
70
92
} ) ( jQuery ) ;
71
93
0 commit comments