MCPcopy Create free account
hub / github.com/cryptii/cryptii / createElement

Method createElement

src/View.js:19–52  ·  view source on GitHub ↗

* Creates element with given tag, attributes and children. * @param {string} type * @param {object} attributes * @param {string|HTMLElement|HTMLElement[]} children * @return {HTMLElement}

(type, attributes = {}, children = null)

Source from the content-addressed store, hash-verified

17 * @return {HTMLElement}
18 */
19 static createElement (type, attributes = {}, children = null) {
20 const $element = document.createElement(type)
21
22 // set element attributes
23 Object.keys(attributes).forEach(name => {
24 const value = attributes[name]
25 if (nonStandardAttributes[name] === undefined) {
26 // lowercase event attributes
27 const attributeName =
28 name.indexOf('on') === 0
29 ? name.toLowerCase()
30 : name
31 $element[attributeName] = value
32 } else {
33 // set non-standard attribute
34 $element.setAttribute(nonStandardAttributes[name], value)
35 }
36 })
37
38 // append children
39 if (children !== null) {
40 switch (Object.prototype.toString.call(children)) {
41 case '[object String]':
42 $element.innerText = children
43 break
44 case '[object Array]':
45 children.forEach($child => $child && $element.appendChild($child))
46 break
47 default:
48 $element.appendChild(children)
49 }
50 }
51 return $element
52 }
53
54 /**
55 * View constructor

Callers 15

renderMethod · 0.80
renderMethod · 0.80
_createPipePartMethod · 0.80
_createBrickPartMethod · 0.80
_createCollapsedPartMethod · 0.80
renderMethod · 0.80
renderDialogMethod · 0.80
renderHeaderMethod · 0.80
renderMethod · 0.80
renderHeaderMethod · 0.80
renderMenuMethod · 0.80
renderSettingsMethod · 0.80

Calls 2

indexOfMethod · 0.80
toLowerCaseMethod · 0.80

Tested by

no test coverage detected