mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-23 07:10:00 +08:00
Added comment reply and delete confirmation.
Also fixed local_id bug Added component helpers Added global scroll & Highlight helpers
This commit is contained in:
@ -16,18 +16,36 @@ let componentMapping = {
|
||||
window.components = {};
|
||||
|
||||
let componentNames = Object.keys(componentMapping);
|
||||
initAll();
|
||||
|
||||
for (let i = 0, len = componentNames.length; i < len; i++) {
|
||||
let name = componentNames[i];
|
||||
let elems = document.querySelectorAll(`[${name}]`);
|
||||
if (elems.length === 0) continue;
|
||||
/**
|
||||
* Initialize components of the given name within the given element.
|
||||
* @param {String} componentName
|
||||
* @param {HTMLElement|Document} parentElement
|
||||
*/
|
||||
function initComponent(componentName, parentElement) {
|
||||
let elems = parentElement.querySelectorAll(`[${componentName}]`);
|
||||
if (elems.length === 0) return;
|
||||
|
||||
let component = componentMapping[name];
|
||||
if (typeof window.components[name] === "undefined") window.components[name] = [];
|
||||
let component = componentMapping[componentName];
|
||||
if (typeof window.components[componentName] === "undefined") window.components[componentName] = [];
|
||||
for (let j = 0, jLen = elems.length; j < jLen; j++) {
|
||||
let instance = new component(elems[j]);
|
||||
if (typeof elems[j].components === 'undefined') elems[j].components = {};
|
||||
elems[j].components[name] = instance;
|
||||
window.components[name].push(instance);
|
||||
let instance = new component(elems[j]);
|
||||
if (typeof elems[j].components === 'undefined') elems[j].components = {};
|
||||
elems[j].components[componentName] = instance;
|
||||
window.components[componentName].push(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all components found within the given element.
|
||||
* @param parentElement
|
||||
*/
|
||||
function initAll(parentElement) {
|
||||
if (typeof parentElement === 'undefined') parentElement = document;
|
||||
for (let i = 0, len = componentNames.length; i < len; i++) {
|
||||
initComponent(componentNames[i], parentElement);
|
||||
}
|
||||
}
|
||||
|
||||
window.components.init = initAll;
|
Reference in New Issue
Block a user