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'),
19 'toggle-switch': require('./toggle-switch'),
20 'page-display': require('./page-display'),
21 'shelf-sort': require('./shelf-sort'),
22 'homepage-control': require('./homepage-control'),
25 window.components = {};
27 let componentNames = Object.keys(componentMapping);
30 * Initialize components of the given name within the given element.
31 * @param {String} componentName
32 * @param {HTMLElement|Document} parentElement
34 function initComponent(componentName, parentElement) {
35 let elems = parentElement.querySelectorAll(`[${componentName}]`);
36 if (elems.length === 0) return;
38 let component = componentMapping[componentName];
39 if (typeof window.components[componentName] === "undefined") window.components[componentName] = [];
40 for (let j = 0, jLen = elems.length; j < jLen; j++) {
41 let instance = new component(elems[j]);
42 if (typeof elems[j].components === 'undefined') elems[j].components = {};
43 elems[j].components[componentName] = instance;
44 window.components[componentName].push(instance);
49 * Initialize all components found within the given element.
50 * @param parentElement
52 function initAll(parentElement) {
53 if (typeof parentElement === 'undefined') parentElement = document;
54 for (let i = 0, len = componentNames.length; i < len; i++) {
55 initComponent(componentNames[i], parentElement);
59 window.components.init = initAll;
61 export default initAll;