jstree.core.js

The only required part of jstree it consists of a few functions bound to the $.jstree object, the actual plugin function and a few core functions for manipulating a tree.

Summary
jstree.core.jsThe only required part of jstree it consists of a few functions bound to the $.jstree object, the actual plugin function and a few core functions for manipulating a tree.
$.jstree.Some static functions and variables, unless you know exactly what you are doing do not use these, but $().jstree instead.
$.jstreeobject Contains all static functions and variables used by jstree, some plugins also append variables.
$.jstree.VERSIONstring the version of jstree
$.jstree.IS_IE6boolean indicating if the client is running Internet Explorer 6
$.jstree.IS_IE7boolean indicating if the client is running Internet Explorer 7
$.jstree.IS_FF2boolean indicating if the client is running Firefox 2
$.jstree.__constructCreates a new jstree instance, any arguments after the first one are merged and used to configure the tree.
$.jstree.
$.jstree.__destructDestroys an instance, and also clears `jstree-` prefixed classes and all events in the `jstree` namespace
$.jstree.__callCall a function on the instance and return the result
$.jstree._referenceReturns an instance
$.jstree._focusedReturns the currently focused instance (by default once an instance is created it is focused)
$.jstree._focusMake an instance focused (which defocuses the previously focused instance)
$.jstree.pluginRegister a plugin
$.jstree.defaultsobject storing all the default configuration options for every plugin and the core.
$().jstree()The actual plugin wrapper, use this to create instances or execute functions on created instances.
$().jstreeCreates an instance using the specified objects for containers, or executes a command on an instance, specified by a container.
$.jstree.
$.jstree.SCROLLBAR_WIDTHinteger indicating the width of the client scrollbar
jstree
dataobject Provides storage for plugins (aside from private variables).
get_indexReturns an integer, which is the instance’s index.
get_containerReturns the jQuery extended container of the tree (the element you used when constructing the tree).
get_container_ulReturns the jQuery extended first UL node inside the container of the tree.
get_settingsReturns the settings for the tree.
__triggerUsed internally to trigger events on the container node.
CORE options
config.core.stringsmixed used to store all localization strings.
CORE functions
_get_stringUsed to get the common string in the tree.
initUsed internally.
__loadedThis event is triggered in the jstree namespace when data is first rendered in the tree.
__readyThis event is triggered in the jstree namespace when all initial loading is done.
lockUsed to lock the tree.
lockThis event is triggered in the jstree namespace when the tree is locked.
unlockUsed to unlock the tree.
unlockThis event is triggered in the jstree namespace when the tree is unlocked.
is_lockedUsed to get the locked status of the tree.
get_nodeGet a hold of the LI node (which represents the jstree node).
get_nextGet the next sibling of a node
get_prevGet the previous sibling of a node
get_parentGet the parent of a node
get_childrenGet all the children of a node
is_parentCheck if a node is a parent.
is_loadedCheck if a node is loaded.
is_loadingCheck if a node is currently loading.
is_openCheck if a node is currently open.
is_closedCheck if a node is currently closed.
is_leafCheck if a node is a leaf node (has no children).
load_nodeLoad the children of a node.
load_nodeThis event is triggered in the jstree namespace when a node is loaded (succesfully or not).
_load_nodeLoad the children of a node, but as opposed to load_node does not change any visual properties or trigger events.
open_nodeOpen a node so that its children are visible.
open_nodeThis event is triggered in the jstree namespace when a node is successfully opened (but if animation is used this event is triggered BEFORE the animation completes).
__after_openThis event is triggered in the jstree namespace when a node is successfully opened AFTER the animation completes).
close_nodeClose a node so that its children are not visible.
close_nodeThis event is triggered in the jstree namespace when a node is closed (but if animation is used this event is triggered BEFORE the animation completes).
__after_closeThis event is triggered in the jstree namespace when a node is closed AFTER the animation completes).
toggle_node
open_allOpen all nodes from a certain node down.
open_allThis event is triggered in the jstree namespace when an open_all call completes.
close_allClose all nodes from a certain node down.
close_allThis event is triggered in the jstree namespace when a close_all call completes.
clean_nodeThis function converts inserted nodes to the required by jsTree format.
correct_nodeThis function corrects the open/closed/leaf state as data changes (as the user interacts with the tree).
scroll_to_nodeThis function scrolls the container to the desired node (if needed).
get_stateThis function returns the current state of the tree (as collected from all active plugins).
set_stateThis function returns sets the state of the tree.
set_stateThis event is triggered in the jstree namespace when a set_state call completes.
refreshThis function saves the current state, reloads the complete tree and returns it to the saved state.
refreshThis event is triggered in the jstree namespace when a refresh call completes.
get_textThis function returns the title of the node.
set_textThis function sets the title of the node.
set_textThis event is triggered in the jstree namespace when a set_text call completes.
parse_jsonThis function returns a jQuery node after parsing a JSON object (a LI node for single elements or an UL node for multiple).
get_jsonThis function returns the whole tree (or a single node) in JSON format.
create_nodeThis function creates a new node.
create_nodeThis event is triggered in the jstree namespace when a new node is created.
rename_nodeThis function renames a new node.
rename_nodeThis event is triggered in the jstree namespace when a node is renamed.
delete_nodeThis function deletes a node.
delete_nodeThis event is triggered in the jstree namespace when a node is deleted.
checkThis function checks if a structure modification is valid.
move_nodeThis function moves a node.
move_nodeThis event is triggered in the jstree namespace when a node is moved.
copy_nodeThis function copies a node.
copy_nodeThis event is triggered in the jstree namespace when a node is copied.

