]> BookStack Code Mirror - bookstack/blobdiff - resources/js/services/dom.js
Updated npm package versions
[bookstack] / resources / js / services / dom.js
index 00b34bf345767e034b9f7b8d6794083d228a6ed0..eb5f6a8530d512c6a4a965baa57d2b24a14c7d51 100644 (file)
@@ -106,4 +106,28 @@ export function findText(selector, text) {
  */
 export function showLoading(element) {
     element.innerHTML = `<div class="loading-container"><div></div><div></div><div></div></div>`;
+}
+
+/**
+ * Remove any loading indicators within the given element.
+ * @param {Element} element
+ */
+export function removeLoading(element) {
+    const loadingEls = element.querySelectorAll('.loading-container');
+    for (const el of loadingEls) {
+        el.remove();
+    }
+}
+
+/**
+ * Convert the given html data into a live DOM element.
+ * Initiates any components defined in the data.
+ * @param {String} html
+ * @returns {Element}
+ */
+export function htmlToDom(html) {
+    const wrap = document.createElement('div');
+    wrap.innerHTML = html;
+    window.components.init(wrap);
+    return wrap.children[0];
 }
\ No newline at end of file