12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- "use strict";
- module.exports = class PortSelect {
- constructor(selectElement) {
- this.selectElement = selectElement;
- this.map = {}; // Cache matching the text value of a port to OPTION element.
- }
- /**
- * Appends a single port to the end of serial port SELECT element.
- * Adds port to map.
- * @param port
- */
- add(port) {
- const option = this.createOption(port);
- this.map[port] = option;
- this.selectElement.appendChild(option);
- }
- /**
- * Removed single port from the serial port SELECT element.
- * Removes port from map.
- * @param port
- */
- remove(port) {
- this.selectElement.removeChild(this.map[port]);
- delete this.map[port];
- }
- /**
- * Removes existing comment, adds ports to the serial port SELECT element.
- * @param ports. An Array of strings.
- */
- addAll(ports) {
- ports.forEach(port => {
- this.add(port);
- });
- }
- /**
- * Creates option with the port text and value.
- * @param port
- * @returns {Element}
- */
- createOption(port) {
- const option = document.createElement("option");
- option.textContent = port;
- option.value = port;
- return option;
- }
- /**
- * Pass through.
- * Updates the disabled attribute on the SELECT element.
- * @param value
- */
- set disabled (value) {
- this.selectElement.disabled = value;
- }
- };
|