$.jstree.

Some static functions and variables, unless you know exactly what you are doing do not use these, but $().jstree instead.

$.jstree

$.jstree

object Contains all static functions and variables used by jstree, some plugins also append variables.

$.jstree.VERSION

string the version of jstree

$.jstree.IS_IE6

boolean indicating if the client is running Internet Explorer 6

$.jstree.IS_IE7

boolean indicating if the client is running Internet Explorer 7

$.jstree.IS_FF2

boolean indicating if the client is running Firefox 2

$.jstree.__construct

Creates a new jstree instance, any arguments after the first one are merged and used to configure the tree.

`.data(“jstree”)` is also called on the container and is used for configuration (keep in mind you can specify this data using a “data-jstree” attribute)

Parameters

containermixed the container of the tree (this should not be the UL node, but a wrapper) - DOM node, jQuery object or selector

$.jstree.

$.jstree.__destruct

Destroys an instance, and also clears `jstree-` prefixed classes and all events in the `jstree` namespace

Parameters

instancemixed the instance to destroy (this argument is passed to $.jstree._reference to get the instance)

See also

$.jstree._reference

$.jstree.__call

Call a function on the instance and return the result

Parameters

instancemixed the instance to destroy (this argument is passed to $.jstree._reference to get the instance)
operationstring the operation to execute
argsarray the arguments to pass to the function

See also

$.jstree._reference

$.jstree._reference

Returns an instance

Parameters

needlemixed - integer, DOM node contained inside a jstree container, ID string, jQuery object, selector

$.jstree._focused

Returns the currently focused instance (by default once an instance is created it is focused)

$.jstree._focus

Make an instance focused (which defocuses the previously focused instance)

Parameters

instancemixed the instance to focus (this argument is passed to $.jstree._reference to get the instance)

See also

$.jstree._reference

$.jstree.plugin

Register a plugin

Parameters

plugin_namestring the name of the new plugin (it will be used as a key in an object - make sure it is valid)
plugin_dataobject consists of 4 keys.  Default is:
{
   __construct : $.noop,   // this function will be executed when a new instance is created
   __destuct   : $.noop,   // this function will be executed when an instance is destroyed
   _fn         : { },      // each key of this object should be a function that will extend the jstree prototype
   defaults    : false     // the default configuration for the plugin (if any)
}

$.jstree.defaults

object storing all the default configuration options for every plugin and the core.  If this is modified all instances created after the modification, which do not explicitly specify some other value will use the new default.

Example

// this instance will use the _default_ theme
$("#div0").jstree({ plugins : ["themes"] });
$.jstree.defaults.themes.theme = "classic";
// this instance will use the _classic_ theme
$("#div1").jstree({ plugins : ["themes"] });
// this instance will use the _apple_ theme
$("#div2").jstree({ themes : { "theme" : "apple" }, plugins : ["themes"] });

$().jstree()

The actual plugin wrapper, use this to create instances or execute functions on created instances.

$().jstree

$.fn.jstree = function (settings)

Creates an instance using the specified objects for containers, or executes a command on an instance, specified by a container.

Parameters

settingsmixed
  • if you pass an object a new instance will be created (using $.jstree.__construct) for each of the objects in the jquery collection, if an instance already exists on the container it will be destroyed first
  • if you pass a string it will be executed using $.jstree.__call on each instance

