<!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 = `
&lt;div class="card widget">
    &lt;div class="card-header">
        &lt;div>           
            &lt;button class="btn btn-sm widget-title" data-toggle="collapse" data-target="#[to be set]">
                Collapsible Group Item
            &lt;/button>
            
            &lt;a class="widget-help external no-arrow bx bx-info-circle">&lt;/a>
        &lt;/div>
        
        &lt;div class="widget-header-actions">&lt;/div>
    &lt;/div>

    &lt;div id="[to be set]" class="collapse body-wrapper" style="transition: none; ">
        &lt;div class="card-body">&lt;/div>
    &lt;/div>
&lt;/div>`;

export default class CollapsibleWidget extends TabAwareWidget {
    get widgetTitle() { return "Untitled widget"; }

    get headerActions() { return []; }

    get help() { return {}; }

    doRender() {
        this.$widget = $(WIDGET_TPL);
        this.contentSized();
        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

        // not using constructor name because of webpack mangling class names ...
        this.widgetName = this.widgetTitle.replace(/[^[a-zA-Z0-9]/g, "_");

        if (!options.is(this.widgetName + 'Collapsed')) {
            this.$bodyWrapper.collapse("show");
        }

        // using immediate variants of the event so that the previous collapse is not caught
        this.$bodyWrapper.on('hide.bs.collapse', () => this.saveCollapsed(true));
        this.$bodyWrapper.on('show.bs.collapse', () => this.saveCollapsed(false));

        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');
        this.$headerActions.append(...this.headerActions);

        this.initialized = this.doRenderBody();

        this.decorateWidget();
    }

    saveCollapsed(collapse) {
        options.save(this.widgetName + 'Collapsed', collapse.toString());

        this.triggerEvent(`widgetCollapsedStateChanged`, {widgetName: this.widgetName, collapse});
    }

    /**
     * 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");
    }
}
</code></pre>
        </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>
    Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.6</a>
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>