1 | import skate from 'skatejs';
|
2 | import {onChildrenChange} from '../internal/detect-children-change';
|
3 | import jQuery from 'jquery';
|
4 |
|
5 | export function createFormsComponentBody(type) {
|
6 |
|
7 | let unsub;
|
8 |
|
9 | return {
|
10 | type: skate.type.CLASSNAME,
|
11 | attached: function(el) {
|
12 |
|
13 | onChildrenChange(el,(unsubscribe) => {
|
14 |
|
15 |
|
16 | unsub = unsubscribe;
|
17 |
|
18 | const innerCheckboxList = jQuery(`input[type=${type}]`, el);
|
19 |
|
20 | innerCheckboxList.each(function (i, radio) {
|
21 | jQuery('<span class="aui-form-glyph"></span>').insertAfter(radio);
|
22 | });
|
23 |
|
24 | const isInsertedAfterChange = innerCheckboxList.length > 0;
|
25 | if (isInsertedAfterChange) {
|
26 | unsub();
|
27 | }
|
28 | });
|
29 | },
|
30 | detached: function(el) {
|
31 | jQuery('.aui-form-glyph', el).remove();
|
32 | if (unsub) {
|
33 | unsub();
|
34 | }
|
35 | }
|
36 | }
|
37 | }
|