Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit ee65677

Browse files
committed
fix(IE): selects not working on IE8
Checks for document.addEventListener support before registering ng-mouseenter and ng-click events Closes #158
2 parents 870dfb1 + ca78e5c commit ee65677

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/uiSelectChoicesDirective.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
uis.directive('uiSelectChoices',
2-
['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile',
3-
function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) {
2+
['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', '$window',
3+
function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile, $window) {
44

55
return {
66
restrict: 'EA',
@@ -45,12 +45,19 @@ uis.directive('uiSelectChoices',
4545
}
4646

4747
choices.attr('ng-repeat', $select.parserResult.repeatExpression(groupByExp))
48-
.attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed
49-
.attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)');
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-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')')
51+
.attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)');
52+
}
5053

5154
var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner');
5255
if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length);
5356
rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat
57+
if (!$window.document.addEventListener) { //crude way to target IE8, specifically, which also cannot capture events - so event bindings must be here
58+
rowsInner.attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')')
59+
.attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)');
60+
}
5461

5562
$compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend
5663

0 commit comments

Comments
 (0)