Examples

// this creates an instance
$("#some-id").jstree({
  plugins : [ "html_data", "themes", "ui" ]
});

// this executes a function on the instance
$("#some-id").jstree("select_node", "#the-id-to-select");

See also

$.jstree.__construct, $.jstree.__destruct, $.jstree.__call

$.jstree.

$.jstree.SCROLLBAR_WIDTH

$.jstree.SCROLLBAR_WIDTH

integer indicating the width of the client scrollbar

jstree

Summary
dataobject Provides storage for plugins (aside from private variables).
get_indexReturns an integer, which is the instance’s index.
get_containerReturns the jQuery extended container of the tree (the element you used when constructing the tree).
get_container_ulReturns the jQuery extended first UL node inside the container of the tree.
get_settingsReturns the settings for the tree.
__triggerUsed internally to trigger events on the container node.
CORE options
config.core.stringsmixed used to store all localization strings.
CORE functions
_get_stringUsed to get the common string in the tree.
initUsed internally.
__loadedThis event is triggered in the jstree namespace when data is first rendered in the tree.
__readyThis event is triggered in the jstree namespace when all initial loading is done.
lockUsed to lock the tree.
lockThis event is triggered in the jstree namespace when the tree is locked.
unlockUsed to unlock the tree.
unlockThis event is triggered in the jstree namespace when the tree is unlocked.
is_lockedUsed to get the locked status of the tree.
get_nodeGet a hold of the LI node (which represents the jstree node).
get_nextGet the next sibling of a node
get_prevGet the previous sibling of a node
get_parentGet the parent of a node
get_childrenGet all the children of a node
is_parentCheck if a node is a parent.
is_loadedCheck if a node is loaded.
is_loadingCheck if a node is currently loading.
is_openCheck if a node is currently open.
is_closedCheck if a node is currently closed.
is_leafCheck if a node is a leaf node (has no children).
load_nodeLoad the children of a node.
load_nodeThis event is triggered in the jstree namespace when a node is loaded (succesfully or not).
_load_nodeLoad the children of a node, but as opposed to load_node does not change any visual properties or trigger events.
open_nodeOpen a node so that its children are visible.
open_nodeThis event is triggered in the jstree namespace when a node is successfully opened (but if animation is used this event is triggered BEFORE the animation completes).
__after_openThis event is triggered in the jstree namespace when a node is successfully opened AFTER the animation completes).
close_nodeClose a node so that its children are not visible.
close_nodeThis event is triggered in the jstree namespace when a node is closed (but if animation is used this event is triggered BEFORE the animation completes).
__after_closeThis event is triggered in the jstree namespace when a node is closed AFTER the animation completes).
toggle_node
open_allOpen all nodes from a certain node down.
open_allThis event is triggered in the jstree namespace when an open_all call completes.
close_allClose all nodes from a certain node down.
close_allThis event is triggered in the jstree namespace when a close_all call completes.
clean_nodeThis function converts inserted nodes to the required by jsTree format.
correct_nodeThis function corrects the open/closed/leaf state as data changes (as the user interacts with the tree).
scroll_to_nodeThis function scrolls the container to the desired node (if needed).
get_stateThis function returns the current state of the tree (as collected from all active plugins).
set_stateThis function returns sets the state of the tree.
set_stateThis event is triggered in the jstree namespace when a set_state call completes.
refreshThis function saves the current state, reloads the complete tree and returns it to the saved state.
refreshThis event is triggered in the jstree namespace when a refresh call completes.
get_textThis function returns the title of the node.
set_textThis function sets the title of the node.
set_textThis event is triggered in the jstree namespace when a set_text call completes.
parse_jsonThis function returns a jQuery node after parsing a JSON object (a LI node for single elements or an UL node for multiple).
get_jsonThis function returns the whole tree (or a single node) in JSON format.
create_nodeThis function creates a new node.
create_nodeThis event is triggered in the jstree namespace when a new node is created.
rename_nodeThis function renames a new node.
rename_nodeThis event is triggered in the jstree namespace when a node is renamed.
delete_nodeThis function deletes a node.
delete_nodeThis event is triggered in the jstree namespace when a node is deleted.
checkThis function checks if a structure modification is valid.
move_nodeThis function moves a node.
move_nodeThis event is triggered in the jstree namespace when a node is moved.
copy_nodeThis function copies a node.
copy_nodeThis event is triggered in the jstree namespace when a node is copied.

data

object Provides storage for plugins (aside from private variables).  Every plugin has an key in this object.

