62
62
close : noop ,
63
63
64
64
// Search method; "strict", "partial", or "fuzzy"
65
- search : "strict" ,
65
+ search : "strict"
66
66
} ,
67
67
68
68
// Common Utilities
90
90
} ,
91
91
92
92
// Shallow object extend
93
- extend : function ( obj ) {
93
+ extend : function ( obj ) {
94
94
Array . prototype . slice . call ( arguments , 1 ) . forEach ( function ( source ) {
95
95
if ( source ) for ( var prop in source ) obj [ prop ] = source [ prop ] ;
96
96
} ) ;
@@ -397,8 +397,10 @@ Dropkick.prototype = {
397
397
option . selected = ! option . selected ;
398
398
399
399
if ( _ . hasClass ( elem , "dk-option-selected" ) ) {
400
+ elem . setAttribute ( "aria-selected" , "true" ) ;
400
401
this . selectedOptions . push ( elem ) ;
401
402
} else {
403
+ elem . setAttribute ( "aria-selected" , "false" ) ;
402
404
index = this . selectedOptions . indexOf ( elem ) ;
403
405
this . selectedOptions . splice ( index , 1 ) ;
404
406
}
@@ -562,7 +564,7 @@ Dropkick.prototype = {
562
564
} ,
563
565
564
566
_delegate : function ( event ) {
565
- var index , firstIndex , lastIndex ,
567
+ var selection , index , firstIndex , lastIndex ,
566
568
target = event . target ;
567
569
568
570
if ( _ . hasClass ( target , "dk-option-disabled" ) ) {
@@ -571,31 +573,33 @@ Dropkick.prototype = {
571
573
572
574
if ( ! this . multiple ) {
573
575
this [ this . isOpen ? "close" : "open" ] ( ) ;
574
- }
575
-
576
- if ( _ . hasClass ( target , "dk-option" ) ) {
577
- window . getSelection ( ) . collapseToStart ( ) ;
576
+ if ( _ . hasClass ( target , "dk-option" ) ) this . select ( target ) ;
577
+ } else {
578
+ if ( _ . hasClass ( target , "dk-option" ) ) {
579
+ selection = window . getSelection ( ) ;
580
+ if ( selection . type == "Range" ) selection . collapseToStart ( ) ;
578
581
579
- if ( event . shiftKey ) {
580
- firstIndex = this . options . indexOf ( this . selectedOptions [ 0 ] ) ;
581
- lastIndex = this . options . indexOf ( this . selectedOptions [ this . selectedOptions . length - 1 ] ) ;
582
- index = this . options . indexOf ( target ) ;
582
+ if ( event . shiftKey ) {
583
+ firstIndex = this . options . indexOf ( this . selectedOptions [ 0 ] ) ;
584
+ lastIndex = this . options . indexOf ( this . selectedOptions [ this . selectedOptions . length - 1 ] ) ;
585
+ index = this . options . indexOf ( target ) ;
583
586
584
- if ( index > firstIndex && index < lastIndex ) index = firstIndex ;
585
- if ( index > lastIndex && lastIndex > firstIndex ) lastIndex = firstIndex ;
587
+ if ( index > firstIndex && index < lastIndex ) index = firstIndex ;
588
+ if ( index > lastIndex && lastIndex > firstIndex ) lastIndex = firstIndex ;
586
589
587
- this . reset ( true ) ;
590
+ this . reset ( true ) ;
588
591
589
- if ( lastIndex > index ) {
590
- while ( index < lastIndex + 1 ) this . select ( index ++ ) ;
592
+ if ( lastIndex > index ) {
593
+ while ( index < lastIndex + 1 ) this . select ( index ++ ) ;
594
+ } else {
595
+ while ( index > lastIndex - 1 ) this . select ( index -- ) ;
596
+ }
597
+ } else if ( event . ctrlKey || event . metaKey ) {
598
+ this . select ( target ) ;
591
599
} else {
592
- while ( index > lastIndex - 1 ) this . select ( index -- ) ;
600
+ this . reset ( true ) ;
601
+ this . select ( target ) ;
593
602
}
594
- } else if ( event . ctrlKey || event . metaKey ) {
595
- this . select ( target ) ;
596
- } else {
597
- this . reset ( true ) ;
598
- this . select ( target ) ;
599
603
}
600
604
}
601
605
} ,
@@ -630,6 +634,7 @@ Dropkick.prototype = {
630
634
switch ( event . keyCode ) {
631
635
case keys . up :
632
636
i = - 1 ;
637
+ // deliberate fallthrough
633
638
case keys . down :
634
639
event . preventDefault ( ) ;
635
640
lastSelected = selected [ selected . length - 1 ] ;
@@ -653,13 +658,15 @@ Dropkick.prototype = {
653
658
this . open ( ) ;
654
659
break ;
655
660
}
661
+ // deliberate fallthrough
656
662
case keys . tab :
657
663
case keys . enter :
658
664
for ( i = 0 ; i < options . length ; i ++ ) {
659
665
if ( _ . hasClass ( options [ i ] , "dk-option-highlight" ) ) {
660
666
this . select ( i ) ;
661
667
}
662
668
}
669
+ // deliberate fallthrough
663
670
case keys . esc :
664
671
if ( this . isOpen ) {
665
672
event . preventDefault ( ) ;
@@ -801,7 +808,6 @@ Dropkick.build = function( sel, idpre ) {
801
808
optList = _ . create ( "ul" , {
802
809
"class" : "dk-select-options" ,
803
810
"id" : idpre + "-listbox" ,
804
- "aria-expanded" : "false" ,
805
811
"role" : "listbox"
806
812
} ) ;
807
813
@@ -815,11 +821,14 @@ Dropkick.build = function( sel, idpre ) {
815
821
"tabindex" : sel . tabindex || 0 ,
816
822
"innerHTML" : sel . options [ sel . selectedIndex ] . text ,
817
823
"id" : idpre + "-combobox" ,
824
+ "aria-live" : "assertive" ,
818
825
"aria-owns" : optList . id ,
819
826
"role" : "combobox"
820
827
} ) ) ;
828
+ optList . setAttribute ( "aria-expanded" , "false" ) ;
821
829
} else {
822
830
ret . elem . setAttribute ( "tabindex" , sel . getAttribute ( "tabindex" ) || "0" ) ;
831
+ optList . setAttribute ( "aria-multiselectable" , "true" ) ;
823
832
}
824
833
825
834
for ( i = sel . children . length ; i -- ; options . unshift ( sel . children [ i ] ) ) ;
0 commit comments