aboutsummaryrefslogtreecommitdiff
path: root/html/DOM_helpers.js
diff options
context:
space:
mode:
authorjahoti <jahoti@tilde.team>2021-08-17 00:00:00 +0000
committerjahoti <jahoti@tilde.team>2021-08-17 00:00:00 +0000
commit5b7c9edbbb46074436b819435feb80ebbd9ab4ad (patch)
treecfa7ef034d99dc1957ce3b146256d766a6a8426d /html/DOM_helpers.js
parent7796e55405e2c27f053122bdec25ffc06df92b4f (diff)
parent443bc095a72949adb4a007c9a19a43da7dd8843d (diff)
downloadbrowser-extension-5b7c9edbbb46074436b819435feb80ebbd9ab4ad.tar.gz
browser-extension-5b7c9edbbb46074436b819435feb80ebbd9ab4ad.zip
Merge remote-tracking branch 'origin/master' into jahoti
Diffstat (limited to 'html/DOM_helpers.js')
-rw-r--r--html/DOM_helpers.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/html/DOM_helpers.js b/html/DOM_helpers.js
new file mode 100644
index 0000000..2bff966
--- /dev/null
+++ b/html/DOM_helpers.js
@@ -0,0 +1,41 @@
+/**
+ * Hachette operations on DOM elements
+ *
+ * Copyright (C) 2021 Wojtek Kosior
+ * Redistribution terms are gathered in the `copyright' file.
+ */
+
+function by_id(id)
+{
+ return document.getElementById(id);
+}
+
+function clone_template(template_id)
+{
+ const clone = document.getElementById(template_id).cloneNode(true);
+ const result_object = {};
+ const to_process = [clone];
+
+ while (to_process.length > 0) {
+ const element = to_process.pop();
+ const template_key = element.getAttribute("data-template");
+
+ if (template_key)
+ result_object[template_key] = element;
+
+ element.removeAttribute("id");
+ element.removeAttribute("template_key");
+
+ for (const child of element.children)
+ to_process.push(child);
+ }
+
+ return result_object;
+}
+
+/*
+ * EXPORTS_START
+ * EXPORT by_id
+ * EXPORT clone_template
+ * EXPORTS_END
+ */