Project

General

Profile

Download (843 Bytes) Statistics
| Branch: | Tag: | Revision:

haketilo / html / DOM_helpers.js @ 792fbe18

1
/**
2
 * Hachette operations on DOM elements
3
 *
4
 * Copyright (C) 2021 Wojtek Kosior
5
 * Redistribution terms are gathered in the `copyright' file.
6
 */
7

    
8
function by_id(id)
9
{
10
    return document.getElementById(id);
11
}
12

    
13
function clone_template(template_id)
14
{
15
    const clone = document.getElementById(template_id).cloneNode(true);
16
    const result_object = {};
17
    const to_process = [clone];
18

    
19
    while (to_process.length > 0) {
20
	const element = to_process.pop();
21
	const template_key = element.getAttribute("data-template");
22

    
23
	if (template_key)
24
	    result_object[template_key] = element;
25

    
26
	element.removeAttribute("id");
27
	element.removeAttribute("template_key");
28

    
29
	for (const child of element.children)
30
	    to_process.push(child);
31
    }
32

    
33
    return result_object;
34
}
35

    
36
/*
37
 * EXPORTS_START
38
 * EXPORT by_id
39
 * EXPORT clone_template
40
 * EXPORTS_END
41
 */
(1-1/8)