Skip to content

Commit

Permalink
some simple code optimizations as a preparation for #mfranzkeGH-39
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximilian committed Aug 27, 2018
1 parent 264c4cc commit 4417291
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions datalist-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

// .matches polyfill
// TODO: probably needs enhancement on the to supported browsers
// TODO: probably needs enhancement on the expected to be supported browsers
if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.msMatchesSelector;
}
Expand Down Expand Up @@ -174,16 +174,15 @@
return;
}

var eventType = event.type,
// Creating the select if there's no instance so far (e.g. because of that it hasn't been handled or it has been dynamically inserted)
var // Creating the select if there's no instance so far (e.g. because of that it hasn't been handled or it has been dynamically inserted)
datalistSelect =
datalist.getElementsByClassName(classNamePolyfillingSelect)[0] ||
setUpPolyfillingSelect(input, datalist),
// Either have the select set to the state to get displayed in case of that it would have been focused or because it's the target on the inputs blur - and check for general existance of any option as suggestions
visible =
datalistSelect &&
datalistSelect.querySelector('option:not(:disabled)') &&
((eventType === 'focusin' && input.value !== '') ||
((event.type === 'focusin' && input.value !== '') ||
(event.relatedTarget && event.relatedTarget === datalistSelect));

// Test for whether this input has already been enhanced by the polyfill
Expand All @@ -198,11 +197,11 @@
input.setAttribute('aria-owns', input.getAttribute('list'));

// Bind the keyup event on the related datalists input
if (eventType === 'focusin') {
if (event.type === 'focusin') {
input.addEventListener('keyup', inputInputList);

input.addEventListener('focusout', changesInputList, true);
} else if (eventType === 'blur') {
} else if (event.type === 'blur') {
input.removeEventListener('keyup', inputInputList);

input.removeEventListener('focusout', changesInputList, true);
Expand Down
2 changes: 1 addition & 1 deletion datalist-polyfill.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4417291

Please sign in to comment.