Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsTree: changing the "open" icon for folders using the "types" plugin

It's easy to specify what the icon should be for a closed folder using the "types" plugin. But can the types plugin also be used to specify what an open folder should look like, or can I only do this with CSS (like below) ?

li.jstree-open > a .jstree-icon 
{
    background:url("folder_open.png") 0px 0px no-repeat !important;
} 
like image 578
Captain Sensible Avatar asked Nov 21 '11 15:11

Captain Sensible


2 Answers

A possible solution is to have two types - one for an open folder, and one for a closed folder. Changing the node type is easy.

From another answer of mine:

<div id="jstree_menu"></div>
<script>
/* Load menu tree data */
$('#jstree_menu').jstree(
    {
        'core' : {
            'data' : {
                'url' : '/jstree-menu-data/index.html',
            }
        },
        'plugins' : [ "types" ],
        'types' : {
            'default' : {
                'icon' : 'fa fa-angle-right fa-fw'
            },
            'f-open' : {
                'icon' : 'fa fa-folder-open fa-fw'
            },
            'f-closed' : {
                'icon' : 'fa fa-folder fa-fw'
            }
        }
    }
);

/* Toggle between folder open and folder closed */
$("#jstree_menu").on('open_node.jstree', function (event, data) {
    data.instance.set_type(data.node,'f-open');
});
$("#jstree_menu").on('close_node.jstree', function (event, data) {
    data.instance.set_type(data.node,'f-closed');
});
</script>
like image 87
Li-aung Yip Avatar answered Oct 12 '22 15:10

Li-aung Yip


@Seventh element:

Your code in the question itself is the answer.It works pretty fine. For open node use

li.jstree-open > a .jstree-icon { background:url("/images/favorites.png") 0px 0px no-repeat !important; }

For closed nodes use

li.jstree-closed > a .jstree-icon { background:url("/images/favorites.png") 0px 0px no-repeat !important; }

Cheers

like image 31
jeev Avatar answered Oct 12 '22 14:10

jeev