| 
									
										
										
										
											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-27 21:31:34 +08:00
										 |  |  |     'entity-selector-popup': require('./entity-selector-popup'), | 
					
						
							|  |  |  |     'entity-selector': require('./entity-selector'), | 
					
						
							| 
									
										
										
										
											2017-08-27 22:16:51 +08:00
										 |  |  |     'sidebar': require('./sidebar'), | 
					
						
							| 
									
										
										
										
											2017-08-28 20:38:32 +08:00
										 |  |  |     'page-picker': require('./page-picker'), | 
					
						
							| 
									
										
										
										
											2017-09-03 23:37:51 +08:00
										 |  |  |     'page-comments': require('./page-comments'), | 
					
						
							| 
									
										
										
										
											2017-09-23 19:24:06 +08:00
										 |  |  |     'wysiwyg-editor': require('./wysiwyg-editor'), | 
					
						
							|  |  |  |     'markdown-editor': require('./markdown-editor'), | 
					
						
							| 
									
										
										
										
											2017-09-25 01:30:21 +08:00
										 |  |  |     'editor-toolbox': require('./editor-toolbox'), | 
					
						
							| 
									
										
										
										
											2017-12-07 01:32:29 +08:00
										 |  |  |     'image-picker': require('./image-picker'), | 
					
						
							| 
									
										
										
										
											2017-12-10 21:46:50 +08:00
										 |  |  |     'collapsible': require('./collapsible'), | 
					
						
							| 
									
										
										
										
											2018-03-18 23:13:46 +08:00
										 |  |  |     'toggle-switch': require('./toggle-switch'), | 
					
						
							| 
									
										
										
										
											2018-04-01 19:46:27 +08:00
										 |  |  |     'page-display': require('./page-display'), | 
					
						
							| 
									
										
										
										
											2017-08-07 01:01:49 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | window.components = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let componentNames = Object.keys(componentMapping); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 22:56:24 +08: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-07 01:01:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 22:56:24 +08:00
										 |  |  |     let component = componentMapping[componentName]; | 
					
						
							|  |  |  |     if (typeof window.components[componentName] === "undefined") window.components[componentName] = []; | 
					
						
							| 
									
										
										
										
											2017-08-07 01:01:49 +08:00
										 |  |  |     for (let j = 0, jLen = elems.length; j < jLen; j++) { | 
					
						
							| 
									
										
										
										
											2017-09-09 22:56:24 +08: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-07 01:01:49 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-09 22:56:24 +08: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-12 00:16:30 +08:00
										 |  |  | window.components.init = initAll; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default initAll; |