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

Commit

Permalink
fix(IE): selects not working on IE8
Browse files Browse the repository at this point in the history
Checks for document.addEventListener support before registering ng-mouseenter and ng-click events

Closes #158
  • Loading branch information
aaronroberson committed Feb 18, 2016
2 parents 870dfb1 + ca78e5c commit ee65677
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/uiSelectChoicesDirective.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uis.directive('uiSelectChoices',
['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile',
function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) {
['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', '$window',
function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile, $window) {

return {
restrict: 'EA',
Expand Down Expand Up @@ -45,12 +45,19 @@ uis.directive('uiSelectChoices',
}

choices.attr('ng-repeat', $select.parserResult.repeatExpression(groupByExp))
.attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed
.attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)');
.attr('ng-if', '$select.open'); //Prevent unnecessary watches when dropdown is closed
if ($window.document.addEventListener) { //crude way to exclude IE8, specifically, which also cannot capture events
choices.attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')')
.attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)');
}

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

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

Expand Down

0 comments on commit ee65677

Please sign in to comment.