2 let componentMapping = {
3 'dropdown': require('./dropdown'),
4 'overlay': require('./overlay'),
5 'back-to-top': require('./back-top-top'),
6 'notification': require('./notification'),
7 'chapter-toggle': require('./chapter-toggle'),
8 'expand-toggle': require('./expand-toggle'),
9 'entity-selector-popup': require('./entity-selector-popup'),
10 'entity-selector': require('./entity-selector'),
11 'sidebar': require('./sidebar'),
12 'page-picker': require('./page-picker'),
13 'page-comments': require('./page-comments'),
14 'wysiwyg-editor': require('./wysiwyg-editor'),
15 'markdown-editor': require('./markdown-editor'),
16 'editor-toolbox': require('./editor-toolbox'),
17 'image-picker': require('./image-picker'),
18 'collapsible': require('./collapsible'),
21 window.components = {};
23 let componentNames = Object.keys(componentMapping);
26 * Initialize components of the given name within the given element.
27 * @param {String} componentName
28 * @param {HTMLElement|Document} parentElement
30 function initComponent(componentName, parentElement) {
31 let elems = parentElement.querySelectorAll(`[${componentName}]`);
32 if (elems.length === 0) return;
34 let component = componentMapping[componentName];
35 if (typeof window.components[componentName] === "undefined") window.components[componentName] = [];
36 for (let j = 0, jLen = elems.length; j < jLen; j++) {
37 let instance = new component(elems[j]);
38 if (typeof elems[j].components === 'undefined') elems[j].components = {};
39 elems[j].components[componentName] = instance;
40 window.components[componentName].push(instance);
45 * Initialize all components found within the given element.
46 * @param parentElement
48 function initAll(parentElement) {
49 if (typeof parentElement === 'undefined') parentElement = document;
50 for (let i = 0, len = componentNames.length; i < len; i++) {
51 initComponent(componentNames[i], parentElement);
55 window.components.init = initAll;
57 export default initAll;