|
24 | 24 | // 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/)
|
25 | 25 | // Tested against the following UA strings: http://useragentstring.com/pages/useragentstring.php?name=Internet+Explorer
|
26 | 26 | // 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)), |
28 | 28 | isEDGE = Boolean(ua.indexOf('Edge/') !== -1);
|
29 | 29 |
|
30 | 30 | // Let's break here, if it's even already supported ... and not IE10+ or EDGE
|
|
51 | 51 | supportedTypes = ['text', 'email', 'number', 'search', 'tel', 'url'],
|
52 | 52 | // Classes for elements
|
53 | 53 | classNameInput = 'polyfilled',
|
54 |
| - classNamePolyfillingSelect = 'polyfilling', |
| 54 | + classNamePolyfillingSelect = '.polyfilling', |
55 | 55 | // Defining a most likely unique polyfill string
|
56 | 56 | uniquePolyfillString = '###[P0LYFlLLed]###';
|
57 | 57 |
|
|
93 | 93 | // Prepare the options and toggle the visiblity afterwards
|
94 | 94 | toggleVisibility(
|
95 | 95 | prepOptions(datalistNeedsAnUpdate, input).length,
|
96 |
| - datalistNeedsAnUpdate.getElementsByClassName( |
97 |
| - classNamePolyfillingSelect |
98 |
| - )[0] |
| 96 | + datalistNeedsAnUpdate.querySelector(classNamePolyfillingSelect) |
99 | 97 | );
|
100 | 98 | }
|
101 | 99 | }
|
|
136 | 134 | var visible = false,
|
137 | 135 | // 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)
|
138 | 136 | datalistSelect =
|
139 |
| - datalist.getElementsByClassName(classNamePolyfillingSelect)[0] || |
| 137 | + datalist.querySelector(classNamePolyfillingSelect) || |
140 | 138 | setUpPolyfillingSelect(input, datalist);
|
141 | 139 |
|
142 | 140 | // 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 | 272 | // Set the value of the first option to it's value - this actually triggers a redraw of the complete list
|
275 | 273 | var firstOption = input.list.options[0];
|
276 | 274 |
|
| 275 | + // eslint-disable-next-line no-self-assign |
277 | 276 | firstOption.value = firstOption.value;
|
278 | 277 | }
|
279 | 278 |
|
|
284 | 283 |
|
285 | 284 | 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)
|
286 | 285 | datalistSelect =
|
287 |
| - datalist.getElementsByClassName(classNamePolyfillingSelect)[0] || |
| 286 | + datalist.querySelector(classNamePolyfillingSelect) || |
288 | 287 | setUpPolyfillingSelect(input, datalist),
|
289 | 288 | // 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
|
290 | 289 | visible =
|
|
373 | 372 |
|
374 | 373 | 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)
|
375 | 374 | datalistSelect =
|
376 |
| - datalist.getElementsByClassName(classNamePolyfillingSelect)[0] || |
| 375 | + datalist.querySelector(classNamePolyfillingSelect) || |
377 | 376 | setUpPolyfillingSelect(input, datalist),
|
378 | 377 | inputValue = getInputValue(input),
|
379 | 378 | newSelectValues = dcmnt.createDocumentFragment(),
|
|
439 | 438 | datalistSelect.multiple = !touched && datalistSelectOptionsLength < 2;
|
440 | 439 |
|
441 | 440 | // 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( |
443 | 442 | disabledValues
|
444 | 443 | );
|
445 | 444 |
|
|
471 | 470 | datalistSelect = dcmnt.createElement('select');
|
472 | 471 |
|
473 | 472 | // Setting a class for easier identifying that select afterwards
|
474 |
| - datalistSelect.setAttribute('class', classNamePolyfillingSelect); |
| 473 | + datalistSelect.setAttribute('class', classNamePolyfillingSelect.slice(1)); |
475 | 474 |
|
476 | 475 | // Set general styling related definitions
|
477 | 476 | datalistSelect.style.position = 'absolute';
|
|
510 | 509 | }
|
511 | 510 |
|
512 | 511 | // 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'); |
516 | 514 | datalistSelect.style.minWidth = rects[0].width + 'px';
|
517 | 515 |
|
518 | 516 | if (touched) {
|
|
668 | 666 | "The list IDL attribute must return the current suggestions source element, if any, or null otherwise."
|
669 | 667 | "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."
|
670 | 668 | */
|
671 |
| - var element = dcmnt.getElementById(this.getAttribute('list')); |
| 669 | + var element = dcmnt.querySelector('#' + this.getAttribute('list')); |
672 | 670 |
|
673 | 671 | return typeof this === 'object' &&
|
674 | 672 | this instanceof constructor &&
|
|
691 | 689 | Object.defineProperty(constructor.prototype, 'options', {
|
692 | 690 | get: function () {
|
693 | 691 | return typeof this === 'object' && this instanceof constructor
|
694 |
| - ? this.getElementsByTagName('option') |
| 692 | + ? this.querySelectorAll('option') |
695 | 693 | : null;
|
696 | 694 | },
|
697 | 695 | });
|
|
0 commit comments