UNPKG

1.03 kBJavaScriptView Raw
1import skate from 'skatejs';
2import {onChildrenChange} from '../internal/detect-children-change';
3import jQuery from 'jquery';
4
5export 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 // Store function that stops subscription
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}