Source: components/expand.js

;(function () {
    'use strict';

    /* global sh */
    
    /**
     * Generic components for toggling expand. Targets elements with <code>data-expand</code> attribute, and adds a click listener that toggles the class <code>active</code>. If no element with the class <code>toggle</code> is found inside the target element, the entire target element recives the click listener.
     * @namespace
     */
    sh.libs.expand = (function($){

        /**
         * Add the 'active' class to target element
         * @public
         * @memberof sh.libs.expand
         * @param {external:jQuery|string} id Selector or jQuery element
         */
        function open(el){
            $(el).addClass('active');
            return el;
        }

        /**
         * Remove the 'active' class from target element
         * @public
         * @memberof sh.libs.expand
         * @param {external:jQuery|string} id Selector or jQuery element
         */
        function close(el){
            $(el).removeClass('active');
            return el;
        }

        /**
         * Toggle the 'active' class on target element
         * @public
         * @memberof sh.libs.expand
         * @param {external:jQuery|string} id Selector or jQuery element
         */
        function toggle(el){
            $(el).toggleClass('active');
            return el;
        }

        /**
         * Initialize the component
         * @public
         * @memberof sh.libs.expand
         */
        function init(){
            $('[data-expand]:not(.caption)').each(function(i, el){
                var $toggle = $(el).find('.toggle');
                if(!$toggle.length) $toggle = $(el);
                $toggle.off('click').on('click', function(){
                    event.preventDefault();
                    event.stopPropagation();
                    toggle( $(el) );
                });
            });
        }

        return {
            init: init,
            reflow: function(){},
            toggle: toggle,
            open: open,
            close: close
        };

    })(jQuery);

})();