| 27457 | } |
| 27458 | |
| 27459 | function createEleFromJson(json) { |
| 27460 | let collection = document.createDocumentFragment(); |
| 27461 | json.forEach(data => { |
| 27462 | if (/^script/i.test(data.node)) return; |
| 27463 | let ele = document.createElement(data.node); |
| 27464 | if (data.text) { |
| 27465 | ele.innerText = data.text; |
| 27466 | } |
| 27467 | if (data.attr) { |
| 27468 | Object.keys(data.attr).forEach(key => { |
| 27469 | if (/^on/i.test(key)) return; |
| 27470 | ele.setAttribute(key, data.attr[key]); |
| 27471 | }); |
| 27472 | } |
| 27473 | if (data.children) { |
| 27474 | let children = createEleFromJson(data.children); |
| 27475 | ele.appendChild(children); |
| 27476 | } |
| 27477 | collection.appendChild(ele); |
| 27478 | }); |
| 27479 | return collection; |
| 27480 | } |
| 27481 | |
| 27482 | window.addEventListener('message', handleMessage, true); |
| 27483 | |