2018-11-09 16:17:35 -05:00
|
|
|
import dropdown from "./dropdown";
|
|
|
|
import overlay from "./overlay";
|
|
|
|
import backToTop from "./back-to-top";
|
|
|
|
import notification from "./notification";
|
|
|
|
import chapterToggle from "./chapter-toggle";
|
|
|
|
import expandToggle from "./expand-toggle";
|
|
|
|
import entitySelectorPopup from "./entity-selector-popup";
|
|
|
|
import entitySelector from "./entity-selector";
|
|
|
|
import sidebar from "./sidebar";
|
|
|
|
import pagePicker from "./page-picker";
|
|
|
|
import pageComments from "./page-comments";
|
|
|
|
import wysiwygEditor from "./wysiwyg-editor";
|
|
|
|
import markdownEditor from "./markdown-editor";
|
|
|
|
import editorToolbox from "./editor-toolbox";
|
|
|
|
import imagePicker from "./image-picker";
|
|
|
|
import collapsible from "./collapsible";
|
|
|
|
import toggleSwitch from "./toggle-switch";
|
|
|
|
import pageDisplay from "./page-display";
|
|
|
|
import shelfSort from "./shelf-sort";
|
|
|
|
import homepageControl from "./homepage-control";
|
2018-11-11 06:44:35 -05:00
|
|
|
import headerMobileToggle from "./header-mobile-toggle";
|
2018-12-07 13:33:32 -05:00
|
|
|
import listSortControl from "./list-sort-control";
|
2018-12-08 18:34:06 -05:00
|
|
|
import triLayout from "./tri-layout";
|
2019-02-24 10:57:35 -05:00
|
|
|
import breadcrumbListing from "./breadcrumb-listing";
|
2019-04-13 07:07:27 -04:00
|
|
|
import permissionsTable from "./permissions-table";
|
2019-06-04 05:45:44 -04:00
|
|
|
import customCheckbox from "./custom-checkbox";
|
2019-06-06 08:09:58 -04:00
|
|
|
import bookSort from "./book-sort";
|
2019-06-06 09:05:06 -04:00
|
|
|
import settingAppColorPicker from "./setting-app-color-picker";
|
2019-06-23 08:29:58 -04:00
|
|
|
import entityPermissionsEditor from "./entity-permissions-editor";
|
2019-08-11 15:04:43 -04:00
|
|
|
import templateManager from "./template-manager";
|
2019-08-18 08:11:30 -04:00
|
|
|
import newUserPassword from "./new-user-password";
|
2018-11-09 16:17:35 -05:00
|
|
|
|
|
|
|
const componentMapping = {
|
|
|
|
'dropdown': dropdown,
|
|
|
|
'overlay': overlay,
|
|
|
|
'back-to-top': backToTop,
|
|
|
|
'notification': notification,
|
|
|
|
'chapter-toggle': chapterToggle,
|
|
|
|
'expand-toggle': expandToggle,
|
|
|
|
'entity-selector-popup': entitySelectorPopup,
|
|
|
|
'entity-selector': entitySelector,
|
|
|
|
'sidebar': sidebar,
|
|
|
|
'page-picker': pagePicker,
|
|
|
|
'page-comments': pageComments,
|
|
|
|
'wysiwyg-editor': wysiwygEditor,
|
|
|
|
'markdown-editor': markdownEditor,
|
|
|
|
'editor-toolbox': editorToolbox,
|
|
|
|
'image-picker': imagePicker,
|
|
|
|
'collapsible': collapsible,
|
|
|
|
'toggle-switch': toggleSwitch,
|
|
|
|
'page-display': pageDisplay,
|
|
|
|
'shelf-sort': shelfSort,
|
|
|
|
'homepage-control': homepageControl,
|
2018-12-07 13:33:32 -05:00
|
|
|
'header-mobile-toggle': headerMobileToggle,
|
|
|
|
'list-sort-control': listSortControl,
|
2018-12-08 18:34:06 -05:00
|
|
|
'tri-layout': triLayout,
|
2019-02-24 10:57:35 -05:00
|
|
|
'breadcrumb-listing': breadcrumbListing,
|
2019-04-13 07:07:27 -04:00
|
|
|
'permissions-table': permissionsTable,
|
2019-06-04 05:45:44 -04:00
|
|
|
'custom-checkbox': customCheckbox,
|
2019-06-06 08:09:58 -04:00
|
|
|
'book-sort': bookSort,
|
2019-06-06 09:05:06 -04:00
|
|
|
'setting-app-color-picker': settingAppColorPicker,
|
2019-08-11 15:04:43 -04:00
|
|
|
'entity-permissions-editor': entityPermissionsEditor,
|
|
|
|
'template-manager': templateManager,
|
2019-08-18 08:11:30 -04:00
|
|
|
'new-user-password': newUserPassword,
|
2017-08-06 13:01:49 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
window.components = {};
|
|
|
|
|
2018-11-09 16:17:35 -05:00
|
|
|
const componentNames = Object.keys(componentMapping);
|
2017-08-06 13:01:49 -04:00
|
|
|
|
2017-09-09 10:56:24 -04:00
|
|
|
/**
|
|
|
|
* 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;
|
2017-08-06 13:01:49 -04:00
|
|
|
|
2017-09-09 10:56:24 -04:00
|
|
|
let component = componentMapping[componentName];
|
|
|
|
if (typeof window.components[componentName] === "undefined") window.components[componentName] = [];
|
2017-08-06 13:01:49 -04:00
|
|
|
for (let j = 0, jLen = elems.length; j < jLen; j++) {
|
2017-09-09 10:56:24 -04:00
|
|
|
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);
|
2017-08-06 13:01:49 -04:00
|
|
|
}
|
2017-09-09 10:56:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-11 12:16:30 -04:00
|
|
|
window.components.init = initAll;
|
|
|
|
|
2018-11-11 06:44:35 -05:00
|
|
|
export default initAll;
|