zhaojs
2023-06-27 0a0d605f68e0f02d518b9106b7433067a18b07c4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
 * ### Wholerow plugin
 *
 * Makes each node appear block level. Making selection easier. May cause slow down for large trees in old browsers.
 */
/*globals jQuery, define, exports, require */
(function (factory) {
    "use strict";
    if (typeof define === 'function' && define.amd) {
        define('jstree.wholerow', ['jquery','./jstree.js'], factory);
    }
    else if(typeof exports === 'object') {
        factory(require('jquery'), require('./jstree.js'));
    }
    else {
        factory(jQuery, jQuery.jstree);
    }
}(function ($, jstree, undefined) {
    "use strict";
 
    if($.jstree.plugins.wholerow) { return; }
 
    var div = document.createElement('DIV');
    div.setAttribute('unselectable','on');
    div.setAttribute('role','presentation');
    div.className = 'jstree-wholerow';
    div.innerHTML = ' ';
    $.jstree.plugins.wholerow = function (options, parent) {
        this.bind = function () {
            parent.bind.call(this);
 
            this.element
                .on('ready.jstree set_state.jstree', function () {
                        this.hide_dots();
                    }.bind(this))
                .on("init.jstree loading.jstree ready.jstree", function () {
                        //div.style.height = this._data.core.li_height + 'px';
                        this.get_container_ul().addClass('jstree-wholerow-ul');
                    }.bind(this))
                .on("deselect_all.jstree", function (e, data) {
                        this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
                    }.bind(this))
                .on("changed.jstree", function (e, data) {
                        this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
                        var tmp = false, i, j;
                        for(i = 0, j = data.selected.length; i < j; i++) {
                            tmp = this.get_node(data.selected[i], true);
                            if(tmp && tmp.length) {
                                tmp.children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
                            }
                        }
                    }.bind(this))
                .on("open_node.jstree", function (e, data) {
                        this.get_node(data.node, true).find('.jstree-clicked').parent().children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
                    }.bind(this))
                .on("hover_node.jstree dehover_node.jstree", function (e, data) {
                        if(e.type === "hover_node" && this.is_disabled(data.node)) { return; }
                        this.get_node(data.node, true).children('.jstree-wholerow')[e.type === "hover_node"?"addClass":"removeClass"]('jstree-wholerow-hovered');
                    }.bind(this))
                .on("contextmenu.jstree", ".jstree-wholerow", function (e) {
                        if (this._data.contextmenu) {
                            e.preventDefault();
                            var tmp = $.Event('contextmenu', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey, pageX : e.pageX, pageY : e.pageY });
                            $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp);
                        }
                    }.bind(this))
                /*!
                .on("mousedown.jstree touchstart.jstree", ".jstree-wholerow", function (e) {
                        if(e.target === e.currentTarget) {
                            var a = $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor");
                            e.target = a[0];
                            a.trigger(e);
                        }
                    })
                */
                .on("click.jstree", ".jstree-wholerow", function (e) {
                        e.stopImmediatePropagation();
                        var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
                        $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).trigger('focus');
                    })
                .on("dblclick.jstree", ".jstree-wholerow", function (e) {
                        e.stopImmediatePropagation();
                        var tmp = $.Event('dblclick', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
                        $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).trigger('focus');
                    })
                .on("click.jstree", ".jstree-leaf > .jstree-ocl", function (e) {
                        e.stopImmediatePropagation();
                        var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
                        $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).trigger('focus');
                    }.bind(this))
                .on("mouseover.jstree", ".jstree-wholerow, .jstree-icon", function (e) {
                        e.stopImmediatePropagation();
                        if(!this.is_disabled(e.currentTarget)) {
                            this.hover_node(e.currentTarget);
                        }
                        return false;
                    }.bind(this))
                .on("mouseleave.jstree", ".jstree-node", function (e) {
                        this.dehover_node(e.currentTarget);
                    }.bind(this));
        };
        this.teardown = function () {
            if(this.settings.wholerow) {
                this.element.find(".jstree-wholerow").remove();
            }
            parent.teardown.call(this);
        };
        this.redraw_node = function(obj, deep, callback, force_render) {
            obj = parent.redraw_node.apply(this, arguments);
            if(obj) {
                var tmp = div.cloneNode(true);
                //tmp.style.height = this._data.core.li_height + 'px';
                if($.inArray(obj.id, this._data.core.selected) !== -1) { tmp.className += ' jstree-wholerow-clicked'; }
                if(this._data.core.focused && this._data.core.focused === obj.id) { tmp.className += ' jstree-wholerow-hovered'; }
                obj.insertBefore(tmp, obj.childNodes[0]);
            }
            return obj;
        };
    };
    // include the wholerow plugin by default
    // $.jstree.defaults.plugins.push("wholerow");
}));