this.data.<plugin_name>;

This is useful for detecting if some plugin is included in the instance (plugins also use this for dependencies and enhancements).

get_index

Returns an integer, which is the instance’s index.  Every instance on the page has an unique index, when destroying an intance the index will not be reused.

get_container

Returns the jQuery extended container of the tree (the element you used when constructing the tree).

get_container_ul

Returns the jQuery extended first UL node inside the container of the tree.

get_settings

Returns the settings for the tree.

Parameters

writableboolean whether to return a copy of the settings object or a reference to it.

Example

$("#div1").jstree("get_settings"); // will return a copy
$.jstree._reference("#div1").get_settings(); // same as above
$.jstree._focused().get_settings(true); // a reference. BE CAREFUL!

__trigger

Used internally to trigger events on the container node.

Parameters

event_namethe name of the event to trigger (the jstree namespace will be appended to it)
datathe additional object to pass along with the event.  By default data.inst will be the current instance, so when you bind to the event, you can access the instance easily.
$("div").bind("some-event.jstree", function (e, data) { data.inst.some_function(); });

CORE options

config.core.strings

mixed used to store all localization strings.  Default is false.

Example 1

$("div").jstree({
   core : {
       strings : function (s) {
           if(s === "Loading ...") { s = "Please wait ..."; }
           return s;
       }
   }
});

Example 2

$("div").jstree({
   core : {
       strings : {
           "Loading ..." : "Please wait ..."
       }
   }
});

See also

_get_string

CORE functions

_get_string

_get_string : function (s)

Used to get the common string in the tree.

If config.core.strings is set to a function, that function is called with a single parameter (the needed string), the response is returned.

If config.core.strings is set to an object, the key named as the needed string is returned.

If config.core.strings is not set, the the needed string is returned.

Parameters

needed_stringstring the needed string

init

Used internally.  This function is called once the core plugin is constructed.

Triggers

__loaded

__loaded

This event is triggered in the jstree namespace when data is first rendered in the tree.  It won’t be triggered after a refresh.  Fires only once.

Parameters

data.instthe instance

Example

$("div").bind("__loaded.jstree", function (e, data) { data.inst.do_something(); });

__ready

This event is triggered in the jstree namespace when all initial loading is done.  It won’t be triggered after a refresh.  Fires only once.

Parameters

data.instthe instance

lock

Used to lock the tree.  When the tree is in a locked state, no functions can be called on the instance (except is_locked and unlock).  Additionally a jstree-locked class is applied on the container.

Triggers

lock

lock

This event is triggered in the jstree namespace when the tree is locked.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else).
data.rsltnull

Example

$("div").bind("lock.jstree", function (e, data) { data.inst.do_something(); });

unlock

Used to unlock the tree.  Instance can be used normally again.  The jstree-locked class is removed from the container.

Triggers

unlock

unlock

This event is triggered in the jstree namespace when the tree is unlocked.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else).
data.rsltnull

Example

$("div").bind("unlock.jstree", function (e, data) { data.inst.do_something(); });

is_locked

is_locked : function ()

Used to get the locked status of the tree.

Returns

lockedboolean true if tree is locked, false otherwise

get_node

get_node : function (obj)

Get a hold of the LI node (which represents the jstree node).

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.

Returns

jquery collectionnode was found, the collection contains the LI node
-1the tree container was referenced
falseon failure (obj is not part of a tree, or does not exists in the DOM)

get_next

get_next : function (obj,
strict)

Get the next sibling of a node

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.
strictboolean if set to true jstree will only return immediate siblings, otherwise, if obj is the last child of its parent, the parent’s next sibling is returned.

Returns

jquery collectionnode was found, the collection contains the LI node
-1the tree container was referenced
falsenode was not found, or failure (obj is not part of a tree, or does not exists in the DOM)

get_prev

get_prev : function (obj,
strict)

Get the previous sibling of a node

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.
strictboolean if set to true jstree will only return immediate siblings, otherwise, if obj is the first child of its parent, the parent’s previous sibling is returned.

Returns

jquery collectionnode was found, the collection contains the LI node
-1the tree container was referenced
falsenode was not found, or failure (obj is not part of a tree, or does not exists in the DOM)

get_parent

get_parent : function (obj)

Get the parent of a node

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.

Returns

jquery collectionnode was found, the collection contains the LI node
-1when obj was a root node
falseon failure (obj is not part of a tree, or does not exists in the DOM)

get_children

get_children : function (obj)

