PageSourceSearch

https://www.tion.ro/wp-content/plugins/endless-core/js/htmlBuilder.js?ver=1790773834

js tion.ro collected 2026-10-01 12:20:27 UTC 3,946 bytes, 92 lines download raw bytes

1const HtmlBuilder = {
2    buildByConfig: function (wrapperId, config, parentSelector) {
3        if (!wrapperId || typeof wrapperId !== 'string' || !isNaN(parseFloat(wrapperId.substring(0, 1)))) {
4            console.error('Invalid wrapper ID provided.');
5            return;
6        }
7        if (!Array.isArray(config)) {
8            config = [];
9        }
10
11        let parent = document.querySelector('body');
12        if (parentSelector && typeof parentSelector === 'string' && document.querySelector(parentSelector)) {
13            parent = document.querySelector(parentSelector);
14        }
15
16        let wrapper = parent.querySelector('#' + wrapperId) ? parent.querySelector('#' + wrapperId) : document.createElement('div');
17        wrapper.setAttribute('id', wrapperId);
18        let classes = [];
19        Object.keys(wrapper.classList).forEach((className) => {
20            if (!classes.contains(className)) {
21                classes.push(className);
22            }
23        });
24        classes.forEach((className) => {
25            wrapper.classList.remove(className);
26        });
27        if (!parent.querySelector('#' + wrapperId)) {
28            parent.appendChild(wrapper);
29        }
30        HtmlBuilder.buildElements(wrapper, config);
31
32        return wrapper;
33    },
34    buildElements: function (parent, elementConfigArray) {
35        while (parent.firstChild) {
36            parent.removeChild(parent.firstChild);
37        }
38
39        elementConfigArray.forEach((elementConfig) => {
40            let element = document.createElement(elementConfig.tag);
41            if (elementConfig.tag === 'button') {
42                element.setAttribute('type', 'button');
43            }
44            if (typeof elementConfig.id !== 'undefined') {
45                element.setAttribute('id', elementConfig.id);
46            }
47            if (typeof elementConfig.name !== 'undefined') {
48                element.setAttribute('name', elementConfig.name);
49            }
50            if (typeof elementConfig.classList !== 'undefined') {
51                element.classList.add(...elementConfig.classList.split(' '));
52            }
53            if (typeof elementConfig.target !== 'undefined') {
54                element.setAttribute('target', elementConfig.target);
55            }
56            if (typeof elementConfig.text !== 'undefined') {
57                element.textContent = elementConfig.text;
58            }
59            if (typeof elementConfig.html !== 'undefined') {
60                element.innerHTML = elementConfig.html;
61            }
62            if (typeof elementConfig.type !== 'undefined') {
63                element.setAttribute('type', elementConfig.type);
64            }
65            if (typeof elementConfig.value !== 'undefined') {
66                element.value = elementConfig.value;
67            }
68            if (typeof elementConfig.for !== 'undefined') {
69                element.setAttribute('for', elementConfig.for);
70            }
71            if (typeof elementConfig.autocomplete !== 'undefined') {
72                element.setAttribute('autocomplete', elementConfig.autocomplete);
73            }
74            if (typeof elementConfig.required !== 'undefined' && elementConfig.required) {
75                element.setAttribute('required', 'required');
76            }
77            if (typeof elementConfig.src !== 'undefined') {
78                element.setAttribute('src', elementConfig.src);
79            }
80            if (typeof elementConfig.href !== 'undefined') {
81                element.setAttribute('href', elementConfig.href);
82            }
83            if (typeof elementConfig.onClick !== 'undefined') {
84                element.addEventListener('click', elementConfig.onClick);
85            }
86            if (typeof elementConfig.children !== 'undefined' && Array.isArray(elementConfig.children)) {
87                HtmlBuilder.buildElements(element, elementConfig.children);
88            }
89            parent.appendChild(element);
90        });
91    }
92};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.