|
1 | 1 | /*!
|
2 | 2 | * ui-select
|
3 | 3 | * http://github.com/angular-ui/ui-select
|
4 |
| - * Version: 0.16.1 - 2016-04-06T16:30:40.497Z |
| 4 | + * Version: 0.16.1 - 2016-04-06T19:55:00.329Z |
5 | 5 | * License: MIT
|
6 | 6 | */
|
7 | 7 |
|
@@ -197,44 +197,46 @@ uis.directive('uiSelectChoices',
|
197 | 197 |
|
198 | 198 | if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression.");
|
199 | 199 |
|
200 |
| - return function link(scope, element, attrs, $select, transcludeFn) { |
| 200 | + // var repeat = RepeatParser.parse(attrs.repeat); |
| 201 | + var groupByExp = tAttrs.groupBy; |
| 202 | + var groupFilterExp = tAttrs.groupFilter; |
201 | 203 |
|
202 |
| - // var repeat = RepeatParser.parse(attrs.repeat); |
203 |
| - var groupByExp = attrs.groupBy; |
204 |
| - var groupFilterExp = attrs.groupFilter; |
| 204 | + if (groupByExp) { |
| 205 | + var groups = tElement.querySelectorAll('.ui-select-choices-group'); |
| 206 | + if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); |
| 207 | + groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); |
| 208 | + } |
205 | 209 |
|
206 |
| - $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult |
| 210 | + var parserResult = RepeatParser.parse(tAttrs.repeat); |
207 | 211 |
|
208 |
| - $select.disableChoiceExpression = attrs.uiDisableChoice; |
209 |
| - $select.onHighlightCallback = attrs.onHighlight; |
| 212 | + var choices = tElement.querySelectorAll('.ui-select-choices-row'); |
| 213 | + if (choices.length !== 1) { |
| 214 | + throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); |
| 215 | + } |
210 | 216 |
|
211 |
| - $select.dropdownPosition = attrs.position ? attrs.position.toLowerCase() : uiSelectConfig.dropdownPosition; |
| 217 | + choices.attr('ng-repeat', parserResult.repeatExpression(groupByExp)) |
| 218 | + .attr('ng-if', '$select.open'); //Prevent unnecessary watches when dropdown is closed |
| 219 | + |
212 | 220 |
|
213 |
| - if(groupByExp) { |
214 |
| - var groups = element.querySelectorAll('.ui-select-choices-group'); |
215 |
| - if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); |
216 |
| - groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); |
217 |
| - } |
| 221 | + var rowsInner = tElement.querySelectorAll('.ui-select-choices-row-inner'); |
| 222 | + if (rowsInner.length !== 1) { |
| 223 | + throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); |
| 224 | + } |
| 225 | + rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat |
218 | 226 |
|
219 |
| - var choices = element.querySelectorAll('.ui-select-choices-row'); |
220 |
| - if (choices.length !== 1) { |
221 |
| - throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); |
222 |
| - } |
| 227 | + // If IE8 then need to target rowsInner to apply the ng-click attr as choices will not capture the event. |
| 228 | + var clickTarget = $window.document.addEventListener ? choices : rowsInner; |
| 229 | + clickTarget.attr('ng-click', '$select.select(' + parserResult.itemName + ',$select.skipFocusser,$event)'); |
| 230 | + |
| 231 | + return function link(scope, element, attrs, $select) { |
223 | 232 |
|
224 |
| - choices.attr('ng-repeat', $select.parserResult.repeatExpression(groupByExp)) |
225 |
| - .attr('ng-if', '$select.open'); //Prevent unnecessary watches when dropdown is closed |
226 |
| - if ($window.document.addEventListener) { //crude way to exclude IE8, specifically, which also cannot capture events |
227 |
| - choices.attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',$select.skipFocusser,$event)'); |
228 |
| - } |
| 233 | + |
| 234 | + $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult |
229 | 235 |
|
230 |
| - var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); |
231 |
| - if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); |
232 |
| - rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat |
233 |
| - if (!$window.document.addEventListener) { //crude way to target IE8, specifically, which also cannot capture events - so event bindings must be here |
234 |
| - rowsInner.attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',$select.skipFocusser,$event)'); |
235 |
| - } |
| 236 | + $select.disableChoiceExpression = attrs.uiDisableChoice; |
| 237 | + $select.onHighlightCallback = attrs.onHighlight; |
236 | 238 |
|
237 |
| - $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend |
| 239 | + $select.dropdownPosition = attrs.position ? attrs.position.toLowerCase() : uiSelectConfig.dropdownPosition; |
238 | 240 |
|
239 | 241 | scope.$on('$destroy', function() {
|
240 | 242 | choices.remove();
|
|
0 commit comments