@@ -20,44 +20,46 @@ uis.directive('uiSelectChoices',
20
20
21
21
if ( ! tAttrs . repeat ) throw uiSelectMinErr ( 'repeat' , "Expected 'repeat' expression." ) ;
22
22
23
- return function link ( scope , element , attrs , $select , transcludeFn ) {
24
-
25
- // var repeat = RepeatParser.parse(attrs.repeat);
26
- var groupByExp = attrs . groupBy ;
27
- var groupFilterExp = attrs . groupFilter ;
28
-
23
+ // var repeat = RepeatParser.parse(attrs.repeat);
24
+ var groupByExp = tAttrs . groupBy ;
25
+ var groupFilterExp = tAttrs . groupFilter ;
26
+
27
+ if ( groupByExp ) {
28
+ var groups = tElement . querySelectorAll ( '.ui-select-choices-group' ) ;
29
+ if ( groups . length !== 1 ) throw uiSelectMinErr ( 'rows' , "Expected 1 .ui-select-choices-group but got '{0}'." , groups . length ) ;
30
+ groups . attr ( 'ng-repeat' , RepeatParser . getGroupNgRepeatExpression ( ) ) ;
31
+ }
32
+
33
+ var parserResult = RepeatParser . parse ( tAttrs . repeat ) ;
34
+
35
+ var choices = tElement . querySelectorAll ( '.ui-select-choices-row' ) ;
36
+ if ( choices . length !== 1 ) {
37
+ throw uiSelectMinErr ( 'rows' , "Expected 1 .ui-select-choices-row but got '{0}'." , choices . length ) ;
38
+ }
39
+
40
+ choices . attr ( 'ng-repeat' , parserResult . repeatExpression ( groupByExp ) )
41
+ . attr ( 'ng-if' , '$select.open' ) ; //Prevent unnecessary watches when dropdown is closed
42
+
43
+
44
+ var rowsInner = tElement . querySelectorAll ( '.ui-select-choices-row-inner' ) ;
45
+ if ( rowsInner . length !== 1 ) {
46
+ throw uiSelectMinErr ( 'rows' , "Expected 1 .ui-select-choices-row-inner but got '{0}'." , rowsInner . length ) ;
47
+ }
48
+ rowsInner . attr ( 'uis-transclude-append' , '' ) ; //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat
49
+
50
+ // If IE8 then need to target rowsInner to apply the ng-click attr as choices will not capture the event.
51
+ var clickTarget = $window . document . addEventListener ? choices : rowsInner ;
52
+ clickTarget . attr ( 'ng-click' , '$select.select(' + parserResult . itemName + ',$select.skipFocusser,$event)' ) ;
53
+
54
+ return function link ( scope , element , attrs , $select ) {
55
+
56
+
29
57
$select . parseRepeatAttr ( attrs . repeat , groupByExp , groupFilterExp ) ; //Result ready at $select.parserResult
30
58
31
59
$select . disableChoiceExpression = attrs . uiDisableChoice ;
32
60
$select . onHighlightCallback = attrs . onHighlight ;
33
61
34
- $select . dropdownPosition = attrs . position ? attrs . position . toLowerCase ( ) : uiSelectConfig . dropdownPosition ;
35
-
36
- if ( groupByExp ) {
37
- var groups = element . querySelectorAll ( '.ui-select-choices-group' ) ;
38
- if ( groups . length !== 1 ) throw uiSelectMinErr ( 'rows' , "Expected 1 .ui-select-choices-group but got '{0}'." , groups . length ) ;
39
- groups . attr ( 'ng-repeat' , RepeatParser . getGroupNgRepeatExpression ( ) ) ;
40
- }
41
-
42
- var choices = element . querySelectorAll ( '.ui-select-choices-row' ) ;
43
- if ( choices . length !== 1 ) {
44
- throw uiSelectMinErr ( 'rows' , "Expected 1 .ui-select-choices-row but got '{0}'." , choices . length ) ;
45
- }
46
-
47
- choices . attr ( 'ng-repeat' , $select . parserResult . repeatExpression ( groupByExp ) )
48
- . attr ( 'ng-if' , '$select.open' ) ; //Prevent unnecessary watches when dropdown is closed
49
- if ( $window . document . addEventListener ) { //crude way to exclude IE8, specifically, which also cannot capture events
50
- choices . attr ( 'ng-click' , '$select.select(' + $select . parserResult . itemName + ',$select.skipFocusser,$event)' ) ;
51
- }
52
-
53
- var rowsInner = element . querySelectorAll ( '.ui-select-choices-row-inner' ) ;
54
- if ( rowsInner . length !== 1 ) throw uiSelectMinErr ( 'rows' , "Expected 1 .ui-select-choices-row-inner but got '{0}'." , rowsInner . length ) ;
55
- rowsInner . attr ( 'uis-transclude-append' , '' ) ; //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat
56
- if ( ! $window . document . addEventListener ) { //crude way to target IE8, specifically, which also cannot capture events - so event bindings must be here
57
- rowsInner . attr ( 'ng-click' , '$select.select(' + $select . parserResult . itemName + ',$select.skipFocusser,$event)' ) ;
58
- }
59
-
60
- $compile ( element , transcludeFn ) ( scope ) ; //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend
62
+ $select . dropdownPosition = attrs . position ? attrs . position . toLowerCase ( ) : uiSelectConfig . dropdownPosition ;
61
63
62
64
scope . $on ( '$destroy' , function ( ) {
63
65
choices . remove ( ) ;
0 commit comments