Total Complexity | 12 |
Complexity/F | 6 |
Lines of Code | 53 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /** |
||
4 | function createElement(options) { |
||
5 | var el, a, i; |
||
6 | if (!options.tagName) { |
||
7 | el = document.createDocumentFragment(); |
||
8 | } else { |
||
9 | el = document.createElement(options.tagName); |
||
10 | if (options.className) { |
||
11 | el.className = options.className; |
||
12 | } |
||
13 | |||
14 | if (options.attributes) { |
||
15 | for (a in options.attributes) { |
||
16 | el.setAttribute(a, options.attributes[a]); |
||
17 | } |
||
18 | } |
||
19 | |||
20 | if (options.html !== undefined) { |
||
21 | el.innerHTML = options.html; |
||
22 | } |
||
23 | } |
||
24 | |||
25 | if (options.text) { |
||
26 | el.appendChild(document.createTextNode(options.text)); |
||
27 | } |
||
28 | |||
29 | // IE 8 doesn"t have HTMLElement |
||
30 | if (window.HTMLElement === undefined) { |
||
31 | // @ts-ignore |
||
32 | window.HTMLElement = Element; |
||
33 | } |
||
34 | |||
35 | if (options.childs && options.childs.length) { |
||
36 | for (i = 0; i < options.childs.length; i++) { |
||
37 | el.appendChild( |
||
38 | options.childs[i] instanceof window.HTMLElement |
||
39 | ? options.childs[i] |
||
40 | : createElement(options.childs[i]) |
||
41 | ); |
||
42 | } |
||
43 | } |
||
44 | |||
45 | return el; |
||
46 | } |
||
47 | |||
48 | class html { |
||
49 | static create(options) { |
||
50 | /** |
||
51 | * @param {createElementOpt} |
||
52 | * @returns {createElement} |
||
53 | */ |
||
54 | return createElement(options); |
||
55 | } |
||
56 | } |
||
57 |