mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-23 07:10:00 +08:00
Added vanilla JS component system
This commit is contained in:
21
resources/assets/js/components/index.js
Normal file
21
resources/assets/js/components/index.js
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
let componentMapping = {
|
||||
'dropdown': require('./dropdown'),
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
let component = componentMapping[name];
|
||||
if (typeof window.components[name] === "undefined") window.components[name] = [];
|
||||
for (let j = 0, jLen = elems.length; j < jLen; j++) {
|
||||
let instance = new component(elems[j]);
|
||||
window.components[name].push(instance);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user