@@ -432,8 +432,8 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
432
432
// remove the index number and spacing number from output model
433
433
delete value [ $scope . indexProperty ] ;
434
434
delete value [ $scope . spacingProperty ] ;
435
- } )
436
- }
435
+ } ) ;
436
+ }
437
437
}
438
438
439
439
// refresh button label
@@ -544,28 +544,10 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
544
544
return true ;
545
545
}
546
546
547
- // Our button accept HTML tags. Depending on browser, the click event might be intercepted by those tags instead of the button.
548
- // Since we want the button to handle click event, we need traverse up to find the button element.
549
- if ( e . target ) {
550
- if ( e . target . tagName . toUpperCase ( ) !== 'BUTTON' && e . target . className . indexOf ( 'multiSelectButton' ) < 0 ) {
551
- if ( attrs . selectionMode && $scope . selectionMode . toUpperCase ( ) === 'SINGLE' ) {
552
- e = $scope . findUpTag ( e . target , 'div' , 'checkboxLayer' ) ;
553
- e = e . previousSibling ;
554
- }
555
- else {
556
- e = $scope . findUpTag ( e . target , 'button' , 'multiSelectButton' ) ;
557
- }
558
- }
559
- else {
560
- e = e . target ;
561
- }
562
- }
563
- clickedEl = e ;
564
- $scope . checkBoxLayer = clickedEl . nextSibling ;
547
+ $scope . checkBoxLayer = angular . element ( element ) . children ( ) [ 1 ] ;
565
548
566
549
// The idea below was taken from another multi-select directive - https://github.com/amitava82/angular-multiselect
567
550
// His version is awesome if you need a more simple multi-select approach.
568
-
569
551
// close
570
552
if ( angular . element ( $scope . checkBoxLayer ) . hasClass ( 'show' ) ) {
571
553
angular . element ( $scope . checkBoxLayer ) . removeClass ( 'show' ) ;
@@ -590,9 +572,6 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
590
572
angular . element ( document ) . bind ( 'click' , $scope . externalClickListener ) ;
591
573
angular . element ( window ) . bind ( 'keydown' , $scope . keyboardListener ) ;
592
574
593
- // open callback
594
- $scope . onOpen ( { data : element } ) ;
595
-
596
575
// to get the initial tab index, depending on how many helper elements we have.
597
576
// priority is to always focus it on the input filter
598
577
$scope . getFormElements ( ) ;
@@ -616,6 +595,9 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
616
595
else {
617
596
$scope . formElements [ $scope . tabIndex ] . focus ( ) ;
618
597
}
598
+
599
+ // open callback
600
+ $scope . onOpen ( { data : element } ) ;
619
601
}
620
602
}
621
603
@@ -639,8 +621,8 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
639
621
// traverse up to find the button tag
640
622
// http://stackoverflow.com/questions/7332179/how-to-recursively-search-all-parentnodes
641
623
$scope . findUpTag = function ( el , tag , className ) {
642
- while ( el . parentNode ) {
643
- el = el . parentNode ;
624
+ while ( el . parentNode ) {
625
+ el = el . parentNode ;
644
626
if ( typeof el . tagName !== 'undefined' ) {
645
627
if ( el . tagName . toUpperCase ( ) === tag . toUpperCase ( ) && el . className . indexOf ( className ) > - 1 ) {
646
628
return el ;
@@ -837,7 +819,9 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
837
819
$scope . refreshOutputModel ( ) ;
838
820
$scope . refreshButton ( ) ;
839
821
if ( $scope . clickedItem !== null ) {
840
- $scope . onItemClick ( { data : $scope . clickedItem } ) ;
822
+ $timeout ( function ( ) {
823
+ $scope . onItemClick ( { data : $scope . clickedItem } ) ;
824
+ } , 0 ) ;
841
825
$scope . clickedItem = null ;
842
826
}
843
827
}
0 commit comments