()
| 28265 | } |
| 28266 | |
| 28267 | function updateOptions() { |
| 28268 | var previousValue = options && selectCtrl.readValue(); |
| 28269 | |
| 28270 | options = ngOptions.getOptions(); |
| 28271 | |
| 28272 | var groupMap = {}; |
| 28273 | var currentElement = selectElement[0].firstChild; |
| 28274 | |
| 28275 | // Ensure that the empty option is always there if it was explicitly provided |
| 28276 | if (providedEmptyOption) { |
| 28277 | selectElement.prepend(emptyOption); |
| 28278 | } |
| 28279 | |
| 28280 | currentElement = skipEmptyAndUnknownOptions(currentElement); |
| 28281 | |
| 28282 | options.items.forEach(function updateOption(option) { |
| 28283 | var group; |
| 28284 | var groupElement; |
| 28285 | var optionElement; |
| 28286 | |
| 28287 | if (isDefined(option.group)) { |
| 28288 | // This option is to live in a group |
| 28289 | // See if we have already created this group |
| 28290 | group = groupMap[option.group]; |
| 28291 | |
| 28292 | if (!group) { |
| 28293 | // We have not already created this group |
| 28294 | groupElement = addOrReuseElement(selectElement[0], |
| 28295 | currentElement, |
| 28296 | 'optgroup', |
| 28297 | optGroupTemplate); |
| 28298 | // Move to the next element |
| 28299 | currentElement = groupElement.nextSibling; |
| 28300 | |
| 28301 | // Update the label on the group element |
| 28302 | groupElement.label = option.group; |
| 28303 | |
| 28304 | // Store it for use later |
| 28305 | group = groupMap[option.group] = { |
| 28306 | groupElement: groupElement, |
| 28307 | currentOptionElement: groupElement.firstChild |
| 28308 | }; |
| 28309 | } |
| 28310 | |
| 28311 | // So now we have a group for this option we add the option to the group |
| 28312 | optionElement = addOrReuseElement(group.groupElement, |
| 28313 | group.currentOptionElement, |
| 28314 | 'option', |
| 28315 | optionTemplate); |
| 28316 | updateOptionElement(option, optionElement); |
| 28317 | // Move to the next element |
| 28318 | group.currentOptionElement = optionElement.nextSibling; |
| 28319 | } else { |
| 28320 | // This option is not in a group |
| 28321 | optionElement = addOrReuseElement(selectElement[0], |
| 28322 | currentElement, |
| 28323 | 'option', |
| 28324 | optionTemplate); |
no test coverage detected