Get all the children of a node

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.  If -1 is used all root nodes are returned.

Returns

jquery collectionnode was found, the collection contains the LI nodes of all immediate children
falseon failure (obj is not part of a tree, or does not exists in the DOM)

is_parent

is_parent : function (obj)

Check if a node is a parent.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.

Returns

trueobj has children or is closed (will be loaded)
falseobj is not a valid node or has no children (leaf node)

is_loaded

is_loaded : function (obj)

Check if a node is loaded.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.

Returns

trueobj has children or is leaf
falseobj is currently loading or is not a leaf, but has no children

is_loading

is_loading : function (obj)

Check if a node is currently loading.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.

Returns

trueobj is currently loading
falseobj is not currently loading

is_open

is_open : function (obj)

Check if a node is currently open.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.

Returns

trueobj is currently open
falseobj is not currently open

is_closed

is_closed : function (obj)

Check if a node is currently closed.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.

Returns

trueobj is currently closed
falseobj is not currently closed

is_leaf

is_leaf : function (obj)

Check if a node is a leaf node (has no children).

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.

Returns

trueobj is a leaf node
falseobj is not a leaf node

load_node

Load the children of a node.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.  Use -1 to load the root nodes.
callbacka function to be executed in the tree’s scope.  Receives two arguments: obj (the same node used to call load_node), status (a boolean indicating if the node was loaded successfully.

Returns

trueobj is a valid node and will try loading it
falseobj is not a valid node

Triggers

load_node

See also

_load_node

load_node

This event is triggered in the jstree namespace when a node is loaded (succesfully or not).

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else).
data.rsltobject which contains two keys obj (the loaded node) and status - whether the node was loaded successfully.

Example

$("div").bind("load_node.jstree", function (e, data) { if(data.rslt.status) { data.inst.open_node(data.rslt.obj); } });

_load_node

_load_node : function (obj,
callback)

Load the children of a node, but as opposed to load_node does not change any visual properties or trigger events.  This function is used in load_node internally.  The idea is for data source plugins to overwrite this function.  This implementation (from the core) only uses markup found in the tree container, and does not load async.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.  Use -1 to load the root nodes.
callbacka function to be executed in the tree’s scope.  Receives one argument: status (a boolean indicating if the node was loaded successfully).

open_node

Open a node so that its children are visible.  If the node is not loaded try loading it first.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.
callbacka function to be executed in the tree’s scope.  Receives two arguments: obj (the node being opened) and status (a boolean indicating if the node was opened successfully).
animationthe duration in miliseconds of the slideDown animation.  If not supplied the jQuery default is used.  Please note that on IE6 a 0 is enforced here due to performance issues.

Triggers

open_node, __after_open

open_node

This event is triggered in the jstree namespace when a node is successfully opened (but if animation is used this event is triggered BEFORE the animation completes).  See __after_open.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else).
data.rsltobject which contains a single key: obj (the opened node).

Example

$("div").bind("open_node.jstree", function (e, data) {
  data.rslt.obj.find('> ul > .jstree-closed').each(function () {
    data.inst.open_node(this);
  }
});

__after_open

This event is triggered in the jstree namespace when a node is successfully opened AFTER the animation completes).  See open_node.

Parameters

data.instthe instance
data.rsltobject which contains a single key: obj (the opened node).

Example

$("div").bind("__after_open.jstree", function (e, data) {
  data.rslt.obj.find('> ul > .jstree-closed').each(function () {
    data.inst.open_node(this);
  }
});

close_node

Close a node so that its children are not visible.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.
animationthe duration in miliseconds of the slideDown animation.  If not supplied the jQuery default is used.  Please note that on IE6 a 0 is enforced here due to performance issues.

Triggers

close_node, __after_close

close_node

This event is triggered in the jstree namespace when a node is closed (but if animation is used this event is triggered BEFORE the animation completes).  See __after_close.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else).
data.rsltobject which contains a single key: obj (the closed node).

Example

$("div").bind("close_node.jstree", function (e, data) {
  data.rslt.obj.children('ul').remove();
});

__after_close

This event is triggered in the jstree namespace when a node is closed AFTER the animation completes).  See close_node.

Parameters

data.instthe instance
data.rsltobject which contains a single key: obj (the opened node).

Example

$("div").bind("__after_close.jstree", function (e, data) {
  data.rslt.obj.children('ul').remove();
});

toggle_node

toggle_node : function (obj)
If a node is closedopen it, if it is open - close it.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.

