Skip to content

Commit 12baf16

Browse files
committedJul 8, 2014
General fixes
1 parent 238f848 commit 12baf16

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed
 

‎dropkick.js

+32-23
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var
6262
close: noop,
6363

6464
// Search method; "strict", "partial", or "fuzzy"
65-
search: "strict",
65+
search: "strict"
6666
},
6767

6868
// Common Utilities
@@ -90,7 +90,7 @@ var
9090
},
9191

9292
// Shallow object extend
93-
extend: function(obj) {
93+
extend: function( obj ) {
9494
Array.prototype.slice.call( arguments, 1 ).forEach( function( source ) {
9595
if ( source ) for ( var prop in source ) obj[ prop ] = source[ prop ];
9696
});
@@ -397,8 +397,10 @@ Dropkick.prototype = {
397397
option.selected = !option.selected;
398398

399399
if ( _.hasClass( elem, "dk-option-selected" ) ) {
400+
elem.setAttribute( "aria-selected", "true" );
400401
this.selectedOptions.push( elem );
401402
} else {
403+
elem.setAttribute( "aria-selected", "false" );
402404
index = this.selectedOptions.indexOf( elem );
403405
this.selectedOptions.splice( index, 1 );
404406
}
@@ -562,7 +564,7 @@ Dropkick.prototype = {
562564
},
563565

564566
_delegate: function( event ) {
565-
var index, firstIndex, lastIndex,
567+
var selection, index, firstIndex, lastIndex,
566568
target = event.target;
567569

568570
if ( _.hasClass( target, "dk-option-disabled" ) ) {
@@ -571,31 +573,33 @@ Dropkick.prototype = {
571573

572574
if ( !this.multiple ) {
573575
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();
578581

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 );
583586

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;
586589

587-
this.reset( true );
590+
this.reset( true );
588591

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 );
591599
} else {
592-
while ( index > lastIndex - 1 ) this.select( index-- );
600+
this.reset( true );
601+
this.select( target );
593602
}
594-
} else if ( event.ctrlKey || event.metaKey ) {
595-
this.select( target );
596-
} else {
597-
this.reset( true );
598-
this.select( target );
599603
}
600604
}
601605
},
@@ -630,6 +634,7 @@ Dropkick.prototype = {
630634
switch ( event.keyCode ) {
631635
case keys.up:
632636
i = -1;
637+
// deliberate fallthrough
633638
case keys.down:
634639
event.preventDefault();
635640
lastSelected = selected[ selected.length - 1 ];
@@ -653,13 +658,15 @@ Dropkick.prototype = {
653658
this.open();
654659
break;
655660
}
661+
// deliberate fallthrough
656662
case keys.tab:
657663
case keys.enter:
658664
for ( i = 0; i < options.length; i++ ) {
659665
if ( _.hasClass( options[ i ], "dk-option-highlight" ) ) {
660666
this.select( i );
661667
}
662668
}
669+
// deliberate fallthrough
663670
case keys.esc:
664671
if ( this.isOpen ) {
665672
event.preventDefault();
@@ -801,7 +808,6 @@ Dropkick.build = function( sel, idpre ) {
801808
optList = _.create( "ul", {
802809
"class": "dk-select-options",
803810
"id": idpre + "-listbox",
804-
"aria-expanded": "false",
805811
"role": "listbox"
806812
});
807813

@@ -815,11 +821,14 @@ Dropkick.build = function( sel, idpre ) {
815821
"tabindex": sel.tabindex || 0,
816822
"innerHTML": sel.options[ sel.selectedIndex ].text,
817823
"id": idpre + "-combobox",
824+
"aria-live": "assertive",
818825
"aria-owns": optList.id,
819826
"role": "combobox"
820827
}));
828+
optList.setAttribute( "aria-expanded", "false" );
821829
} else {
822830
ret.elem.setAttribute( "tabindex", sel.getAttribute( "tabindex" ) || "0" );
831+
optList.setAttribute( "aria-multiselectable", "true" );
823832
}
824833

825834
for ( i = sel.children.length; i--; options.unshift( sel.children[ i ] ) );

0 commit comments

Comments
 (0)
Please sign in to comment.