|
1 | 1 | import $ from 'jquery';
|
| 2 | +import {hideElem, showElem} from '../utils/dom.js'; |
2 | 3 |
|
3 | 4 | export function initTagNameEditor() {
|
4 |
| - const el = document.getElementById('tag-name-editor'); |
5 |
| - if (!el) return; |
| 5 | + const el = document.getElementById('tag-name-editor'); |
| 6 | + if (!el) return; |
6 | 7 |
|
7 |
| - const existingTags = JSON.parse(el.getAttribute('data-existing-tags')) |
8 |
| - if (!Array.isArray(existingTags)) return |
| 8 | + const existingTags = JSON.parse(el.getAttribute('data-existing-tags')); |
| 9 | + if (!Array.isArray(existingTags)) return; |
9 | 10 |
|
10 |
| - const defaultTagHelperText = el.getAttribute('data-tag-helper') |
11 |
| - const newTagHelperText = el.getAttribute('data-tag-helper-new') |
12 |
| - const existingTagHelperText = el.getAttribute('data-tag-helper-existing') |
| 11 | + const defaultTagHelperText = el.getAttribute('data-tag-helper'); |
| 12 | + const newTagHelperText = el.getAttribute('data-tag-helper-new'); |
| 13 | + const existingTagHelperText = el.getAttribute('data-tag-helper-existing'); |
13 | 14 |
|
14 |
| - $('#tag-name').on('keyup', function(e) { |
15 |
| - const value = e.target.value |
16 |
| - if (existingTags.includes(value)) { |
17 |
| - // If the tag already exists, hide the target branch selector. |
18 |
| - $('#tag-target-selector').hide() |
19 |
| - $('#tag-helper').text(existingTagHelperText) |
20 |
| - } else { |
21 |
| - $('#tag-target-selector').show() |
22 |
| - if (typeof value == 'string' && value.length > 0) { |
23 |
| - $('#tag-helper').text(newTagHelperText) |
24 |
| - } else { |
25 |
| - $('#tag-helper').text(defaultTagHelperText) |
26 |
| - } |
27 |
| - } |
28 |
| - }) |
| 15 | + $('#tag-name').on('keyup', (e) => { |
| 16 | + const value = e.target.value; |
| 17 | + if (existingTags.includes(value)) { |
| 18 | + // If the tag already exists, hide the target branch selector. |
| 19 | + hideElem($('#tag-target-selector')); |
| 20 | + $('#tag-helper').text(existingTagHelperText); |
| 21 | + } else { |
| 22 | + showElem($('#tag-target-selector')); |
| 23 | + if (typeof value === 'string' && value.length > 0) { |
| 24 | + $('#tag-helper').text(newTagHelperText); |
| 25 | + } else { |
| 26 | + $('#tag-helper').text(defaultTagHelperText); |
| 27 | + } |
| 28 | + } |
| 29 | + }); |
29 | 30 | }
|
0 commit comments