open_all

Open all nodes from a certain node down.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.  If -1 is used or is omitted all nodes in the tree are opened.
animationthe duration of the slideDown animation when opening the nodes.  If not set 0 is enforced for performance issues.
original_objused internally to keep track of the recursion - do not set manually!

Triggers

open_all

open_all

This event is triggered in the jstree namespace when an open_all call completes.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else).
data.rsltobject which contains a single key: obj (the node used in the call).

Example

$("div").bind("open_all.jstree", function (e, data) {
  alert('DONE');
});

close_all

Close all nodes from a certain node down.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.  If -1 is used or is omitted all nodes in the tree are closed.
animationthe duration of the slideDown animation when closing the nodes.  If not set 0 is enforced for performance issues.

Triggers

close_all

close_all

This event is triggered in the jstree namespace when a close_all call completes.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else).
data.rsltobject which contains a single key: obj (the node used in the call).

Example

$("div").bind("close_all.jstree", function (e, data) {
  alert('DONE');
});

clean_node

clean_node : function (obj)

This function converts inserted nodes to the required by jsTree format.  It takes care of converting a simple unodreder list to the internally used markup.  The core calls this function automatically when new data arrives (by binding to the load_node event).  Each plugin may override this function to include its own source, but keep in mind to do it like that:

clean_node : function(obj) {
 obj = this.__call_old();
 obj.each(function () {
   // do your stuff here
 });
}

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.  If -1 is used or is omitted all nodes in the tree are cleaned.

Returns

jQuery collectionthe cleaned children of the original node.

correct_node

This function corrects the open/closed/leaf state as data changes (as the user interacts with the tree).  The core calls this function automatically when a node is opened, deleted or moved.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.  If -1 is used or is omitted the root nodes are processed.

Returns

jQuery collectionthe processed children of the original node.

scroll_to_node

scroll_to_node : function (obj)

This function scrolls the container to the desired node (if needed).

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.

get_state

get_state : function ()

This function returns the current state of the tree (as collected from all active plugins).  Plugin authors: pay special attention to the way this function is extended for new plugins.  In your plugin code write:

get_state : function () {
  var state = this.__call_old();
  state.your-plugin-name = <some-value-you-collect>;
  return state;
}

Returns

objectthe current state of the instance

set_state

This function returns sets the state of the tree.  Plugin authors: pay special attention to the way this function is extended for new plugins.  In your plugin code write:

set_state : function (state, callback) {
  if(this.__call_old()) {
    if(state.your-plugin-name) {

      // restore using `state.your-plugin-name`
      // if you need some async activity so that you return to this bit of code
      // do not delete state.your-plugin-name and return false (see core's function for example)

      delete state.your-plugin-name;
      this.set_state(state, callback);
      return false;
    }
    return true;
  }
  return false;
}

Parameters

stateobject the state to restore to
callbackfunction this will be executed in the instance’s scope once restoring is done

Returns

booleanthe return value is used to determine the phase of restoration

Triggers

set_state

set_state

This event is triggered in the jstree namespace when a set_state call completes.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else)

refresh

This function saves the current state, reloads the complete tree and returns it to the saved state.

Triggers

refresh

refresh

This event is triggered in the jstree namespace when a refresh call completes.

Parameters

data.instthe instance

get_text

get_text : function (obj,
remove_html)

This function returns the title of the node.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.
remove_htmlboolean set to true to return plain text instead of HTML

Returns

stringthe title of the node, specified by obj

set_text

This function sets the title of the node.  This is a low-level function, you’d be better off using <rename>.

Parameters

objmixed this is used as a jquery selector - can be jQuery object, DOM node, string, etc.
valstring the new title of the node (can be HTMl too)

Returns

booleanwas the rename successfull

Triggers

set_text

set_text

This event is triggered in the jstree namespace when a set_text call completes.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else)
data.rsltobject which contains a two keys: obj (the node) and val (the new title).

Example

$("div").bind("set_text.jstree", function (e, data) {
  alert("Renamed to: " + data.rslt.val);
});

parse_json

parse_json : function (node)

This function returns a jQuery node after parsing a JSON object (a LI node for single elements or an UL node for multiple).  This function will use the default title from jstree.config.core.strings if none is specified.

Parameters

