| 
									
										
										
										
											2020-01-15 21:36:01 +01:00
										 |  |  | import Component from "./component.js"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BasicWidget extends Component { | 
					
						
							| 
									
										
										
										
											2020-03-01 18:57:13 +01:00
										 |  |  |     constructor() { | 
					
						
							|  |  |  |         super(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.attrs = { | 
					
						
							|  |  |  |             style: '' | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         this.classes = []; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     id(id) { | 
					
						
							|  |  |  |         this.attrs.id = id; | 
					
						
							|  |  |  |         return this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class(className) { | 
					
						
							|  |  |  |         this.classes.push(className); | 
					
						
							|  |  |  |         return this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     css(name, value) { | 
					
						
							|  |  |  |         this.attrs.style += `${name}: ${value};`; | 
					
						
							|  |  |  |         return this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     collapsible() { | 
					
						
							|  |  |  |         this.css('min-height', '0'); | 
					
						
							|  |  |  |         return this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-01 19:16:30 +01:00
										 |  |  |     hideInZenMode() { | 
					
						
							|  |  |  |         this.class('hide-in-zen-mode'); | 
					
						
							|  |  |  |         return this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-01 18:57:13 +01:00
										 |  |  |     cssBlock(block) { | 
					
						
							|  |  |  |         this.cssEl = block; | 
					
						
							|  |  |  |         return this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-11 21:19:56 +01:00
										 |  |  |     render() { | 
					
						
							| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  |         const $widget = this.doRender(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 10:50:48 +01:00
										 |  |  |         $widget.addClass('component') | 
					
						
							|  |  |  |             .prop('component', this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 22:17:07 +01:00
										 |  |  |         this.toggleInt(this.isEnabled()); | 
					
						
							| 
									
										
										
										
											2020-02-08 21:54:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-01 18:57:13 +01:00
										 |  |  |         if (this.cssEl) { | 
					
						
							|  |  |  |             const css = this.cssEl.trim().startsWith('<style>') ? this.cssEl : `<style>${this.cssEl}</style>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $widget.append(css); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (const key in this.attrs) { | 
					
						
							|  |  |  |             $widget.attr(key, this.attrs[key]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (const className of this.classes) { | 
					
						
							|  |  |  |             $widget.addClass(className); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  |         return $widget; | 
					
						
							| 
									
										
										
										
											2020-01-11 21:19:56 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-08 21:54:39 +01:00
										 |  |  |     isEnabled() { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-11 21:19:56 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * for overriding | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-01-19 09:02:18 +01:00
										 |  |  |     doRender() {} | 
					
						
							| 
									
										
										
										
											2020-01-11 21:19:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 22:17:07 +01:00
										 |  |  |     toggleInt(show) { | 
					
						
							|  |  |  |         this.$widget.toggleClass('hidden-int', !show); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     toggleExt(show) { | 
					
						
							|  |  |  |         this.$widget.toggleClass('hidden-ext', !show); | 
					
						
							| 
									
										
										
										
											2020-01-14 20:27:40 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-04 22:46:17 +01:00
										 |  |  |     isVisible() { | 
					
						
							|  |  |  |         return this.$widget.is(":visible"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-16 21:16:09 +01:00
										 |  |  |     getPosition() { | 
					
						
							|  |  |  |         return this.position; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-19 21:12:53 +01:00
										 |  |  |     remove() { | 
					
						
							|  |  |  |         if (this.$widget) { | 
					
						
							|  |  |  |             this.$widget.remove(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-11 21:19:56 +01:00
										 |  |  |     cleanup() {} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default BasicWidget; |