Skip to content

Commit 9799734

Browse files
committed
refactor: xo feedback
1 parent 9422790 commit 9799734

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

.xo-config.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
"one-var": 0,
77
"no-use-before-define": 0,
88
"unicorn/prefer-includes": 0,
9-
"unicorn/prefer-dataset": 0
9+
"unicorn/prefer-dataset": 0,
10+
"unicorn/prefer-module": 0,
11+
"no-var": 0,
12+
"unicorn/no-array-for-each": 0,
13+
"unicorn/prefer-dom-node-dataset": 0,
14+
"object-shorthand": 0,
15+
"unicorn/prefer-dom-node-append": 0,
16+
"unicorn/prefer-number-properties": 0
1017
}
1118
}

datalist-polyfill.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// TODO: obviously ugly. But sadly necessary until Microsoft enhances the UX within EDGE (compare to https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9573654/)
2525
// Tested against the following UA strings: http://useragentstring.com/pages/useragentstring.php?name=Internet+Explorer
2626
// And adapted out of https://gist.github.com/gaboratorium/25f08b76eb82b1e7b91b01a0448f8b1d :
27-
isGteIE10 = Boolean(ua.match(/MSIE\s1[01]./) || ua.match(/rv:11./)),
27+
isGteIE10 = Boolean(/MSIE\s1[01]./.test(ua) || /rv:11./.test(ua)),
2828
isEDGE = Boolean(ua.indexOf('Edge/') !== -1);
2929

3030
// Let's break here, if it's even already supported ... and not IE10+ or EDGE
@@ -51,7 +51,7 @@
5151
supportedTypes = ['text', 'email', 'number', 'search', 'tel', 'url'],
5252
// Classes for elements
5353
classNameInput = 'polyfilled',
54-
classNamePolyfillingSelect = 'polyfilling',
54+
classNamePolyfillingSelect = '.polyfilling',
5555
// Defining a most likely unique polyfill string
5656
uniquePolyfillString = '###[P0LYFlLLed]###';
5757

@@ -93,9 +93,7 @@
9393
// Prepare the options and toggle the visiblity afterwards
9494
toggleVisibility(
9595
prepOptions(datalistNeedsAnUpdate, input).length,
96-
datalistNeedsAnUpdate.getElementsByClassName(
97-
classNamePolyfillingSelect
98-
)[0]
96+
datalistNeedsAnUpdate.querySelector(classNamePolyfillingSelect)
9997
);
10098
}
10199
}
@@ -136,7 +134,7 @@
136134
var visible = false,
137135
// 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)
138136
datalistSelect =
139-
datalist.getElementsByClassName(classNamePolyfillingSelect)[0] ||
137+
datalist.querySelector(classNamePolyfillingSelect) ||
140138
setUpPolyfillingSelect(input, datalist);
141139

142140
// On an ESC or ENTER key press within the input, let's break here and afterwards hide the datalist select, but if the input contains a value or one of the opening keys have been pressed ...
@@ -274,6 +272,7 @@
274272
// Set the value of the first option to it's value - this actually triggers a redraw of the complete list
275273
var firstOption = input.list.options[0];
276274

275+
// eslint-disable-next-line no-self-assign
277276
firstOption.value = firstOption.value;
278277
}
279278

@@ -284,7 +283,7 @@
284283

285284
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)
286285
datalistSelect =
287-
datalist.getElementsByClassName(classNamePolyfillingSelect)[0] ||
286+
datalist.querySelector(classNamePolyfillingSelect) ||
288287
setUpPolyfillingSelect(input, datalist),
289288
// 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
290289
visible =
@@ -373,7 +372,7 @@
373372

374373
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)
375374
datalistSelect =
376-
datalist.getElementsByClassName(classNamePolyfillingSelect)[0] ||
375+
datalist.querySelector(classNamePolyfillingSelect) ||
377376
setUpPolyfillingSelect(input, datalist),
378377
inputValue = getInputValue(input),
379378
newSelectValues = dcmnt.createDocumentFragment(),
@@ -439,7 +438,7 @@
439438
datalistSelect.multiple = !touched && datalistSelectOptionsLength < 2;
440439

441440
// Input the unused options as siblings next to the select - and differentiate in between the regular, and the IE9 fix syntax upfront
442-
(datalist.getElementsByClassName('ie9_fix')[0] || datalist).appendChild(
441+
(datalist.querySelectorAll('.ie9_fix')[0] || datalist).appendChild(
443442
disabledValues
444443
);
445444

@@ -471,7 +470,7 @@
471470
datalistSelect = dcmnt.createElement('select');
472471

473472
// Setting a class for easier identifying that select afterwards
474-
datalistSelect.setAttribute('class', classNamePolyfillingSelect);
473+
datalistSelect.setAttribute('class', classNamePolyfillingSelect.slice(1));
475474

476475
// Set general styling related definitions
477476
datalistSelect.style.position = 'absolute';
@@ -510,9 +509,8 @@
510509
}
511510

512511
// Set the polyfilling selects border-radius equally to the one by the polyfilled input
513-
datalistSelect.style.borderRadius = inputStyles.getPropertyValue(
514-
'border-radius'
515-
);
512+
datalistSelect.style.borderRadius =
513+
inputStyles.getPropertyValue('border-radius');
516514
datalistSelect.style.minWidth = rects[0].width + 'px';
517515

518516
if (touched) {
@@ -668,7 +666,7 @@
668666
"The list IDL attribute must return the current suggestions source element, if any, or null otherwise."
669667
"If there is no list attribute, or if there is no element with that ID, or if the first element with that ID is not a datalist element, then there is no suggestions source element."
670668
*/
671-
var element = dcmnt.getElementById(this.getAttribute('list'));
669+
var element = dcmnt.querySelector('#' + this.getAttribute('list'));
672670

673671
return typeof this === 'object' &&
674672
this instanceof constructor &&
@@ -691,7 +689,7 @@
691689
Object.defineProperty(constructor.prototype, 'options', {
692690
get: function () {
693691
return typeof this === 'object' && this instanceof constructor
694-
? this.getElementsByTagName('option')
692+
? this.querySelectorAll('option')
695693
: null;
696694
},
697695
});

0 commit comments

Comments
 (0)