Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
875 lars 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
						e.preventDefault();
62
						var tmp = $.Event('contextmenu', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey, pageX : e.pageX, pageY : e.pageY });
63
						$(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp);
64
					}, this))
65
				/*!
66
				.on("mousedown.jstree touchstart.jstree", ".jstree-wholerow", function (e) {
67
						if(e.target === e.currentTarget) {
68
							var a = $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor");
69
							e.target = a[0];
70
							a.trigger(e);
71
						}
72
					})
73
				*/
74
				.on("click.jstree", ".jstree-wholerow", function (e) {
75
						e.stopImmediatePropagation();
76
						var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
77
						$(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
78
					})
79
				.on("click.jstree", ".jstree-leaf > .jstree-ocl", $.proxy(function (e) {
80
						e.stopImmediatePropagation();
81
						var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
82
						$(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
83
					}, this))
84
				.on("mouseover.jstree", ".jstree-wholerow, .jstree-icon", $.proxy(function (e) {
85
						e.stopImmediatePropagation();
86
						if(!this.is_disabled(e.currentTarget)) {
87
							this.hover_node(e.currentTarget);
88
						}
89
						return false;
90
					}, this))
91
				.on("mouseleave.jstree", ".jstree-node", $.proxy(function (e) {
92
						this.dehover_node(e.currentTarget);
93
					}, this));
94
		};
95
		this.teardown = function () {
96
			if(this.settings.wholerow) {
97
				this.element.find(".jstree-wholerow").remove();
98
			}
99
			parent.teardown.call(this);
100
		};
101
		this.redraw_node = function(obj, deep, callback, force_render) {
102
			obj = parent.redraw_node.apply(this, arguments);
103
			if(obj) {
104
				var tmp = div.cloneNode(true);
105
				//tmp.style.height = this._data.core.li_height + 'px';
106
				if($.inArray(obj.id, this._data.core.selected) !== -1) { tmp.className += ' jstree-wholerow-clicked'; }
107
				if(this._data.core.focused && this._data.core.focused === obj.id) { tmp.className += ' jstree-wholerow-hovered'; }
108
				obj.insertBefore(tmp, obj.childNodes[0]);
109
			}
110
			return obj;
111
		};
112
	};
113
	// include the wholerow plugin by default
114
	// $.jstree.defaults.plugins.push("wholerow");
115
}));