Total Complexity | 4 |
Complexity/F | 1 |
Lines of Code | 35 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | const NewFormButton = { |
||
2 | BUTTON_QUERY: '#new-file', |
||
3 | LAST_FORM_QUERY: '.code-form--file:last-of-type', |
||
4 | |||
5 | init() { |
||
6 | this.index = 0; |
||
7 | const button = document.querySelector(this.BUTTON_QUERY); |
||
8 | button.addEventListener('click', () => this.onClick()); |
||
9 | }, |
||
10 | |||
11 | onClick() { |
||
12 | this.index += 1; |
||
13 | const lastForm = document.querySelector(this.LAST_FORM_QUERY); |
||
14 | const newForm = this.getNewForm(); |
||
15 | const formsWrapper = lastForm.parentNode; |
||
16 | |||
17 | formsWrapper.insertBefore(newForm, lastForm.nextSibling); |
||
18 | }, |
||
19 | |||
20 | getNewForm() { |
||
21 | const newForm = document.createElement('fieldset'); |
||
22 | newForm.setAttribute('class', 'code-form--file'); |
||
23 | newForm.setAttribute('data-index', this.index); |
||
24 | |||
25 | newForm.innerHTML = |
||
26 | `<label class="code-form--label" for="name[${this.index}]">Nazwa pliku (opcjonalna)</label> |
||
27 | <input type="text" id="name[${this.index}]" name="name[${this.index}]" class="code-form--control"> |
||
28 | <label for="content[${this.index}]" class="code-form--label">Treść pliku</label> |
||
29 | <textarea name="content[${this.index}]" id="content[${this.index}]" rows="10" class="code-form--control code-form--control__textarea"></textarea>`; |
||
30 | |||
31 | return newForm; |
||
32 | }, |
||
33 | }; |
||
34 | |||
35 | NewFormButton.init(); |
||
36 |