]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/components/index.js
Update german translation
[bookstack] / resources / assets / js / components / index.js
index 988409fbca08b8c30c8051c1f63c1fffb19f2fcd..768e0983f12b385d4e1b722828f791028cce2bfc 100644 (file)
@@ -10,23 +10,52 @@ let componentMapping = {
     'entity-selector': require('./entity-selector'),
     'sidebar': require('./sidebar'),
     'page-picker': require('./page-picker'),
+    'page-comments': require('./page-comments'),
+    'wysiwyg-editor': require('./wysiwyg-editor'),
+    'markdown-editor': require('./markdown-editor'),
+    'editor-toolbox': require('./editor-toolbox'),
+    'image-picker': require('./image-picker'),
+    'collapsible': require('./collapsible'),
+    'toggle-switch': require('./toggle-switch'),
+    'page-display': require('./page-display'),
+    'shelf-sort': require('./shelf-sort'),
+    'homepage-control': require('./homepage-control'),
 };
 
 window.components = {};
 
 let componentNames = Object.keys(componentMapping);
 
-for (let i = 0, len = componentNames.length; i < len; i++) {
-    let name = componentNames[i];
-    let elems = document.querySelectorAll(`[${name}]`);
-    if (elems.length === 0) continue;
+/**
+ * Initialize components of the given name within the given element.
+ * @param {String} componentName
+ * @param {HTMLElement|Document} parentElement
+ */
+function initComponent(componentName, parentElement) {
+    let elems = parentElement.querySelectorAll(`[${componentName}]`);
+    if (elems.length === 0) return;
 
-    let component = componentMapping[name];
-    if (typeof window.components[name] === "undefined") window.components[name] = [];
+    let component = componentMapping[componentName];
+    if (typeof window.components[componentName] === "undefined") window.components[componentName] = [];
     for (let j = 0, jLen = elems.length; j < jLen; j++) {
-         let instance = new component(elems[j]);
-         if (typeof elems[j].components === 'undefined') elems[j].components = {};
-         elems[j].components[name] = instance;
-         window.components[name].push(instance);
+        let instance = new component(elems[j]);
+        if (typeof elems[j].components === 'undefined') elems[j].components = {};
+        elems[j].components[componentName] = instance;
+        window.components[componentName].push(instance);
     }
-}
\ No newline at end of file
+}
+
+/**
+ * Initialize all components found within the given element.
+ * @param parentElement
+ */
+function initAll(parentElement) {
+    if (typeof parentElement === 'undefined') parentElement = document;
+    for (let i = 0, len = componentNames.length; i < len; i++) {
+        initComponent(componentNames[i], parentElement);
+    }
+}
+
+window.components.init = initAll;
+
+export default initAll;
\ No newline at end of file