2017-08-07 01:01:49 +08:00
|
|
|
|
|
|
|
let componentMapping = {
|
|
|
|
'dropdown': require('./dropdown'),
|
2017-08-07 04:08:03 +08:00
|
|
|
'overlay': require('./overlay'),
|
|
|
|
'back-to-top': require('./back-top-top'),
|
|
|
|
'notification': require('./notification'),
|
|
|
|
'chapter-toggle': require('./chapter-toggle'),
|
|
|
|
'expand-toggle': require('./expand-toggle'),
|
2017-08-07 01:01:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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]);
|
2017-08-10 04:33:00 +08:00
|
|
|
if (typeof elems[j].components === 'undefined') elems[j].components = {};
|
|
|
|
elems[j].components[name] = instance;
|
2017-08-07 01:01:49 +08:00
|
|
|
window.components[name].push(instance);
|
|
|
|
}
|
|
|
|
}
|