| 875 |
lars |
1 |
/**
|
|
|
2 |
* ### Conditionalselect plugin
|
|
|
3 |
*
|
|
|
4 |
* This plugin allows defining a callback to allow or deny node selection by user input (activate node method).
|
|
|
5 |
*/
|
|
|
6 |
/*globals jQuery, define, exports, require, document */
|
|
|
7 |
(function (factory) {
|
|
|
8 |
"use strict";
|
|
|
9 |
if (typeof define === 'function' && define.amd) {
|
|
|
10 |
define('jstree.conditionalselect', ['jquery','jstree'], factory);
|
|
|
11 |
}
|
|
|
12 |
else if(typeof exports === 'object') {
|
|
|
13 |
factory(require('jquery'), require('jstree'));
|
|
|
14 |
}
|
|
|
15 |
else {
|
|
|
16 |
factory(jQuery, jQuery.jstree);
|
|
|
17 |
}
|
|
|
18 |
}(function ($, jstree, undefined) {
|
|
|
19 |
"use strict";
|
|
|
20 |
|
|
|
21 |
if($.jstree.plugins.conditionalselect) { return; }
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* a callback (function) which is invoked in the instance's scope and receives two arguments - the node and the event that triggered the `activate_node` call. Returning false prevents working with the node, returning true allows invoking activate_node. Defaults to returning `true`.
|
|
|
25 |
* @name $.jstree.defaults.checkbox.visible
|
|
|
26 |
* @plugin checkbox
|
|
|
27 |
*/
|
|
|
28 |
$.jstree.defaults.conditionalselect = function () { return true; };
|
|
|
29 |
$.jstree.plugins.conditionalselect = function (options, parent) {
|
|
|
30 |
// own function
|
|
|
31 |
this.activate_node = function (obj, e) {
|
|
|
32 |
if(this.settings.conditionalselect.call(this, this.get_node(obj), e)) {
|
|
|
33 |
parent.activate_node.call(this, obj, e);
|
|
|
34 |
}
|
|
|
35 |
};
|
|
|
36 |
};
|
|
|
37 |
|
|
|
38 |
}));
|