nodemixed the input to parse
// can be a string
"The title of the parsed node"
// array of strings
[ "Node 1", "Node 2" ]
// an object
{ "title" : "The title of the parsed node" }
// you can manipulate the output
{ "title" : "The title of the parsed node", "li_attr" : { "id" : "id_for_li" }, "a_attr" : { "href" : "http://jstree.com" } }
// you can supply metadata, which you can later access using $(the_li_node).data()
{ "title" : "The title of the parsed node", "data" : { <some-values-here> } }
// you can supply children (they can be objects too)
{ "title" : "The title of the parsed node", "children" : [ "Node 1", { "title" : "Node 2" } ] }

Returns

jQuerythe LI (or UL) node which was produced from the JSON

get_json

get_json : function (obj,
is_callback)

This function returns the whole tree (or a single node) in JSON format.  Each plugin may override this function to include its own source, but keep in mind to do it like that:

get_json : function(obj, is_callback) {
 var r = this.__call_old();
 if(is_callback) {
  if(<some-condition>) { r.data.jstree.<some-key> = <some-value-this-plugin-will-process>; }
 }
 return r;
}

Parameters

objmixed the input to parse
is_callbackdo not modify this, jstree uses this parameter to keep track of the recursion

Returns

Arrayan array consisting of objects (one for each node)

create_node

This function creates a new node.

Parameters

parentmixed the parent for the newly created node.  This is used as a jquery selector, can be jQuery object, DOM node, string, etc.  Use -1 to create a new root node.
nodemixed the input to parse, check parse_json for description
positionmixed where to create the new node.  Can be one of “before”, “after”, “first”, “last”, “inside” or a numerical index.
callbackoptional function to be executed once the node is created
is_loadedused internally when a node needs to be loaded - do not pass this

Returns

jQuerythe LI node which was produced from the JSON (may return undefined if the parent node is not yet loaded, but will create the node)

Triggers

create_node

create_node

This event is triggered in the jstree namespace when a new node is created.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else)
data.rsltobject which contains a three keys: obj (the node), parent (the parent) and position which is the numerical index.

Example

$("div").bind("create_node.jstree", function (e, data) {
  alert("Created `" + data.inst.get_text(data.rslt.obj) + "` inside `" + (data.rslt.parent === -1 ? 'the main container' : data.inst.get_text(data.rslt.parent)) + "` at index " + data.rslt.position);
});

rename_node

This function renames a new node.

Parameters

objmixed the node to rename.  This is used as a jquery selector, can be jQuery object, DOM node, string, etc.
valstring the new title

Triggers

rename_node

rename_node

This event is triggered in the jstree namespace when a node is renamed.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else)
data.rsltobject which contains a three keys: obj (the node), title (the new title), old (the old title)

Example

$("div").bind("rename_node.jstree", function (e, data) {
  alert("Node rename from `" + data.rslt.old + "` to `" + data.rslt.title "`");
});

delete_node

This function deletes a node.

Parameters

objmixed the node to remove.  This is used as a jquery selector, can be jQuery object, DOM node, string, etc.

Returns

mixedthe removed node on success, false on failure

Triggers

delete_node

delete_node

This event is triggered in the jstree namespace when a node is deleted.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else)
data.rsltobject which contains a three keys: obj (the removed node), prev (the previous sibling of the removed node), parent (the parent of the removed node)

Example

$("div").bind("delete_node.jstree", function (e, data) {
  alert("Node deleted!");
});

check

check : function (chk,
obj,
par,
pos)

This function checks if a structure modification is valid.

Parameters

chkstring what are we checking (copy_node, move_node, rename_node, create_node, delete_node)
objmixed the node.
parmixed the parent (if dealing with a move or copy - the new parent).
posmixed the index among the parent’s children (or the new name if dealing with a rename)
is_copyboolean is this a copy or a move call

Returns

booleantrue if the move is valid, false otherwise

move_node

This function moves a node.

Parameters

objmixed the node to move.  This is used as a jquery selector, can be jQuery object, DOM node, string, etc.
parentmixed the new parent.  This is used as a jquery selector, can be jQuery object, DOM node, string, etc.  Use -1 to promote to a root node.
positionmixed where to create the new node.  Can be one of “before”, “after”, “first”, “last”, “inside” or a numerical index.
callbackoptional function to be executed once the node is moved
is_loadedused internally when a node needs to be loaded - do not pass this

Returns

booleanindicating if the move was successfull (may return undefined if the parent node is not yet loaded, but will move the node)

Triggers

move_node

move_node

This event is triggered in the jstree namespace when a node is moved.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else)
data.rsltobject which contains a five keys: obj (the node), parent (the new parent) and position which is the numerical index, old parent (the old parent) and is_multi (a boolean indicating if the node is coming from another tree instance)

