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);
27 * Initialize components of the given name within the given element.
28 * @param {String} componentName
29 * @param {HTMLElement|Document} parentElement
31 function initComponent(componentName, parentElement) {
32 let elems = parentElement.querySelectorAll(`[${componentName}]`);
33 if (elems.length === 0) return;
35 let component = componentMapping[componentName];
36 if (typeof window.components[componentName] === "undefined") window.components[componentName] = [];
37 for (let j = 0, jLen = elems.length; j < jLen; j++) {
38 let instance = new component(elems[j]);
39 if (typeof elems[j].components === 'undefined') elems[j].components = {};
40 elems[j].components[componentName] = instance;
41 window.components[componentName].push(instance);
46 * Initialize all components found within the given element.
47 * @param parentElement
49 function initAll(parentElement) {
50 if (typeof parentElement === 'undefined') parentElement = document;
51 for (let i = 0, len = componentNames.length; i < len; i++) {
52 initComponent(componentNames[i], parentElement);
56 window.components.init = initAll;