comparison vakata-jstree-3.3.5/src/jstree.wholerow.js @ 2:c64267b9f754 draft default tip

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