* @method delegate * @private
( event )
| 795 | * @private |
| 796 | */ |
| 797 | _delegate( event ) { |
| 798 | var selection, index, firstIndex, lastIndex, |
| 799 | target = event.target; |
| 800 | |
| 801 | if ( _.hasClass( target, "dk-option-disabled" ) ) { |
| 802 | return false; |
| 803 | } |
| 804 | |
| 805 | if ( !this.multiple ) { |
| 806 | this[ this.isOpen ? "close" : "open" ](); |
| 807 | if ( _.hasClass( target, "dk-option" ) ) { this.select( target ); } |
| 808 | } else { |
| 809 | if ( _.hasClass( target, "dk-option" ) ) { |
| 810 | selection = window.getSelection(); |
| 811 | if ( selection.type === "Range" ) selection.collapseToStart(); |
| 812 | |
| 813 | if ( event.shiftKey ) { |
| 814 | firstIndex = this.options.indexOf( this.selectedOptions[0] ); |
| 815 | lastIndex = this.options.indexOf( this.selectedOptions[ this.selectedOptions.length - 1 ] ); |
| 816 | index = this.options.indexOf( target ); |
| 817 | |
| 818 | if ( index > firstIndex && index < lastIndex ) index = firstIndex; |
| 819 | if ( index > lastIndex && lastIndex > firstIndex ) lastIndex = firstIndex; |
| 820 | |
| 821 | this.reset( true ); |
| 822 | |
| 823 | if ( lastIndex > index ) { |
| 824 | while ( index < lastIndex + 1 ) { this.select( index++ ); } |
| 825 | } else { |
| 826 | while ( index > lastIndex - 1 ) { this.select( index-- ); } |
| 827 | } |
| 828 | } else if ( event.ctrlKey || event.metaKey ) { |
| 829 | this.select( target ); |
| 830 | } else { |
| 831 | this.reset( true ); |
| 832 | this.select( target ); |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * @method highlight |
no test coverage detected