| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  | <!DOCTYPE html> | 
					
						
							|  |  |  | <html lang="en"> | 
					
						
							|  |  |  | <head> | 
					
						
							|  |  |  |     <meta charset="utf-8"> | 
					
						
							|  |  |  |     <title>JSDoc: Source: widgets/collapsible_widget.js</title> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <script src="scripts/prettify/prettify.js"> </script> | 
					
						
							|  |  |  |     <script src="scripts/prettify/lang-css.js"> </script> | 
					
						
							|  |  |  |     <!--[if lt IE 9]>
 | 
					
						
							|  |  |  |       <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> | 
					
						
							|  |  |  |     <![endif]--> | 
					
						
							|  |  |  |     <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> | 
					
						
							|  |  |  |     <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> | 
					
						
							|  |  |  | </head> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <body> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <div id="main"> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <h1 class="page-title">Source: widgets/collapsible_widget.js</h1> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     <section> | 
					
						
							|  |  |  |         <article> | 
					
						
							|  |  |  |             <pre class="prettyprint source linenums"><code>import TabAwareWidget from "./tab_aware_widget.js"; | 
					
						
							|  |  |  | import options from "../services/options.js"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const WIDGET_TPL = ` | 
					
						
							|  |  |  | <div class="card widget"> | 
					
						
							| 
									
										
										
										
											2021-02-17 23:55:51 +01:00
										 |  |  |     <div class="card-header">     | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  |         <div>            | 
					
						
							| 
									
										
										
										
											2021-02-17 23:55:51 +01:00
										 |  |  |             <a class="widget-toggle-button no-arrow"  | 
					
						
							|  |  |  |                 title="Minimize/maximize widget" | 
					
						
							|  |  |  |                 data-toggle="collapse" data-target="#[to be set]"> | 
					
						
							|  |  |  |                  | 
					
						
							|  |  |  |                 <span class="widget-toggle-icon bx"></span> | 
					
						
							|  |  |  |                  | 
					
						
							|  |  |  |                 <span class="widget-title"> | 
					
						
							|  |  |  |                     Collapsible Group Item | 
					
						
							|  |  |  |                 </span>     | 
					
						
							|  |  |  |             </a> | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |             <span class="widget-header-actions"></span> | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  |         </div> | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2021-02-17 23:55:51 +01:00
										 |  |  |         <div> | 
					
						
							|  |  |  |             <a class="widget-help external no-arrow bx bx-info-circle"></a> | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  |     </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <div id="[to be set]" class="collapse body-wrapper" style="transition: none; "> | 
					
						
							|  |  |  |         <div class="card-body"></div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  | </div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default class CollapsibleWidget extends TabAwareWidget { | 
					
						
							|  |  |  |     get widgetTitle() { return "Untitled widget"; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get headerActions() { return []; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get help() { return {}; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     doRender() { | 
					
						
							|  |  |  |         this.$widget = $(WIDGET_TPL); | 
					
						
							| 
									
										
										
										
											2020-09-30 22:48:30 +02:00
										 |  |  |         this.contentSized(); | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  |         this.$widget.find('[data-target]').attr('data-target', "#" + this.componentId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$bodyWrapper = this.$widget.find('.body-wrapper'); | 
					
						
							|  |  |  |         this.$bodyWrapper.attr('id', this.componentId); // for toggle to work we need id | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-30 22:48:30 +02:00
										 |  |  |         // not using constructor name because of webpack mangling class names ... | 
					
						
							|  |  |  |         this.widgetName = this.widgetTitle.replace(/[^[a-zA-Z0-9]/g, "_"); | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 23:55:51 +01:00
										 |  |  |         this.$toggleButton = this.$widget.find('.widget-toggle-button'); | 
					
						
							|  |  |  |         this.$toggleIcon = this.$widget.find('.widget-toggle-icon'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const collapsed = options.is(this.widgetName + 'Collapsed'); | 
					
						
							|  |  |  |         if (!collapsed) { | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  |             this.$bodyWrapper.collapse("show"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 23:55:51 +01:00
										 |  |  |         this.updateToggleIcon(collapsed); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  |         // using immediate variants of the event so that the previous collapse is not caught | 
					
						
							| 
									
										
										
										
											2021-02-17 23:55:51 +01:00
										 |  |  |         this.$bodyWrapper.on('hide.bs.collapse', () => this.toggleCollapsed(true)); | 
					
						
							|  |  |  |         this.$bodyWrapper.on('show.bs.collapse', () => this.toggleCollapsed(false)); | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.$body = this.$bodyWrapper.find('.card-body'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$title = this.$widget.find('.widget-title'); | 
					
						
							|  |  |  |         this.$title.text(this.widgetTitle); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$help = this.$widget.find('.widget-help'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (this.help.title) { | 
					
						
							|  |  |  |             this.$help.attr("title", this.help.title); | 
					
						
							|  |  |  |             this.$help.attr("href", this.help.url || "javascript:"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (!this.help.url) { | 
					
						
							|  |  |  |                 this.$help.addClass('no-link'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             this.$help.hide(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$headerActions = this.$widget.find('.widget-header-actions'); | 
					
						
							| 
									
										
										
										
											2021-02-17 23:55:51 +01:00
										 |  |  |         this.$headerActions.append(this.headerActions); | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.initialized = this.doRenderBody(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.decorateWidget(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 23:55:51 +01:00
										 |  |  |     toggleCollapsed(collapse) { | 
					
						
							|  |  |  |         this.updateToggleIcon(collapse); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  |         options.save(this.widgetName + 'Collapsed', collapse.toString()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.triggerEvent(`widgetCollapsedStateChanged`, {widgetName: this.widgetName, collapse}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 23:55:51 +01:00
										 |  |  |     updateToggleIcon(collapse) { | 
					
						
							|  |  |  |         if (collapse) { | 
					
						
							|  |  |  |             this.$toggleIcon | 
					
						
							|  |  |  |                 .addClass("bx-chevron-right") | 
					
						
							|  |  |  |                 .removeClass("bx-chevron-down") | 
					
						
							|  |  |  |                 .attr("title", "Show"); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             this.$toggleIcon | 
					
						
							|  |  |  |                 .addClass("bx-chevron-down") | 
					
						
							|  |  |  |                 .removeClass("bx-chevron-right") | 
					
						
							|  |  |  |                 .attr("title", "Hide"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * This event is used to synchronize collapsed state of all the tab-cached widgets since they are all rendered | 
					
						
							|  |  |  |      * separately but should behave uniformly for the user. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     widgetCollapsedStateChangedEvent({widgetName, collapse}) { | 
					
						
							|  |  |  |         if (widgetName === this.widgetName) { | 
					
						
							|  |  |  |             this.$bodyWrapper.toggleClass('show', !collapse); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** for overriding */ | 
					
						
							|  |  |  |     decorateWidget() {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** for overriding */ | 
					
						
							|  |  |  |     async doRenderBody() {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     isExpanded() { | 
					
						
							|  |  |  |         return this.$bodyWrapper.hasClass("show"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-30 22:48:30 +02:00
										 |  |  | } | 
					
						
							|  |  |  | </code></pre> | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  |         </article> | 
					
						
							|  |  |  |     </section> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <nav> | 
					
						
							|  |  |  |     <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Branch.html">Branch</a></li><li><a href="FrontendScriptApi.html">FrontendScriptApi</a></li><li><a href="NoteComplement.html">NoteComplement</a></li><li><a href="NoteShort.html">NoteShort</a></li></ul><h3>Global</h3><ul><li><a href="global.html#decorateWidget">decorateWidget</a></li><li><a href="global.html#doRenderBody">doRenderBody</a></li><li><a href="global.html#widgetCollapsedStateChangedEvent">widgetCollapsedStateChangedEvent</a></li></ul> | 
					
						
							|  |  |  | </nav> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <br class="clear"> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <footer> | 
					
						
							| 
									
										
										
										
											2020-09-30 22:48:30 +02:00
										 |  |  |     Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.6</a> | 
					
						
							| 
									
										
										
										
											2020-04-21 23:14:55 +02:00
										 |  |  | </footer> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script> prettyPrint(); </script> | 
					
						
							|  |  |  | <script src="scripts/linenumber.js"> </script> | 
					
						
							|  |  |  | </body> | 
					
						
							|  |  |  | </html> |