annotate vakata-jstree-3.3.5/src/jstree.js @ 4:804fe260ee6c draft default tip

planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
author mingchen0919
date Sun, 30 Dec 2018 14:04:22 -0500
parents c12e291895ff
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1 /*!
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2 * jsTree {{VERSION}}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3 * http://jstree.com/
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
5 * Copyright (c) 2014 Ivan Bozhanov (http://vakata.com)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
6 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
7 * Licensed same as jquery - under the terms of the MIT License
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
8 * http://www.opensource.org/licenses/mit-license.php
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
9 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
10 /*!
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
11 * if using jslint please allow for the jQuery global and use following options:
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
12 * jslint: loopfunc: true, browser: true, ass: true, bitwise: true, continue: true, nomen: true, plusplus: true, regexp: true, unparam: true, todo: true, white: true
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
13 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
14 /*jshint -W083 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
15 /*globals jQuery, define, module, exports, require, window, document, postMessage */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
16 (function (factory) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
17 "use strict";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
18 if (typeof define === 'function' && define.amd) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
19 define(['jquery'], factory);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
20 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
21 else if(typeof module !== 'undefined' && module.exports) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
22 module.exports = factory(require('jquery'));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
23 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
24 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
25 factory(jQuery);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
26 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
27 }(function ($, undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
28 "use strict";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
29
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
30 // prevent another load? maybe there is a better way?
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
31 if($.jstree) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
32 return;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
33 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
34
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
35 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
36 * ### jsTree core functionality
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
37 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
38
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
39 // internal variables
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
40 var instance_counter = 0,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
41 ccp_node = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
42 ccp_mode = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
43 ccp_inst = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
44 themes_loaded = [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
45 src = $('script:last').attr('src'),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
46 document = window.document; // local variable is always faster to access then a global
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
47
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
48 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
49 * holds all jstree related functions and variables, including the actual class and methods to create, access and manipulate instances.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
50 * @name $.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
51 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
52 $.jstree = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
53 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
54 * specifies the jstree version in use
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
55 * @name $.jstree.version
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
56 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
57 version : '{{VERSION}}',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
58 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
59 * holds all the default options used when creating new instances
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
60 * @name $.jstree.defaults
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
61 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
62 defaults : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
63 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
64 * configure which plugins will be active on an instance. Should be an array of strings, where each element is a plugin name. The default is `[]`
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
65 * @name $.jstree.defaults.plugins
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
66 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
67 plugins : []
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
68 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
69 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
70 * stores all loaded jstree plugins (used internally)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
71 * @name $.jstree.plugins
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
72 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
73 plugins : {},
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
74 path : src && src.indexOf('/') !== -1 ? src.replace(/\/[^\/]+$/,'') : '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
75 idregex : /[\\:&!^|()\[\]<>@*'+~#";.,=\- \/${}%?`]/g,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
76 root : '#'
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
77 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
78
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
79 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
80 * creates a jstree instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
81 * @name $.jstree.create(el [, options])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
82 * @param {DOMElement|jQuery|String} el the element to create the instance on, can be jQuery extended or a selector
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
83 * @param {Object} options options for this instance (extends `$.jstree.defaults`)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
84 * @return {jsTree} the new instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
85 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
86 $.jstree.create = function (el, options) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
87 var tmp = new $.jstree.core(++instance_counter),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
88 opt = options;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
89 options = $.extend(true, {}, $.jstree.defaults, options);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
90 if(opt && opt.plugins) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
91 options.plugins = opt.plugins;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
92 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
93 $.each(options.plugins, function (i, k) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
94 if(i !== 'core') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
95 tmp = tmp.plugin(k, options[k]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
96 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
97 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
98 $(el).data('jstree', tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
99 tmp.init(el, options);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
100 return tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
101 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
102 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
103 * remove all traces of jstree from the DOM and destroy all instances
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
104 * @name $.jstree.destroy()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
105 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
106 $.jstree.destroy = function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
107 $('.jstree:jstree').jstree('destroy');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
108 $(document).off('.jstree');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
109 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
110 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
111 * the jstree class constructor, used only internally
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
112 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
113 * @name $.jstree.core(id)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
114 * @param {Number} id this instance's index
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
115 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
116 $.jstree.core = function (id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
117 this._id = id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
118 this._cnt = 0;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
119 this._wrk = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
120 this._data = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
121 core : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
122 themes : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
123 name : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
124 dots : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
125 icons : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
126 ellipsis : false
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
127 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
128 selected : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
129 last_error : {},
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
130 working : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
131 worker_queue : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
132 focused : null
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
133 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
134 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
135 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
136 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
137 * get a reference to an existing instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
138 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
139 * __Examples__
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
140 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
141 * // provided a container with an ID of "tree", and a nested node with an ID of "branch"
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
142 * // all of there will return the same instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
143 * $.jstree.reference('tree');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
144 * $.jstree.reference('#tree');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
145 * $.jstree.reference($('#tree'));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
146 * $.jstree.reference(document.getElementByID('tree'));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
147 * $.jstree.reference('branch');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
148 * $.jstree.reference('#branch');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
149 * $.jstree.reference($('#branch'));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
150 * $.jstree.reference(document.getElementByID('branch'));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
151 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
152 * @name $.jstree.reference(needle)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
153 * @param {DOMElement|jQuery|String} needle
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
154 * @return {jsTree|null} the instance or `null` if not found
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
155 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
156 $.jstree.reference = function (needle) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
157 var tmp = null,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
158 obj = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
159 if(needle && needle.id && (!needle.tagName || !needle.nodeType)) { needle = needle.id; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
160
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
161 if(!obj || !obj.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
162 try { obj = $(needle); } catch (ignore) { }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
163 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
164 if(!obj || !obj.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
165 try { obj = $('#' + needle.replace($.jstree.idregex,'\\$&')); } catch (ignore) { }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
166 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
167 if(obj && obj.length && (obj = obj.closest('.jstree')).length && (obj = obj.data('jstree'))) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
168 tmp = obj;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
169 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
170 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
171 $('.jstree').each(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
172 var inst = $(this).data('jstree');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
173 if(inst && inst._model.data[needle]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
174 tmp = inst;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
175 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
176 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
177 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
178 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
179 return tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
180 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
181 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
182 * Create an instance, get an instance or invoke a command on a instance.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
183 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
184 * If there is no instance associated with the current node a new one is created and `arg` is used to extend `$.jstree.defaults` for this new instance. There would be no return value (chaining is not broken).
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
185 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
186 * If there is an existing instance and `arg` is a string the command specified by `arg` is executed on the instance, with any additional arguments passed to the function. If the function returns a value it will be returned (chaining could break depending on function).
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
187 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
188 * If there is an existing instance and `arg` is not a string the instance itself is returned (similar to `$.jstree.reference`).
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
189 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
190 * In any other case - nothing is returned and chaining is not broken.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
191 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
192 * __Examples__
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
193 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
194 * $('#tree1').jstree(); // creates an instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
195 * $('#tree2').jstree({ plugins : [] }); // create an instance with some options
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
196 * $('#tree1').jstree('open_node', '#branch_1'); // call a method on an existing instance, passing additional arguments
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
197 * $('#tree2').jstree(); // get an existing instance (or create an instance)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
198 * $('#tree2').jstree(true); // get an existing instance (will not create new instance)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
199 * $('#branch_1').jstree().select_node('#branch_1'); // get an instance (using a nested element and call a method)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
200 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
201 * @name $().jstree([arg])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
202 * @param {String|Object} arg
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
203 * @return {Mixed}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
204 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
205 $.fn.jstree = function (arg) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
206 // check for string argument
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
207 var is_method = (typeof arg === 'string'),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
208 args = Array.prototype.slice.call(arguments, 1),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
209 result = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
210 if(arg === true && !this.length) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
211 this.each(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
212 // get the instance (if there is one) and method (if it exists)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
213 var instance = $.jstree.reference(this),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
214 method = is_method && instance ? instance[arg] : null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
215 // if calling a method, and method is available - execute on the instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
216 result = is_method && method ?
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
217 method.apply(instance, args) :
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
218 null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
219 // if there is no instance and no method is being called - create one
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
220 if(!instance && !is_method && (arg === undefined || $.isPlainObject(arg))) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
221 $.jstree.create(this, arg);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
222 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
223 // if there is an instance and no method is called - return the instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
224 if( (instance && !is_method) || arg === true ) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
225 result = instance || false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
226 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
227 // if there was a method call which returned a result - break and return the value
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
228 if(result !== null && result !== undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
229 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
230 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
231 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
232 // if there was a method call with a valid return value - return that, otherwise continue the chain
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
233 return result !== null && result !== undefined ?
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
234 result : this;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
235 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
236 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
237 * used to find elements containing an instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
238 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
239 * __Examples__
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
240 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
241 * $('div:jstree').each(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
242 * $(this).jstree('destroy');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
243 * });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
244 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
245 * @name $(':jstree')
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
246 * @return {jQuery}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
247 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
248 $.expr.pseudos.jstree = $.expr.createPseudo(function(search) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
249 return function(a) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
250 return $(a).hasClass('jstree') &&
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
251 $(a).data('jstree') !== undefined;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
252 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
253 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
254
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
255 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
256 * stores all defaults for the core
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
257 * @name $.jstree.defaults.core
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
258 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
259 $.jstree.defaults.core = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
260 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
261 * data configuration
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
262 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
263 * If left as `false` the HTML inside the jstree container element is used to populate the tree (that should be an unordered list with list items).
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
264 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
265 * You can also pass in a HTML string or a JSON array here.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
266 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
267 * It is possible to pass in a standard jQuery-like AJAX config and jstree will automatically determine if the response is JSON or HTML and use that to populate the tree.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
268 * In addition to the standard jQuery ajax options here you can suppy functions for `data` and `url`, the functions will be run in the current instance's scope and a param will be passed indicating which node is being loaded, the return value of those functions will be used.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
269 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
270 * The last option is to specify a function, that function will receive the node being loaded as argument and a second param which is a function which should be called with the result.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
271 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
272 * __Examples__
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
273 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
274 * // AJAX
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
275 * $('#tree').jstree({
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
276 * 'core' : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
277 * 'data' : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
278 * 'url' : '/get/children/',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
279 * 'data' : function (node) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
280 * return { 'id' : node.id };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
281 * }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
282 * }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
283 * });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
284 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
285 * // direct data
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
286 * $('#tree').jstree({
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
287 * 'core' : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
288 * 'data' : [
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
289 * 'Simple root node',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
290 * {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
291 * 'id' : 'node_2',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
292 * 'text' : 'Root node with options',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
293 * 'state' : { 'opened' : true, 'selected' : true },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
294 * 'children' : [ { 'text' : 'Child 1' }, 'Child 2']
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
295 * }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
296 * ]
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
297 * }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
298 * });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
299 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
300 * // function
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
301 * $('#tree').jstree({
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
302 * 'core' : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
303 * 'data' : function (obj, callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
304 * callback.call(this, ['Root 1', 'Root 2']);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
305 * }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
306 * });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
307 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
308 * @name $.jstree.defaults.core.data
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
309 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
310 data : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
311 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
312 * configure the various strings used throughout the tree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
313 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
314 * You can use an object where the key is the string you need to replace and the value is your replacement.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
315 * Another option is to specify a function which will be called with an argument of the needed string and should return the replacement.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
316 * If left as `false` no replacement is made.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
317 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
318 * __Examples__
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
319 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
320 * $('#tree').jstree({
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
321 * 'core' : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
322 * 'strings' : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
323 * 'Loading ...' : 'Please wait ...'
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
324 * }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
325 * }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
326 * });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
327 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
328 * @name $.jstree.defaults.core.strings
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
329 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
330 strings : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
331 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
332 * determines what happens when a user tries to modify the structure of the tree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
333 * If left as `false` all operations like create, rename, delete, move or copy are prevented.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
334 * You can set this to `true` to allow all interactions or use a function to have better control.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
335 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
336 * __Examples__
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
337 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
338 * $('#tree').jstree({
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
339 * 'core' : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
340 * 'check_callback' : function (operation, node, node_parent, node_position, more) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
341 * // operation can be 'create_node', 'rename_node', 'delete_node', 'move_node', 'copy_node' or 'edit'
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
342 * // in case of 'rename_node' node_position is filled with the new node name
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
343 * return operation === 'rename_node' ? true : false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
344 * }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
345 * }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
346 * });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
347 *
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
348 * @name $.jstree.defaults.core.check_callback
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
349 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
350 check_callback : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
351 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
352 * a callback called with a single object parameter in the instance's scope when something goes wrong (operation prevented, ajax failed, etc)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
353 * @name $.jstree.defaults.core.error
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
354 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
355 error : $.noop,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
356 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
357 * the open / close animation duration in milliseconds - set this to `false` to disable the animation (default is `200`)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
358 * @name $.jstree.defaults.core.animation
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
359 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
360 animation : 200,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
361 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
362 * a boolean indicating if multiple nodes can be selected
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
363 * @name $.jstree.defaults.core.multiple
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
364 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
365 multiple : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
366 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
367 * theme configuration object
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
368 * @name $.jstree.defaults.core.themes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
369 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
370 themes : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
371 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
372 * the name of the theme to use (if left as `false` the default theme is used)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
373 * @name $.jstree.defaults.core.themes.name
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
374 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
375 name : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
376 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
377 * the URL of the theme's CSS file, leave this as `false` if you have manually included the theme CSS (recommended). You can set this to `true` too which will try to autoload the theme.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
378 * @name $.jstree.defaults.core.themes.url
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
379 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
380 url : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
381 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
382 * the location of all jstree themes - only used if `url` is set to `true`
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
383 * @name $.jstree.defaults.core.themes.dir
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
384 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
385 dir : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
386 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
387 * a boolean indicating if connecting dots are shown
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
388 * @name $.jstree.defaults.core.themes.dots
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
389 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
390 dots : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
391 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
392 * a boolean indicating if node icons are shown
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
393 * @name $.jstree.defaults.core.themes.icons
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
394 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
395 icons : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
396 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
397 * a boolean indicating if node ellipsis should be shown - this only works with a fixed with on the container
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
398 * @name $.jstree.defaults.core.themes.ellipsis
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
399 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
400 ellipsis : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
401 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
402 * a boolean indicating if the tree background is striped
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
403 * @name $.jstree.defaults.core.themes.stripes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
404 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
405 stripes : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
406 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
407 * a string (or boolean `false`) specifying the theme variant to use (if the theme supports variants)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
408 * @name $.jstree.defaults.core.themes.variant
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
409 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
410 variant : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
411 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
412 * a boolean specifying if a reponsive version of the theme should kick in on smaller screens (if the theme supports it). Defaults to `false`.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
413 * @name $.jstree.defaults.core.themes.responsive
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
414 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
415 responsive : false
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
416 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
417 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
418 * if left as `true` all parents of all selected nodes will be opened once the tree loads (so that all selected nodes are visible to the user)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
419 * @name $.jstree.defaults.core.expand_selected_onload
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
420 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
421 expand_selected_onload : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
422 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
423 * if left as `true` web workers will be used to parse incoming JSON data where possible, so that the UI will not be blocked by large requests. Workers are however about 30% slower. Defaults to `true`
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
424 * @name $.jstree.defaults.core.worker
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
425 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
426 worker : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
427 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
428 * Force node text to plain text (and escape HTML). Defaults to `false`
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
429 * @name $.jstree.defaults.core.force_text
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
430 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
431 force_text : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
432 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
433 * Should the node should be toggled if the text is double clicked . Defaults to `true`
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
434 * @name $.jstree.defaults.core.dblclick_toggle
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
435 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
436 dblclick_toggle : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
437 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
438 * Should the loaded nodes be part of the state. Defaults to `false`
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
439 * @name $.jstree.defaults.core.loaded_state
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
440 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
441 loaded_state : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
442 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
443 * Should the last active node be focused when the tree container is blurred and the focused again. This helps working with screen readers. Defaults to `true`
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
444 * @name $.jstree.defaults.core.restore_focus
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
445 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
446 restore_focus : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
447 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
448 * Default keyboard shortcuts (an object where each key is the button name or combo - like 'enter', 'ctrl-space', 'p', etc and the value is the function to execute in the instance's scope)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
449 * @name $.jstree.defaults.core.keyboard
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
450 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
451 keyboard : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
452 'ctrl-space': function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
453 // aria defines space only with Ctrl
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
454 e.type = "click";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
455 $(e.currentTarget).trigger(e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
456 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
457 'enter': function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
458 // enter
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
459 e.type = "click";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
460 $(e.currentTarget).trigger(e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
461 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
462 'left': function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
463 // left
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
464 e.preventDefault();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
465 if(this.is_open(e.currentTarget)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
466 this.close_node(e.currentTarget);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
467 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
468 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
469 var o = this.get_parent(e.currentTarget);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
470 if(o && o.id !== $.jstree.root) { this.get_node(o, true).children('.jstree-anchor').focus(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
471 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
472 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
473 'up': function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
474 // up
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
475 e.preventDefault();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
476 var o = this.get_prev_dom(e.currentTarget);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
477 if(o && o.length) { o.children('.jstree-anchor').focus(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
478 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
479 'right': function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
480 // right
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
481 e.preventDefault();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
482 if(this.is_closed(e.currentTarget)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
483 this.open_node(e.currentTarget, function (o) { this.get_node(o, true).children('.jstree-anchor').focus(); });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
484 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
485 else if (this.is_open(e.currentTarget)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
486 var o = this.get_node(e.currentTarget, true).children('.jstree-children')[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
487 if(o) { $(this._firstChild(o)).children('.jstree-anchor').focus(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
488 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
489 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
490 'down': function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
491 // down
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
492 e.preventDefault();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
493 var o = this.get_next_dom(e.currentTarget);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
494 if(o && o.length) { o.children('.jstree-anchor').focus(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
495 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
496 '*': function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
497 // aria defines * on numpad as open_all - not very common
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
498 this.open_all();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
499 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
500 'home': function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
501 // home
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
502 e.preventDefault();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
503 var o = this._firstChild(this.get_container_ul()[0]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
504 if(o) { $(o).children('.jstree-anchor').filter(':visible').focus(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
505 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
506 'end': function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
507 // end
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
508 e.preventDefault();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
509 this.element.find('.jstree-anchor').filter(':visible').last().focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
510 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
511 'f2': function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
512 // f2 - safe to include - if check_callback is false it will fail
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
513 e.preventDefault();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
514 this.edit(e.currentTarget);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
515 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
516 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
517 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
518 $.jstree.core.prototype = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
519 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
520 * used to decorate an instance with a plugin. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
521 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
522 * @name plugin(deco [, opts])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
523 * @param {String} deco the plugin to decorate with
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
524 * @param {Object} opts options for the plugin
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
525 * @return {jsTree}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
526 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
527 plugin : function (deco, opts) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
528 var Child = $.jstree.plugins[deco];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
529 if(Child) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
530 this._data[deco] = {};
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
531 Child.prototype = this;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
532 return new Child(opts, this);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
533 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
534 return this;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
535 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
536 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
537 * initialize the instance. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
538 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
539 * @name init(el, optons)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
540 * @param {DOMElement|jQuery|String} el the element we are transforming
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
541 * @param {Object} options options for this instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
542 * @trigger init.jstree, loading.jstree, loaded.jstree, ready.jstree, changed.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
543 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
544 init : function (el, options) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
545 this._model = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
546 data : {},
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
547 changed : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
548 force_full_redraw : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
549 redraw_timeout : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
550 default_state : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
551 loaded : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
552 opened : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
553 selected : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
554 disabled : false
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
555 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
556 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
557 this._model.data[$.jstree.root] = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
558 id : $.jstree.root,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
559 parent : null,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
560 parents : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
561 children : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
562 children_d : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
563 state : { loaded : false }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
564 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
565
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
566 this.element = $(el).addClass('jstree jstree-' + this._id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
567 this.settings = options;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
568
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
569 this._data.core.ready = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
570 this._data.core.loaded = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
571 this._data.core.rtl = (this.element.css("direction") === "rtl");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
572 this.element[this._data.core.rtl ? 'addClass' : 'removeClass']("jstree-rtl");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
573 this.element.attr('role','tree');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
574 if(this.settings.core.multiple) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
575 this.element.attr('aria-multiselectable', true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
576 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
577 if(!this.element.attr('tabindex')) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
578 this.element.attr('tabindex','0');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
579 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
580
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
581 this.bind();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
582 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
583 * triggered after all events are bound
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
584 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
585 * @name init.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
586 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
587 this.trigger("init");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
588
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
589 this._data.core.original_container_html = this.element.find(" > ul > li").clone(true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
590 this._data.core.original_container_html
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
591 .find("li").addBack()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
592 .contents().filter(function() {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
593 return this.nodeType === 3 && (!this.nodeValue || /^\s+$/.test(this.nodeValue));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
594 })
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
595 .remove();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
596 this.element.html("<"+"ul class='jstree-container-ul jstree-children' role='group'><"+"li id='j"+this._id+"_loading' class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='tree-item'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
597 this.element.attr('aria-activedescendant','j' + this._id + '_loading');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
598 this._data.core.li_height = this.get_container_ul().children("li").first().outerHeight() || 24;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
599 this._data.core.node = this._create_prototype_node();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
600 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
601 * triggered after the loading text is shown and before loading starts
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
602 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
603 * @name loading.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
604 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
605 this.trigger("loading");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
606 this.load_node($.jstree.root);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
607 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
608 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
609 * destroy an instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
610 * @name destroy()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
611 * @param {Boolean} keep_html if not set to `true` the container will be emptied, otherwise the current DOM elements will be kept intact
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
612 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
613 destroy : function (keep_html) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
614 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
615 * triggered before the tree is destroyed
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
616 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
617 * @name destroy.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
618 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
619 this.trigger("destroy");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
620 if(this._wrk) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
621 try {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
622 window.URL.revokeObjectURL(this._wrk);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
623 this._wrk = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
624 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
625 catch (ignore) { }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
626 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
627 if(!keep_html) { this.element.empty(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
628 this.teardown();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
629 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
630 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
631 * Create a prototype node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
632 * @name _create_prototype_node()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
633 * @return {DOMElement}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
634 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
635 _create_prototype_node : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
636 var _node = document.createElement('LI'), _temp1, _temp2;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
637 _node.setAttribute('role', 'treeitem');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
638 _temp1 = document.createElement('I');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
639 _temp1.className = 'jstree-icon jstree-ocl';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
640 _temp1.setAttribute('role', 'presentation');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
641 _node.appendChild(_temp1);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
642 _temp1 = document.createElement('A');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
643 _temp1.className = 'jstree-anchor';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
644 _temp1.setAttribute('href','#');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
645 _temp1.setAttribute('tabindex','-1');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
646 _temp2 = document.createElement('I');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
647 _temp2.className = 'jstree-icon jstree-themeicon';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
648 _temp2.setAttribute('role', 'presentation');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
649 _temp1.appendChild(_temp2);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
650 _node.appendChild(_temp1);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
651 _temp1 = _temp2 = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
652
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
653 return _node;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
654 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
655 _kbevent_to_func : function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
656 var keys = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
657 8: "Backspace", 9: "Tab", 13: "Return", 19: "Pause", 27: "Esc",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
658 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", 36: "Home",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
659 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "Print", 45: "Insert",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
660 46: "Delete", 96: "Numpad0", 97: "Numpad1", 98: "Numpad2", 99 : "Numpad3",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
661 100: "Numpad4", 101: "Numpad5", 102: "Numpad6", 103: "Numpad7",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
662 104: "Numpad8", 105: "Numpad9", '-13': "NumpadEnter", 112: "F1",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
663 113: "F2", 114: "F3", 115: "F4", 116: "F5", 117: "F6", 118: "F7",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
664 119: "F8", 120: "F9", 121: "F10", 122: "F11", 123: "F12", 144: "Numlock",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
665 145: "Scrolllock", 16: 'Shift', 17: 'Ctrl', 18: 'Alt',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
666 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
667 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
668 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
669 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
670 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
671 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
672 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
673 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*', 173: '-'
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
674 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
675 var parts = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
676 if (e.ctrlKey) { parts.push('ctrl'); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
677 if (e.altKey) { parts.push('alt'); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
678 if (e.shiftKey) { parts.push('shift'); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
679 parts.push(keys[e.which] || e.which);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
680 parts = parts.sort().join('-').toLowerCase();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
681
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
682 var kb = this.settings.core.keyboard, i, tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
683 for (i in kb) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
684 if (kb.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
685 tmp = i;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
686 if (tmp !== '-' && tmp !== '+') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
687 tmp = tmp.replace('--', '-MINUS').replace('+-', '-MINUS').replace('++', '-PLUS').replace('-+', '-PLUS');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
688 tmp = tmp.split(/-|\+/).sort().join('-').replace('MINUS', '-').replace('PLUS', '+').toLowerCase();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
689 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
690 if (tmp === parts) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
691 return kb[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
692 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
693 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
694 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
695 return null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
696 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
697 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
698 * part of the destroying of an instance. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
699 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
700 * @name teardown()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
701 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
702 teardown : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
703 this.unbind();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
704 this.element
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
705 .removeClass('jstree')
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
706 .removeData('jstree')
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
707 .find("[class^='jstree']")
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
708 .addBack()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
709 .attr("class", function () { return this.className.replace(/jstree[^ ]*|$/ig,''); });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
710 this.element = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
711 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
712 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
713 * bind all events. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
714 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
715 * @name bind()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
716 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
717 bind : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
718 var word = '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
719 tout = null,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
720 was_click = 0;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
721 this.element
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
722 .on("dblclick.jstree", function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
723 if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
724 if(document.selection && document.selection.empty) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
725 document.selection.empty();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
726 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
727 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
728 if(window.getSelection) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
729 var sel = window.getSelection();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
730 try {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
731 sel.removeAllRanges();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
732 sel.collapse();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
733 } catch (ignore) { }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
734 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
735 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
736 })
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
737 .on("mousedown.jstree", $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
738 if(e.target === this.element[0]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
739 e.preventDefault(); // prevent losing focus when clicking scroll arrows (FF, Chrome)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
740 was_click = +(new Date()); // ie does not allow to prevent losing focus
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
741 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
742 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
743 .on("mousedown.jstree", ".jstree-ocl", function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
744 e.preventDefault(); // prevent any node inside from losing focus when clicking the open/close icon
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
745 })
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
746 .on("click.jstree", ".jstree-ocl", $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
747 this.toggle_node(e.target);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
748 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
749 .on("dblclick.jstree", ".jstree-anchor", $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
750 if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
751 if(this.settings.core.dblclick_toggle) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
752 this.toggle_node(e.target);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
753 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
754 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
755 .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
756 e.preventDefault();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
757 if(e.currentTarget !== document.activeElement) { $(e.currentTarget).focus(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
758 this.activate_node(e.currentTarget, e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
759 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
760 .on('keydown.jstree', '.jstree-anchor', $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
761 if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
762 if(this._data.core.rtl) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
763 if(e.which === 37) { e.which = 39; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
764 else if(e.which === 39) { e.which = 37; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
765 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
766 var f = this._kbevent_to_func(e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
767 if (f) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
768 var r = f.call(this, e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
769 if (r === false || r === true) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
770 return r;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
771 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
772 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
773 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
774 .on("load_node.jstree", $.proxy(function (e, data) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
775 if(data.status) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
776 if(data.node.id === $.jstree.root && !this._data.core.loaded) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
777 this._data.core.loaded = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
778 if(this._firstChild(this.get_container_ul()[0])) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
779 this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
780 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
781 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
782 * triggered after the root node is loaded for the first time
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
783 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
784 * @name loaded.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
785 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
786 this.trigger("loaded");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
787 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
788 if(!this._data.core.ready) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
789 setTimeout($.proxy(function() {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
790 if(this.element && !this.get_container_ul().find('.jstree-loading').length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
791 this._data.core.ready = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
792 if(this._data.core.selected.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
793 if(this.settings.core.expand_selected_onload) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
794 var tmp = [], i, j;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
795 for(i = 0, j = this._data.core.selected.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
796 tmp = tmp.concat(this._model.data[this._data.core.selected[i]].parents);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
797 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
798 tmp = $.vakata.array_unique(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
799 for(i = 0, j = tmp.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
800 this.open_node(tmp[i], false, 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
801 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
802 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
803 this.trigger('changed', { 'action' : 'ready', 'selected' : this._data.core.selected });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
804 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
805 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
806 * triggered after all nodes are finished loading
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
807 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
808 * @name ready.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
809 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
810 this.trigger("ready");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
811 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
812 }, this), 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
813 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
814 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
815 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
816 // quick searching when the tree is focused
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
817 .on('keypress.jstree', $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
818 if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
819 if(tout) { clearTimeout(tout); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
820 tout = setTimeout(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
821 word = '';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
822 }, 500);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
823
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
824 var chr = String.fromCharCode(e.which).toLowerCase(),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
825 col = this.element.find('.jstree-anchor').filter(':visible'),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
826 ind = col.index(document.activeElement) || 0,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
827 end = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
828 word += chr;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
829
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
830 // match for whole word from current node down (including the current node)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
831 if(word.length > 1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
832 col.slice(ind).each($.proxy(function (i, v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
833 if($(v).text().toLowerCase().indexOf(word) === 0) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
834 $(v).focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
835 end = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
836 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
837 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
838 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
839 if(end) { return; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
840
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
841 // match for whole word from the beginning of the tree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
842 col.slice(0, ind).each($.proxy(function (i, v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
843 if($(v).text().toLowerCase().indexOf(word) === 0) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
844 $(v).focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
845 end = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
846 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
847 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
848 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
849 if(end) { return; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
850 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
851 // list nodes that start with that letter (only if word consists of a single char)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
852 if(new RegExp('^' + chr.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '+$').test(word)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
853 // search for the next node starting with that letter
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
854 col.slice(ind + 1).each($.proxy(function (i, v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
855 if($(v).text().toLowerCase().charAt(0) === chr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
856 $(v).focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
857 end = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
858 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
859 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
860 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
861 if(end) { return; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
862
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
863 // search from the beginning
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
864 col.slice(0, ind + 1).each($.proxy(function (i, v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
865 if($(v).text().toLowerCase().charAt(0) === chr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
866 $(v).focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
867 end = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
868 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
869 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
870 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
871 if(end) { return; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
872 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
873 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
874 // THEME RELATED
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
875 .on("init.jstree", $.proxy(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
876 var s = this.settings.core.themes;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
877 this._data.core.themes.dots = s.dots;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
878 this._data.core.themes.stripes = s.stripes;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
879 this._data.core.themes.icons = s.icons;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
880 this._data.core.themes.ellipsis = s.ellipsis;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
881 this.set_theme(s.name || "default", s.url);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
882 this.set_theme_variant(s.variant);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
883 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
884 .on("loading.jstree", $.proxy(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
885 this[ this._data.core.themes.dots ? "show_dots" : "hide_dots" ]();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
886 this[ this._data.core.themes.icons ? "show_icons" : "hide_icons" ]();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
887 this[ this._data.core.themes.stripes ? "show_stripes" : "hide_stripes" ]();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
888 this[ this._data.core.themes.ellipsis ? "show_ellipsis" : "hide_ellipsis" ]();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
889 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
890 .on('blur.jstree', '.jstree-anchor', $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
891 this._data.core.focused = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
892 $(e.currentTarget).filter('.jstree-hovered').mouseleave();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
893 this.element.attr('tabindex', '0');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
894 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
895 .on('focus.jstree', '.jstree-anchor', $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
896 var tmp = this.get_node(e.currentTarget);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
897 if(tmp && tmp.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
898 this._data.core.focused = tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
899 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
900 this.element.find('.jstree-hovered').not(e.currentTarget).mouseleave();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
901 $(e.currentTarget).mouseenter();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
902 this.element.attr('tabindex', '-1');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
903 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
904 .on('focus.jstree', $.proxy(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
905 if(+(new Date()) - was_click > 500 && !this._data.core.focused && this.settings.core.restore_focus) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
906 was_click = 0;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
907 var act = this.get_node(this.element.attr('aria-activedescendant'), true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
908 if(act) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
909 act.find('> .jstree-anchor').focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
910 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
911 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
912 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
913 .on('mouseenter.jstree', '.jstree-anchor', $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
914 this.hover_node(e.currentTarget);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
915 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
916 .on('mouseleave.jstree', '.jstree-anchor', $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
917 this.dehover_node(e.currentTarget);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
918 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
919 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
920 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
921 * part of the destroying of an instance. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
922 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
923 * @name unbind()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
924 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
925 unbind : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
926 this.element.off('.jstree');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
927 $(document).off('.jstree-' + this._id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
928 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
929 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
930 * trigger an event. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
931 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
932 * @name trigger(ev [, data])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
933 * @param {String} ev the name of the event to trigger
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
934 * @param {Object} data additional data to pass with the event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
935 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
936 trigger : function (ev, data) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
937 if(!data) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
938 data = {};
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
939 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
940 data.instance = this;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
941 this.element.triggerHandler(ev.replace('.jstree','') + '.jstree', data);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
942 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
943 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
944 * returns the jQuery extended instance container
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
945 * @name get_container()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
946 * @return {jQuery}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
947 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
948 get_container : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
949 return this.element;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
950 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
951 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
952 * returns the jQuery extended main UL node inside the instance container. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
953 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
954 * @name get_container_ul()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
955 * @return {jQuery}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
956 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
957 get_container_ul : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
958 return this.element.children(".jstree-children").first();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
959 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
960 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
961 * gets string replacements (localization). Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
962 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
963 * @name get_string(key)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
964 * @param {String} key
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
965 * @return {String}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
966 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
967 get_string : function (key) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
968 var a = this.settings.core.strings;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
969 if($.isFunction(a)) { return a.call(this, key); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
970 if(a && a[key]) { return a[key]; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
971 return key;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
972 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
973 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
974 * gets the first child of a DOM node. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
975 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
976 * @name _firstChild(dom)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
977 * @param {DOMElement} dom
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
978 * @return {DOMElement}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
979 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
980 _firstChild : function (dom) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
981 dom = dom ? dom.firstChild : null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
982 while(dom !== null && dom.nodeType !== 1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
983 dom = dom.nextSibling;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
984 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
985 return dom;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
986 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
987 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
988 * gets the next sibling of a DOM node. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
989 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
990 * @name _nextSibling(dom)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
991 * @param {DOMElement} dom
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
992 * @return {DOMElement}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
993 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
994 _nextSibling : function (dom) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
995 dom = dom ? dom.nextSibling : null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
996 while(dom !== null && dom.nodeType !== 1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
997 dom = dom.nextSibling;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
998 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
999 return dom;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1000 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1001 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1002 * gets the previous sibling of a DOM node. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1003 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1004 * @name _previousSibling(dom)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1005 * @param {DOMElement} dom
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1006 * @return {DOMElement}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1007 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1008 _previousSibling : function (dom) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1009 dom = dom ? dom.previousSibling : null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1010 while(dom !== null && dom.nodeType !== 1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1011 dom = dom.previousSibling;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1012 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1013 return dom;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1014 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1015 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1016 * get the JSON representation of a node (or the actual jQuery extended DOM node) by using any input (child DOM element, ID string, selector, etc)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1017 * @name get_node(obj [, as_dom])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1018 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1019 * @param {Boolean} as_dom
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1020 * @return {Object|jQuery}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1021 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1022 get_node : function (obj, as_dom) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1023 if(obj && obj.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1024 obj = obj.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1025 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1026 var dom;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1027 try {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1028 if(this._model.data[obj]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1029 obj = this._model.data[obj];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1030 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1031 else if(typeof obj === "string" && this._model.data[obj.replace(/^#/, '')]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1032 obj = this._model.data[obj.replace(/^#/, '')];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1033 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1034 else if(typeof obj === "string" && (dom = $('#' + obj.replace($.jstree.idregex,'\\$&'), this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1035 obj = this._model.data[dom.closest('.jstree-node').attr('id')];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1036 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1037 else if((dom = $(obj, this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1038 obj = this._model.data[dom.closest('.jstree-node').attr('id')];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1039 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1040 else if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1041 obj = this._model.data[$.jstree.root];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1042 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1043 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1044 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1045 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1046
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1047 if(as_dom) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1048 obj = obj.id === $.jstree.root ? this.element : $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1049 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1050 return obj;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1051 } catch (ex) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1052 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1053 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1054 * get the path to a node, either consisting of node texts, or of node IDs, optionally glued together (otherwise an array)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1055 * @name get_path(obj [, glue, ids])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1056 * @param {mixed} obj the node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1057 * @param {String} glue if you want the path as a string - pass the glue here (for example '/'), if a falsy value is supplied here, an array is returned
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1058 * @param {Boolean} ids if set to true build the path using ID, otherwise node text is used
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1059 * @return {mixed}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1060 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1061 get_path : function (obj, glue, ids) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1062 obj = obj.parents ? obj : this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1063 if(!obj || obj.id === $.jstree.root || !obj.parents) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1064 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1065 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1066 var i, j, p = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1067 p.push(ids ? obj.id : obj.text);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1068 for(i = 0, j = obj.parents.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1069 p.push(ids ? obj.parents[i] : this.get_text(obj.parents[i]));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1070 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1071 p = p.reverse().slice(1);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1072 return glue ? p.join(glue) : p;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1073 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1074 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1075 * get the next visible node that is below the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1076 * @name get_next_dom(obj [, strict])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1077 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1078 * @param {Boolean} strict
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1079 * @return {jQuery}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1080 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1081 get_next_dom : function (obj, strict) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1082 var tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1083 obj = this.get_node(obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1084 if(obj[0] === this.element[0]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1085 tmp = this._firstChild(this.get_container_ul()[0]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1086 while (tmp && tmp.offsetHeight === 0) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1087 tmp = this._nextSibling(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1088 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1089 return tmp ? $(tmp) : false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1090 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1091 if(!obj || !obj.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1092 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1093 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1094 if(strict) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1095 tmp = obj[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1096 do {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1097 tmp = this._nextSibling(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1098 } while (tmp && tmp.offsetHeight === 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1099 return tmp ? $(tmp) : false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1100 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1101 if(obj.hasClass("jstree-open")) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1102 tmp = this._firstChild(obj.children('.jstree-children')[0]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1103 while (tmp && tmp.offsetHeight === 0) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1104 tmp = this._nextSibling(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1105 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1106 if(tmp !== null) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1107 return $(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1108 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1109 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1110 tmp = obj[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1111 do {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1112 tmp = this._nextSibling(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1113 } while (tmp && tmp.offsetHeight === 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1114 if(tmp !== null) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1115 return $(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1116 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1117 return obj.parentsUntil(".jstree",".jstree-node").nextAll(".jstree-node:visible").first();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1118 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1119 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1120 * get the previous visible node that is above the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1121 * @name get_prev_dom(obj [, strict])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1122 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1123 * @param {Boolean} strict
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1124 * @return {jQuery}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1125 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1126 get_prev_dom : function (obj, strict) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1127 var tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1128 obj = this.get_node(obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1129 if(obj[0] === this.element[0]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1130 tmp = this.get_container_ul()[0].lastChild;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1131 while (tmp && tmp.offsetHeight === 0) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1132 tmp = this._previousSibling(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1133 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1134 return tmp ? $(tmp) : false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1135 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1136 if(!obj || !obj.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1137 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1138 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1139 if(strict) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1140 tmp = obj[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1141 do {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1142 tmp = this._previousSibling(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1143 } while (tmp && tmp.offsetHeight === 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1144 return tmp ? $(tmp) : false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1145 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1146 tmp = obj[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1147 do {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1148 tmp = this._previousSibling(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1149 } while (tmp && tmp.offsetHeight === 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1150 if(tmp !== null) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1151 obj = $(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1152 while(obj.hasClass("jstree-open")) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1153 obj = obj.children(".jstree-children").first().children(".jstree-node:visible:last");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1154 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1155 return obj;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1156 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1157 tmp = obj[0].parentNode.parentNode;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1158 return tmp && tmp.className && tmp.className.indexOf('jstree-node') !== -1 ? $(tmp) : false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1159 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1160 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1161 * get the parent ID of a node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1162 * @name get_parent(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1163 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1164 * @return {String}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1165 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1166 get_parent : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1167 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1168 if(!obj || obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1169 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1170 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1171 return obj.parent;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1172 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1173 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1174 * get a jQuery collection of all the children of a node (node must be rendered), returns false on error
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1175 * @name get_children_dom(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1176 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1177 * @return {jQuery}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1178 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1179 get_children_dom : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1180 obj = this.get_node(obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1181 if(obj[0] === this.element[0]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1182 return this.get_container_ul().children(".jstree-node");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1183 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1184 if(!obj || !obj.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1185 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1186 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1187 return obj.children(".jstree-children").children(".jstree-node");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1188 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1189 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1190 * checks if a node has children
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1191 * @name is_parent(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1192 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1193 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1194 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1195 is_parent : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1196 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1197 return obj && (obj.state.loaded === false || obj.children.length > 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1198 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1199 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1200 * checks if a node is loaded (its children are available)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1201 * @name is_loaded(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1202 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1203 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1204 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1205 is_loaded : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1206 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1207 return obj && obj.state.loaded;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1208 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1209 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1210 * check if a node is currently loading (fetching children)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1211 * @name is_loading(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1212 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1213 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1214 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1215 is_loading : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1216 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1217 return obj && obj.state && obj.state.loading;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1218 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1219 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1220 * check if a node is opened
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1221 * @name is_open(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1222 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1223 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1224 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1225 is_open : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1226 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1227 return obj && obj.state.opened;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1228 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1229 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1230 * check if a node is in a closed state
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1231 * @name is_closed(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1232 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1233 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1234 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1235 is_closed : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1236 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1237 return obj && this.is_parent(obj) && !obj.state.opened;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1238 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1239 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1240 * check if a node has no children
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1241 * @name is_leaf(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1242 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1243 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1244 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1245 is_leaf : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1246 return !this.is_parent(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1247 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1248 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1249 * loads a node (fetches its children using the `core.data` setting). Multiple nodes can be passed to by using an array.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1250 * @name load_node(obj [, callback])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1251 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1252 * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives two arguments - the node and a boolean status
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1253 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1254 * @trigger load_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1255 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1256 load_node : function (obj, callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1257 var k, l, i, j, c;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1258 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1259 this._load_nodes(obj.slice(), callback);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1260 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1261 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1262 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1263 if(!obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1264 if(callback) { callback.call(this, obj, false); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1265 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1266 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1267 // if(obj.state.loading) { } // the node is already loading - just wait for it to load and invoke callback? but if called implicitly it should be loaded again?
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1268 if(obj.state.loaded) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1269 obj.state.loaded = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1270 for(i = 0, j = obj.parents.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1271 this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1272 return $.inArray(v, obj.children_d) === -1;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1273 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1274 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1275 for(k = 0, l = obj.children_d.length; k < l; k++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1276 if(this._model.data[obj.children_d[k]].state.selected) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1277 c = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1278 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1279 delete this._model.data[obj.children_d[k]];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1280 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1281 if (c) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1282 this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1283 return $.inArray(v, obj.children_d) === -1;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1284 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1285 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1286 obj.children = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1287 obj.children_d = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1288 if(c) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1289 this.trigger('changed', { 'action' : 'load_node', 'node' : obj, 'selected' : this._data.core.selected });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1290 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1291 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1292 obj.state.failed = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1293 obj.state.loading = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1294 this.get_node(obj, true).addClass("jstree-loading").attr('aria-busy',true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1295 this._load_node(obj, $.proxy(function (status) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1296 obj = this._model.data[obj.id];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1297 obj.state.loading = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1298 obj.state.loaded = status;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1299 obj.state.failed = !obj.state.loaded;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1300 var dom = this.get_node(obj, true), i = 0, j = 0, m = this._model.data, has_children = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1301 for(i = 0, j = obj.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1302 if(m[obj.children[i]] && !m[obj.children[i]].state.hidden) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1303 has_children = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1304 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1305 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1306 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1307 if(obj.state.loaded && dom && dom.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1308 dom.removeClass('jstree-closed jstree-open jstree-leaf');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1309 if (!has_children) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1310 dom.addClass('jstree-leaf');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1311 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1312 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1313 if (obj.id !== '#') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1314 dom.addClass(obj.state.opened ? 'jstree-open' : 'jstree-closed');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1315 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1316 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1317 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1318 dom.removeClass("jstree-loading").attr('aria-busy',false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1319 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1320 * triggered after a node is loaded
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1321 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1322 * @name load_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1323 * @param {Object} node the node that was loading
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1324 * @param {Boolean} status was the node loaded successfully
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1325 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1326 this.trigger('load_node', { "node" : obj, "status" : status });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1327 if(callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1328 callback.call(this, obj, status);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1329 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1330 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1331 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1332 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1333 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1334 * load an array of nodes (will also load unavailable nodes as soon as the appear in the structure). Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1335 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1336 * @name _load_nodes(nodes [, callback])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1337 * @param {array} nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1338 * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives one argument - the array passed to _load_nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1339 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1340 _load_nodes : function (nodes, callback, is_callback, force_reload) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1341 var r = true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1342 c = function () { this._load_nodes(nodes, callback, true); },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1343 m = this._model.data, i, j, tmp = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1344 for(i = 0, j = nodes.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1345 if(m[nodes[i]] && ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || (!is_callback && force_reload) )) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1346 if(!this.is_loading(nodes[i])) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1347 this.load_node(nodes[i], c);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1348 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1349 r = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1350 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1351 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1352 if(r) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1353 for(i = 0, j = nodes.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1354 if(m[nodes[i]] && m[nodes[i]].state.loaded) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1355 tmp.push(nodes[i]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1356 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1357 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1358 if(callback && !callback.done) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1359 callback.call(this, tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1360 callback.done = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1361 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1362 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1363 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1364 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1365 * loads all unloaded nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1366 * @name load_all([obj, callback])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1367 * @param {mixed} obj the node to load recursively, omit to load all nodes in the tree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1368 * @param {function} callback a function to be executed once loading all the nodes is complete,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1369 * @trigger load_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1370 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1371 load_all : function (obj, callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1372 if(!obj) { obj = $.jstree.root; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1373 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1374 if(!obj) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1375 var to_load = [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1376 m = this._model.data,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1377 c = m[obj.id].children_d,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1378 i, j;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1379 if(obj.state && !obj.state.loaded) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1380 to_load.push(obj.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1381 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1382 for(i = 0, j = c.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1383 if(m[c[i]] && m[c[i]].state && !m[c[i]].state.loaded) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1384 to_load.push(c[i]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1385 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1386 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1387 if(to_load.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1388 this._load_nodes(to_load, function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1389 this.load_all(obj, callback);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1390 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1391 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1392 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1393 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1394 * triggered after a load_all call completes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1395 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1396 * @name load_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1397 * @param {Object} node the recursively loaded node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1398 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1399 if(callback) { callback.call(this, obj); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1400 this.trigger('load_all', { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1401 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1402 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1403 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1404 * handles the actual loading of a node. Used only internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1405 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1406 * @name _load_node(obj [, callback])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1407 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1408 * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives one argument - a boolean status
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1409 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1410 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1411 _load_node : function (obj, callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1412 var s = this.settings.core.data, t;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1413 var notTextOrCommentNode = function notTextOrCommentNode () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1414 return this.nodeType !== 3 && this.nodeType !== 8;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1415 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1416 // use original HTML
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1417 if(!s) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1418 if(obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1419 return this._append_html_data(obj, this._data.core.original_container_html.clone(true), function (status) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1420 callback.call(this, status);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1421 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1422 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1423 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1424 return callback.call(this, false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1425 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1426 // return callback.call(this, obj.id === $.jstree.root ? this._append_html_data(obj, this._data.core.original_container_html.clone(true)) : false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1427 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1428 if($.isFunction(s)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1429 return s.call(this, obj, $.proxy(function (d) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1430 if(d === false) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1431 callback.call(this, false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1432 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1433 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1434 this[typeof d === 'string' ? '_append_html_data' : '_append_json_data'](obj, typeof d === 'string' ? $($.parseHTML(d)).filter(notTextOrCommentNode) : d, function (status) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1435 callback.call(this, status);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1436 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1437 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1438 // return d === false ? callback.call(this, false) : callback.call(this, this[typeof d === 'string' ? '_append_html_data' : '_append_json_data'](obj, typeof d === 'string' ? $(d) : d));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1439 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1440 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1441 if(typeof s === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1442 if(s.url) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1443 s = $.extend(true, {}, s);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1444 if($.isFunction(s.url)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1445 s.url = s.url.call(this, obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1446 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1447 if($.isFunction(s.data)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1448 s.data = s.data.call(this, obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1449 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1450 return $.ajax(s)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1451 .done($.proxy(function (d,t,x) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1452 var type = x.getResponseHeader('Content-Type');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1453 if((type && type.indexOf('json') !== -1) || typeof d === "object") {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1454 return this._append_json_data(obj, d, function (status) { callback.call(this, status); });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1455 //return callback.call(this, this._append_json_data(obj, d));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1456 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1457 if((type && type.indexOf('html') !== -1) || typeof d === "string") {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1458 return this._append_html_data(obj, $($.parseHTML(d)).filter(notTextOrCommentNode), function (status) { callback.call(this, status); });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1459 // return callback.call(this, this._append_html_data(obj, $(d)));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1460 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1461 this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'core', 'id' : 'core_04', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id, 'xhr' : x }) };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1462 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1463 return callback.call(this, false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1464 }, this))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1465 .fail($.proxy(function (f) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1466 this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'core', 'id' : 'core_04', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id, 'xhr' : f }) };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1467 callback.call(this, false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1468 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1469 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1470 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1471 if ($.isArray(s)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1472 t = $.extend(true, [], s);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1473 } else if ($.isPlainObject(s)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1474 t = $.extend(true, {}, s);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1475 } else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1476 t = s;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1477 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1478 if(obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1479 return this._append_json_data(obj, t, function (status) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1480 callback.call(this, status);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1481 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1482 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1483 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1484 this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_05', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1485 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1486 return callback.call(this, false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1487 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1488 //return callback.call(this, (obj.id === $.jstree.root ? this._append_json_data(obj, t) : false) );
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1489 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1490 if(typeof s === 'string') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1491 if(obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1492 return this._append_html_data(obj, $($.parseHTML(s)).filter(notTextOrCommentNode), function (status) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1493 callback.call(this, status);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1494 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1495 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1496 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1497 this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_06', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1498 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1499 return callback.call(this, false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1500 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1501 //return callback.call(this, (obj.id === $.jstree.root ? this._append_html_data(obj, $(s)) : false) );
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1502 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1503 return callback.call(this, false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1504 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1505 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1506 * adds a node to the list of nodes to redraw. Used only internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1507 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1508 * @name _node_changed(obj [, callback])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1509 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1510 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1511 _node_changed : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1512 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1513 if (obj && $.inArray(obj.id, this._model.changed) === -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1514 this._model.changed.push(obj.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1515 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1516 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1517 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1518 * appends HTML content to the tree. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1519 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1520 * @name _append_html_data(obj, data)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1521 * @param {mixed} obj the node to append to
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1522 * @param {String} data the HTML string to parse and append
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1523 * @trigger model.jstree, changed.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1524 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1525 _append_html_data : function (dom, data, cb) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1526 dom = this.get_node(dom);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1527 dom.children = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1528 dom.children_d = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1529 var dat = data.is('ul') ? data.children() : data,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1530 par = dom.id,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1531 chd = [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1532 dpc = [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1533 m = this._model.data,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1534 p = m[par],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1535 s = this._data.core.selected.length,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1536 tmp, i, j;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1537 dat.each($.proxy(function (i, v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1538 tmp = this._parse_model_from_html($(v), par, p.parents.concat());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1539 if(tmp) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1540 chd.push(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1541 dpc.push(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1542 if(m[tmp].children_d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1543 dpc = dpc.concat(m[tmp].children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1544 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1545 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1546 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1547 p.children = chd;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1548 p.children_d = dpc;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1549 for(i = 0, j = p.parents.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1550 m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1551 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1552 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1553 * triggered when new data is inserted to the tree model
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1554 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1555 * @name model.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1556 * @param {Array} nodes an array of node IDs
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1557 * @param {String} parent the parent ID of the nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1558 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1559 this.trigger('model', { "nodes" : dpc, 'parent' : par });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1560 if(par !== $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1561 this._node_changed(par);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1562 this.redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1563 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1564 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1565 this.get_container_ul().children('.jstree-initial-node').remove();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1566 this.redraw(true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1567 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1568 if(this._data.core.selected.length !== s) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1569 this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1570 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1571 cb.call(this, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1572 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1573 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1574 * appends JSON content to the tree. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1575 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1576 * @name _append_json_data(obj, data)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1577 * @param {mixed} obj the node to append to
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1578 * @param {String} data the JSON object to parse and append
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1579 * @param {Boolean} force_processing internal param - do not set
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1580 * @trigger model.jstree, changed.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1581 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1582 _append_json_data : function (dom, data, cb, force_processing) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1583 if(this.element === null) { return; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1584 dom = this.get_node(dom);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1585 dom.children = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1586 dom.children_d = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1587 // *%$@!!!
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1588 if(data.d) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1589 data = data.d;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1590 if(typeof data === "string") {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1591 data = JSON.parse(data);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1592 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1593 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1594 if(!$.isArray(data)) { data = [data]; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1595 var w = null,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1596 args = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1597 'df' : this._model.default_state,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1598 'dat' : data,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1599 'par' : dom.id,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1600 'm' : this._model.data,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1601 't_id' : this._id,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1602 't_cnt' : this._cnt,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1603 'sel' : this._data.core.selected
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1604 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1605 func = function (data, undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1606 if(data.data) { data = data.data; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1607 var dat = data.dat,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1608 par = data.par,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1609 chd = [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1610 dpc = [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1611 add = [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1612 df = data.df,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1613 t_id = data.t_id,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1614 t_cnt = data.t_cnt,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1615 m = data.m,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1616 p = m[par],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1617 sel = data.sel,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1618 tmp, i, j, rslt,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1619 parse_flat = function (d, p, ps) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1620 if(!ps) { ps = []; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1621 else { ps = ps.concat(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1622 if(p) { ps.unshift(p); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1623 var tid = d.id.toString(),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1624 i, j, c, e,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1625 tmp = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1626 id : tid,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1627 text : d.text || '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1628 icon : d.icon !== undefined ? d.icon : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1629 parent : p,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1630 parents : ps,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1631 children : d.children || [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1632 children_d : d.children_d || [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1633 data : d.data,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1634 state : { },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1635 li_attr : { id : false },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1636 a_attr : { href : '#' },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1637 original : false
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1638 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1639 for(i in df) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1640 if(df.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1641 tmp.state[i] = df[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1642 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1643 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1644 if(d && d.data && d.data.jstree && d.data.jstree.icon) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1645 tmp.icon = d.data.jstree.icon;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1646 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1647 if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1648 tmp.icon = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1649 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1650 if(d && d.data) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1651 tmp.data = d.data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1652 if(d.data.jstree) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1653 for(i in d.data.jstree) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1654 if(d.data.jstree.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1655 tmp.state[i] = d.data.jstree[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1656 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1657 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1658 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1659 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1660 if(d && typeof d.state === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1661 for (i in d.state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1662 if(d.state.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1663 tmp.state[i] = d.state[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1664 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1665 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1666 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1667 if(d && typeof d.li_attr === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1668 for (i in d.li_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1669 if(d.li_attr.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1670 tmp.li_attr[i] = d.li_attr[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1671 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1672 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1673 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1674 if(!tmp.li_attr.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1675 tmp.li_attr.id = tid;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1676 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1677 if(d && typeof d.a_attr === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1678 for (i in d.a_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1679 if(d.a_attr.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1680 tmp.a_attr[i] = d.a_attr[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1681 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1682 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1683 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1684 if(d && d.children && d.children === true) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1685 tmp.state.loaded = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1686 tmp.children = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1687 tmp.children_d = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1688 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1689 m[tmp.id] = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1690 for(i = 0, j = tmp.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1691 c = parse_flat(m[tmp.children[i]], tmp.id, ps);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1692 e = m[c];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1693 tmp.children_d.push(c);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1694 if(e.children_d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1695 tmp.children_d = tmp.children_d.concat(e.children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1696 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1697 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1698 delete d.data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1699 delete d.children;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1700 m[tmp.id].original = d;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1701 if(tmp.state.selected) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1702 add.push(tmp.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1703 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1704 return tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1705 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1706 parse_nest = function (d, p, ps) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1707 if(!ps) { ps = []; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1708 else { ps = ps.concat(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1709 if(p) { ps.unshift(p); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1710 var tid = false, i, j, c, e, tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1711 do {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1712 tid = 'j' + t_id + '_' + (++t_cnt);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1713 } while(m[tid]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1714
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1715 tmp = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1716 id : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1717 text : typeof d === 'string' ? d : '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1718 icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1719 parent : p,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1720 parents : ps,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1721 children : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1722 children_d : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1723 data : null,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1724 state : { },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1725 li_attr : { id : false },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1726 a_attr : { href : '#' },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1727 original : false
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1728 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1729 for(i in df) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1730 if(df.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1731 tmp.state[i] = df[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1732 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1733 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1734 if(d && d.id) { tmp.id = d.id.toString(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1735 if(d && d.text) { tmp.text = d.text; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1736 if(d && d.data && d.data.jstree && d.data.jstree.icon) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1737 tmp.icon = d.data.jstree.icon;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1738 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1739 if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1740 tmp.icon = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1741 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1742 if(d && d.data) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1743 tmp.data = d.data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1744 if(d.data.jstree) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1745 for(i in d.data.jstree) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1746 if(d.data.jstree.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1747 tmp.state[i] = d.data.jstree[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1748 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1749 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1750 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1751 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1752 if(d && typeof d.state === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1753 for (i in d.state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1754 if(d.state.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1755 tmp.state[i] = d.state[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1756 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1757 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1758 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1759 if(d && typeof d.li_attr === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1760 for (i in d.li_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1761 if(d.li_attr.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1762 tmp.li_attr[i] = d.li_attr[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1763 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1764 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1765 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1766 if(tmp.li_attr.id && !tmp.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1767 tmp.id = tmp.li_attr.id.toString();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1768 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1769 if(!tmp.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1770 tmp.id = tid;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1771 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1772 if(!tmp.li_attr.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1773 tmp.li_attr.id = tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1774 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1775 if(d && typeof d.a_attr === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1776 for (i in d.a_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1777 if(d.a_attr.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1778 tmp.a_attr[i] = d.a_attr[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1779 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1780 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1781 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1782 if(d && d.children && d.children.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1783 for(i = 0, j = d.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1784 c = parse_nest(d.children[i], tmp.id, ps);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1785 e = m[c];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1786 tmp.children.push(c);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1787 if(e.children_d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1788 tmp.children_d = tmp.children_d.concat(e.children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1789 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1790 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1791 tmp.children_d = tmp.children_d.concat(tmp.children);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1792 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1793 if(d && d.children && d.children === true) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1794 tmp.state.loaded = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1795 tmp.children = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1796 tmp.children_d = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1797 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1798 delete d.data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1799 delete d.children;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1800 tmp.original = d;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1801 m[tmp.id] = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1802 if(tmp.state.selected) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1803 add.push(tmp.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1804 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1805 return tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1806 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1807
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1808 if(dat.length && dat[0].id !== undefined && dat[0].parent !== undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1809 // Flat JSON support (for easy import from DB):
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1810 // 1) convert to object (foreach)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1811 for(i = 0, j = dat.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1812 if(!dat[i].children) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1813 dat[i].children = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1814 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1815 if(!dat[i].state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1816 dat[i].state = {};
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1817 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1818 m[dat[i].id.toString()] = dat[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1819 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1820 // 2) populate children (foreach)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1821 for(i = 0, j = dat.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1822 if (!m[dat[i].parent.toString()]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1823 this._data.core.last_error = { 'error' : 'parse', 'plugin' : 'core', 'id' : 'core_07', 'reason' : 'Node with invalid parent', 'data' : JSON.stringify({ 'id' : dat[i].id.toString(), 'parent' : dat[i].parent.toString() }) };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1824 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1825 continue;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1826 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1827
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1828 m[dat[i].parent.toString()].children.push(dat[i].id.toString());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1829 // populate parent.children_d
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1830 p.children_d.push(dat[i].id.toString());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1831 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1832 // 3) normalize && populate parents and children_d with recursion
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1833 for(i = 0, j = p.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1834 tmp = parse_flat(m[p.children[i]], par, p.parents.concat());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1835 dpc.push(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1836 if(m[tmp].children_d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1837 dpc = dpc.concat(m[tmp].children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1838 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1839 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1840 for(i = 0, j = p.parents.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1841 m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1842 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1843 // ?) three_state selection - p.state.selected && t - (if three_state foreach(dat => ch) -> foreach(parents) if(parent.selected) child.selected = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1844 rslt = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1845 'cnt' : t_cnt,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1846 'mod' : m,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1847 'sel' : sel,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1848 'par' : par,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1849 'dpc' : dpc,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1850 'add' : add
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1851 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1852 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1853 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1854 for(i = 0, j = dat.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1855 tmp = parse_nest(dat[i], par, p.parents.concat());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1856 if(tmp) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1857 chd.push(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1858 dpc.push(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1859 if(m[tmp].children_d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1860 dpc = dpc.concat(m[tmp].children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1861 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1862 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1863 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1864 p.children = chd;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1865 p.children_d = dpc;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1866 for(i = 0, j = p.parents.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1867 m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1868 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1869 rslt = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1870 'cnt' : t_cnt,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1871 'mod' : m,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1872 'sel' : sel,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1873 'par' : par,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1874 'dpc' : dpc,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1875 'add' : add
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1876 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1877 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1878 if(typeof window === 'undefined' || typeof window.document === 'undefined') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1879 postMessage(rslt);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1880 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1881 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1882 return rslt;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1883 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1884 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1885 rslt = function (rslt, worker) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1886 if(this.element === null) { return; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1887 this._cnt = rslt.cnt;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1888 var i, m = this._model.data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1889 for (i in m) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1890 if (m.hasOwnProperty(i) && m[i].state && m[i].state.loading && rslt.mod[i]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1891 rslt.mod[i].state.loading = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1892 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1893 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1894 this._model.data = rslt.mod; // breaks the reference in load_node - careful
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1895
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1896 if(worker) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1897 var j, a = rslt.add, r = rslt.sel, s = this._data.core.selected.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1898 m = this._model.data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1899 // if selection was changed while calculating in worker
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1900 if(r.length !== s.length || $.vakata.array_unique(r.concat(s)).length !== r.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1901 // deselect nodes that are no longer selected
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1902 for(i = 0, j = r.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1903 if($.inArray(r[i], a) === -1 && $.inArray(r[i], s) === -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1904 m[r[i]].state.selected = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1905 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1906 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1907 // select nodes that were selected in the mean time
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1908 for(i = 0, j = s.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1909 if($.inArray(s[i], r) === -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1910 m[s[i]].state.selected = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1911 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1912 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1913 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1914 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1915 if(rslt.add.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1916 this._data.core.selected = this._data.core.selected.concat(rslt.add);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1917 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1918
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1919 this.trigger('model', { "nodes" : rslt.dpc, 'parent' : rslt.par });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1920
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1921 if(rslt.par !== $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1922 this._node_changed(rslt.par);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1923 this.redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1924 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1925 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1926 // this.get_container_ul().children('.jstree-initial-node').remove();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1927 this.redraw(true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1928 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1929 if(rslt.add.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1930 this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1931 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1932 cb.call(this, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1933 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1934 if(this.settings.core.worker && window.Blob && window.URL && window.Worker) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1935 try {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1936 if(this._wrk === null) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1937 this._wrk = window.URL.createObjectURL(
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1938 new window.Blob(
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1939 ['self.onmessage = ' + func.toString()],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1940 {type:"text/javascript"}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1941 )
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1942 );
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1943 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1944 if(!this._data.core.working || force_processing) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1945 this._data.core.working = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1946 w = new window.Worker(this._wrk);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1947 w.onmessage = $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1948 rslt.call(this, e.data, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1949 try { w.terminate(); w = null; } catch(ignore) { }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1950 if(this._data.core.worker_queue.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1951 this._append_json_data.apply(this, this._data.core.worker_queue.shift());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1952 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1953 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1954 this._data.core.working = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1955 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1956 }, this);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1957 if(!args.par) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1958 if(this._data.core.worker_queue.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1959 this._append_json_data.apply(this, this._data.core.worker_queue.shift());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1960 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1961 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1962 this._data.core.working = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1963 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1964 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1965 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1966 w.postMessage(args);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1967 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1968 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1969 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1970 this._data.core.worker_queue.push([dom, data, cb, true]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1971 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1972 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1973 catch(e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1974 rslt.call(this, func(args), false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1975 if(this._data.core.worker_queue.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1976 this._append_json_data.apply(this, this._data.core.worker_queue.shift());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1977 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1978 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1979 this._data.core.working = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1980 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1981 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1982 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1983 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1984 rslt.call(this, func(args), false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1985 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1986 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1987 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1988 * parses a node from a jQuery object and appends them to the in memory tree model. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1989 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1990 * @name _parse_model_from_html(d [, p, ps])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1991 * @param {jQuery} d the jQuery object to parse
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1992 * @param {String} p the parent ID
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1993 * @param {Array} ps list of all parents
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1994 * @return {String} the ID of the object added to the model
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1995 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1996 _parse_model_from_html : function (d, p, ps) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1997 if(!ps) { ps = []; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1998 else { ps = [].concat(ps); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
1999 if(p) { ps.unshift(p); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2000 var c, e, m = this._model.data,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2001 data = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2002 id : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2003 text : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2004 icon : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2005 parent : p,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2006 parents : ps,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2007 children : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2008 children_d : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2009 data : null,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2010 state : { },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2011 li_attr : { id : false },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2012 a_attr : { href : '#' },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2013 original : false
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2014 }, i, tmp, tid;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2015 for(i in this._model.default_state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2016 if(this._model.default_state.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2017 data.state[i] = this._model.default_state[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2018 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2019 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2020 tmp = $.vakata.attributes(d, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2021 $.each(tmp, function (i, v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2022 v = $.trim(v);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2023 if(!v.length) { return true; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2024 data.li_attr[i] = v;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2025 if(i === 'id') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2026 data.id = v.toString();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2027 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2028 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2029 tmp = d.children('a').first();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2030 if(tmp.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2031 tmp = $.vakata.attributes(tmp, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2032 $.each(tmp, function (i, v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2033 v = $.trim(v);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2034 if(v.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2035 data.a_attr[i] = v;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2036 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2037 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2038 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2039 tmp = d.children("a").first().length ? d.children("a").first().clone() : d.clone();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2040 tmp.children("ins, i, ul").remove();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2041 tmp = tmp.html();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2042 tmp = $('<div />').html(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2043 data.text = this.settings.core.force_text ? tmp.text() : tmp.html();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2044 tmp = d.data();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2045 data.data = tmp ? $.extend(true, {}, tmp) : null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2046 data.state.opened = d.hasClass('jstree-open');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2047 data.state.selected = d.children('a').hasClass('jstree-clicked');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2048 data.state.disabled = d.children('a').hasClass('jstree-disabled');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2049 if(data.data && data.data.jstree) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2050 for(i in data.data.jstree) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2051 if(data.data.jstree.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2052 data.state[i] = data.data.jstree[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2053 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2054 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2055 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2056 tmp = d.children("a").children(".jstree-themeicon");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2057 if(tmp.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2058 data.icon = tmp.hasClass('jstree-themeicon-hidden') ? false : tmp.attr('rel');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2059 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2060 if(data.state.icon !== undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2061 data.icon = data.state.icon;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2062 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2063 if(data.icon === undefined || data.icon === null || data.icon === "") {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2064 data.icon = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2065 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2066 tmp = d.children("ul").children("li");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2067 do {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2068 tid = 'j' + this._id + '_' + (++this._cnt);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2069 } while(m[tid]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2070 data.id = data.li_attr.id ? data.li_attr.id.toString() : tid;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2071 if(tmp.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2072 tmp.each($.proxy(function (i, v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2073 c = this._parse_model_from_html($(v), data.id, ps);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2074 e = this._model.data[c];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2075 data.children.push(c);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2076 if(e.children_d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2077 data.children_d = data.children_d.concat(e.children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2078 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2079 }, this));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2080 data.children_d = data.children_d.concat(data.children);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2081 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2082 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2083 if(d.hasClass('jstree-closed')) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2084 data.state.loaded = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2085 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2086 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2087 if(data.li_attr['class']) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2088 data.li_attr['class'] = data.li_attr['class'].replace('jstree-closed','').replace('jstree-open','');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2089 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2090 if(data.a_attr['class']) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2091 data.a_attr['class'] = data.a_attr['class'].replace('jstree-clicked','').replace('jstree-disabled','');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2092 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2093 m[data.id] = data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2094 if(data.state.selected) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2095 this._data.core.selected.push(data.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2096 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2097 return data.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2098 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2099 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2100 * parses a node from a JSON object (used when dealing with flat data, which has no nesting of children, but has id and parent properties) and appends it to the in memory tree model. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2101 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2102 * @name _parse_model_from_flat_json(d [, p, ps])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2103 * @param {Object} d the JSON object to parse
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2104 * @param {String} p the parent ID
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2105 * @param {Array} ps list of all parents
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2106 * @return {String} the ID of the object added to the model
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2107 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2108 _parse_model_from_flat_json : function (d, p, ps) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2109 if(!ps) { ps = []; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2110 else { ps = ps.concat(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2111 if(p) { ps.unshift(p); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2112 var tid = d.id.toString(),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2113 m = this._model.data,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2114 df = this._model.default_state,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2115 i, j, c, e,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2116 tmp = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2117 id : tid,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2118 text : d.text || '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2119 icon : d.icon !== undefined ? d.icon : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2120 parent : p,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2121 parents : ps,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2122 children : d.children || [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2123 children_d : d.children_d || [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2124 data : d.data,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2125 state : { },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2126 li_attr : { id : false },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2127 a_attr : { href : '#' },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2128 original : false
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2129 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2130 for(i in df) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2131 if(df.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2132 tmp.state[i] = df[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2133 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2134 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2135 if(d && d.data && d.data.jstree && d.data.jstree.icon) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2136 tmp.icon = d.data.jstree.icon;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2137 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2138 if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2139 tmp.icon = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2140 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2141 if(d && d.data) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2142 tmp.data = d.data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2143 if(d.data.jstree) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2144 for(i in d.data.jstree) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2145 if(d.data.jstree.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2146 tmp.state[i] = d.data.jstree[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2147 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2148 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2149 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2150 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2151 if(d && typeof d.state === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2152 for (i in d.state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2153 if(d.state.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2154 tmp.state[i] = d.state[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2155 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2156 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2157 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2158 if(d && typeof d.li_attr === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2159 for (i in d.li_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2160 if(d.li_attr.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2161 tmp.li_attr[i] = d.li_attr[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2162 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2163 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2164 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2165 if(!tmp.li_attr.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2166 tmp.li_attr.id = tid;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2167 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2168 if(d && typeof d.a_attr === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2169 for (i in d.a_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2170 if(d.a_attr.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2171 tmp.a_attr[i] = d.a_attr[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2172 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2173 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2174 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2175 if(d && d.children && d.children === true) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2176 tmp.state.loaded = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2177 tmp.children = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2178 tmp.children_d = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2179 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2180 m[tmp.id] = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2181 for(i = 0, j = tmp.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2182 c = this._parse_model_from_flat_json(m[tmp.children[i]], tmp.id, ps);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2183 e = m[c];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2184 tmp.children_d.push(c);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2185 if(e.children_d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2186 tmp.children_d = tmp.children_d.concat(e.children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2187 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2188 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2189 delete d.data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2190 delete d.children;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2191 m[tmp.id].original = d;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2192 if(tmp.state.selected) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2193 this._data.core.selected.push(tmp.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2194 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2195 return tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2196 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2197 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2198 * parses a node from a JSON object and appends it to the in memory tree model. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2199 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2200 * @name _parse_model_from_json(d [, p, ps])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2201 * @param {Object} d the JSON object to parse
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2202 * @param {String} p the parent ID
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2203 * @param {Array} ps list of all parents
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2204 * @return {String} the ID of the object added to the model
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2205 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2206 _parse_model_from_json : function (d, p, ps) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2207 if(!ps) { ps = []; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2208 else { ps = ps.concat(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2209 if(p) { ps.unshift(p); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2210 var tid = false, i, j, c, e, m = this._model.data, df = this._model.default_state, tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2211 do {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2212 tid = 'j' + this._id + '_' + (++this._cnt);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2213 } while(m[tid]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2214
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2215 tmp = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2216 id : false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2217 text : typeof d === 'string' ? d : '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2218 icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2219 parent : p,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2220 parents : ps,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2221 children : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2222 children_d : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2223 data : null,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2224 state : { },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2225 li_attr : { id : false },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2226 a_attr : { href : '#' },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2227 original : false
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2228 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2229 for(i in df) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2230 if(df.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2231 tmp.state[i] = df[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2232 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2233 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2234 if(d && d.id) { tmp.id = d.id.toString(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2235 if(d && d.text) { tmp.text = d.text; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2236 if(d && d.data && d.data.jstree && d.data.jstree.icon) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2237 tmp.icon = d.data.jstree.icon;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2238 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2239 if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2240 tmp.icon = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2241 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2242 if(d && d.data) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2243 tmp.data = d.data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2244 if(d.data.jstree) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2245 for(i in d.data.jstree) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2246 if(d.data.jstree.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2247 tmp.state[i] = d.data.jstree[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2248 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2249 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2250 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2251 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2252 if(d && typeof d.state === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2253 for (i in d.state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2254 if(d.state.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2255 tmp.state[i] = d.state[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2256 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2257 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2258 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2259 if(d && typeof d.li_attr === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2260 for (i in d.li_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2261 if(d.li_attr.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2262 tmp.li_attr[i] = d.li_attr[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2263 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2264 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2265 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2266 if(tmp.li_attr.id && !tmp.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2267 tmp.id = tmp.li_attr.id.toString();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2268 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2269 if(!tmp.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2270 tmp.id = tid;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2271 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2272 if(!tmp.li_attr.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2273 tmp.li_attr.id = tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2274 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2275 if(d && typeof d.a_attr === 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2276 for (i in d.a_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2277 if(d.a_attr.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2278 tmp.a_attr[i] = d.a_attr[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2279 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2280 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2281 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2282 if(d && d.children && d.children.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2283 for(i = 0, j = d.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2284 c = this._parse_model_from_json(d.children[i], tmp.id, ps);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2285 e = m[c];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2286 tmp.children.push(c);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2287 if(e.children_d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2288 tmp.children_d = tmp.children_d.concat(e.children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2289 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2290 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2291 tmp.children_d = tmp.children_d.concat(tmp.children);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2292 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2293 if(d && d.children && d.children === true) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2294 tmp.state.loaded = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2295 tmp.children = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2296 tmp.children_d = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2297 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2298 delete d.data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2299 delete d.children;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2300 tmp.original = d;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2301 m[tmp.id] = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2302 if(tmp.state.selected) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2303 this._data.core.selected.push(tmp.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2304 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2305 return tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2306 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2307 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2308 * redraws all nodes that need to be redrawn. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2309 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2310 * @name _redraw()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2311 * @trigger redraw.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2312 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2313 _redraw : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2314 var nodes = this._model.force_full_redraw ? this._model.data[$.jstree.root].children.concat([]) : this._model.changed.concat([]),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2315 f = document.createElement('UL'), tmp, i, j, fe = this._data.core.focused;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2316 for(i = 0, j = nodes.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2317 tmp = this.redraw_node(nodes[i], true, this._model.force_full_redraw);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2318 if(tmp && this._model.force_full_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2319 f.appendChild(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2320 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2321 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2322 if(this._model.force_full_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2323 f.className = this.get_container_ul()[0].className;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2324 f.setAttribute('role','group');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2325 this.element.empty().append(f);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2326 //this.get_container_ul()[0].appendChild(f);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2327 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2328 if(fe !== null) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2329 tmp = this.get_node(fe, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2330 if(tmp && tmp.length && tmp.children('.jstree-anchor')[0] !== document.activeElement) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2331 tmp.children('.jstree-anchor').focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2332 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2333 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2334 this._data.core.focused = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2335 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2336 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2337 this._model.force_full_redraw = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2338 this._model.changed = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2339 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2340 * triggered after nodes are redrawn
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2341 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2342 * @name redraw.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2343 * @param {array} nodes the redrawn nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2344 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2345 this.trigger('redraw', { "nodes" : nodes });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2346 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2347 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2348 * redraws all nodes that need to be redrawn or optionally - the whole tree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2349 * @name redraw([full])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2350 * @param {Boolean} full if set to `true` all nodes are redrawn.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2351 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2352 redraw : function (full) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2353 if(full) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2354 this._model.force_full_redraw = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2355 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2356 //if(this._model.redraw_timeout) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2357 // clearTimeout(this._model.redraw_timeout);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2358 //}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2359 //this._model.redraw_timeout = setTimeout($.proxy(this._redraw, this),0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2360 this._redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2361 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2362 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2363 * redraws a single node's children. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2364 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2365 * @name draw_children(node)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2366 * @param {mixed} node the node whose children will be redrawn
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2367 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2368 draw_children : function (node) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2369 var obj = this.get_node(node),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2370 i = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2371 j = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2372 k = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2373 d = document;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2374 if(!obj) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2375 if(obj.id === $.jstree.root) { return this.redraw(true); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2376 node = this.get_node(node, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2377 if(!node || !node.length) { return false; } // TODO: quick toggle
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2378
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2379 node.children('.jstree-children').remove();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2380 node = node[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2381 if(obj.children.length && obj.state.loaded) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2382 k = d.createElement('UL');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2383 k.setAttribute('role', 'group');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2384 k.className = 'jstree-children';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2385 for(i = 0, j = obj.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2386 k.appendChild(this.redraw_node(obj.children[i], true, true));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2387 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2388 node.appendChild(k);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2389 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2390 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2391 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2392 * redraws a single node. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2393 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2394 * @name redraw_node(node, deep, is_callback, force_render)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2395 * @param {mixed} node the node to redraw
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2396 * @param {Boolean} deep should child nodes be redrawn too
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2397 * @param {Boolean} is_callback is this a recursion call
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2398 * @param {Boolean} force_render should children of closed parents be drawn anyway
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2399 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2400 redraw_node : function (node, deep, is_callback, force_render) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2401 var obj = this.get_node(node),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2402 par = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2403 ind = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2404 old = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2405 i = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2406 j = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2407 k = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2408 c = '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2409 d = document,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2410 m = this._model.data,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2411 f = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2412 s = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2413 tmp = null,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2414 t = 0,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2415 l = 0,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2416 has_children = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2417 last_sibling = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2418 if(!obj) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2419 if(obj.id === $.jstree.root) { return this.redraw(true); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2420 deep = deep || obj.children.length === 0;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2421 node = !document.querySelector ? document.getElementById(obj.id) : this.element[0].querySelector('#' + ("0123456789".indexOf(obj.id[0]) !== -1 ? '\\3' + obj.id[0] + ' ' + obj.id.substr(1).replace($.jstree.idregex,'\\$&') : obj.id.replace($.jstree.idregex,'\\$&')) ); //, this.element);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2422 if(!node) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2423 deep = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2424 //node = d.createElement('LI');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2425 if(!is_callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2426 par = obj.parent !== $.jstree.root ? $('#' + obj.parent.replace($.jstree.idregex,'\\$&'), this.element)[0] : null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2427 if(par !== null && (!par || !m[obj.parent].state.opened)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2428 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2429 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2430 ind = $.inArray(obj.id, par === null ? m[$.jstree.root].children : m[obj.parent].children);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2431 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2432 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2433 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2434 node = $(node);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2435 if(!is_callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2436 par = node.parent().parent()[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2437 if(par === this.element[0]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2438 par = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2439 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2440 ind = node.index();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2441 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2442 // m[obj.id].data = node.data(); // use only node's data, no need to touch jquery storage
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2443 if(!deep && obj.children.length && !node.children('.jstree-children').length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2444 deep = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2445 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2446 if(!deep) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2447 old = node.children('.jstree-children')[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2448 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2449 f = node.children('.jstree-anchor')[0] === document.activeElement;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2450 node.remove();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2451 //node = d.createElement('LI');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2452 //node = node[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2453 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2454 node = this._data.core.node.cloneNode(true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2455 // node is DOM, deep is boolean
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2456
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2457 c = 'jstree-node ';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2458 for(i in obj.li_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2459 if(obj.li_attr.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2460 if(i === 'id') { continue; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2461 if(i !== 'class') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2462 node.setAttribute(i, obj.li_attr[i]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2463 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2464 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2465 c += obj.li_attr[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2466 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2467 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2468 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2469 if(!obj.a_attr.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2470 obj.a_attr.id = obj.id + '_anchor';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2471 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2472 node.setAttribute('aria-selected', !!obj.state.selected);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2473 node.setAttribute('aria-level', obj.parents.length);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2474 node.setAttribute('aria-labelledby', obj.a_attr.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2475 if(obj.state.disabled) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2476 node.setAttribute('aria-disabled', true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2477 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2478
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2479 for(i = 0, j = obj.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2480 if(!m[obj.children[i]].state.hidden) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2481 has_children = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2482 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2483 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2484 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2485 if(obj.parent !== null && m[obj.parent] && !obj.state.hidden) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2486 i = $.inArray(obj.id, m[obj.parent].children);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2487 last_sibling = obj.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2488 if(i !== -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2489 i++;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2490 for(j = m[obj.parent].children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2491 if(!m[m[obj.parent].children[i]].state.hidden) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2492 last_sibling = m[obj.parent].children[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2493 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2494 if(last_sibling !== obj.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2495 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2496 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2497 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2498 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2499 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2500
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2501 if(obj.state.hidden) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2502 c += ' jstree-hidden';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2503 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2504 if (obj.state.loading) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2505 c += ' jstree-loading';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2506 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2507 if(obj.state.loaded && !has_children) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2508 c += ' jstree-leaf';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2509 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2510 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2511 c += obj.state.opened && obj.state.loaded ? ' jstree-open' : ' jstree-closed';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2512 node.setAttribute('aria-expanded', (obj.state.opened && obj.state.loaded) );
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2513 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2514 if(last_sibling === obj.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2515 c += ' jstree-last';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2516 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2517 node.id = obj.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2518 node.className = c;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2519 c = ( obj.state.selected ? ' jstree-clicked' : '') + ( obj.state.disabled ? ' jstree-disabled' : '');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2520 for(j in obj.a_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2521 if(obj.a_attr.hasOwnProperty(j)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2522 if(j === 'href' && obj.a_attr[j] === '#') { continue; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2523 if(j !== 'class') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2524 node.childNodes[1].setAttribute(j, obj.a_attr[j]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2525 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2526 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2527 c += ' ' + obj.a_attr[j];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2528 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2529 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2530 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2531 if(c.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2532 node.childNodes[1].className = 'jstree-anchor ' + c;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2533 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2534 if((obj.icon && obj.icon !== true) || obj.icon === false) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2535 if(obj.icon === false) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2536 node.childNodes[1].childNodes[0].className += ' jstree-themeicon-hidden';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2537 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2538 else if(obj.icon.indexOf('/') === -1 && obj.icon.indexOf('.') === -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2539 node.childNodes[1].childNodes[0].className += ' ' + obj.icon + ' jstree-themeicon-custom';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2540 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2541 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2542 node.childNodes[1].childNodes[0].style.backgroundImage = 'url("'+obj.icon+'")';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2543 node.childNodes[1].childNodes[0].style.backgroundPosition = 'center center';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2544 node.childNodes[1].childNodes[0].style.backgroundSize = 'auto';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2545 node.childNodes[1].childNodes[0].className += ' jstree-themeicon-custom';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2546 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2547 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2548
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2549 if(this.settings.core.force_text) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2550 node.childNodes[1].appendChild(d.createTextNode(obj.text));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2551 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2552 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2553 node.childNodes[1].innerHTML += obj.text;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2554 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2555
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2556
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2557 if(deep && obj.children.length && (obj.state.opened || force_render) && obj.state.loaded) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2558 k = d.createElement('UL');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2559 k.setAttribute('role', 'group');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2560 k.className = 'jstree-children';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2561 for(i = 0, j = obj.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2562 k.appendChild(this.redraw_node(obj.children[i], deep, true));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2563 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2564 node.appendChild(k);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2565 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2566 if(old) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2567 node.appendChild(old);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2568 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2569 if(!is_callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2570 // append back using par / ind
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2571 if(!par) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2572 par = this.element[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2573 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2574 for(i = 0, j = par.childNodes.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2575 if(par.childNodes[i] && par.childNodes[i].className && par.childNodes[i].className.indexOf('jstree-children') !== -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2576 tmp = par.childNodes[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2577 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2578 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2579 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2580 if(!tmp) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2581 tmp = d.createElement('UL');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2582 tmp.setAttribute('role', 'group');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2583 tmp.className = 'jstree-children';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2584 par.appendChild(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2585 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2586 par = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2587
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2588 if(ind < par.childNodes.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2589 par.insertBefore(node, par.childNodes[ind]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2590 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2591 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2592 par.appendChild(node);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2593 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2594 if(f) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2595 t = this.element[0].scrollTop;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2596 l = this.element[0].scrollLeft;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2597 node.childNodes[1].focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2598 this.element[0].scrollTop = t;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2599 this.element[0].scrollLeft = l;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2600 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2601 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2602 if(obj.state.opened && !obj.state.loaded) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2603 obj.state.opened = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2604 setTimeout($.proxy(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2605 this.open_node(obj.id, false, 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2606 }, this), 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2607 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2608 return node;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2609 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2610 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2611 * opens a node, revaling its children. If the node is not loaded it will be loaded and opened once ready.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2612 * @name open_node(obj [, callback, animation])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2613 * @param {mixed} obj the node to open
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2614 * @param {Function} callback a function to execute once the node is opened
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2615 * @param {Number} animation the animation duration in milliseconds when opening the node (overrides the `core.animation` setting). Use `false` for no animation.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2616 * @trigger open_node.jstree, after_open.jstree, before_open.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2617 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2618 open_node : function (obj, callback, animation) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2619 var t1, t2, d, t;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2620 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2621 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2622 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2623 this.open_node(obj[t1], callback, animation);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2624 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2625 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2626 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2627 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2628 if(!obj || obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2629 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2630 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2631 animation = animation === undefined ? this.settings.core.animation : animation;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2632 if(!this.is_closed(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2633 if(callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2634 callback.call(this, obj, false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2635 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2636 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2637 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2638 if(!this.is_loaded(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2639 if(this.is_loading(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2640 return setTimeout($.proxy(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2641 this.open_node(obj, callback, animation);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2642 }, this), 500);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2643 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2644 this.load_node(obj, function (o, ok) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2645 return ok ? this.open_node(o, callback, animation) : (callback ? callback.call(this, o, false) : false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2646 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2647 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2648 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2649 d = this.get_node(obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2650 t = this;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2651 if(d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2652 if(animation && d.children(".jstree-children").length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2653 d.children(".jstree-children").stop(true, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2654 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2655 if(obj.children.length && !this._firstChild(d.children('.jstree-children')[0])) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2656 this.draw_children(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2657 //d = this.get_node(obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2658 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2659 if(!animation) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2660 this.trigger('before_open', { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2661 d[0].className = d[0].className.replace('jstree-closed', 'jstree-open');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2662 d[0].setAttribute("aria-expanded", true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2663 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2664 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2665 this.trigger('before_open', { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2666 d
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2667 .children(".jstree-children").css("display","none").end()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2668 .removeClass("jstree-closed").addClass("jstree-open").attr("aria-expanded", true)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2669 .children(".jstree-children").stop(true, true)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2670 .slideDown(animation, function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2671 this.style.display = "";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2672 if (t.element) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2673 t.trigger("after_open", { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2674 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2675 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2676 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2677 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2678 obj.state.opened = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2679 if(callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2680 callback.call(this, obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2681 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2682 if(!d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2683 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2684 * triggered when a node is about to be opened (if the node is supposed to be in the DOM, it will be, but it won't be visible yet)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2685 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2686 * @name before_open.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2687 * @param {Object} node the opened node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2688 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2689 this.trigger('before_open', { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2690 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2691 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2692 * triggered when a node is opened (if there is an animation it will not be completed yet)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2693 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2694 * @name open_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2695 * @param {Object} node the opened node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2696 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2697 this.trigger('open_node', { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2698 if(!animation || !d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2699 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2700 * triggered when a node is opened and the animation is complete
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2701 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2702 * @name after_open.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2703 * @param {Object} node the opened node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2704 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2705 this.trigger("after_open", { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2706 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2707 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2708 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2709 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2710 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2711 * opens every parent of a node (node should be loaded)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2712 * @name _open_to(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2713 * @param {mixed} obj the node to reveal
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2714 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2715 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2716 _open_to : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2717 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2718 if(!obj || obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2719 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2720 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2721 var i, j, p = obj.parents;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2722 for(i = 0, j = p.length; i < j; i+=1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2723 if(i !== $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2724 this.open_node(p[i], false, 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2725 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2726 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2727 return $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2728 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2729 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2730 * closes a node, hiding its children
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2731 * @name close_node(obj [, animation])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2732 * @param {mixed} obj the node to close
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2733 * @param {Number} animation the animation duration in milliseconds when closing the node (overrides the `core.animation` setting). Use `false` for no animation.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2734 * @trigger close_node.jstree, after_close.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2735 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2736 close_node : function (obj, animation) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2737 var t1, t2, t, d;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2738 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2739 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2740 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2741 this.close_node(obj[t1], animation);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2742 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2743 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2744 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2745 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2746 if(!obj || obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2747 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2748 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2749 if(this.is_closed(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2750 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2751 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2752 animation = animation === undefined ? this.settings.core.animation : animation;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2753 t = this;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2754 d = this.get_node(obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2755
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2756 obj.state.opened = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2757 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2758 * triggered when a node is closed (if there is an animation it will not be complete yet)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2759 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2760 * @name close_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2761 * @param {Object} node the closed node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2762 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2763 this.trigger('close_node',{ "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2764 if(!d.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2765 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2766 * triggered when a node is closed and the animation is complete
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2767 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2768 * @name after_close.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2769 * @param {Object} node the closed node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2770 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2771 this.trigger("after_close", { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2772 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2773 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2774 if(!animation) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2775 d[0].className = d[0].className.replace('jstree-open', 'jstree-closed');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2776 d.attr("aria-expanded", false).children('.jstree-children').remove();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2777 this.trigger("after_close", { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2778 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2779 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2780 d
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2781 .children(".jstree-children").attr("style","display:block !important").end()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2782 .removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded", false)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2783 .children(".jstree-children").stop(true, true).slideUp(animation, function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2784 this.style.display = "";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2785 d.children('.jstree-children').remove();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2786 if (t.element) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2787 t.trigger("after_close", { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2788 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2789 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2790 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2791 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2792 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2793 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2794 * toggles a node - closing it if it is open, opening it if it is closed
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2795 * @name toggle_node(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2796 * @param {mixed} obj the node to toggle
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2797 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2798 toggle_node : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2799 var t1, t2;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2800 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2801 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2802 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2803 this.toggle_node(obj[t1]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2804 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2805 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2806 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2807 if(this.is_closed(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2808 return this.open_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2809 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2810 if(this.is_open(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2811 return this.close_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2812 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2813 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2814 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2815 * opens all nodes within a node (or the tree), revaling their children. If the node is not loaded it will be loaded and opened once ready.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2816 * @name open_all([obj, animation, original_obj])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2817 * @param {mixed} obj the node to open recursively, omit to open all nodes in the tree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2818 * @param {Number} animation the animation duration in milliseconds when opening the nodes, the default is no animation
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2819 * @param {jQuery} reference to the node that started the process (internal use)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2820 * @trigger open_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2821 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2822 open_all : function (obj, animation, original_obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2823 if(!obj) { obj = $.jstree.root; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2824 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2825 if(!obj) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2826 var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true), i, j, _this;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2827 if(!dom.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2828 for(i = 0, j = obj.children_d.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2829 if(this.is_closed(this._model.data[obj.children_d[i]])) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2830 this._model.data[obj.children_d[i]].state.opened = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2831 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2832 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2833 return this.trigger('open_all', { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2834 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2835 original_obj = original_obj || dom;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2836 _this = this;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2837 dom = this.is_closed(obj) ? dom.find('.jstree-closed').addBack() : dom.find('.jstree-closed');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2838 dom.each(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2839 _this.open_node(
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2840 this,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2841 function(node, status) { if(status && this.is_parent(node)) { this.open_all(node, animation, original_obj); } },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2842 animation || 0
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2843 );
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2844 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2845 if(original_obj.find('.jstree-closed').length === 0) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2846 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2847 * triggered when an `open_all` call completes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2848 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2849 * @name open_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2850 * @param {Object} node the opened node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2851 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2852 this.trigger('open_all', { "node" : this.get_node(original_obj) });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2853 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2854 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2855 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2856 * closes all nodes within a node (or the tree), revaling their children
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2857 * @name close_all([obj, animation])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2858 * @param {mixed} obj the node to close recursively, omit to close all nodes in the tree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2859 * @param {Number} animation the animation duration in milliseconds when closing the nodes, the default is no animation
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2860 * @trigger close_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2861 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2862 close_all : function (obj, animation) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2863 if(!obj) { obj = $.jstree.root; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2864 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2865 if(!obj) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2866 var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2867 _this = this, i, j;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2868 if(dom.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2869 dom = this.is_open(obj) ? dom.find('.jstree-open').addBack() : dom.find('.jstree-open');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2870 $(dom.get().reverse()).each(function () { _this.close_node(this, animation || 0); });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2871 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2872 for(i = 0, j = obj.children_d.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2873 this._model.data[obj.children_d[i]].state.opened = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2874 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2875 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2876 * triggered when an `close_all` call completes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2877 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2878 * @name close_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2879 * @param {Object} node the closed node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2880 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2881 this.trigger('close_all', { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2882 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2883 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2884 * checks if a node is disabled (not selectable)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2885 * @name is_disabled(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2886 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2887 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2888 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2889 is_disabled : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2890 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2891 return obj && obj.state && obj.state.disabled;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2892 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2893 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2894 * enables a node - so that it can be selected
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2895 * @name enable_node(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2896 * @param {mixed} obj the node to enable
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2897 * @trigger enable_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2898 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2899 enable_node : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2900 var t1, t2;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2901 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2902 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2903 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2904 this.enable_node(obj[t1]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2905 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2906 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2907 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2908 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2909 if(!obj || obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2910 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2911 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2912 obj.state.disabled = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2913 this.get_node(obj,true).children('.jstree-anchor').removeClass('jstree-disabled').attr('aria-disabled', false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2914 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2915 * triggered when an node is enabled
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2916 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2917 * @name enable_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2918 * @param {Object} node the enabled node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2919 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2920 this.trigger('enable_node', { 'node' : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2921 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2922 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2923 * disables a node - so that it can not be selected
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2924 * @name disable_node(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2925 * @param {mixed} obj the node to disable
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2926 * @trigger disable_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2927 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2928 disable_node : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2929 var t1, t2;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2930 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2931 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2932 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2933 this.disable_node(obj[t1]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2934 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2935 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2936 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2937 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2938 if(!obj || obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2939 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2940 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2941 obj.state.disabled = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2942 this.get_node(obj,true).children('.jstree-anchor').addClass('jstree-disabled').attr('aria-disabled', true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2943 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2944 * triggered when an node is disabled
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2945 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2946 * @name disable_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2947 * @param {Object} node the disabled node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2948 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2949 this.trigger('disable_node', { 'node' : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2950 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2951 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2952 * determines if a node is hidden
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2953 * @name is_hidden(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2954 * @param {mixed} obj the node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2955 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2956 is_hidden : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2957 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2958 return obj.state.hidden === true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2959 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2960 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2961 * hides a node - it is still in the structure but will not be visible
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2962 * @name hide_node(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2963 * @param {mixed} obj the node to hide
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2964 * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2965 * @trigger hide_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2966 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2967 hide_node : function (obj, skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2968 var t1, t2;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2969 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2970 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2971 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2972 this.hide_node(obj[t1], true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2973 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2974 if (!skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2975 this.redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2976 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2977 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2978 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2979 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2980 if(!obj || obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2981 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2982 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2983 if(!obj.state.hidden) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2984 obj.state.hidden = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2985 this._node_changed(obj.parent);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2986 if(!skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2987 this.redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2988 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2989 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2990 * triggered when an node is hidden
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2991 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2992 * @name hide_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2993 * @param {Object} node the hidden node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2994 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2995 this.trigger('hide_node', { 'node' : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2996 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2997 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2998 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
2999 * shows a node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3000 * @name show_node(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3001 * @param {mixed} obj the node to show
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3002 * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3003 * @trigger show_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3004 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3005 show_node : function (obj, skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3006 var t1, t2;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3007 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3008 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3009 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3010 this.show_node(obj[t1], true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3011 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3012 if (!skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3013 this.redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3014 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3015 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3016 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3017 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3018 if(!obj || obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3019 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3020 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3021 if(obj.state.hidden) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3022 obj.state.hidden = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3023 this._node_changed(obj.parent);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3024 if(!skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3025 this.redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3026 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3027 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3028 * triggered when an node is shown
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3029 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3030 * @name show_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3031 * @param {Object} node the shown node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3032 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3033 this.trigger('show_node', { 'node' : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3034 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3035 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3036 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3037 * hides all nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3038 * @name hide_all()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3039 * @trigger hide_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3040 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3041 hide_all : function (skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3042 var i, m = this._model.data, ids = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3043 for(i in m) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3044 if(m.hasOwnProperty(i) && i !== $.jstree.root && !m[i].state.hidden) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3045 m[i].state.hidden = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3046 ids.push(i);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3047 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3048 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3049 this._model.force_full_redraw = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3050 if(!skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3051 this.redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3052 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3053 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3054 * triggered when all nodes are hidden
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3055 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3056 * @name hide_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3057 * @param {Array} nodes the IDs of all hidden nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3058 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3059 this.trigger('hide_all', { 'nodes' : ids });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3060 return ids;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3061 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3062 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3063 * shows all nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3064 * @name show_all()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3065 * @trigger show_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3066 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3067 show_all : function (skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3068 var i, m = this._model.data, ids = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3069 for(i in m) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3070 if(m.hasOwnProperty(i) && i !== $.jstree.root && m[i].state.hidden) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3071 m[i].state.hidden = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3072 ids.push(i);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3073 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3074 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3075 this._model.force_full_redraw = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3076 if(!skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3077 this.redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3078 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3079 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3080 * triggered when all nodes are shown
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3081 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3082 * @name show_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3083 * @param {Array} nodes the IDs of all shown nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3084 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3085 this.trigger('show_all', { 'nodes' : ids });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3086 return ids;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3087 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3088 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3089 * called when a node is selected by the user. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3090 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3091 * @name activate_node(obj, e)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3092 * @param {mixed} obj the node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3093 * @param {Object} e the related event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3094 * @trigger activate_node.jstree, changed.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3095 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3096 activate_node : function (obj, e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3097 if(this.is_disabled(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3098 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3099 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3100 if(!e || typeof e !== 'object') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3101 e = {};
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3102 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3103
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3104 // ensure last_clicked is still in the DOM, make it fresh (maybe it was moved?) and make sure it is still selected, if not - make last_clicked the last selected node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3105 this._data.core.last_clicked = this._data.core.last_clicked && this._data.core.last_clicked.id !== undefined ? this.get_node(this._data.core.last_clicked.id) : null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3106 if(this._data.core.last_clicked && !this._data.core.last_clicked.state.selected) { this._data.core.last_clicked = null; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3107 if(!this._data.core.last_clicked && this._data.core.selected.length) { this._data.core.last_clicked = this.get_node(this._data.core.selected[this._data.core.selected.length - 1]); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3108
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3109 if(!this.settings.core.multiple || (!e.metaKey && !e.ctrlKey && !e.shiftKey) || (e.shiftKey && (!this._data.core.last_clicked || !this.get_parent(obj) || this.get_parent(obj) !== this._data.core.last_clicked.parent ) )) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3110 if(!this.settings.core.multiple && (e.metaKey || e.ctrlKey || e.shiftKey) && this.is_selected(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3111 this.deselect_node(obj, false, e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3112 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3113 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3114 this.deselect_all(true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3115 this.select_node(obj, false, false, e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3116 this._data.core.last_clicked = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3117 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3118 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3119 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3120 if(e.shiftKey) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3121 var o = this.get_node(obj).id,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3122 l = this._data.core.last_clicked.id,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3123 p = this.get_node(this._data.core.last_clicked.parent).children,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3124 c = false,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3125 i, j;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3126 for(i = 0, j = p.length; i < j; i += 1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3127 // separate IFs work whem o and l are the same
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3128 if(p[i] === o) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3129 c = !c;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3130 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3131 if(p[i] === l) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3132 c = !c;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3133 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3134 if(!this.is_disabled(p[i]) && (c || p[i] === o || p[i] === l)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3135 if (!this.is_hidden(p[i])) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3136 this.select_node(p[i], true, false, e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3137 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3138 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3139 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3140 this.deselect_node(p[i], true, e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3141 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3142 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3143 this.trigger('changed', { 'action' : 'select_node', 'node' : this.get_node(obj), 'selected' : this._data.core.selected, 'event' : e });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3144 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3145 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3146 if(!this.is_selected(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3147 this.select_node(obj, false, false, e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3148 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3149 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3150 this.deselect_node(obj, false, e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3151 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3152 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3153 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3154 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3155 * triggered when an node is clicked or intercated with by the user
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3156 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3157 * @name activate_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3158 * @param {Object} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3159 * @param {Object} event the ooriginal event (if any) which triggered the call (may be an empty object)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3160 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3161 this.trigger('activate_node', { 'node' : this.get_node(obj), 'event' : e });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3162 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3163 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3164 * applies the hover state on a node, called when a node is hovered by the user. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3165 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3166 * @name hover_node(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3167 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3168 * @trigger hover_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3169 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3170 hover_node : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3171 obj = this.get_node(obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3172 if(!obj || !obj.length || obj.children('.jstree-hovered').length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3173 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3174 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3175 var o = this.element.find('.jstree-hovered'), t = this.element;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3176 if(o && o.length) { this.dehover_node(o); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3177
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3178 obj.children('.jstree-anchor').addClass('jstree-hovered');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3179 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3180 * triggered when an node is hovered
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3181 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3182 * @name hover_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3183 * @param {Object} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3184 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3185 this.trigger('hover_node', { 'node' : this.get_node(obj) });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3186 setTimeout(function () { t.attr('aria-activedescendant', obj[0].id); }, 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3187 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3188 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3189 * removes the hover state from a nodecalled when a node is no longer hovered by the user. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3190 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3191 * @name dehover_node(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3192 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3193 * @trigger dehover_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3194 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3195 dehover_node : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3196 obj = this.get_node(obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3197 if(!obj || !obj.length || !obj.children('.jstree-hovered').length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3198 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3199 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3200 obj.children('.jstree-anchor').removeClass('jstree-hovered');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3201 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3202 * triggered when an node is no longer hovered
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3203 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3204 * @name dehover_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3205 * @param {Object} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3206 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3207 this.trigger('dehover_node', { 'node' : this.get_node(obj) });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3208 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3209 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3210 * select a node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3211 * @name select_node(obj [, supress_event, prevent_open])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3212 * @param {mixed} obj an array can be used to select multiple nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3213 * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3214 * @param {Boolean} prevent_open if set to `true` parents of the selected node won't be opened
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3215 * @trigger select_node.jstree, changed.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3216 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3217 select_node : function (obj, supress_event, prevent_open, e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3218 var dom, t1, t2, th;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3219 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3220 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3221 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3222 this.select_node(obj[t1], supress_event, prevent_open, e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3223 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3224 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3225 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3226 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3227 if(!obj || obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3228 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3229 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3230 dom = this.get_node(obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3231 if(!obj.state.selected) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3232 obj.state.selected = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3233 this._data.core.selected.push(obj.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3234 if(!prevent_open) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3235 dom = this._open_to(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3236 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3237 if(dom && dom.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3238 dom.attr('aria-selected', true).children('.jstree-anchor').addClass('jstree-clicked');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3239 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3240 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3241 * triggered when an node is selected
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3242 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3243 * @name select_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3244 * @param {Object} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3245 * @param {Array} selected the current selection
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3246 * @param {Object} event the event (if any) that triggered this select_node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3247 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3248 this.trigger('select_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3249 if(!supress_event) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3250 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3251 * triggered when selection changes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3252 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3253 * @name changed.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3254 * @param {Object} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3255 * @param {Object} action the action that caused the selection to change
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3256 * @param {Array} selected the current selection
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3257 * @param {Object} event the event (if any) that triggered this changed event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3258 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3259 this.trigger('changed', { 'action' : 'select_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3260 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3261 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3262 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3263 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3264 * deselect a node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3265 * @name deselect_node(obj [, supress_event])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3266 * @param {mixed} obj an array can be used to deselect multiple nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3267 * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3268 * @trigger deselect_node.jstree, changed.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3269 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3270 deselect_node : function (obj, supress_event, e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3271 var t1, t2, dom;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3272 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3273 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3274 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3275 this.deselect_node(obj[t1], supress_event, e);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3276 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3277 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3278 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3279 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3280 if(!obj || obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3281 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3282 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3283 dom = this.get_node(obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3284 if(obj.state.selected) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3285 obj.state.selected = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3286 this._data.core.selected = $.vakata.array_remove_item(this._data.core.selected, obj.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3287 if(dom.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3288 dom.attr('aria-selected', false).children('.jstree-anchor').removeClass('jstree-clicked');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3289 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3290 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3291 * triggered when an node is deselected
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3292 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3293 * @name deselect_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3294 * @param {Object} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3295 * @param {Array} selected the current selection
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3296 * @param {Object} event the event (if any) that triggered this deselect_node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3297 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3298 this.trigger('deselect_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3299 if(!supress_event) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3300 this.trigger('changed', { 'action' : 'deselect_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3301 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3302 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3303 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3304 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3305 * select all nodes in the tree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3306 * @name select_all([supress_event])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3307 * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3308 * @trigger select_all.jstree, changed.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3309 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3310 select_all : function (supress_event) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3311 var tmp = this._data.core.selected.concat([]), i, j;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3312 this._data.core.selected = this._model.data[$.jstree.root].children_d.concat();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3313 for(i = 0, j = this._data.core.selected.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3314 if(this._model.data[this._data.core.selected[i]]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3315 this._model.data[this._data.core.selected[i]].state.selected = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3316 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3317 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3318 this.redraw(true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3319 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3320 * triggered when all nodes are selected
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3321 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3322 * @name select_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3323 * @param {Array} selected the current selection
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3324 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3325 this.trigger('select_all', { 'selected' : this._data.core.selected });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3326 if(!supress_event) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3327 this.trigger('changed', { 'action' : 'select_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3328 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3329 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3330 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3331 * deselect all selected nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3332 * @name deselect_all([supress_event])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3333 * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3334 * @trigger deselect_all.jstree, changed.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3335 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3336 deselect_all : function (supress_event) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3337 var tmp = this._data.core.selected.concat([]), i, j;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3338 for(i = 0, j = this._data.core.selected.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3339 if(this._model.data[this._data.core.selected[i]]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3340 this._model.data[this._data.core.selected[i]].state.selected = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3341 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3342 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3343 this._data.core.selected = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3344 this.element.find('.jstree-clicked').removeClass('jstree-clicked').parent().attr('aria-selected', false);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3345 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3346 * triggered when all nodes are deselected
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3347 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3348 * @name deselect_all.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3349 * @param {Object} node the previous selection
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3350 * @param {Array} selected the current selection
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3351 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3352 this.trigger('deselect_all', { 'selected' : this._data.core.selected, 'node' : tmp });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3353 if(!supress_event) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3354 this.trigger('changed', { 'action' : 'deselect_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3355 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3356 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3357 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3358 * checks if a node is selected
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3359 * @name is_selected(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3360 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3361 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3362 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3363 is_selected : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3364 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3365 if(!obj || obj.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3366 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3367 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3368 return obj.state.selected;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3369 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3370 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3371 * get an array of all selected nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3372 * @name get_selected([full])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3373 * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3374 * @return {Array}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3375 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3376 get_selected : function (full) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3377 return full ? $.map(this._data.core.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.core.selected.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3378 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3379 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3380 * get an array of all top level selected nodes (ignoring children of selected nodes)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3381 * @name get_top_selected([full])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3382 * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3383 * @return {Array}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3384 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3385 get_top_selected : function (full) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3386 var tmp = this.get_selected(true),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3387 obj = {}, i, j, k, l;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3388 for(i = 0, j = tmp.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3389 obj[tmp[i].id] = tmp[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3390 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3391 for(i = 0, j = tmp.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3392 for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3393 if(obj[tmp[i].children_d[k]]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3394 delete obj[tmp[i].children_d[k]];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3395 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3396 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3397 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3398 tmp = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3399 for(i in obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3400 if(obj.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3401 tmp.push(i);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3402 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3403 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3404 return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3405 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3406 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3407 * get an array of all bottom level selected nodes (ignoring selected parents)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3408 * @name get_bottom_selected([full])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3409 * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3410 * @return {Array}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3411 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3412 get_bottom_selected : function (full) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3413 var tmp = this.get_selected(true),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3414 obj = [], i, j;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3415 for(i = 0, j = tmp.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3416 if(!tmp[i].children.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3417 obj.push(tmp[i].id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3418 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3419 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3420 return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3421 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3422 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3423 * gets the current state of the tree so that it can be restored later with `set_state(state)`. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3424 * @name get_state()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3425 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3426 * @return {Object}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3427 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3428 get_state : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3429 var state = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3430 'core' : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3431 'open' : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3432 'loaded' : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3433 'scroll' : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3434 'left' : this.element.scrollLeft(),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3435 'top' : this.element.scrollTop()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3436 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3437 /*!
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3438 'themes' : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3439 'name' : this.get_theme(),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3440 'icons' : this._data.core.themes.icons,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3441 'dots' : this._data.core.themes.dots
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3442 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3443 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3444 'selected' : []
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3445 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3446 }, i;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3447 for(i in this._model.data) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3448 if(this._model.data.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3449 if(i !== $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3450 if(this._model.data[i].state.loaded && this.settings.core.loaded_state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3451 state.core.loaded.push(i);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3452 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3453 if(this._model.data[i].state.opened) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3454 state.core.open.push(i);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3455 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3456 if(this._model.data[i].state.selected) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3457 state.core.selected.push(i);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3458 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3459 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3460 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3461 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3462 return state;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3463 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3464 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3465 * sets the state of the tree. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3466 * @name set_state(state [, callback])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3467 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3468 * @param {Object} state the state to restore. Keep in mind this object is passed by reference and jstree will modify it.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3469 * @param {Function} callback an optional function to execute once the state is restored.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3470 * @trigger set_state.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3471 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3472 set_state : function (state, callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3473 if(state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3474 if(state.core && state.core.selected && state.core.initial_selection === undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3475 state.core.initial_selection = this._data.core.selected.concat([]).sort().join(',');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3476 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3477 if(state.core) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3478 var res, n, t, _this, i;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3479 if(state.core.loaded) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3480 if(!this.settings.core.loaded_state || !$.isArray(state.core.loaded) || !state.core.loaded.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3481 delete state.core.loaded;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3482 this.set_state(state, callback);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3483 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3484 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3485 this._load_nodes(state.core.loaded, function (nodes) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3486 delete state.core.loaded;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3487 this.set_state(state, callback);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3488 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3489 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3490 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3491 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3492 if(state.core.open) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3493 if(!$.isArray(state.core.open) || !state.core.open.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3494 delete state.core.open;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3495 this.set_state(state, callback);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3496 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3497 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3498 this._load_nodes(state.core.open, function (nodes) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3499 this.open_node(nodes, false, 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3500 delete state.core.open;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3501 this.set_state(state, callback);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3502 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3503 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3504 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3505 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3506 if(state.core.scroll) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3507 if(state.core.scroll && state.core.scroll.left !== undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3508 this.element.scrollLeft(state.core.scroll.left);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3509 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3510 if(state.core.scroll && state.core.scroll.top !== undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3511 this.element.scrollTop(state.core.scroll.top);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3512 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3513 delete state.core.scroll;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3514 this.set_state(state, callback);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3515 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3516 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3517 if(state.core.selected) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3518 _this = this;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3519 if (state.core.initial_selection === undefined ||
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3520 state.core.initial_selection === this._data.core.selected.concat([]).sort().join(',')
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3521 ) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3522 this.deselect_all();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3523 $.each(state.core.selected, function (i, v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3524 _this.select_node(v, false, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3525 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3526 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3527 delete state.core.initial_selection;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3528 delete state.core.selected;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3529 this.set_state(state, callback);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3530 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3531 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3532 for(i in state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3533 if(state.hasOwnProperty(i) && i !== "core" && $.inArray(i, this.settings.plugins) === -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3534 delete state[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3535 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3536 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3537 if($.isEmptyObject(state.core)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3538 delete state.core;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3539 this.set_state(state, callback);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3540 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3541 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3542 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3543 if($.isEmptyObject(state)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3544 state = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3545 if(callback) { callback.call(this); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3546 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3547 * triggered when a `set_state` call completes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3548 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3549 * @name set_state.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3550 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3551 this.trigger('set_state');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3552 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3553 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3554 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3555 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3556 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3557 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3558 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3559 * refreshes the tree - all nodes are reloaded with calls to `load_node`.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3560 * @name refresh()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3561 * @param {Boolean} skip_loading an option to skip showing the loading indicator
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3562 * @param {Mixed} forget_state if set to `true` state will not be reapplied, if set to a function (receiving the current state as argument) the result of that function will be used as state
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3563 * @trigger refresh.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3564 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3565 refresh : function (skip_loading, forget_state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3566 this._data.core.state = forget_state === true ? {} : this.get_state();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3567 if(forget_state && $.isFunction(forget_state)) { this._data.core.state = forget_state.call(this, this._data.core.state); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3568 this._cnt = 0;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3569 this._model.data = {};
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3570 this._model.data[$.jstree.root] = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3571 id : $.jstree.root,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3572 parent : null,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3573 parents : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3574 children : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3575 children_d : [],
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3576 state : { loaded : false }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3577 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3578 this._data.core.selected = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3579 this._data.core.last_clicked = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3580 this._data.core.focused = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3581
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3582 var c = this.get_container_ul()[0].className;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3583 if(!skip_loading) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3584 this.element.html("<"+"ul class='"+c+"' role='group'><"+"li class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='treeitem' id='j"+this._id+"_loading'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3585 this.element.attr('aria-activedescendant','j'+this._id+'_loading');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3586 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3587 this.load_node($.jstree.root, function (o, s) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3588 if(s) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3589 this.get_container_ul()[0].className = c;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3590 if(this._firstChild(this.get_container_ul()[0])) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3591 this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3592 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3593 this.set_state($.extend(true, {}, this._data.core.state), function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3594 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3595 * triggered when a `refresh` call completes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3596 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3597 * @name refresh.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3598 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3599 this.trigger('refresh');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3600 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3601 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3602 this._data.core.state = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3603 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3604 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3605 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3606 * refreshes a node in the tree (reload its children) all opened nodes inside that node are reloaded with calls to `load_node`.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3607 * @name refresh_node(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3608 * @param {mixed} obj the node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3609 * @trigger refresh_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3610 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3611 refresh_node : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3612 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3613 if(!obj || obj.id === $.jstree.root) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3614 var opened = [], to_load = [], s = this._data.core.selected.concat([]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3615 to_load.push(obj.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3616 if(obj.state.opened === true) { opened.push(obj.id); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3617 this.get_node(obj, true).find('.jstree-open').each(function() { to_load.push(this.id); opened.push(this.id); });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3618 this._load_nodes(to_load, $.proxy(function (nodes) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3619 this.open_node(opened, false, 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3620 this.select_node(s);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3621 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3622 * triggered when a node is refreshed
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3623 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3624 * @name refresh_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3625 * @param {Object} node - the refreshed node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3626 * @param {Array} nodes - an array of the IDs of the nodes that were reloaded
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3627 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3628 this.trigger('refresh_node', { 'node' : obj, 'nodes' : nodes });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3629 }, this), false, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3630 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3631 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3632 * set (change) the ID of a node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3633 * @name set_id(obj, id)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3634 * @param {mixed} obj the node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3635 * @param {String} id the new ID
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3636 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3637 * @trigger set_id.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3638 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3639 set_id : function (obj, id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3640 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3641 if(!obj || obj.id === $.jstree.root) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3642 var i, j, m = this._model.data, old = obj.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3643 id = id.toString();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3644 // update parents (replace current ID with new one in children and children_d)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3645 m[obj.parent].children[$.inArray(obj.id, m[obj.parent].children)] = id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3646 for(i = 0, j = obj.parents.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3647 m[obj.parents[i]].children_d[$.inArray(obj.id, m[obj.parents[i]].children_d)] = id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3648 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3649 // update children (replace current ID with new one in parent and parents)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3650 for(i = 0, j = obj.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3651 m[obj.children[i]].parent = id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3652 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3653 for(i = 0, j = obj.children_d.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3654 m[obj.children_d[i]].parents[$.inArray(obj.id, m[obj.children_d[i]].parents)] = id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3655 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3656 i = $.inArray(obj.id, this._data.core.selected);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3657 if(i !== -1) { this._data.core.selected[i] = id; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3658 // update model and obj itself (obj.id, this._model.data[KEY])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3659 i = this.get_node(obj.id, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3660 if(i) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3661 i.attr('id', id); //.children('.jstree-anchor').attr('id', id + '_anchor').end().attr('aria-labelledby', id + '_anchor');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3662 if(this.element.attr('aria-activedescendant') === obj.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3663 this.element.attr('aria-activedescendant', id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3664 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3665 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3666 delete m[obj.id];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3667 obj.id = id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3668 obj.li_attr.id = id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3669 m[id] = obj;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3670 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3671 * triggered when a node id value is changed
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3672 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3673 * @name set_id.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3674 * @param {Object} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3675 * @param {String} old the old id
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3676 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3677 this.trigger('set_id',{ "node" : obj, "new" : obj.id, "old" : old });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3678 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3679 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3680 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3681 * get the text value of a node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3682 * @name get_text(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3683 * @param {mixed} obj the node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3684 * @return {String}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3685 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3686 get_text : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3687 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3688 return (!obj || obj.id === $.jstree.root) ? false : obj.text;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3689 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3690 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3691 * set the text value of a node. Used internally, please use `rename_node(obj, val)`.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3692 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3693 * @name set_text(obj, val)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3694 * @param {mixed} obj the node, you can pass an array to set the text on multiple nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3695 * @param {String} val the new text value
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3696 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3697 * @trigger set_text.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3698 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3699 set_text : function (obj, val) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3700 var t1, t2;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3701 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3702 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3703 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3704 this.set_text(obj[t1], val);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3705 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3706 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3707 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3708 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3709 if(!obj || obj.id === $.jstree.root) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3710 obj.text = val;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3711 if(this.get_node(obj, true).length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3712 this.redraw_node(obj.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3713 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3714 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3715 * triggered when a node text value is changed
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3716 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3717 * @name set_text.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3718 * @param {Object} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3719 * @param {String} text the new value
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3720 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3721 this.trigger('set_text',{ "obj" : obj, "text" : val });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3722 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3723 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3724 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3725 * gets a JSON representation of a node (or the whole tree)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3726 * @name get_json([obj, options])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3727 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3728 * @param {Object} options
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3729 * @param {Boolean} options.no_state do not return state information
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3730 * @param {Boolean} options.no_id do not return ID
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3731 * @param {Boolean} options.no_children do not include children
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3732 * @param {Boolean} options.no_data do not include node data
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3733 * @param {Boolean} options.no_li_attr do not include LI attributes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3734 * @param {Boolean} options.no_a_attr do not include A attributes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3735 * @param {Boolean} options.flat return flat JSON instead of nested
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3736 * @return {Object}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3737 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3738 get_json : function (obj, options, flat) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3739 obj = this.get_node(obj || $.jstree.root);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3740 if(!obj) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3741 if(options && options.flat && !flat) { flat = []; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3742 var tmp = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3743 'id' : obj.id,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3744 'text' : obj.text,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3745 'icon' : this.get_icon(obj),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3746 'li_attr' : $.extend(true, {}, obj.li_attr),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3747 'a_attr' : $.extend(true, {}, obj.a_attr),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3748 'state' : {},
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3749 'data' : options && options.no_data ? false : $.extend(true, $.isArray(obj.data)?[]:{}, obj.data)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3750 //( this.get_node(obj, true).length ? this.get_node(obj, true).data() : obj.data ),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3751 }, i, j;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3752 if(options && options.flat) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3753 tmp.parent = obj.parent;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3754 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3755 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3756 tmp.children = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3757 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3758 if(!options || !options.no_state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3759 for(i in obj.state) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3760 if(obj.state.hasOwnProperty(i)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3761 tmp.state[i] = obj.state[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3762 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3763 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3764 } else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3765 delete tmp.state;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3766 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3767 if(options && options.no_li_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3768 delete tmp.li_attr;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3769 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3770 if(options && options.no_a_attr) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3771 delete tmp.a_attr;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3772 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3773 if(options && options.no_id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3774 delete tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3775 if(tmp.li_attr && tmp.li_attr.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3776 delete tmp.li_attr.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3777 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3778 if(tmp.a_attr && tmp.a_attr.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3779 delete tmp.a_attr.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3780 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3781 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3782 if(options && options.flat && obj.id !== $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3783 flat.push(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3784 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3785 if(!options || !options.no_children) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3786 for(i = 0, j = obj.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3787 if(options && options.flat) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3788 this.get_json(obj.children[i], options, flat);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3789 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3790 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3791 tmp.children.push(this.get_json(obj.children[i], options));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3792 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3793 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3794 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3795 return options && options.flat ? flat : (obj.id === $.jstree.root ? tmp.children : tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3796 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3797 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3798 * create a new node (do not confuse with load_node)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3799 * @name create_node([par, node, pos, callback, is_loaded])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3800 * @param {mixed} par the parent node (to create a root node use either "#" (string) or `null`)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3801 * @param {mixed} node the data for the new node (a valid JSON object, or a simple string with the name)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3802 * @param {mixed} pos the index at which to insert the node, "first" and "last" are also supported, default is "last"
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3803 * @param {Function} callback a function to be called once the node is created
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3804 * @param {Boolean} is_loaded internal argument indicating if the parent node was succesfully loaded
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3805 * @return {String} the ID of the newly create node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3806 * @trigger model.jstree, create_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3807 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3808 create_node : function (par, node, pos, callback, is_loaded) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3809 if(par === null) { par = $.jstree.root; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3810 par = this.get_node(par);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3811 if(!par) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3812 pos = pos === undefined ? "last" : pos;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3813 if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3814 return this.load_node(par, function () { this.create_node(par, node, pos, callback, true); });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3815 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3816 if(!node) { node = { "text" : this.get_string('New node') }; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3817 if(typeof node === "string") {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3818 node = { "text" : node };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3819 } else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3820 node = $.extend(true, {}, node);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3821 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3822 if(node.text === undefined) { node.text = this.get_string('New node'); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3823 var tmp, dpc, i, j;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3824
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3825 if(par.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3826 if(pos === "before") { pos = "first"; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3827 if(pos === "after") { pos = "last"; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3828 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3829 switch(pos) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3830 case "before":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3831 tmp = this.get_node(par.parent);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3832 pos = $.inArray(par.id, tmp.children);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3833 par = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3834 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3835 case "after" :
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3836 tmp = this.get_node(par.parent);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3837 pos = $.inArray(par.id, tmp.children) + 1;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3838 par = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3839 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3840 case "inside":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3841 case "first":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3842 pos = 0;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3843 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3844 case "last":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3845 pos = par.children.length;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3846 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3847 default:
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3848 if(!pos) { pos = 0; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3849 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3850 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3851 if(pos > par.children.length) { pos = par.children.length; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3852 if(!node.id) { node.id = true; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3853 if(!this.check("create_node", node, par, pos)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3854 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3855 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3856 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3857 if(node.id === true) { delete node.id; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3858 node = this._parse_model_from_json(node, par.id, par.parents.concat());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3859 if(!node) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3860 tmp = this.get_node(node);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3861 dpc = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3862 dpc.push(node);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3863 dpc = dpc.concat(tmp.children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3864 this.trigger('model', { "nodes" : dpc, "parent" : par.id });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3865
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3866 par.children_d = par.children_d.concat(dpc);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3867 for(i = 0, j = par.parents.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3868 this._model.data[par.parents[i]].children_d = this._model.data[par.parents[i]].children_d.concat(dpc);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3869 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3870 node = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3871 tmp = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3872 for(i = 0, j = par.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3873 tmp[i >= pos ? i+1 : i] = par.children[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3874 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3875 tmp[pos] = node.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3876 par.children = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3877
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3878 this.redraw_node(par, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3879 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3880 * triggered when a node is created
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3881 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3882 * @name create_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3883 * @param {Object} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3884 * @param {String} parent the parent's ID
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3885 * @param {Number} position the position of the new node among the parent's children
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3886 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3887 this.trigger('create_node', { "node" : this.get_node(node), "parent" : par.id, "position" : pos });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3888 if(callback) { callback.call(this, this.get_node(node)); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3889 return node.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3890 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3891 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3892 * set the text value of a node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3893 * @name rename_node(obj, val)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3894 * @param {mixed} obj the node, you can pass an array to rename multiple nodes to the same name
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3895 * @param {String} val the new text value
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3896 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3897 * @trigger rename_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3898 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3899 rename_node : function (obj, val) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3900 var t1, t2, old;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3901 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3902 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3903 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3904 this.rename_node(obj[t1], val);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3905 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3906 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3907 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3908 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3909 if(!obj || obj.id === $.jstree.root) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3910 old = obj.text;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3911 if(!this.check("rename_node", obj, this.get_parent(obj), val)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3912 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3913 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3914 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3915 this.set_text(obj, val); // .apply(this, Array.prototype.slice.call(arguments))
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3916 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3917 * triggered when a node is renamed
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3918 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3919 * @name rename_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3920 * @param {Object} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3921 * @param {String} text the new value
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3922 * @param {String} old the old value
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3923 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3924 this.trigger('rename_node', { "node" : obj, "text" : val, "old" : old });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3925 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3926 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3927 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3928 * remove a node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3929 * @name delete_node(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3930 * @param {mixed} obj the node, you can pass an array to delete multiple nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3931 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3932 * @trigger delete_node.jstree, changed.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3933 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3934 delete_node : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3935 var t1, t2, par, pos, tmp, i, j, k, l, c, top, lft;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3936 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3937 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3938 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3939 this.delete_node(obj[t1]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3940 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3941 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3942 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3943 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3944 if(!obj || obj.id === $.jstree.root) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3945 par = this.get_node(obj.parent);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3946 pos = $.inArray(obj.id, par.children);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3947 c = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3948 if(!this.check("delete_node", obj, par, pos)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3949 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3950 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3951 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3952 if(pos !== -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3953 par.children = $.vakata.array_remove(par.children, pos);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3954 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3955 tmp = obj.children_d.concat([]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3956 tmp.push(obj.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3957 for(i = 0, j = obj.parents.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3958 this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3959 return $.inArray(v, tmp) === -1;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3960 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3961 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3962 for(k = 0, l = tmp.length; k < l; k++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3963 if(this._model.data[tmp[k]].state.selected) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3964 c = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3965 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3966 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3967 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3968 if (c) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3969 this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3970 return $.inArray(v, tmp) === -1;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3971 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3972 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3973 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3974 * triggered when a node is deleted
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3975 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3976 * @name delete_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3977 * @param {Object} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3978 * @param {String} parent the parent's ID
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3979 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3980 this.trigger('delete_node', { "node" : obj, "parent" : par.id });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3981 if(c) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3982 this.trigger('changed', { 'action' : 'delete_node', 'node' : obj, 'selected' : this._data.core.selected, 'parent' : par.id });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3983 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3984 for(k = 0, l = tmp.length; k < l; k++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3985 delete this._model.data[tmp[k]];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3986 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3987 if($.inArray(this._data.core.focused, tmp) !== -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3988 this._data.core.focused = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3989 top = this.element[0].scrollTop;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3990 lft = this.element[0].scrollLeft;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3991 if(par.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3992 if (this._model.data[$.jstree.root].children[0]) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3993 this.get_node(this._model.data[$.jstree.root].children[0], true).children('.jstree-anchor').focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3994 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3995 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3996 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3997 this.get_node(par, true).children('.jstree-anchor').focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3998 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
3999 this.element[0].scrollTop = top;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4000 this.element[0].scrollLeft = lft;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4001 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4002 this.redraw_node(par, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4003 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4004 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4005 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4006 * check if an operation is premitted on the tree. Used internally.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4007 * @private
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4008 * @name check(chk, obj, par, pos)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4009 * @param {String} chk the operation to check, can be "create_node", "rename_node", "delete_node", "copy_node" or "move_node"
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4010 * @param {mixed} obj the node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4011 * @param {mixed} par the parent
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4012 * @param {mixed} pos the position to insert at, or if "rename_node" - the new name
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4013 * @param {mixed} more some various additional information, for example if a "move_node" operations is triggered by DND this will be the hovered node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4014 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4015 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4016 check : function (chk, obj, par, pos, more) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4017 obj = obj && obj.id ? obj : this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4018 par = par && par.id ? par : this.get_node(par);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4019 var tmp = chk.match(/^move_node|copy_node|create_node$/i) ? par : obj,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4020 chc = this.settings.core.check_callback;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4021 if(chk === "move_node" || chk === "copy_node") {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4022 if((!more || !more.is_multi) && (obj.id === par.id || (chk === "move_node" && $.inArray(obj.id, par.children) === pos) || $.inArray(par.id, obj.children_d) !== -1)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4023 this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_01', 'reason' : 'Moving parent inside child', 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4024 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4025 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4026 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4027 if(tmp && tmp.data) { tmp = tmp.data; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4028 if(tmp && tmp.functions && (tmp.functions[chk] === false || tmp.functions[chk] === true)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4029 if(tmp.functions[chk] === false) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4030 this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_02', 'reason' : 'Node data prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4031 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4032 return tmp.functions[chk];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4033 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4034 if(chc === false || ($.isFunction(chc) && chc.call(this, chk, obj, par, pos, more) === false) || (chc && chc[chk] === false)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4035 this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_03', 'reason' : 'User config for core.check_callback prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4036 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4037 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4038 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4039 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4040 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4041 * get the last error
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4042 * @name last_error()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4043 * @return {Object}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4044 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4045 last_error : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4046 return this._data.core.last_error;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4047 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4048 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4049 * move a node to a new parent
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4050 * @name move_node(obj, par [, pos, callback, is_loaded])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4051 * @param {mixed} obj the node to move, pass an array to move multiple nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4052 * @param {mixed} par the new parent
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4053 * @param {mixed} pos the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer `0`
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4054 * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4055 * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4056 * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4057 * @param {Boolean} instance internal parameter indicating if the node comes from another instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4058 * @trigger move_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4059 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4060 move_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4061 var t1, t2, old_par, old_pos, new_par, old_ins, is_multi, dpc, tmp, i, j, k, l, p;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4062
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4063 par = this.get_node(par);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4064 pos = pos === undefined ? 0 : pos;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4065 if(!par) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4066 if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4067 return this.load_node(par, function () { this.move_node(obj, par, pos, callback, true, false, origin); });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4068 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4069
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4070 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4071 if(obj.length === 1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4072 obj = obj[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4073 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4074 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4075 //obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4076 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4077 if((tmp = this.move_node(obj[t1], par, pos, callback, is_loaded, false, origin))) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4078 par = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4079 pos = "after";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4080 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4081 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4082 this.redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4083 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4084 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4085 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4086 obj = obj && obj.id ? obj : this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4087
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4088 if(!obj || obj.id === $.jstree.root) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4089
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4090 old_par = (obj.parent || $.jstree.root).toString();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4091 new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4092 old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4093 is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4094 old_pos = old_ins && old_ins._id && old_par && old_ins._model.data[old_par] && old_ins._model.data[old_par].children ? $.inArray(obj.id, old_ins._model.data[old_par].children) : -1;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4095 if(old_ins && old_ins._id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4096 obj = old_ins._model.data[obj.id];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4097 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4098
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4099 if(is_multi) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4100 if((tmp = this.copy_node(obj, par, pos, callback, is_loaded, false, origin))) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4101 if(old_ins) { old_ins.delete_node(obj); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4102 return tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4103 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4104 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4105 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4106 //var m = this._model.data;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4107 if(par.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4108 if(pos === "before") { pos = "first"; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4109 if(pos === "after") { pos = "last"; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4110 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4111 switch(pos) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4112 case "before":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4113 pos = $.inArray(par.id, new_par.children);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4114 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4115 case "after" :
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4116 pos = $.inArray(par.id, new_par.children) + 1;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4117 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4118 case "inside":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4119 case "first":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4120 pos = 0;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4121 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4122 case "last":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4123 pos = new_par.children.length;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4124 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4125 default:
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4126 if(!pos) { pos = 0; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4127 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4128 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4129 if(pos > new_par.children.length) { pos = new_par.children.length; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4130 if(!this.check("move_node", obj, new_par, pos, { 'core' : true, 'origin' : origin, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id) })) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4131 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4132 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4133 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4134 if(obj.parent === new_par.id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4135 dpc = new_par.children.concat();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4136 tmp = $.inArray(obj.id, dpc);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4137 if(tmp !== -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4138 dpc = $.vakata.array_remove(dpc, tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4139 if(pos > tmp) { pos--; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4140 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4141 tmp = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4142 for(i = 0, j = dpc.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4143 tmp[i >= pos ? i+1 : i] = dpc[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4144 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4145 tmp[pos] = obj.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4146 new_par.children = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4147 this._node_changed(new_par.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4148 this.redraw(new_par.id === $.jstree.root);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4149 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4150 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4151 // clean old parent and up
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4152 tmp = obj.children_d.concat();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4153 tmp.push(obj.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4154 for(i = 0, j = obj.parents.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4155 dpc = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4156 p = old_ins._model.data[obj.parents[i]].children_d;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4157 for(k = 0, l = p.length; k < l; k++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4158 if($.inArray(p[k], tmp) === -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4159 dpc.push(p[k]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4160 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4161 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4162 old_ins._model.data[obj.parents[i]].children_d = dpc;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4163 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4164 old_ins._model.data[old_par].children = $.vakata.array_remove_item(old_ins._model.data[old_par].children, obj.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4165
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4166 // insert into new parent and up
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4167 for(i = 0, j = new_par.parents.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4168 this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4169 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4170 dpc = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4171 for(i = 0, j = new_par.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4172 dpc[i >= pos ? i+1 : i] = new_par.children[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4173 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4174 dpc[pos] = obj.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4175 new_par.children = dpc;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4176 new_par.children_d.push(obj.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4177 new_par.children_d = new_par.children_d.concat(obj.children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4178
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4179 // update object
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4180 obj.parent = new_par.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4181 tmp = new_par.parents.concat();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4182 tmp.unshift(new_par.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4183 p = obj.parents.length;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4184 obj.parents = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4185
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4186 // update object children
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4187 tmp = tmp.concat();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4188 for(i = 0, j = obj.children_d.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4189 this._model.data[obj.children_d[i]].parents = this._model.data[obj.children_d[i]].parents.slice(0,p*-1);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4190 Array.prototype.push.apply(this._model.data[obj.children_d[i]].parents, tmp);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4191 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4192
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4193 if(old_par === $.jstree.root || new_par.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4194 this._model.force_full_redraw = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4195 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4196 if(!this._model.force_full_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4197 this._node_changed(old_par);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4198 this._node_changed(new_par.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4199 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4200 if(!skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4201 this.redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4202 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4203 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4204 if(callback) { callback.call(this, obj, new_par, pos); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4205 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4206 * triggered when a node is moved
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4207 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4208 * @name move_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4209 * @param {Object} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4210 * @param {String} parent the parent's ID
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4211 * @param {Number} position the position of the node among the parent's children
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4212 * @param {String} old_parent the old parent of the node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4213 * @param {Number} old_position the old position of the node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4214 * @param {Boolean} is_multi do the node and new parent belong to different instances
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4215 * @param {jsTree} old_instance the instance the node came from
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4216 * @param {jsTree} new_instance the instance of the new parent
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4217 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4218 this.trigger('move_node', { "node" : obj, "parent" : new_par.id, "position" : pos, "old_parent" : old_par, "old_position" : old_pos, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id), 'old_instance' : old_ins, 'new_instance' : this });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4219 return obj.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4220 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4221 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4222 * copy a node to a new parent
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4223 * @name copy_node(obj, par [, pos, callback, is_loaded])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4224 * @param {mixed} obj the node to copy, pass an array to copy multiple nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4225 * @param {mixed} par the new parent
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4226 * @param {mixed} pos the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer `0`
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4227 * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4228 * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4229 * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4230 * @param {Boolean} instance internal parameter indicating if the node comes from another instance
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4231 * @trigger model.jstree copy_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4232 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4233 copy_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4234 var t1, t2, dpc, tmp, i, j, node, old_par, new_par, old_ins, is_multi;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4235
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4236 par = this.get_node(par);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4237 pos = pos === undefined ? 0 : pos;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4238 if(!par) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4239 if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4240 return this.load_node(par, function () { this.copy_node(obj, par, pos, callback, true, false, origin); });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4241 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4242
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4243 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4244 if(obj.length === 1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4245 obj = obj[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4246 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4247 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4248 //obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4249 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4250 if((tmp = this.copy_node(obj[t1], par, pos, callback, is_loaded, true, origin))) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4251 par = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4252 pos = "after";
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4253 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4254 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4255 this.redraw();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4256 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4257 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4258 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4259 obj = obj && obj.id ? obj : this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4260 if(!obj || obj.id === $.jstree.root) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4261
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4262 old_par = (obj.parent || $.jstree.root).toString();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4263 new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4264 old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4265 is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4266
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4267 if(old_ins && old_ins._id) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4268 obj = old_ins._model.data[obj.id];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4269 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4270
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4271 if(par.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4272 if(pos === "before") { pos = "first"; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4273 if(pos === "after") { pos = "last"; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4274 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4275 switch(pos) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4276 case "before":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4277 pos = $.inArray(par.id, new_par.children);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4278 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4279 case "after" :
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4280 pos = $.inArray(par.id, new_par.children) + 1;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4281 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4282 case "inside":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4283 case "first":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4284 pos = 0;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4285 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4286 case "last":
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4287 pos = new_par.children.length;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4288 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4289 default:
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4290 if(!pos) { pos = 0; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4291 break;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4292 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4293 if(pos > new_par.children.length) { pos = new_par.children.length; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4294 if(!this.check("copy_node", obj, new_par, pos, { 'core' : true, 'origin' : origin, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id) })) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4295 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4296 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4297 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4298 node = old_ins ? old_ins.get_json(obj, { no_id : true, no_data : true, no_state : true }) : obj;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4299 if(!node) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4300 if(node.id === true) { delete node.id; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4301 node = this._parse_model_from_json(node, new_par.id, new_par.parents.concat());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4302 if(!node) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4303 tmp = this.get_node(node);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4304 if(obj && obj.state && obj.state.loaded === false) { tmp.state.loaded = false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4305 dpc = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4306 dpc.push(node);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4307 dpc = dpc.concat(tmp.children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4308 this.trigger('model', { "nodes" : dpc, "parent" : new_par.id });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4309
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4310 // insert into new parent and up
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4311 for(i = 0, j = new_par.parents.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4312 this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(dpc);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4313 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4314 dpc = [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4315 for(i = 0, j = new_par.children.length; i < j; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4316 dpc[i >= pos ? i+1 : i] = new_par.children[i];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4317 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4318 dpc[pos] = tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4319 new_par.children = dpc;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4320 new_par.children_d.push(tmp.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4321 new_par.children_d = new_par.children_d.concat(tmp.children_d);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4322
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4323 if(new_par.id === $.jstree.root) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4324 this._model.force_full_redraw = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4325 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4326 if(!this._model.force_full_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4327 this._node_changed(new_par.id);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4328 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4329 if(!skip_redraw) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4330 this.redraw(new_par.id === $.jstree.root);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4331 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4332 if(callback) { callback.call(this, tmp, new_par, pos); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4333 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4334 * triggered when a node is copied
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4335 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4336 * @name copy_node.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4337 * @param {Object} node the copied node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4338 * @param {Object} original the original node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4339 * @param {String} parent the parent's ID
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4340 * @param {Number} position the position of the node among the parent's children
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4341 * @param {String} old_parent the old parent of the node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4342 * @param {Number} old_position the position of the original node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4343 * @param {Boolean} is_multi do the node and new parent belong to different instances
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4344 * @param {jsTree} old_instance the instance the node came from
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4345 * @param {jsTree} new_instance the instance of the new parent
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4346 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4347 this.trigger('copy_node', { "node" : tmp, "original" : obj, "parent" : new_par.id, "position" : pos, "old_parent" : old_par, "old_position" : old_ins && old_ins._id && old_par && old_ins._model.data[old_par] && old_ins._model.data[old_par].children ? $.inArray(obj.id, old_ins._model.data[old_par].children) : -1,'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id), 'old_instance' : old_ins, 'new_instance' : this });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4348 return tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4349 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4350 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4351 * cut a node (a later call to `paste(obj)` would move the node)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4352 * @name cut(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4353 * @param {mixed} obj multiple objects can be passed using an array
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4354 * @trigger cut.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4355 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4356 cut : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4357 if(!obj) { obj = this._data.core.selected.concat(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4358 if(!$.isArray(obj)) { obj = [obj]; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4359 if(!obj.length) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4360 var tmp = [], o, t1, t2;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4361 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4362 o = this.get_node(obj[t1]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4363 if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4364 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4365 if(!tmp.length) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4366 ccp_node = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4367 ccp_inst = this;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4368 ccp_mode = 'move_node';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4369 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4370 * triggered when nodes are added to the buffer for moving
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4371 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4372 * @name cut.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4373 * @param {Array} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4374 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4375 this.trigger('cut', { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4376 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4377 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4378 * copy a node (a later call to `paste(obj)` would copy the node)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4379 * @name copy(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4380 * @param {mixed} obj multiple objects can be passed using an array
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4381 * @trigger copy.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4382 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4383 copy : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4384 if(!obj) { obj = this._data.core.selected.concat(); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4385 if(!$.isArray(obj)) { obj = [obj]; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4386 if(!obj.length) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4387 var tmp = [], o, t1, t2;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4388 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4389 o = this.get_node(obj[t1]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4390 if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4391 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4392 if(!tmp.length) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4393 ccp_node = tmp;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4394 ccp_inst = this;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4395 ccp_mode = 'copy_node';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4396 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4397 * triggered when nodes are added to the buffer for copying
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4398 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4399 * @name copy.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4400 * @param {Array} node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4401 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4402 this.trigger('copy', { "node" : obj });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4403 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4404 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4405 * get the current buffer (any nodes that are waiting for a paste operation)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4406 * @name get_buffer()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4407 * @return {Object} an object consisting of `mode` ("copy_node" or "move_node"), `node` (an array of objects) and `inst` (the instance)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4408 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4409 get_buffer : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4410 return { 'mode' : ccp_mode, 'node' : ccp_node, 'inst' : ccp_inst };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4411 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4412 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4413 * check if there is something in the buffer to paste
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4414 * @name can_paste()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4415 * @return {Boolean}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4416 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4417 can_paste : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4418 return ccp_mode !== false && ccp_node !== false; // && ccp_inst._model.data[ccp_node];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4419 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4420 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4421 * copy or move the previously cut or copied nodes to a new parent
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4422 * @name paste(obj [, pos])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4423 * @param {mixed} obj the new parent
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4424 * @param {mixed} pos the position to insert at (besides integer, "first" and "last" are supported), defaults to integer `0`
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4425 * @trigger paste.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4426 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4427 paste : function (obj, pos) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4428 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4429 if(!obj || !ccp_mode || !ccp_mode.match(/^(copy_node|move_node)$/) || !ccp_node) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4430 if(this[ccp_mode](ccp_node, obj, pos, false, false, false, ccp_inst)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4431 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4432 * triggered when paste is invoked
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4433 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4434 * @name paste.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4435 * @param {String} parent the ID of the receiving node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4436 * @param {Array} node the nodes in the buffer
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4437 * @param {String} mode the performed operation - "copy_node" or "move_node"
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4438 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4439 this.trigger('paste', { "parent" : obj.id, "node" : ccp_node, "mode" : ccp_mode });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4440 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4441 ccp_node = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4442 ccp_mode = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4443 ccp_inst = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4444 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4445 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4446 * clear the buffer of previously copied or cut nodes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4447 * @name clear_buffer()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4448 * @trigger clear_buffer.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4449 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4450 clear_buffer : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4451 ccp_node = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4452 ccp_mode = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4453 ccp_inst = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4454 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4455 * triggered when the copy / cut buffer is cleared
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4456 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4457 * @name clear_buffer.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4458 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4459 this.trigger('clear_buffer');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4460 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4461 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4462 * put a node in edit mode (input field to rename the node)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4463 * @name edit(obj [, default_text, callback])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4464 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4465 * @param {String} default_text the text to populate the input with (if omitted or set to a non-string value the node's text value is used)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4466 * @param {Function} callback a function to be called once the text box is blurred, it is called in the instance's scope and receives the node, a status parameter (true if the rename is successful, false otherwise) and a boolean indicating if the user cancelled the edit. You can access the node's title using .text
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4467 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4468 edit : function (obj, default_text, callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4469 var rtl, w, a, s, t, h1, h2, fn, tmp, cancel = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4470 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4471 if(!obj) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4472 if(!this.check("edit", obj, this.get_parent(obj))) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4473 this.settings.core.error.call(this, this._data.core.last_error);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4474 return false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4475 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4476 tmp = obj;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4477 default_text = typeof default_text === 'string' ? default_text : obj.text;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4478 this.set_text(obj, "");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4479 obj = this._open_to(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4480 tmp.text = default_text;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4481
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4482 rtl = this._data.core.rtl;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4483 w = this.element.width();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4484 this._data.core.focused = tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4485 a = obj.children('.jstree-anchor').focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4486 s = $('<span>');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4487 /*!
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4488 oi = obj.children("i:visible"),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4489 ai = a.children("i:visible"),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4490 w1 = oi.width() * oi.length,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4491 w2 = ai.width() * ai.length,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4492 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4493 t = default_text;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4494 h1 = $("<"+"div />", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo("body");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4495 h2 = $("<"+"input />", {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4496 "value" : t,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4497 "class" : "jstree-rename-input",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4498 // "size" : t.length,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4499 "css" : {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4500 "padding" : "0",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4501 "border" : "1px solid silver",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4502 "box-sizing" : "border-box",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4503 "display" : "inline-block",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4504 "height" : (this._data.core.li_height) + "px",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4505 "lineHeight" : (this._data.core.li_height) + "px",
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4506 "width" : "150px" // will be set a bit further down
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4507 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4508 "blur" : $.proxy(function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4509 e.stopImmediatePropagation();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4510 e.preventDefault();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4511 var i = s.children(".jstree-rename-input"),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4512 v = i.val(),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4513 f = this.settings.core.force_text,
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4514 nv;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4515 if(v === "") { v = t; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4516 h1.remove();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4517 s.replaceWith(a);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4518 s.remove();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4519 t = f ? t : $('<div></div>').append($.parseHTML(t)).html();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4520 this.set_text(obj, t);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4521 nv = !!this.rename_node(obj, f ? $('<div></div>').text(v).text() : $('<div></div>').append($.parseHTML(v)).html());
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4522 if(!nv) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4523 this.set_text(obj, t); // move this up? and fix #483
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4524 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4525 this._data.core.focused = tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4526 setTimeout($.proxy(function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4527 var node = this.get_node(tmp.id, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4528 if(node.length) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4529 this._data.core.focused = tmp.id;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4530 node.children('.jstree-anchor').focus();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4531 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4532 }, this), 0);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4533 if(callback) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4534 callback.call(this, tmp, nv, cancel);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4535 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4536 h2 = null;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4537 }, this),
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4538 "keydown" : function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4539 var key = e.which;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4540 if(key === 27) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4541 cancel = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4542 this.value = t;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4543 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4544 if(key === 27 || key === 13 || key === 37 || key === 38 || key === 39 || key === 40 || key === 32) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4545 e.stopImmediatePropagation();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4546 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4547 if(key === 27 || key === 13) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4548 e.preventDefault();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4549 this.blur();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4550 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4551 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4552 "click" : function (e) { e.stopImmediatePropagation(); },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4553 "mousedown" : function (e) { e.stopImmediatePropagation(); },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4554 "keyup" : function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4555 h2.width(Math.min(h1.text("pW" + this.value).width(),w));
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4556 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4557 "keypress" : function(e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4558 if(e.which === 13) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4559 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4560 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4561 fn = {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4562 fontFamily : a.css('fontFamily') || '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4563 fontSize : a.css('fontSize') || '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4564 fontWeight : a.css('fontWeight') || '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4565 fontStyle : a.css('fontStyle') || '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4566 fontStretch : a.css('fontStretch') || '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4567 fontVariant : a.css('fontVariant') || '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4568 letterSpacing : a.css('letterSpacing') || '',
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4569 wordSpacing : a.css('wordSpacing') || ''
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4570 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4571 s.attr('class', a.attr('class')).append(a.contents().clone()).append(h2);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4572 a.replaceWith(s);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4573 h1.css(fn);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4574 h2.css(fn).width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4575 $(document).one('mousedown.jstree touchstart.jstree dnd_start.vakata', function (e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4576 if (h2 && e.target !== h2) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4577 $(h2).blur();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4578 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4579 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4580 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4581
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4582
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4583 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4584 * changes the theme
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4585 * @name set_theme(theme_name [, theme_url])
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4586 * @param {String} theme_name the name of the new theme to apply
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4587 * @param {mixed} theme_url the location of the CSS file for this theme. Omit or set to `false` if you manually included the file. Set to `true` to autoload from the `core.themes.dir` directory.
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4588 * @trigger set_theme.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4589 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4590 set_theme : function (theme_name, theme_url) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4591 if(!theme_name) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4592 if(theme_url === true) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4593 var dir = this.settings.core.themes.dir;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4594 if(!dir) { dir = $.jstree.path + '/themes'; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4595 theme_url = dir + '/' + theme_name + '/style.css';
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4596 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4597 if(theme_url && $.inArray(theme_url, themes_loaded) === -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4598 $('head').append('<'+'link rel="stylesheet" href="' + theme_url + '" type="text/css" />');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4599 themes_loaded.push(theme_url);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4600 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4601 if(this._data.core.themes.name) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4602 this.element.removeClass('jstree-' + this._data.core.themes.name);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4603 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4604 this._data.core.themes.name = theme_name;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4605 this.element.addClass('jstree-' + theme_name);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4606 this.element[this.settings.core.themes.responsive ? 'addClass' : 'removeClass' ]('jstree-' + theme_name + '-responsive');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4607 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4608 * triggered when a theme is set
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4609 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4610 * @name set_theme.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4611 * @param {String} theme the new theme
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4612 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4613 this.trigger('set_theme', { 'theme' : theme_name });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4614 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4615 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4616 * gets the name of the currently applied theme name
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4617 * @name get_theme()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4618 * @return {String}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4619 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4620 get_theme : function () { return this._data.core.themes.name; },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4621 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4622 * changes the theme variant (if the theme has variants)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4623 * @name set_theme_variant(variant_name)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4624 * @param {String|Boolean} variant_name the variant to apply (if `false` is used the current variant is removed)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4625 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4626 set_theme_variant : function (variant_name) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4627 if(this._data.core.themes.variant) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4628 this.element.removeClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4629 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4630 this._data.core.themes.variant = variant_name;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4631 if(variant_name) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4632 this.element.addClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4633 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4634 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4635 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4636 * gets the name of the currently applied theme variant
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4637 * @name get_theme()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4638 * @return {String}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4639 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4640 get_theme_variant : function () { return this._data.core.themes.variant; },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4641 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4642 * shows a striped background on the container (if the theme supports it)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4643 * @name show_stripes()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4644 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4645 show_stripes : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4646 this._data.core.themes.stripes = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4647 this.get_container_ul().addClass("jstree-striped");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4648 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4649 * triggered when stripes are shown
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4650 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4651 * @name show_stripes.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4652 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4653 this.trigger('show_stripes');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4654 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4655 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4656 * hides the striped background on the container
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4657 * @name hide_stripes()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4658 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4659 hide_stripes : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4660 this._data.core.themes.stripes = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4661 this.get_container_ul().removeClass("jstree-striped");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4662 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4663 * triggered when stripes are hidden
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4664 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4665 * @name hide_stripes.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4666 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4667 this.trigger('hide_stripes');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4668 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4669 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4670 * toggles the striped background on the container
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4671 * @name toggle_stripes()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4672 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4673 toggle_stripes : function () { if(this._data.core.themes.stripes) { this.hide_stripes(); } else { this.show_stripes(); } },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4674 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4675 * shows the connecting dots (if the theme supports it)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4676 * @name show_dots()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4677 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4678 show_dots : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4679 this._data.core.themes.dots = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4680 this.get_container_ul().removeClass("jstree-no-dots");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4681 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4682 * triggered when dots are shown
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4683 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4684 * @name show_dots.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4685 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4686 this.trigger('show_dots');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4687 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4688 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4689 * hides the connecting dots
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4690 * @name hide_dots()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4691 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4692 hide_dots : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4693 this._data.core.themes.dots = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4694 this.get_container_ul().addClass("jstree-no-dots");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4695 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4696 * triggered when dots are hidden
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4697 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4698 * @name hide_dots.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4699 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4700 this.trigger('hide_dots');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4701 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4702 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4703 * toggles the connecting dots
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4704 * @name toggle_dots()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4705 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4706 toggle_dots : function () { if(this._data.core.themes.dots) { this.hide_dots(); } else { this.show_dots(); } },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4707 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4708 * show the node icons
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4709 * @name show_icons()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4710 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4711 show_icons : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4712 this._data.core.themes.icons = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4713 this.get_container_ul().removeClass("jstree-no-icons");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4714 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4715 * triggered when icons are shown
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4716 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4717 * @name show_icons.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4718 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4719 this.trigger('show_icons');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4720 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4721 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4722 * hide the node icons
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4723 * @name hide_icons()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4724 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4725 hide_icons : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4726 this._data.core.themes.icons = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4727 this.get_container_ul().addClass("jstree-no-icons");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4728 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4729 * triggered when icons are hidden
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4730 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4731 * @name hide_icons.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4732 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4733 this.trigger('hide_icons');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4734 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4735 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4736 * toggle the node icons
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4737 * @name toggle_icons()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4738 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4739 toggle_icons : function () { if(this._data.core.themes.icons) { this.hide_icons(); } else { this.show_icons(); } },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4740 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4741 * show the node ellipsis
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4742 * @name show_icons()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4743 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4744 show_ellipsis : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4745 this._data.core.themes.ellipsis = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4746 this.get_container_ul().addClass("jstree-ellipsis");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4747 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4748 * triggered when ellisis is shown
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4749 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4750 * @name show_ellipsis.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4751 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4752 this.trigger('show_ellipsis');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4753 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4754 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4755 * hide the node ellipsis
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4756 * @name hide_ellipsis()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4757 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4758 hide_ellipsis : function () {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4759 this._data.core.themes.ellipsis = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4760 this.get_container_ul().removeClass("jstree-ellipsis");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4761 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4762 * triggered when ellisis is hidden
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4763 * @event
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4764 * @name hide_ellipsis.jstree
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4765 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4766 this.trigger('hide_ellipsis');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4767 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4768 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4769 * toggle the node ellipsis
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4770 * @name toggle_icons()
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4771 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4772 toggle_ellipsis : function () { if(this._data.core.themes.ellipsis) { this.hide_ellipsis(); } else { this.show_ellipsis(); } },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4773 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4774 * set the node icon for a node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4775 * @name set_icon(obj, icon)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4776 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4777 * @param {String} icon the new icon - can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4778 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4779 set_icon : function (obj, icon) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4780 var t1, t2, dom, old;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4781 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4782 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4783 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4784 this.set_icon(obj[t1], icon);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4785 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4786 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4787 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4788 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4789 if(!obj || obj.id === $.jstree.root) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4790 old = obj.icon;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4791 obj.icon = icon === true || icon === null || icon === undefined || icon === '' ? true : icon;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4792 dom = this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4793 if(icon === false) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4794 dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4795 this.hide_icon(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4796 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4797 else if(icon === true || icon === null || icon === undefined || icon === '') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4798 dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4799 if(old === false) { this.show_icon(obj); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4800 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4801 else if(icon.indexOf("/") === -1 && icon.indexOf(".") === -1) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4802 dom.removeClass(old).css("background","");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4803 dom.addClass(icon + ' jstree-themeicon-custom').attr("rel",icon);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4804 if(old === false) { this.show_icon(obj); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4805 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4806 else {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4807 dom.removeClass(old).css("background","");
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4808 dom.addClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4809 if(old === false) { this.show_icon(obj); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4810 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4811 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4812 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4813 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4814 * get the node icon for a node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4815 * @name get_icon(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4816 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4817 * @return {String}
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4818 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4819 get_icon : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4820 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4821 return (!obj || obj.id === $.jstree.root) ? false : obj.icon;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4822 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4823 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4824 * hide the icon on an individual node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4825 * @name hide_icon(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4826 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4827 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4828 hide_icon : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4829 var t1, t2;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4830 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4831 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4832 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4833 this.hide_icon(obj[t1]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4834 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4835 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4836 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4837 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4838 if(!obj || obj === $.jstree.root) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4839 obj.icon = false;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4840 this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon").addClass('jstree-themeicon-hidden');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4841 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4842 },
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4843 /**
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4844 * show the icon on an individual node
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4845 * @name show_icon(obj)
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4846 * @param {mixed} obj
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4847 */
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4848 show_icon : function (obj) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4849 var t1, t2, dom;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4850 if($.isArray(obj)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4851 obj = obj.slice();
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4852 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4853 this.show_icon(obj[t1]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4854 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4855 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4856 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4857 obj = this.get_node(obj);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4858 if(!obj || obj === $.jstree.root) { return false; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4859 dom = this.get_node(obj, true);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4860 obj.icon = dom.length ? dom.children(".jstree-anchor").children(".jstree-themeicon").attr('rel') : true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4861 if(!obj.icon) { obj.icon = true; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4862 dom.children(".jstree-anchor").children(".jstree-themeicon").removeClass('jstree-themeicon-hidden');
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4863 return true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4864 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4865 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4866
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4867 // helpers
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4868 $.vakata = {};
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4869 // collect attributes
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4870 $.vakata.attributes = function(node, with_values) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4871 node = $(node)[0];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4872 var attr = with_values ? {} : [];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4873 if(node && node.attributes) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4874 $.each(node.attributes, function (i, v) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4875 if($.inArray(v.name.toLowerCase(),['style','contenteditable','hasfocus','tabindex']) !== -1) { return; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4876 if(v.value !== null && $.trim(v.value) !== '') {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4877 if(with_values) { attr[v.name] = v.value; }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4878 else { attr.push(v.name); }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4879 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4880 });
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4881 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4882 return attr;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4883 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4884 $.vakata.array_unique = function(array) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4885 var a = [], i, j, l, o = {};
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4886 for(i = 0, l = array.length; i < l; i++) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4887 if(o[array[i]] === undefined) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4888 a.push(array[i]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4889 o[array[i]] = true;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4890 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4891 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4892 return a;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4893 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4894 // remove item from array
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4895 $.vakata.array_remove = function(array, from) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4896 array.splice(from, 1);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4897 return array;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4898 //var rest = array.slice((to || from) + 1 || array.length);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4899 //array.length = from < 0 ? array.length + from : from;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4900 //array.push.apply(array, rest);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4901 //return array;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4902 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4903 // remove item from array
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4904 $.vakata.array_remove_item = function(array, item) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4905 var tmp = $.inArray(item, array);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4906 return tmp !== -1 ? $.vakata.array_remove(array, tmp) : array;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4907 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4908 $.vakata.array_filter = function(c,a,b,d,e) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4909 if (c.filter) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4910 return c.filter(a, b);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4911 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4912 d=[];
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4913 for (e in c) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4914 if (~~e+''===e+'' && e>=0 && a.call(b,c[e],+e,c)) {
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4915 d.push(c[e]);
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4916 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4917 }
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4918 return d;
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4919 };
c12e291895ff planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff changeset
4920 }));