@@ -7,36 +7,36 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
7
7
. service ( 'dropdownService' , [ '$document' , '$rootScope' , function ( $document , $rootScope ) {
8
8
var openScope = null ;
9
9
10
- this . open = function ( dropdownScope ) {
11
- if ( ! openScope ) {
10
+ this . open = function ( dropdownScope ) {
11
+ if ( ! openScope ) {
12
12
$document . bind ( 'click' , closeDropdown ) ;
13
13
$document . bind ( 'keydown' , keybindFilter ) ;
14
14
}
15
15
16
- if ( openScope && openScope !== dropdownScope ) {
16
+ if ( openScope && openScope !== dropdownScope ) {
17
17
openScope . isOpen = false ;
18
18
}
19
19
20
20
openScope = dropdownScope ;
21
21
} ;
22
22
23
- this . close = function ( dropdownScope ) {
24
- if ( openScope === dropdownScope ) {
23
+ this . close = function ( dropdownScope ) {
24
+ if ( openScope === dropdownScope ) {
25
25
openScope = null ;
26
26
$document . unbind ( 'click' , closeDropdown ) ;
27
27
$document . unbind ( 'keydown' , keybindFilter ) ;
28
28
}
29
29
} ;
30
30
31
- var closeDropdown = function ( evt ) {
31
+ var closeDropdown = function ( evt ) {
32
32
// This method may still be called during the same mouse event that
33
33
// unbound this event handler. So check openScope before proceeding.
34
34
if ( ! openScope ) { return ; }
35
35
36
- if ( evt && openScope . getAutoClose ( ) === 'disabled' ) { return ; }
36
+ if ( evt && openScope . getAutoClose ( ) === 'disabled' ) { return ; }
37
37
38
38
var toggleElement = openScope . getToggleElement ( ) ;
39
- if ( evt && toggleElement && toggleElement [ 0 ] . contains ( evt . target ) ) {
39
+ if ( evt && toggleElement && toggleElement [ 0 ] . contains ( evt . target ) ) {
40
40
return ;
41
41
}
42
42
@@ -53,12 +53,12 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
53
53
}
54
54
} ;
55
55
56
- var keybindFilter = function ( evt ) {
57
- if ( evt . which === 27 ) {
56
+ var keybindFilter = function ( evt ) {
57
+ if ( evt . which === 27 ) {
58
58
openScope . focusToggleElement ( ) ;
59
59
closeDropdown ( ) ;
60
60
}
61
- else if ( openScope . isKeynavEnabled ( ) && / ( 3 8 | 4 0 ) / . test ( evt . which ) && openScope . isOpen ) {
61
+ else if ( openScope . isKeynavEnabled ( ) && / ( 3 8 | 4 0 ) / . test ( evt . which ) && openScope . isOpen ) {
62
62
evt . preventDefault ( ) ;
63
63
evt . stopPropagation ( ) ;
64
64
openScope . focusDropdownEntry ( evt . which ) ;
@@ -69,7 +69,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
69
69
. controller ( 'DropdownController' , [ '$scope' , '$attrs' , '$parse' , 'dropdownConfig' , 'dropdownService' , '$animate' , '$position' , '$document' , '$compile' , '$templateRequest' , function ( $scope , $attrs , $parse , dropdownConfig , dropdownService , $animate , $position , $document , $compile , $templateRequest ) {
70
70
var self = this ,
71
71
scope = $scope . $new ( ) , // create a child scope so we are not polluting original one
72
- templateScope ,
72
+ templateScope ,
73
73
openClass = dropdownConfig . openClass ,
74
74
getIsOpen ,
75
75
setIsOpen = angular . noop ,
@@ -78,10 +78,10 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
78
78
keynavEnabled = false ,
79
79
selectedOption = null ;
80
80
81
- this . init = function ( element ) {
81
+ this . init = function ( element ) {
82
82
self . $element = element ;
83
83
84
- if ( $attrs . isOpen ) {
84
+ if ( $attrs . isOpen ) {
85
85
getIsOpen = $parse ( $attrs . isOpen ) ;
86
86
setIsOpen = getIsOpen . assign ;
87
87
@@ -93,15 +93,15 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
93
93
appendToBody = angular . isDefined ( $attrs . dropdownAppendToBody ) ;
94
94
keynavEnabled = angular . isDefined ( $attrs . keyboardNav ) ;
95
95
96
- if ( appendToBody && self . dropdownMenu ) {
96
+ if ( appendToBody && self . dropdownMenu ) {
97
97
$document . find ( 'body' ) . append ( self . dropdownMenu ) ;
98
98
element . on ( '$destroy' , function handleDestroyEvent ( ) {
99
99
self . dropdownMenu . remove ( ) ;
100
100
} ) ;
101
101
}
102
102
} ;
103
103
104
- this . toggle = function ( open ) {
104
+ this . toggle = function ( open ) {
105
105
return scope . isOpen = arguments . length ? ! ! open : ! scope . isOpen ;
106
106
} ;
107
107
@@ -133,7 +133,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
133
133
134
134
switch ( keyCode ) {
135
135
case ( 40 ) : {
136
- if ( ! angular . isNumber ( self . selectedOption ) ) {
136
+ if ( ! angular . isNumber ( self . selectedOption ) ) {
137
137
self . selectedOption = 0 ;
138
138
} else {
139
139
self . selectedOption = ( self . selectedOption === elems . length - 1 ?
@@ -143,12 +143,11 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
143
143
break ;
144
144
}
145
145
case ( 38 ) : {
146
- if ( ! angular . isNumber ( self . selectedOption ) ) {
146
+ if ( ! angular . isNumber ( self . selectedOption ) ) {
147
147
return ;
148
148
} else {
149
- self . selectedOption = ( self . selectedOption === 0 ?
150
- 0 :
151
- self . selectedOption - 1 ) ;
149
+ self . selectedOption = self . selectedOption === 0 ?
150
+ 0 : self . selectedOption - 1 ;
152
151
}
153
152
break ;
154
153
}
@@ -161,38 +160,38 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
161
160
} ;
162
161
163
162
scope . focusToggleElement = function ( ) {
164
- if ( self . toggleElement ) {
163
+ if ( self . toggleElement ) {
165
164
self . toggleElement [ 0 ] . focus ( ) ;
166
165
}
167
166
} ;
168
167
169
- scope . $watch ( 'isOpen' , function ( isOpen , wasOpen ) {
168
+ scope . $watch ( 'isOpen' , function ( isOpen , wasOpen ) {
170
169
if ( appendToBody && self . dropdownMenu ) {
171
- var pos = $position . positionElements ( self . $element , self . dropdownMenu , 'bottom-left' , true ) ;
172
- var css = {
173
- top : pos . top + 'px' ,
174
- display : isOpen ? 'block' : 'none'
175
- } ;
176
-
177
- var rightalign = self . dropdownMenu . hasClass ( 'dropdown-menu-right' ) ;
178
- if ( ! rightalign ) {
179
- css . left = pos . left + 'px' ;
180
- css . right = 'auto' ;
181
- } else {
182
- css . left = 'auto' ;
183
- css . right = ( window . innerWidth - ( pos . left + self . $element . prop ( 'offsetWidth' ) ) ) + 'px' ;
184
- }
170
+ var pos = $position . positionElements ( self . $element , self . dropdownMenu , 'bottom-left' , true ) ;
171
+ var css = {
172
+ top : pos . top + 'px' ,
173
+ display : isOpen ? 'block' : 'none'
174
+ } ;
175
+
176
+ var rightalign = self . dropdownMenu . hasClass ( 'dropdown-menu-right' ) ;
177
+ if ( ! rightalign ) {
178
+ css . left = pos . left + 'px' ;
179
+ css . right = 'auto' ;
180
+ } else {
181
+ css . left = 'auto' ;
182
+ css . right = ( window . innerWidth - ( pos . left + self . $element . prop ( 'offsetWidth' ) ) ) + 'px' ;
183
+ }
185
184
186
- self . dropdownMenu . css ( css ) ;
185
+ self . dropdownMenu . css ( css ) ;
187
186
}
188
187
189
188
$animate [ isOpen ? 'addClass' : 'removeClass' ] ( self . $element , openClass ) . then ( function ( ) {
190
- if ( angular . isDefined ( isOpen ) && isOpen !== wasOpen ) {
191
- toggleInvoker ( $scope , { open : ! ! isOpen } ) ;
192
- }
189
+ if ( angular . isDefined ( isOpen ) && isOpen !== wasOpen ) {
190
+ toggleInvoker ( $scope , { open : ! ! isOpen } ) ;
191
+ }
193
192
} ) ;
194
193
195
- if ( isOpen ) {
194
+ if ( isOpen ) {
196
195
if ( self . dropdownMenuTemplateUrl ) {
197
196
$templateRequest ( self . dropdownMenuTemplateUrl ) . then ( function ( tplContent ) {
198
197
templateScope = scope . $new ( ) ;
@@ -205,7 +204,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
205
204
}
206
205
207
206
scope . focusToggleElement ( ) ;
208
- dropdownService . open ( scope ) ;
207
+ dropdownService . open ( scope ) ;
209
208
} else {
210
209
if ( self . dropdownMenuTemplateUrl ) {
211
210
if ( templateScope ) {
@@ -216,7 +215,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
216
215
self . dropdownMenu = newEl ;
217
216
}
218
217
219
- dropdownService . close ( scope ) ;
218
+ dropdownService . close ( scope ) ;
220
219
self . selectedOption = null ;
221
220
}
222
221
@@ -272,28 +271,27 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
272
271
link : function ( scope , element , attrs , dropdownCtrl ) {
273
272
274
273
element . bind ( 'keydown' , function ( e ) {
275
-
276
274
if ( [ 38 , 40 ] . indexOf ( e . which ) !== - 1 ) {
277
-
278
275
e . preventDefault ( ) ;
279
276
e . stopPropagation ( ) ;
280
277
281
278
var elems = dropdownCtrl . dropdownMenu . find ( 'a' ) ;
282
279
283
280
switch ( e . which ) {
284
281
case ( 40 ) : { // Down
285
- if ( ! angular . isNumber ( dropdownCtrl . selectedOption ) ) {
282
+ if ( ! angular . isNumber ( dropdownCtrl . selectedOption ) ) {
286
283
dropdownCtrl . selectedOption = 0 ;
287
284
} else {
288
- dropdownCtrl . selectedOption = ( dropdownCtrl . selectedOption === elems . length - 1 ? dropdownCtrl . selectedOption : dropdownCtrl . selectedOption + 1 ) ;
285
+ dropdownCtrl . selectedOption = dropdownCtrl . selectedOption === elems . length - 1 ?
286
+ dropdownCtrl . selectedOption : dropdownCtrl . selectedOption + 1 ;
289
287
}
290
-
288
+ break ;
291
289
}
292
- break ;
293
290
case ( 38 ) : { // Up
294
- dropdownCtrl . selectedOption = ( dropdownCtrl . selectedOption === 0 ? 0 : dropdownCtrl . selectedOption - 1 ) ;
291
+ dropdownCtrl . selectedOption = dropdownCtrl . selectedOption === 0 ?
292
+ 0 : dropdownCtrl . selectedOption - 1 ;
293
+ break ;
295
294
}
296
- break ;
297
295
}
298
296
elems [ dropdownCtrl . selectedOption ] . focus ( ) ;
299
297
}
@@ -307,7 +305,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
307
305
return {
308
306
require : '?^dropdown' ,
309
307
link : function ( scope , element , attrs , dropdownCtrl ) {
310
- if ( ! dropdownCtrl ) {
308
+ if ( ! dropdownCtrl ) {
311
309
return ;
312
310
}
313
311
@@ -318,7 +316,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
318
316
var toggleDropdown = function ( event ) {
319
317
event . preventDefault ( ) ;
320
318
321
- if ( ! element . hasClass ( 'disabled' ) && ! attrs . disabled ) {
319
+ if ( ! element . hasClass ( 'disabled' ) && ! attrs . disabled ) {
322
320
scope . $apply ( function ( ) {
323
321
dropdownCtrl . toggle ( ) ;
324
322
} ) ;
0 commit comments