@@ -432,8 +432,8 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
432432 // remove the index number and spacing number from output model
433433 delete value [ $scope . indexProperty ] ;
434434 delete value [ $scope . spacingProperty ] ;
435- } )
436- }
435+ } ) ;
436+ }
437437 }
438438
439439 // refresh button label
@@ -544,28 +544,10 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
544544 return true ;
545545 }
546546
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 ] ;
565548
566549 // The idea below was taken from another multi-select directive - https://github.com/amitava82/angular-multiselect
567550 // His version is awesome if you need a more simple multi-select approach.
568-
569551 // close
570552 if ( angular . element ( $scope . checkBoxLayer ) . hasClass ( 'show' ) ) {
571553 angular . element ( $scope . checkBoxLayer ) . removeClass ( 'show' ) ;
@@ -590,9 +572,6 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
590572 angular . element ( document ) . bind ( 'click' , $scope . externalClickListener ) ;
591573 angular . element ( window ) . bind ( 'keydown' , $scope . keyboardListener ) ;
592574
593- // open callback
594- $scope . onOpen ( { data : element } ) ;
595-
596575 // to get the initial tab index, depending on how many helper elements we have.
597576 // priority is to always focus it on the input filter
598577 $scope . getFormElements ( ) ;
@@ -616,6 +595,9 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
616595 else {
617596 $scope . formElements [ $scope . tabIndex ] . focus ( ) ;
618597 }
598+
599+ // open callback
600+ $scope . onOpen ( { data : element } ) ;
619601 }
620602 }
621603
@@ -639,8 +621,8 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
639621 // traverse up to find the button tag
640622 // http://stackoverflow.com/questions/7332179/how-to-recursively-search-all-parentnodes
641623 $scope . findUpTag = function ( el , tag , className ) {
642- while ( el . parentNode ) {
643- el = el . parentNode ;
624+ while ( el . parentNode ) {
625+ el = el . parentNode ;
644626 if ( typeof el . tagName !== 'undefined' ) {
645627 if ( el . tagName . toUpperCase ( ) === tag . toUpperCase ( ) && el . className . indexOf ( className ) > - 1 ) {
646628 return el ;
@@ -837,7 +819,9 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
837819 $scope . refreshOutputModel ( ) ;
838820 $scope . refreshButton ( ) ;
839821 if ( $scope . clickedItem !== null ) {
840- $scope . onItemClick ( { data : $scope . clickedItem } ) ;
822+ $timeout ( function ( ) {
823+ $scope . onItemClick ( { data : $scope . clickedItem } ) ;
824+ } , 0 ) ;
841825 $scope . clickedItem = null ;
842826 }
843827 }
0 commit comments