Example

$("div").bind("move_node.jstree", function (e, data) {
  alert("Moved `" + data.inst.get_text(data.rslt.obj) + "` inside `" + (data.rslt.parent === -1 ? 'the main container' : data.inst.get_text(data.rslt.parent)) + "` at index " + data.rslt.position);
});

copy_node

This function copies a node.

Parameters

objmixed the node to copy.  This is used as a jquery selector, can be jQuery object, DOM node, string, etc.
parentmixed the new parent.  This is used as a jquery selector, can be jQuery object, DOM node, string, etc.  Use -1 to promote to a root node.
positionmixed where to create the new node.  Can be one of “before”, “after”, “first”, “last”, “inside” or a numerical index.
callbackoptional function to be executed once the node is moved
is_loadedused internally when a node needs to be loaded - do not pass this

Returns

booleanindicating if the move was successfull (may return undefined if the parent node is not yet loaded, but will move the node)

Triggers

copy_node

copy_node

This event is triggered in the jstree namespace when a node is copied.

Parameters

data.instthe instance
data.argsarray the arguments passed to the function
data.pluginstring the function’s plugin (here it will be ”core” but if the function is extended it may be something else)
data.rsltobject which contains a five keys: obj (the node), parent (the new parent) and position which is the numerical index, original (the original object) and is_multi (a boolean indicating if the node is coming from another tree instance)

Example

$("div").bind("copy_node.jstree", function (e, data) {
  alert("Copied `" + data.inst.get_text(data.rslt.original) + "` inside `" + (data.rslt.parent === -1 ? 'the main container' : data.inst.get_text(data.rslt.parent)) + "` at index " + data.rslt.position);
});
The actual plugin wrapper, use this to create instances or execute functions on created instances.
$.jstree
object Contains all static functions and variables used by jstree, some plugins also append variables.
$.jstree.SCROLLBAR_WIDTH
integer indicating the width of the client scrollbar
_get_string : function (s)
Used to get the common string in the tree.
is_locked : function ()
Used to get the locked status of the tree.
get_node : function (obj)
Get a hold of the LI node (which represents the jstree node).
get_next : function (obj,
strict)
Get the next sibling of a node
get_prev : function (obj,
strict)
Get the previous sibling of a node
get_parent : function (obj)
Get the parent of a node
get_children : function (obj)
Get all the children of a node
is_parent : function (obj)
Check if a node is a parent.
is_loaded : function (obj)
Check if a node is loaded.
is_loading : function (obj)
Check if a node is currently loading.
is_open : function (obj)
Check if a node is currently open.
is_closed : function (obj)
Check if a node is currently closed.
is_leaf : function (obj)
Check if a node is a leaf node (has no children).
_load_node : function (obj,
callback)
Load the children of a node, but as opposed to load_node does not change any visual properties or trigger events.
Load the children of a node.
toggle_node : function (obj)
clean_node : function (obj)
This function converts inserted nodes to the required by jsTree format.
scroll_to_node : function (obj)
This function scrolls the container to the desired node (if needed).
get_state : function ()
This function returns the current state of the tree (as collected from all active plugins).
get_text : function (obj,
remove_html)
This function returns the title of the node.
parse_json : function (node)
This function returns a jQuery node after parsing a JSON object (a LI node for single elements or an UL node for multiple).
get_json : function (obj,
is_callback)
This function returns the whole tree (or a single node) in JSON format.
check : function (chk,
obj,
par,
pos)
This function checks if a structure modification is valid.
Returns an instance
Creates a new jstree instance, any arguments after the first one are merged and used to configure the tree.
Call a function on the instance and return the result
Destroys an instance, and also clears `jstree-` prefixed classes and all events in the `jstree` namespace
mixed used to store all localization strings.
This event is triggered in the jstree namespace when data is first rendered in the tree.
Used to unlock the tree.
Used to lock the tree.
Open a node so that its children are visible.
This event is triggered in the jstree namespace when a node is successfully opened AFTER the animation completes).
Close a node so that its children are not visible.
This event is triggered in the jstree namespace when a node is closed AFTER the animation completes).
Open all nodes from a certain node down.
Close all nodes from a certain node down.
This function returns sets the state of the tree.
This function saves the current state, reloads the complete tree and returns it to the saved state.
This function sets the title of the node.
This function creates a new node.
This function renames a new node.
This function deletes a node.
This function moves a node.
This function copies a node.
Close