This repository was archived by the owner on Oct 2, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-20
lines changed Expand file tree Collapse file tree 2 files changed +26
-20
lines changed Original file line number Diff line number Diff line change 65
65
} ;
66
66
}
67
67
68
+ /**
69
+ * Add closest() to jqLite.
70
+ */
71
+ if ( angular . element . prototype . closest === undefined ) {
72
+ angular . element . prototype . closest = function ( selector ) {
73
+ var elem = this [ 0 ] ;
74
+ var matchesSelector = elem . matches || elem . webkitMatchesSelector || elem . mozMatchesSelector || elem . msMatchesSelector ;
75
+
76
+ while ( elem ) {
77
+ if ( matchesSelector . bind ( elem ) ( selector ) ) {
78
+ return elem ;
79
+ } else {
80
+ elem = elem . parentElement ;
81
+ }
82
+ }
83
+ return false ;
84
+ } ;
85
+ }
86
+
68
87
angular . module ( 'ui.select' , [ ] )
69
88
70
89
. constant ( 'uiSelectConfig' , {
1079
1098
$select . selected = ngModel . $viewValue ;
1080
1099
} ;
1081
1100
1082
- /**
1083
- * Checks if the current target is a ui-select-match element
1084
- *
1085
- * @param target
1086
- * @returns {boolean }
1087
- */
1088
- function isClosedUiSelect ( target ) {
1089
- var node = target . parentNode ;
1090
- while ( node !== null ) {
1091
- if ( angular . element ( node ) . hasClass ( 'ui-select-container' ) &&
1092
- angular . element ( node ) . hasClass ( 'open' ) ) {
1093
- return true ;
1094
- }
1095
- node = node . parentNode ;
1096
- }
1097
- return false ;
1098
- }
1099
-
1100
1101
function onDocumentClick ( e ) {
1101
1102
var contains = false ;
1102
1103
1109
1110
}
1110
1111
1111
1112
if ( ! contains && ! $select . clickTriggeredSelect ) {
1112
- $select . close ( isClosedUiSelect ( e . target ) ) ; // Skip focusser if the target is another select
1113
+ $select . close ( angular . element ( e . target ) . closest ( '.ui-select-container.open' ) . length > 0 ) ; // Skip focusser if the target is another select
1113
1114
scope . $digest ( ) ;
1114
1115
}
1115
1116
$select . clickTriggeredSelect = false ;
Original file line number Diff line number Diff line change @@ -318,6 +318,8 @@ describe('ui-select tests', function() {
318
318
it ( 'should close an opened select when another one is opened' , function ( ) {
319
319
var el1 = createUiSelect ( ) ;
320
320
var el2 = createUiSelect ( ) ;
321
+ el1 . appendTo ( document . body ) ;
322
+ el2 . appendTo ( document . body ) ;
321
323
322
324
expect ( isDropdownOpened ( el1 ) ) . toEqual ( false ) ;
323
325
expect ( isDropdownOpened ( el2 ) ) . toEqual ( false ) ;
@@ -327,7 +329,10 @@ describe('ui-select tests', function() {
327
329
clickMatch ( el2 ) ;
328
330
expect ( isDropdownOpened ( el1 ) ) . toEqual ( false ) ;
329
331
expect ( isDropdownOpened ( el2 ) ) . toEqual ( true ) ;
330
- } ) ;
332
+
333
+ el1 . remove ( ) ;
334
+ el2 . remove ( ) ;
335
+ } ) ;
331
336
332
337
describe ( 'disabled options' , function ( ) {
333
338
function createUiSelect ( attrs ) {
You can’t perform that action at this time.
0 commit comments