|
14 | 14 | *
|
15 | 15 | * @param {string} selector - css selector for target element
|
16 | 16 | */
|
17 |
| - function registerTaskListExpandListeners(selector) { |
| 17 | + const registerTaskListExpandListeners = (selector) => { |
18 | 18 | document.querySelectorAll(selector).forEach((element) => {
|
19 | 19 | element.addEventListener("click", (e) => {
|
20 | 20 | e.stopPropagation();
|
21 | 21 | element.classList.toggle("TaskList-expanded");
|
22 | 22 | element.nextElementSibling.classList.toggle("TaskList-expanded");
|
23 | 23 | });
|
24 | 24 | });
|
25 |
| - } |
| 25 | + }; |
26 | 26 |
|
27 |
| - registerTaskListExpandListeners(".TaskList-expandableItem"); |
28 |
| -})(); |
| 27 | + /** |
| 28 | + * addSliceRow creates and appends a row to a slice parameter |
| 29 | + * for filling in an element. |
| 30 | + * |
| 31 | + * @param {HTMLElement} container - the container element |
| 32 | + * @param {string} paramName - the parameter name |
| 33 | + * @param {string} element - the element tag to create |
| 34 | + * @param {string} inputType - the type attribute if element is "input" |
| 35 | + * @param {string} paramExample - an example value for the parameter |
| 36 | + */ |
| 37 | + const addSliceRow = (container, paramName, element, inputType, paramExample) => { |
| 38 | + /* |
| 39 | + Create an input element, a button to remove it, group them in a "parameterRow" div: |
29 | 40 |
|
30 |
| -/* eslint-disable no-unused-vars */ |
31 |
| -/** |
32 |
| - * addSliceRow creates and appends a row to a slice parameter |
33 |
| - * for filling in an element. |
34 |
| - * |
35 |
| - * @param {HTMLElement} container - the container element |
36 |
| - * @param {string} paramName - the parameter name |
37 |
| - * @param {string} element - the element tag to create |
38 |
| - * @param {string} inputType - the type attribute if element is "input" |
39 |
| - * @param {string} paramExample - an example value for the parameter |
40 |
| - */ |
41 |
| -function addSliceRow(container, paramName, element, inputType, paramExample) { |
42 |
| - /* |
43 |
| - Create an input element, a button to remove it, group them in a "parameterRow" div: |
| 41 | + <div class="NewWorkflow-parameterRow"> |
| 42 | + <input name="workflow.params.{{$p.Name}}" placeholder="{{paramExample}}" /> |
| 43 | + <button title="Remove this row from the slice." onclick="/ * Remove this row. * /">-</button> |
| 44 | + </div> |
| 45 | + */ |
| 46 | + const input = document.createElement(element); |
| 47 | + input.name = "workflow.params." + paramName; |
| 48 | + if (element === "input") { |
| 49 | + input.type = inputType; |
| 50 | + } |
| 51 | + input.placeholder = paramExample; |
| 52 | + const removeButton = document.createElement("button"); |
| 53 | + removeButton.title = "Remove this row from the slice."; |
| 54 | + removeButton.addEventListener("click", (e) => { |
| 55 | + e.preventDefault(); |
| 56 | + container.removeChild(div); |
| 57 | + }); |
| 58 | + removeButton.appendChild(document.createTextNode("-")); |
| 59 | + const div = document.createElement("div"); |
| 60 | + div.className = "NewWorkflow-parameterRow"; |
| 61 | + div.appendChild(input); |
| 62 | + div.appendChild(removeButton); |
44 | 63 |
|
45 |
| - <div class="NewWorkflow-parameterRow"> |
46 |
| - <input name="workflow.params.{{$p.Name}}" placeholder="{{paramExample}}" /> |
47 |
| - <button title="Remove this row from the slice." onclick="/ * Remove this row. * /">-</button> |
48 |
| - </div> |
49 |
| - */ |
50 |
| - const input = document.createElement(element); |
51 |
| - input.name = "workflow.params." + paramName; |
52 |
| - if (element === "input") { |
53 |
| - input.type = inputType; |
54 |
| - } |
55 |
| - input.placeholder = paramExample; |
56 |
| - const removeButton = document.createElement("button"); |
57 |
| - removeButton.title = "Remove this row from the slice."; |
58 |
| - removeButton.addEventListener("click", (e) => { |
59 |
| - e.preventDefault(); |
60 |
| - container.removeChild(div); |
61 |
| - }); |
62 |
| - removeButton.appendChild(document.createTextNode("-")); |
63 |
| - const div = document.createElement("div"); |
64 |
| - div.className = "NewWorkflow-parameterRow"; |
65 |
| - div.appendChild(input); |
66 |
| - div.appendChild(removeButton); |
| 64 | + // Add the "parameterRow" div to the document. |
| 65 | + container.appendChild(div); |
| 66 | + }; |
67 | 67 |
|
68 |
| - // Add the "parameterRow" div to the document. |
69 |
| - container.appendChild(div); |
70 |
| -} |
71 |
| -/* eslint-enable no-unused-vars */ |
| 68 | + /** addSliceRowListener registers listeners for addSliceRow. |
| 69 | + * |
| 70 | + * @param {string} selector - elements to add click listener for addSliceRow. |
| 71 | + */ |
| 72 | + const addSliceRowListener = (selector) => { |
| 73 | + document.querySelectorAll(selector).forEach((element) => { |
| 74 | + element.addEventListener("click", (e) => { |
| 75 | + e.stopPropagation(); |
| 76 | + addSliceRow( |
| 77 | + element.parentElement.parentElement, |
| 78 | + element.dataset.paramname, |
| 79 | + element.dataset.element, |
| 80 | + element.dataset.inputtype, |
| 81 | + element.dataset.paramexample |
| 82 | + ); |
| 83 | + }); |
| 84 | + }); |
| 85 | + }; |
| 86 | + |
| 87 | + const registerListeners = () => { |
| 88 | + registerTaskListExpandListeners(".TaskList-expandableItem"); |
| 89 | + addSliceRowListener(".NewWorkflow-addSliceRowButton"); |
| 90 | + }; |
| 91 | + if (document.readyState === "loading") { |
| 92 | + document.addEventListener("DOMContentLoaded", registerListeners); |
| 93 | + } else { |
| 94 | + registerListeners(); |
| 95 | + } |
| 96 | +})(); |
0 commit comments