#

API Docs for: 3.10.3
Show: Inherited Protected Private Deprecated

# File: tree/js/extensions/tree-node-openable.js

    /**
    @module tree
    @submodule tree-openable
    **/

    /**
    `Tree.Node` extension that adds methods useful for nodes in trees that use the
    `Tree.Openable` extension.

    @class Tree.Node.Openable
    @constructor
    @extensionfor Tree.Node
    **/

    function NodeOpenable() {}

    NodeOpenable.prototype = {
        /**
        Closes this node if it's currently open.

        @method close
        @param {Object} [options] Options.
            @param {Boolean} [options.silent=false] If `true`, the `close` event
                will be suppressed.
            @param {String} [options.src] Source of the change, to be passed along
                to the event facade of the resulting event. This can be used to
                distinguish between changes triggered by a user and changes
                triggered programmatically, for example.
        @chainable
        **/
        close: function (options) {
            this.tree.closeNode(this, options);
            return this;
        },

        /**
        Returns `true` if this node is currently open.

        Note: the root node of a tree is always considered to be open.

        @method isOpen
        @return {Boolean} `true` if this node is currently open, `false` otherwise.
        **/
        isOpen: function () {
            return !!this.state.open || this.isRoot();
        },

        /**
        Opens this node if it's currently closed.

        @method open
        @param {Object} [options] Options.
            @param {Boolean} [options.silent=false] If `true`, the `open` event
                will be suppressed.
            @param {String} [options.src] Source of the change, to be passed along
                to the event facade of the resulting event. This can be used to
                distinguish between changes triggered by a user and changes
                triggered programmatically, for example.
        @chainable
        **/
        open: function (options) {
            this.tree.openNode(this, options);
            return this;
        },

        /**
        Toggles the open/closed state of this node, closing it if it's currently
        open or opening it if it's currently closed.

        @method toggleOpen
        @param {Object} [options] Options.
            @param {Boolean} [options.silent=false] If `true`, events will be
                suppressed.
            @param {String} [options.src] Source of the change, to be passed along
                to the event facade of the resulting event. This can be used to
                distinguish between changes triggered by a user and changes
                triggered programmatically, for example.
        @chainable
        **/
        toggleOpen: function (options) {
            this.tree.toggleOpenNode(this, options);
            return this;
        }
    };

    Y.Tree.Node.Openable = NodeOpenable;