]> BookStack Code Mirror - bookstack/blob - resources/assets/js/components/index.js
Migrated entity selector out of angular
[bookstack] / resources / assets / js / components / index.js
1
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 };
12
13 window.components = {};
14
15 let componentNames = Object.keys(componentMapping);
16
17 for (let i = 0, len = componentNames.length; i < len; i++) {
18     let name = componentNames[i];
19     let elems = document.querySelectorAll(`[${name}]`);
20     if (elems.length === 0) continue;
21
22     let component = componentMapping[name];
23     if (typeof window.components[name] === "undefined") window.components[name] = [];
24     for (let j = 0, jLen = elems.length; j < jLen; j++) {
25          let instance = new component(elems[j]);
26          if (typeof elems[j].components === 'undefined') elems[j].components = {};
27          elems[j].components[name] = instance;
28          window.components[name].push(instance);
29     }
30 }