@@ -30,11 +30,12 @@ function Typeahead(o) {
30
30
this . autoselect = ! ! o . autoselect ;
31
31
this . openOnFocus = ! ! o . openOnFocus ;
32
32
this . minLength = _ . isNumber ( o . minLength ) ? o . minLength : 1 ;
33
+ this . cssClasses = o . cssClasses = _ . mixin ( { } , css . defaultClasses , o . cssClasses || { } ) ;
33
34
this . $node = buildDom ( o ) ;
34
35
35
- $menu = this . $node . find ( '.aa-dropdown-menu' ) ;
36
- $input = this . $node . find ( '.aa- input' ) ;
37
- $hint = this . $node . find ( '.aa- hint' ) ;
36
+ $menu = this . $node . find ( _ . className ( this . cssClasses . prefix , this . cssClasses . dropdownMenu ) ) ;
37
+ $input = this . $node . find ( _ . className ( this . cssClasses . prefix , this . cssClasses . input ) ) ;
38
+ $hint = this . $node . find ( _ . className ( this . cssClasses . prefix , this . cssClasses . hint ) ) ;
38
39
39
40
if ( o . dropdownMenuContainer ) {
40
41
DOM . element ( o . dropdownMenuContainer )
@@ -62,7 +63,7 @@ function Typeahead(o) {
62
63
63
64
this . eventBus = o . eventBus || new EventBus ( { el : $input } ) ;
64
65
65
- this . dropdown = new Typeahead . Dropdown ( { menu : $menu , datasets : o . datasets , templates : o . templates } )
66
+ this . dropdown = new Typeahead . Dropdown ( { menu : $menu , datasets : o . datasets , templates : o . templates , cssClasses : this . cssClasses } )
66
67
. onSync ( 'suggestionClicked' , this . _onSuggestionClicked , this )
67
68
. onSync ( 'cursorMoved' , this . _onCursorMoved , this )
68
69
. onSync ( 'cursorRemoved' , this . _onCursorRemoved , this )
@@ -365,7 +366,7 @@ _.mixin(Typeahead.prototype, {
365
366
this . input . destroy ( ) ;
366
367
this . dropdown . destroy ( ) ;
367
368
368
- destroyDomStructure ( this . $node ) ;
369
+ destroyDomStructure ( this . $node , this . cssClasses ) ;
369
370
370
371
this . $node = null ;
371
372
}
@@ -378,22 +379,25 @@ function buildDom(options) {
378
379
var $hint ;
379
380
380
381
$input = DOM . element ( options . input ) ;
381
- $wrapper = DOM . element ( html . wrapper ) . css ( css . wrapper ) ;
382
+ $wrapper = DOM . element ( html . wrapper . replace ( '%ROOT%' , options . cssClasses . root ) ) . css ( css . wrapper ) ;
382
383
// override the display property with the table-cell value
383
384
// if the parent element is a table and the original input was a block
384
385
// -> https://github.com/algolia/autocomplete.js/issues/16
385
386
if ( $input . css ( 'display' ) === 'block' && $input . parent ( ) . css ( 'display' ) === 'table' ) {
386
387
$wrapper . css ( 'display' , 'table-cell' ) ;
387
388
}
388
- $dropdown = DOM . element ( html . dropdown ) . css ( css . dropdown ) ;
389
+ var dropdownHtml = html . dropdown .
390
+ replace ( '%PREFIX%' , options . cssClasses . prefix ) .
391
+ replace ( '%DROPDOWN_MENU%' , options . cssClasses . dropdownMenu ) ;
392
+ $dropdown = DOM . element ( dropdownHtml ) . css ( css . dropdown ) ;
389
393
if ( options . templates && options . templates . dropdownMenu ) {
390
394
$dropdown . html ( _ . templatify ( options . templates . dropdownMenu ) ( ) ) ;
391
395
}
392
396
$hint = $input . clone ( ) . css ( css . hint ) . css ( getBackgroundStyles ( $input ) ) ;
393
397
394
398
$hint
395
399
. val ( '' )
396
- . addClass ( 'aa- hint' )
400
+ . addClass ( _ . className ( options . cssClasses . prefix , options . cssClasses . hint , true ) )
397
401
. removeAttr ( 'id name placeholder required' )
398
402
. prop ( 'readonly' , true )
399
403
. attr ( { autocomplete : 'off' , spellcheck : 'false' , tabindex : - 1 } ) ;
@@ -411,7 +415,7 @@ function buildDom(options) {
411
415
} ) ;
412
416
413
417
$input
414
- . addClass ( 'aa- input' )
418
+ . addClass ( _ . className ( options . cssClasses . prefix , options . cssClasses . input , true ) )
415
419
. attr ( { autocomplete : 'off' , spellcheck : false } )
416
420
. css ( options . hint ? css . input : css . inputWithNoHint ) ;
417
421
@@ -444,8 +448,8 @@ function getBackgroundStyles($el) {
444
448
} ;
445
449
}
446
450
447
- function destroyDomStructure ( $node ) {
448
- var $input = $node . find ( '.aa- input' ) ;
451
+ function destroyDomStructure ( $node , cssClasses ) {
452
+ var $input = $node . find ( _ . className ( cssClasses . prefix , cssClasses . input ) ) ;
449
453
450
454
// need to remove attrs that weren't previously defined and
451
455
// revert attrs that originally had a value
@@ -459,7 +463,7 @@ function destroyDomStructure($node) {
459
463
460
464
$input
461
465
. detach ( )
462
- . removeClass ( 'aa- input' )
466
+ . removeClass ( _ . className ( cssClasses . prefix , cssClasses . input , true ) )
463
467
. insertAfter ( $node ) ;
464
468
if ( $input . removeData ) {
465
469
$input . removeData ( attrsKey ) ;
0 commit comments