sequenceserver 2.0.0.rc8 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/bin/sequenceserver +22 -30
  3. data/lib/sequenceserver/api_errors.rb +5 -1
  4. data/lib/sequenceserver/blast/constants.rb +1 -1
  5. data/lib/sequenceserver/blast/hit.rb +5 -16
  6. data/lib/sequenceserver/blast/job.rb +9 -18
  7. data/lib/sequenceserver/blast/report.rb +5 -3
  8. data/lib/sequenceserver/config.rb +4 -1
  9. data/lib/sequenceserver/database.rb +69 -9
  10. data/lib/sequenceserver/job.rb +1 -1
  11. data/lib/sequenceserver/makeblastdb.rb +40 -45
  12. data/lib/sequenceserver/routes.rb +4 -0
  13. data/lib/sequenceserver/version.rb +1 -1
  14. data/lib/sequenceserver.rb +15 -11
  15. data/public/config.js +143 -142
  16. data/public/css/fonts.css +23 -22
  17. data/public/css/grapher.css +598 -594
  18. data/public/css/sequenceserver.css +86 -24
  19. data/public/css/sequenceserver.min.css +2 -2
  20. data/public/js/alignment_exporter.js +14 -14
  21. data/public/js/databases_tree.js +215 -0
  22. data/public/js/download_fasta.js +1 -1
  23. data/public/js/hit.js +6 -2
  24. data/public/js/hits_overview.js +1 -1
  25. data/public/js/length_distribution.js +5 -5
  26. data/public/js/query.js +4 -7
  27. data/public/js/report.js +12 -24
  28. data/public/js/search.js +21 -2
  29. data/public/js/sidebar.js +4 -4
  30. data/public/js/svgExporter.js +12 -12
  31. data/public/js/visualisation_helpers.js +4 -5
  32. data/public/sequenceserver-report.min.js +11 -11
  33. data/public/sequenceserver-search.min.js +15 -11
  34. data/public/vendor/github/vakata/jstree@3.3.8/LICENSE-MIT +22 -0
  35. data/public/vendor/github/vakata/jstree@3.3.8/README.md +663 -0
  36. data/public/vendor/github/vakata/jstree@3.3.8/bower.json +33 -0
  37. data/public/vendor/github/vakata/jstree@3.3.8/component.json +28 -0
  38. data/public/vendor/github/vakata/jstree@3.3.8/composer.json +46 -0
  39. data/public/vendor/github/vakata/jstree@3.3.8/demo/README.md +2 -0
  40. data/public/vendor/github/vakata/jstree@3.3.8/demo/basic/index.html +146 -0
  41. data/public/vendor/github/vakata/jstree@3.3.8/demo/basic/root.json +1 -0
  42. data/public/vendor/github/vakata/jstree@3.3.8/dist/jstree.js +8612 -0
  43. data/public/vendor/github/vakata/jstree@3.3.8/dist/jstree.min.js +6 -0
  44. data/public/vendor/github/vakata/jstree@3.3.8/dist/themes/default/32px.png +0 -0
  45. data/public/vendor/github/vakata/jstree@3.3.8/dist/themes/default/40px.png +0 -0
  46. data/public/vendor/github/vakata/jstree@3.3.8/dist/themes/default/style.css +1102 -0
  47. data/public/vendor/github/vakata/jstree@3.3.8/dist/themes/default/style.min.css +1 -0
  48. data/public/vendor/github/vakata/jstree@3.3.8/dist/themes/default/throbber.gif +0 -0
  49. data/public/vendor/github/vakata/jstree@3.3.8/dist/themes/default-dark/32px.png +0 -0
  50. data/public/vendor/github/vakata/jstree@3.3.8/dist/themes/default-dark/40px.png +0 -0
  51. data/public/vendor/github/vakata/jstree@3.3.8/dist/themes/default-dark/style.css +1146 -0
  52. data/public/vendor/github/vakata/jstree@3.3.8/dist/themes/default-dark/style.min.css +1 -0
  53. data/public/vendor/github/vakata/jstree@3.3.8/dist/themes/default-dark/throbber.gif +0 -0
  54. data/public/vendor/github/vakata/jstree@3.3.8/gruntfile.js +242 -0
  55. data/public/vendor/github/vakata/jstree@3.3.8/jstree.jquery.json +28 -0
  56. data/public/vendor/github/vakata/jstree@3.3.8/package.json +58 -0
  57. data/public/vendor/github/vakata/jstree@3.3.8/src/intro.js +14 -0
  58. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.changed.js +69 -0
  59. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.checkbox.js +976 -0
  60. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.conditionalselect.js +38 -0
  61. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.contextmenu.js +661 -0
  62. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.dnd.js +669 -0
  63. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.js +4931 -0
  64. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.massload.js +137 -0
  65. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.search.js +421 -0
  66. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.sort.js +74 -0
  67. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.state.js +138 -0
  68. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.types.js +372 -0
  69. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.unique.js +164 -0
  70. data/public/vendor/github/vakata/jstree@3.3.8/src/jstree.wholerow.js +122 -0
  71. data/public/vendor/github/vakata/jstree@3.3.8/src/misc.js +656 -0
  72. data/public/vendor/github/vakata/jstree@3.3.8/src/outro.js +1 -0
  73. data/public/vendor/github/vakata/jstree@3.3.8/src/sample.js +93 -0
  74. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/base.less +93 -0
  75. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/default/32px.png +0 -0
  76. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/default/40px.png +0 -0
  77. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/default/style.css +1102 -0
  78. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/default/style.less +22 -0
  79. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/default/throbber.gif +0 -0
  80. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/default-dark/32px.png +0 -0
  81. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/default-dark/40px.png +0 -0
  82. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/default-dark/style.css +1146 -0
  83. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/default-dark/style.less +50 -0
  84. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/default-dark/throbber.gif +0 -0
  85. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/main.less +77 -0
  86. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/mixins.less +104 -0
  87. data/public/vendor/github/vakata/jstree@3.3.8/src/themes/responsive.less +67 -0
  88. data/public/vendor/github/vakata/jstree@3.3.8/src/vakata-jstree.js +38 -0
  89. data/public/vendor/github/vakata/jstree@3.3.8/test/unit/index.html +16 -0
  90. data/public/vendor/github/vakata/jstree@3.3.8/test/unit/libs/qunit.css +244 -0
  91. data/public/vendor/github/vakata/jstree@3.3.8/test/unit/libs/qunit.js +2212 -0
  92. data/public/vendor/github/vakata/jstree@3.3.8/test/unit/test.js +11 -0
  93. data/public/vendor/github/vakata/jstree@3.3.8/test/visual/desktop/index.html +44 -0
  94. data/public/vendor/github/vakata/jstree@3.3.8/test/visual/mobile/index.html +42 -0
  95. data/public/vendor/github/vakata/jstree@3.3.8/test/visual/screenshots/desktop/desktop.png +0 -0
  96. data/public/vendor/github/vakata/jstree@3.3.8/test/visual/screenshots/desktop/home.png +0 -0
  97. data/public/vendor/github/vakata/jstree@3.3.8/test/visual/screenshots/mobile/home.png +0 -0
  98. data/public/vendor/github/vakata/jstree@3.3.8/test/visual/screenshots/mobile/mobile.png +0 -0
  99. data/public/vendor/github/vakata/jstree@3.3.8.js +3 -0
  100. data/public/vendor/system-csp-production.js +3 -3
  101. data/public/vendor/system-csp-production.js.map +1 -1
  102. data/public/vendor/system-csp-production.src.js +146 -140
  103. data/public/vendor/system-polyfills.js.map +1 -1
  104. data/public/vendor/system-polyfills.src.js +1 -0
  105. data/public/vendor/system.js +3 -3
  106. data/public/vendor/system.js.map +1 -1
  107. data/public/vendor/system.src.js +4771 -2383
  108. data/views/_options.erb +21 -0
  109. data/views/layout.erb +17 -18
  110. metadata +102 -43
  111. data/bin/chromedriver +0 -0
  112. data/bin/geckodriver +0 -0
  113. data/public/shims/form-core.js +0 -3
  114. data/public/shims/form-validation.js +0 -3
  115. data/public/shims/plugins/jquery.ui.position.js +0 -13
  116. data/public/shims/styles/shim.css +0 -1
@@ -0,0 +1,4931 @@
1
+ /*!
2
+ * jsTree {{VERSION}}
3
+ * http://jstree.com/
4
+ *
5
+ * Copyright (c) 2014 Ivan Bozhanov (http://vakata.com)
6
+ *
7
+ * Licensed same as jquery - under the terms of the MIT License
8
+ * http://www.opensource.org/licenses/mit-license.php
9
+ */
10
+ /*!
11
+ * if using jslint please allow for the jQuery global and use following options:
12
+ * jslint: loopfunc: true, browser: true, ass: true, bitwise: true, continue: true, nomen: true, plusplus: true, regexp: true, unparam: true, todo: true, white: true
13
+ */
14
+ /*jshint -W083 */
15
+ /*globals jQuery, define, module, exports, require, window, document, postMessage */
16
+ (function (factory) {
17
+ "use strict";
18
+ if (typeof define === 'function' && define.amd) {
19
+ define(['jquery'], factory);
20
+ }
21
+ else if(typeof module !== 'undefined' && module.exports) {
22
+ module.exports = factory(require('jquery'));
23
+ }
24
+ else {
25
+ factory(jQuery);
26
+ }
27
+ }(function ($, undefined) {
28
+ "use strict";
29
+
30
+ // prevent another load? maybe there is a better way?
31
+ if($.jstree) {
32
+ return;
33
+ }
34
+
35
+ /**
36
+ * ### jsTree core functionality
37
+ */
38
+
39
+ // internal variables
40
+ var instance_counter = 0,
41
+ ccp_node = false,
42
+ ccp_mode = false,
43
+ ccp_inst = false,
44
+ themes_loaded = [],
45
+ src = $('script:last').attr('src'),
46
+ document = window.document; // local variable is always faster to access then a global
47
+
48
+ /**
49
+ * holds all jstree related functions and variables, including the actual class and methods to create, access and manipulate instances.
50
+ * @name $.jstree
51
+ */
52
+ $.jstree = {
53
+ /**
54
+ * specifies the jstree version in use
55
+ * @name $.jstree.version
56
+ */
57
+ version : '{{VERSION}}',
58
+ /**
59
+ * holds all the default options used when creating new instances
60
+ * @name $.jstree.defaults
61
+ */
62
+ defaults : {
63
+ /**
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 `[]`
65
+ * @name $.jstree.defaults.plugins
66
+ */
67
+ plugins : []
68
+ },
69
+ /**
70
+ * stores all loaded jstree plugins (used internally)
71
+ * @name $.jstree.plugins
72
+ */
73
+ plugins : {},
74
+ path : src && src.indexOf('/') !== -1 ? src.replace(/\/[^\/]+$/,'') : '',
75
+ idregex : /[\\:&!^|()\[\]<>@*'+~#";.,=\- \/${}%?`]/g,
76
+ root : '#'
77
+ };
78
+
79
+ /**
80
+ * creates a jstree instance
81
+ * @name $.jstree.create(el [, options])
82
+ * @param {DOMElement|jQuery|String} el the element to create the instance on, can be jQuery extended or a selector
83
+ * @param {Object} options options for this instance (extends `$.jstree.defaults`)
84
+ * @return {jsTree} the new instance
85
+ */
86
+ $.jstree.create = function (el, options) {
87
+ var tmp = new $.jstree.core(++instance_counter),
88
+ opt = options;
89
+ options = $.extend(true, {}, $.jstree.defaults, options);
90
+ if(opt && opt.plugins) {
91
+ options.plugins = opt.plugins;
92
+ }
93
+ $.each(options.plugins, function (i, k) {
94
+ if(i !== 'core') {
95
+ tmp = tmp.plugin(k, options[k]);
96
+ }
97
+ });
98
+ $(el).data('jstree', tmp);
99
+ tmp.init(el, options);
100
+ return tmp;
101
+ };
102
+ /**
103
+ * remove all traces of jstree from the DOM and destroy all instances
104
+ * @name $.jstree.destroy()
105
+ */
106
+ $.jstree.destroy = function () {
107
+ $('.jstree:jstree').jstree('destroy');
108
+ $(document).off('.jstree');
109
+ };
110
+ /**
111
+ * the jstree class constructor, used only internally
112
+ * @private
113
+ * @name $.jstree.core(id)
114
+ * @param {Number} id this instance's index
115
+ */
116
+ $.jstree.core = function (id) {
117
+ this._id = id;
118
+ this._cnt = 0;
119
+ this._wrk = null;
120
+ this._data = {
121
+ core : {
122
+ themes : {
123
+ name : false,
124
+ dots : false,
125
+ icons : false,
126
+ ellipsis : false
127
+ },
128
+ selected : [],
129
+ last_error : {},
130
+ working : false,
131
+ worker_queue : [],
132
+ focused : null
133
+ }
134
+ };
135
+ };
136
+ /**
137
+ * get a reference to an existing instance
138
+ *
139
+ * __Examples__
140
+ *
141
+ * // provided a container with an ID of "tree", and a nested node with an ID of "branch"
142
+ * // all of there will return the same instance
143
+ * $.jstree.reference('tree');
144
+ * $.jstree.reference('#tree');
145
+ * $.jstree.reference($('#tree'));
146
+ * $.jstree.reference(document.getElementByID('tree'));
147
+ * $.jstree.reference('branch');
148
+ * $.jstree.reference('#branch');
149
+ * $.jstree.reference($('#branch'));
150
+ * $.jstree.reference(document.getElementByID('branch'));
151
+ *
152
+ * @name $.jstree.reference(needle)
153
+ * @param {DOMElement|jQuery|String} needle
154
+ * @return {jsTree|null} the instance or `null` if not found
155
+ */
156
+ $.jstree.reference = function (needle) {
157
+ var tmp = null,
158
+ obj = null;
159
+ if(needle && needle.id && (!needle.tagName || !needle.nodeType)) { needle = needle.id; }
160
+
161
+ if(!obj || !obj.length) {
162
+ try { obj = $(needle); } catch (ignore) { }
163
+ }
164
+ if(!obj || !obj.length) {
165
+ try { obj = $('#' + needle.replace($.jstree.idregex,'\\$&')); } catch (ignore) { }
166
+ }
167
+ if(obj && obj.length && (obj = obj.closest('.jstree')).length && (obj = obj.data('jstree'))) {
168
+ tmp = obj;
169
+ }
170
+ else {
171
+ $('.jstree').each(function () {
172
+ var inst = $(this).data('jstree');
173
+ if(inst && inst._model.data[needle]) {
174
+ tmp = inst;
175
+ return false;
176
+ }
177
+ });
178
+ }
179
+ return tmp;
180
+ };
181
+ /**
182
+ * Create an instance, get an instance or invoke a command on a instance.
183
+ *
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).
185
+ *
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).
187
+ *
188
+ * If there is an existing instance and `arg` is not a string the instance itself is returned (similar to `$.jstree.reference`).
189
+ *
190
+ * In any other case - nothing is returned and chaining is not broken.
191
+ *
192
+ * __Examples__
193
+ *
194
+ * $('#tree1').jstree(); // creates an instance
195
+ * $('#tree2').jstree({ plugins : [] }); // create an instance with some options
196
+ * $('#tree1').jstree('open_node', '#branch_1'); // call a method on an existing instance, passing additional arguments
197
+ * $('#tree2').jstree(); // get an existing instance (or create an instance)
198
+ * $('#tree2').jstree(true); // get an existing instance (will not create new instance)
199
+ * $('#branch_1').jstree().select_node('#branch_1'); // get an instance (using a nested element and call a method)
200
+ *
201
+ * @name $().jstree([arg])
202
+ * @param {String|Object} arg
203
+ * @return {Mixed}
204
+ */
205
+ $.fn.jstree = function (arg) {
206
+ // check for string argument
207
+ var is_method = (typeof arg === 'string'),
208
+ args = Array.prototype.slice.call(arguments, 1),
209
+ result = null;
210
+ if(arg === true && !this.length) { return false; }
211
+ this.each(function () {
212
+ // get the instance (if there is one) and method (if it exists)
213
+ var instance = $.jstree.reference(this),
214
+ method = is_method && instance ? instance[arg] : null;
215
+ // if calling a method, and method is available - execute on the instance
216
+ result = is_method && method ?
217
+ method.apply(instance, args) :
218
+ null;
219
+ // if there is no instance and no method is being called - create one
220
+ if(!instance && !is_method && (arg === undefined || $.isPlainObject(arg))) {
221
+ $.jstree.create(this, arg);
222
+ }
223
+ // if there is an instance and no method is called - return the instance
224
+ if( (instance && !is_method) || arg === true ) {
225
+ result = instance || false;
226
+ }
227
+ // if there was a method call which returned a result - break and return the value
228
+ if(result !== null && result !== undefined) {
229
+ return false;
230
+ }
231
+ });
232
+ // if there was a method call with a valid return value - return that, otherwise continue the chain
233
+ return result !== null && result !== undefined ?
234
+ result : this;
235
+ };
236
+ /**
237
+ * used to find elements containing an instance
238
+ *
239
+ * __Examples__
240
+ *
241
+ * $('div:jstree').each(function () {
242
+ * $(this).jstree('destroy');
243
+ * });
244
+ *
245
+ * @name $(':jstree')
246
+ * @return {jQuery}
247
+ */
248
+ $.expr.pseudos.jstree = $.expr.createPseudo(function(search) {
249
+ return function(a) {
250
+ return $(a).hasClass('jstree') &&
251
+ $(a).data('jstree') !== undefined;
252
+ };
253
+ });
254
+
255
+ /**
256
+ * stores all defaults for the core
257
+ * @name $.jstree.defaults.core
258
+ */
259
+ $.jstree.defaults.core = {
260
+ /**
261
+ * data configuration
262
+ *
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).
264
+ *
265
+ * You can also pass in a HTML string or a JSON array here.
266
+ *
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.
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.
269
+ *
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.
271
+ *
272
+ * __Examples__
273
+ *
274
+ * // AJAX
275
+ * $('#tree').jstree({
276
+ * 'core' : {
277
+ * 'data' : {
278
+ * 'url' : '/get/children/',
279
+ * 'data' : function (node) {
280
+ * return { 'id' : node.id };
281
+ * }
282
+ * }
283
+ * });
284
+ *
285
+ * // direct data
286
+ * $('#tree').jstree({
287
+ * 'core' : {
288
+ * 'data' : [
289
+ * 'Simple root node',
290
+ * {
291
+ * 'id' : 'node_2',
292
+ * 'text' : 'Root node with options',
293
+ * 'state' : { 'opened' : true, 'selected' : true },
294
+ * 'children' : [ { 'text' : 'Child 1' }, 'Child 2']
295
+ * }
296
+ * ]
297
+ * }
298
+ * });
299
+ *
300
+ * // function
301
+ * $('#tree').jstree({
302
+ * 'core' : {
303
+ * 'data' : function (obj, callback) {
304
+ * callback.call(this, ['Root 1', 'Root 2']);
305
+ * }
306
+ * });
307
+ *
308
+ * @name $.jstree.defaults.core.data
309
+ */
310
+ data : false,
311
+ /**
312
+ * configure the various strings used throughout the tree
313
+ *
314
+ * You can use an object where the key is the string you need to replace and the value is your replacement.
315
+ * Another option is to specify a function which will be called with an argument of the needed string and should return the replacement.
316
+ * If left as `false` no replacement is made.
317
+ *
318
+ * __Examples__
319
+ *
320
+ * $('#tree').jstree({
321
+ * 'core' : {
322
+ * 'strings' : {
323
+ * 'Loading ...' : 'Please wait ...'
324
+ * }
325
+ * }
326
+ * });
327
+ *
328
+ * @name $.jstree.defaults.core.strings
329
+ */
330
+ strings : false,
331
+ /**
332
+ * determines what happens when a user tries to modify the structure of the tree
333
+ * If left as `false` all operations like create, rename, delete, move or copy are prevented.
334
+ * You can set this to `true` to allow all interactions or use a function to have better control.
335
+ *
336
+ * __Examples__
337
+ *
338
+ * $('#tree').jstree({
339
+ * 'core' : {
340
+ * 'check_callback' : function (operation, node, node_parent, node_position, more) {
341
+ * // operation can be 'create_node', 'rename_node', 'delete_node', 'move_node', 'copy_node' or 'edit'
342
+ * // in case of 'rename_node' node_position is filled with the new node name
343
+ * return operation === 'rename_node' ? true : false;
344
+ * }
345
+ * }
346
+ * });
347
+ *
348
+ * @name $.jstree.defaults.core.check_callback
349
+ */
350
+ check_callback : false,
351
+ /**
352
+ * a callback called with a single object parameter in the instance's scope when something goes wrong (operation prevented, ajax failed, etc)
353
+ * @name $.jstree.defaults.core.error
354
+ */
355
+ error : $.noop,
356
+ /**
357
+ * the open / close animation duration in milliseconds - set this to `false` to disable the animation (default is `200`)
358
+ * @name $.jstree.defaults.core.animation
359
+ */
360
+ animation : 200,
361
+ /**
362
+ * a boolean indicating if multiple nodes can be selected
363
+ * @name $.jstree.defaults.core.multiple
364
+ */
365
+ multiple : true,
366
+ /**
367
+ * theme configuration object
368
+ * @name $.jstree.defaults.core.themes
369
+ */
370
+ themes : {
371
+ /**
372
+ * the name of the theme to use (if left as `false` the default theme is used)
373
+ * @name $.jstree.defaults.core.themes.name
374
+ */
375
+ name : false,
376
+ /**
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.
378
+ * @name $.jstree.defaults.core.themes.url
379
+ */
380
+ url : false,
381
+ /**
382
+ * the location of all jstree themes - only used if `url` is set to `true`
383
+ * @name $.jstree.defaults.core.themes.dir
384
+ */
385
+ dir : false,
386
+ /**
387
+ * a boolean indicating if connecting dots are shown
388
+ * @name $.jstree.defaults.core.themes.dots
389
+ */
390
+ dots : true,
391
+ /**
392
+ * a boolean indicating if node icons are shown
393
+ * @name $.jstree.defaults.core.themes.icons
394
+ */
395
+ icons : true,
396
+ /**
397
+ * a boolean indicating if node ellipsis should be shown - this only works with a fixed with on the container
398
+ * @name $.jstree.defaults.core.themes.ellipsis
399
+ */
400
+ ellipsis : false,
401
+ /**
402
+ * a boolean indicating if the tree background is striped
403
+ * @name $.jstree.defaults.core.themes.stripes
404
+ */
405
+ stripes : false,
406
+ /**
407
+ * a string (or boolean `false`) specifying the theme variant to use (if the theme supports variants)
408
+ * @name $.jstree.defaults.core.themes.variant
409
+ */
410
+ variant : false,
411
+ /**
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`.
413
+ * @name $.jstree.defaults.core.themes.responsive
414
+ */
415
+ responsive : false
416
+ },
417
+ /**
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)
419
+ * @name $.jstree.defaults.core.expand_selected_onload
420
+ */
421
+ expand_selected_onload : true,
422
+ /**
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`
424
+ * @name $.jstree.defaults.core.worker
425
+ */
426
+ worker : true,
427
+ /**
428
+ * Force node text to plain text (and escape HTML). Defaults to `false`
429
+ * @name $.jstree.defaults.core.force_text
430
+ */
431
+ force_text : false,
432
+ /**
433
+ * Should the node be toggled if the text is double clicked. Defaults to `true`
434
+ * @name $.jstree.defaults.core.dblclick_toggle
435
+ */
436
+ dblclick_toggle : true,
437
+ /**
438
+ * Should the loaded nodes be part of the state. Defaults to `false`
439
+ * @name $.jstree.defaults.core.loaded_state
440
+ */
441
+ loaded_state : false,
442
+ /**
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`
444
+ * @name $.jstree.defaults.core.restore_focus
445
+ */
446
+ restore_focus : true,
447
+ /**
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)
449
+ * @name $.jstree.defaults.core.keyboard
450
+ */
451
+ keyboard : {
452
+ 'ctrl-space': function (e) {
453
+ // aria defines space only with Ctrl
454
+ e.type = "click";
455
+ $(e.currentTarget).trigger(e);
456
+ },
457
+ 'enter': function (e) {
458
+ // enter
459
+ e.type = "click";
460
+ $(e.currentTarget).trigger(e);
461
+ },
462
+ 'left': function (e) {
463
+ // left
464
+ e.preventDefault();
465
+ if(this.is_open(e.currentTarget)) {
466
+ this.close_node(e.currentTarget);
467
+ }
468
+ else {
469
+ var o = this.get_parent(e.currentTarget);
470
+ if(o && o.id !== $.jstree.root) { this.get_node(o, true).children('.jstree-anchor').focus(); }
471
+ }
472
+ },
473
+ 'up': function (e) {
474
+ // up
475
+ e.preventDefault();
476
+ var o = this.get_prev_dom(e.currentTarget);
477
+ if(o && o.length) { o.children('.jstree-anchor').focus(); }
478
+ },
479
+ 'right': function (e) {
480
+ // right
481
+ e.preventDefault();
482
+ if(this.is_closed(e.currentTarget)) {
483
+ this.open_node(e.currentTarget, function (o) { this.get_node(o, true).children('.jstree-anchor').focus(); });
484
+ }
485
+ else if (this.is_open(e.currentTarget)) {
486
+ var o = this.get_node(e.currentTarget, true).children('.jstree-children')[0];
487
+ if(o) { $(this._firstChild(o)).children('.jstree-anchor').focus(); }
488
+ }
489
+ },
490
+ 'down': function (e) {
491
+ // down
492
+ e.preventDefault();
493
+ var o = this.get_next_dom(e.currentTarget);
494
+ if(o && o.length) { o.children('.jstree-anchor').focus(); }
495
+ },
496
+ '*': function (e) {
497
+ // aria defines * on numpad as open_all - not very common
498
+ this.open_all();
499
+ },
500
+ 'home': function (e) {
501
+ // home
502
+ e.preventDefault();
503
+ var o = this._firstChild(this.get_container_ul()[0]);
504
+ if(o) { $(o).children('.jstree-anchor').filter(':visible').focus(); }
505
+ },
506
+ 'end': function (e) {
507
+ // end
508
+ e.preventDefault();
509
+ this.element.find('.jstree-anchor').filter(':visible').last().focus();
510
+ },
511
+ 'f2': function (e) {
512
+ // f2 - safe to include - if check_callback is false it will fail
513
+ e.preventDefault();
514
+ this.edit(e.currentTarget);
515
+ }
516
+ }
517
+ };
518
+ $.jstree.core.prototype = {
519
+ /**
520
+ * used to decorate an instance with a plugin. Used internally.
521
+ * @private
522
+ * @name plugin(deco [, opts])
523
+ * @param {String} deco the plugin to decorate with
524
+ * @param {Object} opts options for the plugin
525
+ * @return {jsTree}
526
+ */
527
+ plugin : function (deco, opts) {
528
+ var Child = $.jstree.plugins[deco];
529
+ if(Child) {
530
+ this._data[deco] = {};
531
+ Child.prototype = this;
532
+ return new Child(opts, this);
533
+ }
534
+ return this;
535
+ },
536
+ /**
537
+ * initialize the instance. Used internally.
538
+ * @private
539
+ * @name init(el, optons)
540
+ * @param {DOMElement|jQuery|String} el the element we are transforming
541
+ * @param {Object} options options for this instance
542
+ * @trigger init.jstree, loading.jstree, loaded.jstree, ready.jstree, changed.jstree
543
+ */
544
+ init : function (el, options) {
545
+ this._model = {
546
+ data : {},
547
+ changed : [],
548
+ force_full_redraw : false,
549
+ redraw_timeout : false,
550
+ default_state : {
551
+ loaded : true,
552
+ opened : false,
553
+ selected : false,
554
+ disabled : false
555
+ }
556
+ };
557
+ this._model.data[$.jstree.root] = {
558
+ id : $.jstree.root,
559
+ parent : null,
560
+ parents : [],
561
+ children : [],
562
+ children_d : [],
563
+ state : { loaded : false }
564
+ };
565
+
566
+ this.element = $(el).addClass('jstree jstree-' + this._id);
567
+ this.settings = options;
568
+
569
+ this._data.core.ready = false;
570
+ this._data.core.loaded = false;
571
+ this._data.core.rtl = (this.element.css("direction") === "rtl");
572
+ this.element[this._data.core.rtl ? 'addClass' : 'removeClass']("jstree-rtl");
573
+ this.element.attr('role','tree');
574
+ if(this.settings.core.multiple) {
575
+ this.element.attr('aria-multiselectable', true);
576
+ }
577
+ if(!this.element.attr('tabindex')) {
578
+ this.element.attr('tabindex','0');
579
+ }
580
+
581
+ this.bind();
582
+ /**
583
+ * triggered after all events are bound
584
+ * @event
585
+ * @name init.jstree
586
+ */
587
+ this.trigger("init");
588
+
589
+ this._data.core.original_container_html = this.element.find(" > ul > li").clone(true);
590
+ this._data.core.original_container_html
591
+ .find("li").addBack()
592
+ .contents().filter(function() {
593
+ return this.nodeType === 3 && (!this.nodeValue || /^\s+$/.test(this.nodeValue));
594
+ })
595
+ .remove();
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>");
597
+ this.element.attr('aria-activedescendant','j' + this._id + '_loading');
598
+ this._data.core.li_height = this.get_container_ul().children("li").first().outerHeight() || 24;
599
+ this._data.core.node = this._create_prototype_node();
600
+ /**
601
+ * triggered after the loading text is shown and before loading starts
602
+ * @event
603
+ * @name loading.jstree
604
+ */
605
+ this.trigger("loading");
606
+ this.load_node($.jstree.root);
607
+ },
608
+ /**
609
+ * destroy an instance
610
+ * @name destroy()
611
+ * @param {Boolean} keep_html if not set to `true` the container will be emptied, otherwise the current DOM elements will be kept intact
612
+ */
613
+ destroy : function (keep_html) {
614
+ /**
615
+ * triggered before the tree is destroyed
616
+ * @event
617
+ * @name destroy.jstree
618
+ */
619
+ this.trigger("destroy");
620
+ if(this._wrk) {
621
+ try {
622
+ window.URL.revokeObjectURL(this._wrk);
623
+ this._wrk = null;
624
+ }
625
+ catch (ignore) { }
626
+ }
627
+ if(!keep_html) { this.element.empty(); }
628
+ this.teardown();
629
+ },
630
+ /**
631
+ * Create a prototype node
632
+ * @name _create_prototype_node()
633
+ * @return {DOMElement}
634
+ */
635
+ _create_prototype_node : function () {
636
+ var _node = document.createElement('LI'), _temp1, _temp2;
637
+ _node.setAttribute('role', 'treeitem');
638
+ _temp1 = document.createElement('I');
639
+ _temp1.className = 'jstree-icon jstree-ocl';
640
+ _temp1.setAttribute('role', 'presentation');
641
+ _node.appendChild(_temp1);
642
+ _temp1 = document.createElement('A');
643
+ _temp1.className = 'jstree-anchor';
644
+ _temp1.setAttribute('href','#');
645
+ _temp1.setAttribute('tabindex','-1');
646
+ _temp2 = document.createElement('I');
647
+ _temp2.className = 'jstree-icon jstree-themeicon';
648
+ _temp2.setAttribute('role', 'presentation');
649
+ _temp1.appendChild(_temp2);
650
+ _node.appendChild(_temp1);
651
+ _temp1 = _temp2 = null;
652
+
653
+ return _node;
654
+ },
655
+ _kbevent_to_func : function (e) {
656
+ var keys = {
657
+ 8: "Backspace", 9: "Tab", 13: "Enter", 19: "Pause", 27: "Esc",
658
+ 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", 36: "Home",
659
+ 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "Print", 45: "Insert",
660
+ 46: "Delete", 96: "Numpad0", 97: "Numpad1", 98: "Numpad2", 99 : "Numpad3",
661
+ 100: "Numpad4", 101: "Numpad5", 102: "Numpad6", 103: "Numpad7",
662
+ 104: "Numpad8", 105: "Numpad9", '-13': "NumpadEnter", 112: "F1",
663
+ 113: "F2", 114: "F3", 115: "F4", 116: "F5", 117: "F6", 118: "F7",
664
+ 119: "F8", 120: "F9", 121: "F10", 122: "F11", 123: "F12", 144: "Numlock",
665
+ 145: "Scrolllock", 16: 'Shift', 17: 'Ctrl', 18: 'Alt',
666
+ 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
667
+ 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
668
+ 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
669
+ 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
670
+ 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
671
+ 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
672
+ 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
673
+ 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*', 173: '-'
674
+ };
675
+ var parts = [];
676
+ if (e.ctrlKey) { parts.push('ctrl'); }
677
+ if (e.altKey) { parts.push('alt'); }
678
+ if (e.shiftKey) { parts.push('shift'); }
679
+ parts.push(keys[e.which] || e.which);
680
+ parts = parts.sort().join('-').toLowerCase();
681
+
682
+ var kb = this.settings.core.keyboard, i, tmp;
683
+ for (i in kb) {
684
+ if (kb.hasOwnProperty(i)) {
685
+ tmp = i;
686
+ if (tmp !== '-' && tmp !== '+') {
687
+ tmp = tmp.replace('--', '-MINUS').replace('+-', '-MINUS').replace('++', '-PLUS').replace('-+', '-PLUS');
688
+ tmp = tmp.split(/-|\+/).sort().join('-').replace('MINUS', '-').replace('PLUS', '+').toLowerCase();
689
+ }
690
+ if (tmp === parts) {
691
+ return kb[i];
692
+ }
693
+ }
694
+ }
695
+ return null;
696
+ },
697
+ /**
698
+ * part of the destroying of an instance. Used internally.
699
+ * @private
700
+ * @name teardown()
701
+ */
702
+ teardown : function () {
703
+ this.unbind();
704
+ this.element
705
+ .removeClass('jstree')
706
+ .removeData('jstree')
707
+ .find("[class^='jstree']")
708
+ .addBack()
709
+ .attr("class", function () { return this.className.replace(/jstree[^ ]*|$/ig,''); });
710
+ this.element = null;
711
+ },
712
+ /**
713
+ * bind all events. Used internally.
714
+ * @private
715
+ * @name bind()
716
+ */
717
+ bind : function () {
718
+ var word = '',
719
+ tout = null,
720
+ was_click = 0;
721
+ this.element
722
+ .on("dblclick.jstree", function (e) {
723
+ if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
724
+ if(document.selection && document.selection.empty) {
725
+ document.selection.empty();
726
+ }
727
+ else {
728
+ if(window.getSelection) {
729
+ var sel = window.getSelection();
730
+ try {
731
+ sel.removeAllRanges();
732
+ sel.collapse();
733
+ } catch (ignore) { }
734
+ }
735
+ }
736
+ })
737
+ .on("mousedown.jstree", $.proxy(function (e) {
738
+ if(e.target === this.element[0]) {
739
+ e.preventDefault(); // prevent losing focus when clicking scroll arrows (FF, Chrome)
740
+ was_click = +(new Date()); // ie does not allow to prevent losing focus
741
+ }
742
+ }, this))
743
+ .on("mousedown.jstree", ".jstree-ocl", function (e) {
744
+ e.preventDefault(); // prevent any node inside from losing focus when clicking the open/close icon
745
+ })
746
+ .on("click.jstree", ".jstree-ocl", $.proxy(function (e) {
747
+ this.toggle_node(e.target);
748
+ }, this))
749
+ .on("dblclick.jstree", ".jstree-anchor", $.proxy(function (e) {
750
+ if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
751
+ if(this.settings.core.dblclick_toggle) {
752
+ this.toggle_node(e.target);
753
+ }
754
+ }, this))
755
+ .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
756
+ e.preventDefault();
757
+ if(e.currentTarget !== document.activeElement) { $(e.currentTarget).focus(); }
758
+ this.activate_node(e.currentTarget, e);
759
+ }, this))
760
+ .on('keydown.jstree', '.jstree-anchor', $.proxy(function (e) {
761
+ if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
762
+ if(this._data.core.rtl) {
763
+ if(e.which === 37) { e.which = 39; }
764
+ else if(e.which === 39) { e.which = 37; }
765
+ }
766
+ var f = this._kbevent_to_func(e);
767
+ if (f) {
768
+ var r = f.call(this, e);
769
+ if (r === false || r === true) {
770
+ return r;
771
+ }
772
+ }
773
+ }, this))
774
+ .on("load_node.jstree", $.proxy(function (e, data) {
775
+ if(data.status) {
776
+ if(data.node.id === $.jstree.root && !this._data.core.loaded) {
777
+ this._data.core.loaded = true;
778
+ if(this._firstChild(this.get_container_ul()[0])) {
779
+ this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
780
+ }
781
+ /**
782
+ * triggered after the root node is loaded for the first time
783
+ * @event
784
+ * @name loaded.jstree
785
+ */
786
+ this.trigger("loaded");
787
+ }
788
+ if(!this._data.core.ready) {
789
+ setTimeout($.proxy(function() {
790
+ if(this.element && !this.get_container_ul().find('.jstree-loading').length) {
791
+ this._data.core.ready = true;
792
+ if(this._data.core.selected.length) {
793
+ if(this.settings.core.expand_selected_onload) {
794
+ var tmp = [], i, j;
795
+ for(i = 0, j = this._data.core.selected.length; i < j; i++) {
796
+ tmp = tmp.concat(this._model.data[this._data.core.selected[i]].parents);
797
+ }
798
+ tmp = $.vakata.array_unique(tmp);
799
+ for(i = 0, j = tmp.length; i < j; i++) {
800
+ this.open_node(tmp[i], false, 0);
801
+ }
802
+ }
803
+ this.trigger('changed', { 'action' : 'ready', 'selected' : this._data.core.selected });
804
+ }
805
+ /**
806
+ * triggered after all nodes are finished loading
807
+ * @event
808
+ * @name ready.jstree
809
+ */
810
+ this.trigger("ready");
811
+ }
812
+ }, this), 0);
813
+ }
814
+ }
815
+ }, this))
816
+ // quick searching when the tree is focused
817
+ .on('keypress.jstree', $.proxy(function (e) {
818
+ if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
819
+ if(tout) { clearTimeout(tout); }
820
+ tout = setTimeout(function () {
821
+ word = '';
822
+ }, 500);
823
+
824
+ var chr = String.fromCharCode(e.which).toLowerCase(),
825
+ col = this.element.find('.jstree-anchor').filter(':visible'),
826
+ ind = col.index(document.activeElement) || 0,
827
+ end = false;
828
+ word += chr;
829
+
830
+ // match for whole word from current node down (including the current node)
831
+ if(word.length > 1) {
832
+ col.slice(ind).each($.proxy(function (i, v) {
833
+ if($(v).text().toLowerCase().indexOf(word) === 0) {
834
+ $(v).focus();
835
+ end = true;
836
+ return false;
837
+ }
838
+ }, this));
839
+ if(end) { return; }
840
+
841
+ // match for whole word from the beginning of the tree
842
+ col.slice(0, ind).each($.proxy(function (i, v) {
843
+ if($(v).text().toLowerCase().indexOf(word) === 0) {
844
+ $(v).focus();
845
+ end = true;
846
+ return false;
847
+ }
848
+ }, this));
849
+ if(end) { return; }
850
+ }
851
+ // list nodes that start with that letter (only if word consists of a single char)
852
+ if(new RegExp('^' + chr.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '+$').test(word)) {
853
+ // search for the next node starting with that letter
854
+ col.slice(ind + 1).each($.proxy(function (i, v) {
855
+ if($(v).text().toLowerCase().charAt(0) === chr) {
856
+ $(v).focus();
857
+ end = true;
858
+ return false;
859
+ }
860
+ }, this));
861
+ if(end) { return; }
862
+
863
+ // search from the beginning
864
+ col.slice(0, ind + 1).each($.proxy(function (i, v) {
865
+ if($(v).text().toLowerCase().charAt(0) === chr) {
866
+ $(v).focus();
867
+ end = true;
868
+ return false;
869
+ }
870
+ }, this));
871
+ if(end) { return; }
872
+ }
873
+ }, this))
874
+ // THEME RELATED
875
+ .on("init.jstree", $.proxy(function () {
876
+ var s = this.settings.core.themes;
877
+ this._data.core.themes.dots = s.dots;
878
+ this._data.core.themes.stripes = s.stripes;
879
+ this._data.core.themes.icons = s.icons;
880
+ this._data.core.themes.ellipsis = s.ellipsis;
881
+ this.set_theme(s.name || "default", s.url);
882
+ this.set_theme_variant(s.variant);
883
+ }, this))
884
+ .on("loading.jstree", $.proxy(function () {
885
+ this[ this._data.core.themes.dots ? "show_dots" : "hide_dots" ]();
886
+ this[ this._data.core.themes.icons ? "show_icons" : "hide_icons" ]();
887
+ this[ this._data.core.themes.stripes ? "show_stripes" : "hide_stripes" ]();
888
+ this[ this._data.core.themes.ellipsis ? "show_ellipsis" : "hide_ellipsis" ]();
889
+ }, this))
890
+ .on('blur.jstree', '.jstree-anchor', $.proxy(function (e) {
891
+ this._data.core.focused = null;
892
+ $(e.currentTarget).filter('.jstree-hovered').trigger('mouseleave');
893
+ this.element.attr('tabindex', '0');
894
+ }, this))
895
+ .on('focus.jstree', '.jstree-anchor', $.proxy(function (e) {
896
+ var tmp = this.get_node(e.currentTarget);
897
+ if(tmp && tmp.id) {
898
+ this._data.core.focused = tmp.id;
899
+ }
900
+ this.element.find('.jstree-hovered').not(e.currentTarget).trigger('mouseleave');
901
+ $(e.currentTarget).trigger('mouseenter');
902
+ this.element.attr('tabindex', '-1');
903
+ }, this))
904
+ .on('focus.jstree', $.proxy(function () {
905
+ if(+(new Date()) - was_click > 500 && !this._data.core.focused && this.settings.core.restore_focus) {
906
+ was_click = 0;
907
+ var act = this.get_node(this.element.attr('aria-activedescendant'), true);
908
+ if(act) {
909
+ act.find('> .jstree-anchor').focus();
910
+ }
911
+ }
912
+ }, this))
913
+ .on('mouseenter.jstree', '.jstree-anchor', $.proxy(function (e) {
914
+ this.hover_node(e.currentTarget);
915
+ }, this))
916
+ .on('mouseleave.jstree', '.jstree-anchor', $.proxy(function (e) {
917
+ this.dehover_node(e.currentTarget);
918
+ }, this));
919
+ },
920
+ /**
921
+ * part of the destroying of an instance. Used internally.
922
+ * @private
923
+ * @name unbind()
924
+ */
925
+ unbind : function () {
926
+ this.element.off('.jstree');
927
+ $(document).off('.jstree-' + this._id);
928
+ },
929
+ /**
930
+ * trigger an event. Used internally.
931
+ * @private
932
+ * @name trigger(ev [, data])
933
+ * @param {String} ev the name of the event to trigger
934
+ * @param {Object} data additional data to pass with the event
935
+ */
936
+ trigger : function (ev, data) {
937
+ if(!data) {
938
+ data = {};
939
+ }
940
+ data.instance = this;
941
+ this.element.triggerHandler(ev.replace('.jstree','') + '.jstree', data);
942
+ },
943
+ /**
944
+ * returns the jQuery extended instance container
945
+ * @name get_container()
946
+ * @return {jQuery}
947
+ */
948
+ get_container : function () {
949
+ return this.element;
950
+ },
951
+ /**
952
+ * returns the jQuery extended main UL node inside the instance container. Used internally.
953
+ * @private
954
+ * @name get_container_ul()
955
+ * @return {jQuery}
956
+ */
957
+ get_container_ul : function () {
958
+ return this.element.children(".jstree-children").first();
959
+ },
960
+ /**
961
+ * gets string replacements (localization). Used internally.
962
+ * @private
963
+ * @name get_string(key)
964
+ * @param {String} key
965
+ * @return {String}
966
+ */
967
+ get_string : function (key) {
968
+ var a = this.settings.core.strings;
969
+ if($.isFunction(a)) { return a.call(this, key); }
970
+ if(a && a[key]) { return a[key]; }
971
+ return key;
972
+ },
973
+ /**
974
+ * gets the first child of a DOM node. Used internally.
975
+ * @private
976
+ * @name _firstChild(dom)
977
+ * @param {DOMElement} dom
978
+ * @return {DOMElement}
979
+ */
980
+ _firstChild : function (dom) {
981
+ dom = dom ? dom.firstChild : null;
982
+ while(dom !== null && dom.nodeType !== 1) {
983
+ dom = dom.nextSibling;
984
+ }
985
+ return dom;
986
+ },
987
+ /**
988
+ * gets the next sibling of a DOM node. Used internally.
989
+ * @private
990
+ * @name _nextSibling(dom)
991
+ * @param {DOMElement} dom
992
+ * @return {DOMElement}
993
+ */
994
+ _nextSibling : function (dom) {
995
+ dom = dom ? dom.nextSibling : null;
996
+ while(dom !== null && dom.nodeType !== 1) {
997
+ dom = dom.nextSibling;
998
+ }
999
+ return dom;
1000
+ },
1001
+ /**
1002
+ * gets the previous sibling of a DOM node. Used internally.
1003
+ * @private
1004
+ * @name _previousSibling(dom)
1005
+ * @param {DOMElement} dom
1006
+ * @return {DOMElement}
1007
+ */
1008
+ _previousSibling : function (dom) {
1009
+ dom = dom ? dom.previousSibling : null;
1010
+ while(dom !== null && dom.nodeType !== 1) {
1011
+ dom = dom.previousSibling;
1012
+ }
1013
+ return dom;
1014
+ },
1015
+ /**
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)
1017
+ * @name get_node(obj [, as_dom])
1018
+ * @param {mixed} obj
1019
+ * @param {Boolean} as_dom
1020
+ * @return {Object|jQuery}
1021
+ */
1022
+ get_node : function (obj, as_dom) {
1023
+ if(obj && obj.id) {
1024
+ obj = obj.id;
1025
+ }
1026
+ if (obj instanceof $ && obj.length && obj[0].id) {
1027
+ obj = obj[0].id;
1028
+ }
1029
+ var dom;
1030
+ try {
1031
+ if(this._model.data[obj]) {
1032
+ obj = this._model.data[obj];
1033
+ }
1034
+ else if(typeof obj === "string" && this._model.data[obj.replace(/^#/, '')]) {
1035
+ obj = this._model.data[obj.replace(/^#/, '')];
1036
+ }
1037
+ else if(typeof obj === "string" && (dom = $('#' + obj.replace($.jstree.idregex,'\\$&'), this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
1038
+ obj = this._model.data[dom.closest('.jstree-node').attr('id')];
1039
+ }
1040
+ else if((dom = this.element.find(obj)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
1041
+ obj = this._model.data[dom.closest('.jstree-node').attr('id')];
1042
+ }
1043
+ else if((dom = this.element.find(obj)).length && dom.hasClass('jstree')) {
1044
+ obj = this._model.data[$.jstree.root];
1045
+ }
1046
+ else {
1047
+ return false;
1048
+ }
1049
+
1050
+ if(as_dom) {
1051
+ obj = obj.id === $.jstree.root ? this.element : $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
1052
+ }
1053
+ return obj;
1054
+ } catch (ex) { return false; }
1055
+ },
1056
+ /**
1057
+ * get the path to a node, either consisting of node texts, or of node IDs, optionally glued together (otherwise an array)
1058
+ * @name get_path(obj [, glue, ids])
1059
+ * @param {mixed} obj the node
1060
+ * @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
1061
+ * @param {Boolean} ids if set to true build the path using ID, otherwise node text is used
1062
+ * @return {mixed}
1063
+ */
1064
+ get_path : function (obj, glue, ids) {
1065
+ obj = obj.parents ? obj : this.get_node(obj);
1066
+ if(!obj || obj.id === $.jstree.root || !obj.parents) {
1067
+ return false;
1068
+ }
1069
+ var i, j, p = [];
1070
+ p.push(ids ? obj.id : obj.text);
1071
+ for(i = 0, j = obj.parents.length; i < j; i++) {
1072
+ p.push(ids ? obj.parents[i] : this.get_text(obj.parents[i]));
1073
+ }
1074
+ p = p.reverse().slice(1);
1075
+ return glue ? p.join(glue) : p;
1076
+ },
1077
+ /**
1078
+ * get the next visible node that is below the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
1079
+ * @name get_next_dom(obj [, strict])
1080
+ * @param {mixed} obj
1081
+ * @param {Boolean} strict
1082
+ * @return {jQuery}
1083
+ */
1084
+ get_next_dom : function (obj, strict) {
1085
+ var tmp;
1086
+ obj = this.get_node(obj, true);
1087
+ if(obj[0] === this.element[0]) {
1088
+ tmp = this._firstChild(this.get_container_ul()[0]);
1089
+ while (tmp && tmp.offsetHeight === 0) {
1090
+ tmp = this._nextSibling(tmp);
1091
+ }
1092
+ return tmp ? $(tmp) : false;
1093
+ }
1094
+ if(!obj || !obj.length) {
1095
+ return false;
1096
+ }
1097
+ if(strict) {
1098
+ tmp = obj[0];
1099
+ do {
1100
+ tmp = this._nextSibling(tmp);
1101
+ } while (tmp && tmp.offsetHeight === 0);
1102
+ return tmp ? $(tmp) : false;
1103
+ }
1104
+ if(obj.hasClass("jstree-open")) {
1105
+ tmp = this._firstChild(obj.children('.jstree-children')[0]);
1106
+ while (tmp && tmp.offsetHeight === 0) {
1107
+ tmp = this._nextSibling(tmp);
1108
+ }
1109
+ if(tmp !== null) {
1110
+ return $(tmp);
1111
+ }
1112
+ }
1113
+ tmp = obj[0];
1114
+ do {
1115
+ tmp = this._nextSibling(tmp);
1116
+ } while (tmp && tmp.offsetHeight === 0);
1117
+ if(tmp !== null) {
1118
+ return $(tmp);
1119
+ }
1120
+ return obj.parentsUntil(".jstree",".jstree-node").nextAll(".jstree-node:visible").first();
1121
+ },
1122
+ /**
1123
+ * get the previous visible node that is above the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
1124
+ * @name get_prev_dom(obj [, strict])
1125
+ * @param {mixed} obj
1126
+ * @param {Boolean} strict
1127
+ * @return {jQuery}
1128
+ */
1129
+ get_prev_dom : function (obj, strict) {
1130
+ var tmp;
1131
+ obj = this.get_node(obj, true);
1132
+ if(obj[0] === this.element[0]) {
1133
+ tmp = this.get_container_ul()[0].lastChild;
1134
+ while (tmp && tmp.offsetHeight === 0) {
1135
+ tmp = this._previousSibling(tmp);
1136
+ }
1137
+ return tmp ? $(tmp) : false;
1138
+ }
1139
+ if(!obj || !obj.length) {
1140
+ return false;
1141
+ }
1142
+ if(strict) {
1143
+ tmp = obj[0];
1144
+ do {
1145
+ tmp = this._previousSibling(tmp);
1146
+ } while (tmp && tmp.offsetHeight === 0);
1147
+ return tmp ? $(tmp) : false;
1148
+ }
1149
+ tmp = obj[0];
1150
+ do {
1151
+ tmp = this._previousSibling(tmp);
1152
+ } while (tmp && tmp.offsetHeight === 0);
1153
+ if(tmp !== null) {
1154
+ obj = $(tmp);
1155
+ while(obj.hasClass("jstree-open")) {
1156
+ obj = obj.children(".jstree-children").first().children(".jstree-node:visible:last");
1157
+ }
1158
+ return obj;
1159
+ }
1160
+ tmp = obj[0].parentNode.parentNode;
1161
+ return tmp && tmp.className && tmp.className.indexOf('jstree-node') !== -1 ? $(tmp) : false;
1162
+ },
1163
+ /**
1164
+ * get the parent ID of a node
1165
+ * @name get_parent(obj)
1166
+ * @param {mixed} obj
1167
+ * @return {String}
1168
+ */
1169
+ get_parent : function (obj) {
1170
+ obj = this.get_node(obj);
1171
+ if(!obj || obj.id === $.jstree.root) {
1172
+ return false;
1173
+ }
1174
+ return obj.parent;
1175
+ },
1176
+ /**
1177
+ * get a jQuery collection of all the children of a node (node must be rendered), returns false on error
1178
+ * @name get_children_dom(obj)
1179
+ * @param {mixed} obj
1180
+ * @return {jQuery}
1181
+ */
1182
+ get_children_dom : function (obj) {
1183
+ obj = this.get_node(obj, true);
1184
+ if(obj[0] === this.element[0]) {
1185
+ return this.get_container_ul().children(".jstree-node");
1186
+ }
1187
+ if(!obj || !obj.length) {
1188
+ return false;
1189
+ }
1190
+ return obj.children(".jstree-children").children(".jstree-node");
1191
+ },
1192
+ /**
1193
+ * checks if a node has children
1194
+ * @name is_parent(obj)
1195
+ * @param {mixed} obj
1196
+ * @return {Boolean}
1197
+ */
1198
+ is_parent : function (obj) {
1199
+ obj = this.get_node(obj);
1200
+ return obj && (obj.state.loaded === false || obj.children.length > 0);
1201
+ },
1202
+ /**
1203
+ * checks if a node is loaded (its children are available)
1204
+ * @name is_loaded(obj)
1205
+ * @param {mixed} obj
1206
+ * @return {Boolean}
1207
+ */
1208
+ is_loaded : function (obj) {
1209
+ obj = this.get_node(obj);
1210
+ return obj && obj.state.loaded;
1211
+ },
1212
+ /**
1213
+ * check if a node is currently loading (fetching children)
1214
+ * @name is_loading(obj)
1215
+ * @param {mixed} obj
1216
+ * @return {Boolean}
1217
+ */
1218
+ is_loading : function (obj) {
1219
+ obj = this.get_node(obj);
1220
+ return obj && obj.state && obj.state.loading;
1221
+ },
1222
+ /**
1223
+ * check if a node is opened
1224
+ * @name is_open(obj)
1225
+ * @param {mixed} obj
1226
+ * @return {Boolean}
1227
+ */
1228
+ is_open : function (obj) {
1229
+ obj = this.get_node(obj);
1230
+ return obj && obj.state.opened;
1231
+ },
1232
+ /**
1233
+ * check if a node is in a closed state
1234
+ * @name is_closed(obj)
1235
+ * @param {mixed} obj
1236
+ * @return {Boolean}
1237
+ */
1238
+ is_closed : function (obj) {
1239
+ obj = this.get_node(obj);
1240
+ return obj && this.is_parent(obj) && !obj.state.opened;
1241
+ },
1242
+ /**
1243
+ * check if a node has no children
1244
+ * @name is_leaf(obj)
1245
+ * @param {mixed} obj
1246
+ * @return {Boolean}
1247
+ */
1248
+ is_leaf : function (obj) {
1249
+ return !this.is_parent(obj);
1250
+ },
1251
+ /**
1252
+ * loads a node (fetches its children using the `core.data` setting). Multiple nodes can be passed to by using an array.
1253
+ * @name load_node(obj [, callback])
1254
+ * @param {mixed} obj
1255
+ * @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
1256
+ * @return {Boolean}
1257
+ * @trigger load_node.jstree
1258
+ */
1259
+ load_node : function (obj, callback) {
1260
+ var k, l, i, j, c;
1261
+ if($.isArray(obj)) {
1262
+ this._load_nodes(obj.slice(), callback);
1263
+ return true;
1264
+ }
1265
+ obj = this.get_node(obj);
1266
+ if(!obj) {
1267
+ if(callback) { callback.call(this, obj, false); }
1268
+ return false;
1269
+ }
1270
+ // 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?
1271
+ if(obj.state.loaded) {
1272
+ obj.state.loaded = false;
1273
+ for(i = 0, j = obj.parents.length; i < j; i++) {
1274
+ this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
1275
+ return $.inArray(v, obj.children_d) === -1;
1276
+ });
1277
+ }
1278
+ for(k = 0, l = obj.children_d.length; k < l; k++) {
1279
+ if(this._model.data[obj.children_d[k]].state.selected) {
1280
+ c = true;
1281
+ }
1282
+ delete this._model.data[obj.children_d[k]];
1283
+ }
1284
+ if (c) {
1285
+ this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
1286
+ return $.inArray(v, obj.children_d) === -1;
1287
+ });
1288
+ }
1289
+ obj.children = [];
1290
+ obj.children_d = [];
1291
+ if(c) {
1292
+ this.trigger('changed', { 'action' : 'load_node', 'node' : obj, 'selected' : this._data.core.selected });
1293
+ }
1294
+ }
1295
+ obj.state.failed = false;
1296
+ obj.state.loading = true;
1297
+ this.get_node(obj, true).addClass("jstree-loading").attr('aria-busy',true);
1298
+ this._load_node(obj, $.proxy(function (status) {
1299
+ obj = this._model.data[obj.id];
1300
+ obj.state.loading = false;
1301
+ obj.state.loaded = status;
1302
+ obj.state.failed = !obj.state.loaded;
1303
+ var dom = this.get_node(obj, true), i = 0, j = 0, m = this._model.data, has_children = false;
1304
+ for(i = 0, j = obj.children.length; i < j; i++) {
1305
+ if(m[obj.children[i]] && !m[obj.children[i]].state.hidden) {
1306
+ has_children = true;
1307
+ break;
1308
+ }
1309
+ }
1310
+ if(obj.state.loaded && dom && dom.length) {
1311
+ dom.removeClass('jstree-closed jstree-open jstree-leaf');
1312
+ if (!has_children) {
1313
+ dom.addClass('jstree-leaf');
1314
+ }
1315
+ else {
1316
+ if (obj.id !== '#') {
1317
+ dom.addClass(obj.state.opened ? 'jstree-open' : 'jstree-closed');
1318
+ }
1319
+ }
1320
+ }
1321
+ dom.removeClass("jstree-loading").attr('aria-busy',false);
1322
+ /**
1323
+ * triggered after a node is loaded
1324
+ * @event
1325
+ * @name load_node.jstree
1326
+ * @param {Object} node the node that was loading
1327
+ * @param {Boolean} status was the node loaded successfully
1328
+ */
1329
+ this.trigger('load_node', { "node" : obj, "status" : status });
1330
+ if(callback) {
1331
+ callback.call(this, obj, status);
1332
+ }
1333
+ }, this));
1334
+ return true;
1335
+ },
1336
+ /**
1337
+ * load an array of nodes (will also load unavailable nodes as soon as they appear in the structure). Used internally.
1338
+ * @private
1339
+ * @name _load_nodes(nodes [, callback])
1340
+ * @param {array} nodes
1341
+ * @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
1342
+ */
1343
+ _load_nodes : function (nodes, callback, is_callback, force_reload) {
1344
+ var r = true,
1345
+ c = function () { this._load_nodes(nodes, callback, true); },
1346
+ m = this._model.data, i, j, tmp = [];
1347
+ for(i = 0, j = nodes.length; i < j; i++) {
1348
+ if(m[nodes[i]] && ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || (!is_callback && force_reload) )) {
1349
+ if(!this.is_loading(nodes[i])) {
1350
+ this.load_node(nodes[i], c);
1351
+ }
1352
+ r = false;
1353
+ }
1354
+ }
1355
+ if(r) {
1356
+ for(i = 0, j = nodes.length; i < j; i++) {
1357
+ if(m[nodes[i]] && m[nodes[i]].state.loaded) {
1358
+ tmp.push(nodes[i]);
1359
+ }
1360
+ }
1361
+ if(callback && !callback.done) {
1362
+ callback.call(this, tmp);
1363
+ callback.done = true;
1364
+ }
1365
+ }
1366
+ },
1367
+ /**
1368
+ * loads all unloaded nodes
1369
+ * @name load_all([obj, callback])
1370
+ * @param {mixed} obj the node to load recursively, omit to load all nodes in the tree
1371
+ * @param {function} callback a function to be executed once loading all the nodes is complete,
1372
+ * @trigger load_all.jstree
1373
+ */
1374
+ load_all : function (obj, callback) {
1375
+ if(!obj) { obj = $.jstree.root; }
1376
+ obj = this.get_node(obj);
1377
+ if(!obj) { return false; }
1378
+ var to_load = [],
1379
+ m = this._model.data,
1380
+ c = m[obj.id].children_d,
1381
+ i, j;
1382
+ if(obj.state && !obj.state.loaded) {
1383
+ to_load.push(obj.id);
1384
+ }
1385
+ for(i = 0, j = c.length; i < j; i++) {
1386
+ if(m[c[i]] && m[c[i]].state && !m[c[i]].state.loaded) {
1387
+ to_load.push(c[i]);
1388
+ }
1389
+ }
1390
+ if(to_load.length) {
1391
+ this._load_nodes(to_load, function () {
1392
+ this.load_all(obj, callback);
1393
+ });
1394
+ }
1395
+ else {
1396
+ /**
1397
+ * triggered after a load_all call completes
1398
+ * @event
1399
+ * @name load_all.jstree
1400
+ * @param {Object} node the recursively loaded node
1401
+ */
1402
+ if(callback) { callback.call(this, obj); }
1403
+ this.trigger('load_all', { "node" : obj });
1404
+ }
1405
+ },
1406
+ /**
1407
+ * handles the actual loading of a node. Used only internally.
1408
+ * @private
1409
+ * @name _load_node(obj [, callback])
1410
+ * @param {mixed} obj
1411
+ * @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
1412
+ * @return {Boolean}
1413
+ */
1414
+ _load_node : function (obj, callback) {
1415
+ var s = this.settings.core.data, t;
1416
+ var notTextOrCommentNode = function notTextOrCommentNode () {
1417
+ return this.nodeType !== 3 && this.nodeType !== 8;
1418
+ };
1419
+ // use original HTML
1420
+ if(!s) {
1421
+ if(obj.id === $.jstree.root) {
1422
+ return this._append_html_data(obj, this._data.core.original_container_html.clone(true), function (status) {
1423
+ callback.call(this, status);
1424
+ });
1425
+ }
1426
+ else {
1427
+ return callback.call(this, false);
1428
+ }
1429
+ // return callback.call(this, obj.id === $.jstree.root ? this._append_html_data(obj, this._data.core.original_container_html.clone(true)) : false);
1430
+ }
1431
+ if($.isFunction(s)) {
1432
+ return s.call(this, obj, $.proxy(function (d) {
1433
+ if(d === false) {
1434
+ callback.call(this, false);
1435
+ }
1436
+ else {
1437
+ this[typeof d === 'string' ? '_append_html_data' : '_append_json_data'](obj, typeof d === 'string' ? $($.parseHTML(d)).filter(notTextOrCommentNode) : d, function (status) {
1438
+ callback.call(this, status);
1439
+ });
1440
+ }
1441
+ // 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));
1442
+ }, this));
1443
+ }
1444
+ if(typeof s === 'object') {
1445
+ if(s.url) {
1446
+ s = $.extend(true, {}, s);
1447
+ if($.isFunction(s.url)) {
1448
+ s.url = s.url.call(this, obj);
1449
+ }
1450
+ if($.isFunction(s.data)) {
1451
+ s.data = s.data.call(this, obj);
1452
+ }
1453
+ return $.ajax(s)
1454
+ .done($.proxy(function (d,t,x) {
1455
+ var type = x.getResponseHeader('Content-Type');
1456
+ if((type && type.indexOf('json') !== -1) || typeof d === "object") {
1457
+ return this._append_json_data(obj, d, function (status) { callback.call(this, status); });
1458
+ //return callback.call(this, this._append_json_data(obj, d));
1459
+ }
1460
+ if((type && type.indexOf('html') !== -1) || typeof d === "string") {
1461
+ return this._append_html_data(obj, $($.parseHTML(d)).filter(notTextOrCommentNode), function (status) { callback.call(this, status); });
1462
+ // return callback.call(this, this._append_html_data(obj, $(d)));
1463
+ }
1464
+ 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 }) };
1465
+ this.settings.core.error.call(this, this._data.core.last_error);
1466
+ return callback.call(this, false);
1467
+ }, this))
1468
+ .fail($.proxy(function (f) {
1469
+ 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 }) };
1470
+ callback.call(this, false);
1471
+ this.settings.core.error.call(this, this._data.core.last_error);
1472
+ }, this));
1473
+ }
1474
+ if ($.isArray(s)) {
1475
+ t = $.extend(true, [], s);
1476
+ } else if ($.isPlainObject(s)) {
1477
+ t = $.extend(true, {}, s);
1478
+ } else {
1479
+ t = s;
1480
+ }
1481
+ if(obj.id === $.jstree.root) {
1482
+ return this._append_json_data(obj, t, function (status) {
1483
+ callback.call(this, status);
1484
+ });
1485
+ }
1486
+ else {
1487
+ this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_05', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
1488
+ this.settings.core.error.call(this, this._data.core.last_error);
1489
+ return callback.call(this, false);
1490
+ }
1491
+ //return callback.call(this, (obj.id === $.jstree.root ? this._append_json_data(obj, t) : false) );
1492
+ }
1493
+ if(typeof s === 'string') {
1494
+ if(obj.id === $.jstree.root) {
1495
+ return this._append_html_data(obj, $($.parseHTML(s)).filter(notTextOrCommentNode), function (status) {
1496
+ callback.call(this, status);
1497
+ });
1498
+ }
1499
+ else {
1500
+ this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_06', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
1501
+ this.settings.core.error.call(this, this._data.core.last_error);
1502
+ return callback.call(this, false);
1503
+ }
1504
+ //return callback.call(this, (obj.id === $.jstree.root ? this._append_html_data(obj, $(s)) : false) );
1505
+ }
1506
+ return callback.call(this, false);
1507
+ },
1508
+ /**
1509
+ * adds a node to the list of nodes to redraw. Used only internally.
1510
+ * @private
1511
+ * @name _node_changed(obj [, callback])
1512
+ * @param {mixed} obj
1513
+ */
1514
+ _node_changed : function (obj) {
1515
+ obj = this.get_node(obj);
1516
+ if (obj && $.inArray(obj.id, this._model.changed) === -1) {
1517
+ this._model.changed.push(obj.id);
1518
+ }
1519
+ },
1520
+ /**
1521
+ * appends HTML content to the tree. Used internally.
1522
+ * @private
1523
+ * @name _append_html_data(obj, data)
1524
+ * @param {mixed} obj the node to append to
1525
+ * @param {String} data the HTML string to parse and append
1526
+ * @trigger model.jstree, changed.jstree
1527
+ */
1528
+ _append_html_data : function (dom, data, cb) {
1529
+ dom = this.get_node(dom);
1530
+ dom.children = [];
1531
+ dom.children_d = [];
1532
+ var dat = data.is('ul') ? data.children() : data,
1533
+ par = dom.id,
1534
+ chd = [],
1535
+ dpc = [],
1536
+ m = this._model.data,
1537
+ p = m[par],
1538
+ s = this._data.core.selected.length,
1539
+ tmp, i, j;
1540
+ dat.each($.proxy(function (i, v) {
1541
+ tmp = this._parse_model_from_html($(v), par, p.parents.concat());
1542
+ if(tmp) {
1543
+ chd.push(tmp);
1544
+ dpc.push(tmp);
1545
+ if(m[tmp].children_d.length) {
1546
+ dpc = dpc.concat(m[tmp].children_d);
1547
+ }
1548
+ }
1549
+ }, this));
1550
+ p.children = chd;
1551
+ p.children_d = dpc;
1552
+ for(i = 0, j = p.parents.length; i < j; i++) {
1553
+ m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
1554
+ }
1555
+ /**
1556
+ * triggered when new data is inserted to the tree model
1557
+ * @event
1558
+ * @name model.jstree
1559
+ * @param {Array} nodes an array of node IDs
1560
+ * @param {String} parent the parent ID of the nodes
1561
+ */
1562
+ this.trigger('model', { "nodes" : dpc, 'parent' : par });
1563
+ if(par !== $.jstree.root) {
1564
+ this._node_changed(par);
1565
+ this.redraw();
1566
+ }
1567
+ else {
1568
+ this.get_container_ul().children('.jstree-initial-node').remove();
1569
+ this.redraw(true);
1570
+ }
1571
+ if(this._data.core.selected.length !== s) {
1572
+ this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
1573
+ }
1574
+ cb.call(this, true);
1575
+ },
1576
+ /**
1577
+ * appends JSON content to the tree. Used internally.
1578
+ * @private
1579
+ * @name _append_json_data(obj, data)
1580
+ * @param {mixed} obj the node to append to
1581
+ * @param {String} data the JSON object to parse and append
1582
+ * @param {Boolean} force_processing internal param - do not set
1583
+ * @trigger model.jstree, changed.jstree
1584
+ */
1585
+ _append_json_data : function (dom, data, cb, force_processing) {
1586
+ if(this.element === null) { return; }
1587
+ dom = this.get_node(dom);
1588
+ dom.children = [];
1589
+ dom.children_d = [];
1590
+ // *%$@!!!
1591
+ if(data.d) {
1592
+ data = data.d;
1593
+ if(typeof data === "string") {
1594
+ data = JSON.parse(data);
1595
+ }
1596
+ }
1597
+ if(!$.isArray(data)) { data = [data]; }
1598
+ var w = null,
1599
+ args = {
1600
+ 'df' : this._model.default_state,
1601
+ 'dat' : data,
1602
+ 'par' : dom.id,
1603
+ 'm' : this._model.data,
1604
+ 't_id' : this._id,
1605
+ 't_cnt' : this._cnt,
1606
+ 'sel' : this._data.core.selected
1607
+ },
1608
+ inst = this,
1609
+ func = function (data, undefined) {
1610
+ if(data.data) { data = data.data; }
1611
+ var dat = data.dat,
1612
+ par = data.par,
1613
+ chd = [],
1614
+ dpc = [],
1615
+ add = [],
1616
+ df = data.df,
1617
+ t_id = data.t_id,
1618
+ t_cnt = data.t_cnt,
1619
+ m = data.m,
1620
+ p = m[par],
1621
+ sel = data.sel,
1622
+ tmp, i, j, rslt,
1623
+ parse_flat = function (d, p, ps) {
1624
+ if(!ps) { ps = []; }
1625
+ else { ps = ps.concat(); }
1626
+ if(p) { ps.unshift(p); }
1627
+ var tid = d.id.toString(),
1628
+ i, j, c, e,
1629
+ tmp = {
1630
+ id : tid,
1631
+ text : d.text || '',
1632
+ icon : d.icon !== undefined ? d.icon : true,
1633
+ parent : p,
1634
+ parents : ps,
1635
+ children : d.children || [],
1636
+ children_d : d.children_d || [],
1637
+ data : d.data,
1638
+ state : { },
1639
+ li_attr : { id : false },
1640
+ a_attr : { href : '#' },
1641
+ original : false
1642
+ };
1643
+ for(i in df) {
1644
+ if(df.hasOwnProperty(i)) {
1645
+ tmp.state[i] = df[i];
1646
+ }
1647
+ }
1648
+ if(d && d.data && d.data.jstree && d.data.jstree.icon) {
1649
+ tmp.icon = d.data.jstree.icon;
1650
+ }
1651
+ if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
1652
+ tmp.icon = true;
1653
+ }
1654
+ if(d && d.data) {
1655
+ tmp.data = d.data;
1656
+ if(d.data.jstree) {
1657
+ for(i in d.data.jstree) {
1658
+ if(d.data.jstree.hasOwnProperty(i)) {
1659
+ tmp.state[i] = d.data.jstree[i];
1660
+ }
1661
+ }
1662
+ }
1663
+ }
1664
+ if(d && typeof d.state === 'object') {
1665
+ for (i in d.state) {
1666
+ if(d.state.hasOwnProperty(i)) {
1667
+ tmp.state[i] = d.state[i];
1668
+ }
1669
+ }
1670
+ }
1671
+ if(d && typeof d.li_attr === 'object') {
1672
+ for (i in d.li_attr) {
1673
+ if(d.li_attr.hasOwnProperty(i)) {
1674
+ tmp.li_attr[i] = d.li_attr[i];
1675
+ }
1676
+ }
1677
+ }
1678
+ if(!tmp.li_attr.id) {
1679
+ tmp.li_attr.id = tid;
1680
+ }
1681
+ if(d && typeof d.a_attr === 'object') {
1682
+ for (i in d.a_attr) {
1683
+ if(d.a_attr.hasOwnProperty(i)) {
1684
+ tmp.a_attr[i] = d.a_attr[i];
1685
+ }
1686
+ }
1687
+ }
1688
+ if(d && d.children && d.children === true) {
1689
+ tmp.state.loaded = false;
1690
+ tmp.children = [];
1691
+ tmp.children_d = [];
1692
+ }
1693
+ m[tmp.id] = tmp;
1694
+ for(i = 0, j = tmp.children.length; i < j; i++) {
1695
+ c = parse_flat(m[tmp.children[i]], tmp.id, ps);
1696
+ e = m[c];
1697
+ tmp.children_d.push(c);
1698
+ if(e.children_d.length) {
1699
+ tmp.children_d = tmp.children_d.concat(e.children_d);
1700
+ }
1701
+ }
1702
+ delete d.data;
1703
+ delete d.children;
1704
+ m[tmp.id].original = d;
1705
+ if(tmp.state.selected) {
1706
+ add.push(tmp.id);
1707
+ }
1708
+ return tmp.id;
1709
+ },
1710
+ parse_nest = function (d, p, ps) {
1711
+ if(!ps) { ps = []; }
1712
+ else { ps = ps.concat(); }
1713
+ if(p) { ps.unshift(p); }
1714
+ var tid = false, i, j, c, e, tmp;
1715
+ do {
1716
+ tid = 'j' + t_id + '_' + (++t_cnt);
1717
+ } while(m[tid]);
1718
+
1719
+ tmp = {
1720
+ id : false,
1721
+ text : typeof d === 'string' ? d : '',
1722
+ icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
1723
+ parent : p,
1724
+ parents : ps,
1725
+ children : [],
1726
+ children_d : [],
1727
+ data : null,
1728
+ state : { },
1729
+ li_attr : { id : false },
1730
+ a_attr : { href : '#' },
1731
+ original : false
1732
+ };
1733
+ for(i in df) {
1734
+ if(df.hasOwnProperty(i)) {
1735
+ tmp.state[i] = df[i];
1736
+ }
1737
+ }
1738
+ if(d && d.id) { tmp.id = d.id.toString(); }
1739
+ if(d && d.text) { tmp.text = d.text; }
1740
+ if(d && d.data && d.data.jstree && d.data.jstree.icon) {
1741
+ tmp.icon = d.data.jstree.icon;
1742
+ }
1743
+ if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
1744
+ tmp.icon = true;
1745
+ }
1746
+ if(d && d.data) {
1747
+ tmp.data = d.data;
1748
+ if(d.data.jstree) {
1749
+ for(i in d.data.jstree) {
1750
+ if(d.data.jstree.hasOwnProperty(i)) {
1751
+ tmp.state[i] = d.data.jstree[i];
1752
+ }
1753
+ }
1754
+ }
1755
+ }
1756
+ if(d && typeof d.state === 'object') {
1757
+ for (i in d.state) {
1758
+ if(d.state.hasOwnProperty(i)) {
1759
+ tmp.state[i] = d.state[i];
1760
+ }
1761
+ }
1762
+ }
1763
+ if(d && typeof d.li_attr === 'object') {
1764
+ for (i in d.li_attr) {
1765
+ if(d.li_attr.hasOwnProperty(i)) {
1766
+ tmp.li_attr[i] = d.li_attr[i];
1767
+ }
1768
+ }
1769
+ }
1770
+ if(tmp.li_attr.id && !tmp.id) {
1771
+ tmp.id = tmp.li_attr.id.toString();
1772
+ }
1773
+ if(!tmp.id) {
1774
+ tmp.id = tid;
1775
+ }
1776
+ if(!tmp.li_attr.id) {
1777
+ tmp.li_attr.id = tmp.id;
1778
+ }
1779
+ if(d && typeof d.a_attr === 'object') {
1780
+ for (i in d.a_attr) {
1781
+ if(d.a_attr.hasOwnProperty(i)) {
1782
+ tmp.a_attr[i] = d.a_attr[i];
1783
+ }
1784
+ }
1785
+ }
1786
+ if(d && d.children && d.children.length) {
1787
+ for(i = 0, j = d.children.length; i < j; i++) {
1788
+ c = parse_nest(d.children[i], tmp.id, ps);
1789
+ e = m[c];
1790
+ tmp.children.push(c);
1791
+ if(e.children_d.length) {
1792
+ tmp.children_d = tmp.children_d.concat(e.children_d);
1793
+ }
1794
+ }
1795
+ tmp.children_d = tmp.children_d.concat(tmp.children);
1796
+ }
1797
+ if(d && d.children && d.children === true) {
1798
+ tmp.state.loaded = false;
1799
+ tmp.children = [];
1800
+ tmp.children_d = [];
1801
+ }
1802
+ delete d.data;
1803
+ delete d.children;
1804
+ tmp.original = d;
1805
+ m[tmp.id] = tmp;
1806
+ if(tmp.state.selected) {
1807
+ add.push(tmp.id);
1808
+ }
1809
+ return tmp.id;
1810
+ };
1811
+
1812
+ if(dat.length && dat[0].id !== undefined && dat[0].parent !== undefined) {
1813
+ // Flat JSON support (for easy import from DB):
1814
+ // 1) convert to object (foreach)
1815
+ for(i = 0, j = dat.length; i < j; i++) {
1816
+ if(!dat[i].children) {
1817
+ dat[i].children = [];
1818
+ }
1819
+ if(!dat[i].state) {
1820
+ dat[i].state = {};
1821
+ }
1822
+ m[dat[i].id.toString()] = dat[i];
1823
+ }
1824
+ // 2) populate children (foreach)
1825
+ for(i = 0, j = dat.length; i < j; i++) {
1826
+ if (!m[dat[i].parent.toString()]) {
1827
+ if (typeof inst !== "undefined") {
1828
+ inst._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() }) };
1829
+ inst.settings.core.error.call(inst, inst._data.core.last_error);
1830
+ }
1831
+ continue;
1832
+ }
1833
+
1834
+ m[dat[i].parent.toString()].children.push(dat[i].id.toString());
1835
+ // populate parent.children_d
1836
+ p.children_d.push(dat[i].id.toString());
1837
+ }
1838
+ // 3) normalize && populate parents and children_d with recursion
1839
+ for(i = 0, j = p.children.length; i < j; i++) {
1840
+ tmp = parse_flat(m[p.children[i]], par, p.parents.concat());
1841
+ dpc.push(tmp);
1842
+ if(m[tmp].children_d.length) {
1843
+ dpc = dpc.concat(m[tmp].children_d);
1844
+ }
1845
+ }
1846
+ for(i = 0, j = p.parents.length; i < j; i++) {
1847
+ m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
1848
+ }
1849
+ // ?) three_state selection - p.state.selected && t - (if three_state foreach(dat => ch) -> foreach(parents) if(parent.selected) child.selected = true;
1850
+ rslt = {
1851
+ 'cnt' : t_cnt,
1852
+ 'mod' : m,
1853
+ 'sel' : sel,
1854
+ 'par' : par,
1855
+ 'dpc' : dpc,
1856
+ 'add' : add
1857
+ };
1858
+ }
1859
+ else {
1860
+ for(i = 0, j = dat.length; i < j; i++) {
1861
+ tmp = parse_nest(dat[i], par, p.parents.concat());
1862
+ if(tmp) {
1863
+ chd.push(tmp);
1864
+ dpc.push(tmp);
1865
+ if(m[tmp].children_d.length) {
1866
+ dpc = dpc.concat(m[tmp].children_d);
1867
+ }
1868
+ }
1869
+ }
1870
+ p.children = chd;
1871
+ p.children_d = dpc;
1872
+ for(i = 0, j = p.parents.length; i < j; i++) {
1873
+ m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
1874
+ }
1875
+ rslt = {
1876
+ 'cnt' : t_cnt,
1877
+ 'mod' : m,
1878
+ 'sel' : sel,
1879
+ 'par' : par,
1880
+ 'dpc' : dpc,
1881
+ 'add' : add
1882
+ };
1883
+ }
1884
+ if(typeof window === 'undefined' || typeof window.document === 'undefined') {
1885
+ postMessage(rslt);
1886
+ }
1887
+ else {
1888
+ return rslt;
1889
+ }
1890
+ },
1891
+ rslt = function (rslt, worker) {
1892
+ if(this.element === null) { return; }
1893
+ this._cnt = rslt.cnt;
1894
+ var i, m = this._model.data;
1895
+ for (i in m) {
1896
+ if (m.hasOwnProperty(i) && m[i].state && m[i].state.loading && rslt.mod[i]) {
1897
+ rslt.mod[i].state.loading = true;
1898
+ }
1899
+ }
1900
+ this._model.data = rslt.mod; // breaks the reference in load_node - careful
1901
+
1902
+ if(worker) {
1903
+ var j, a = rslt.add, r = rslt.sel, s = this._data.core.selected.slice();
1904
+ m = this._model.data;
1905
+ // if selection was changed while calculating in worker
1906
+ if(r.length !== s.length || $.vakata.array_unique(r.concat(s)).length !== r.length) {
1907
+ // deselect nodes that are no longer selected
1908
+ for(i = 0, j = r.length; i < j; i++) {
1909
+ if($.inArray(r[i], a) === -1 && $.inArray(r[i], s) === -1) {
1910
+ m[r[i]].state.selected = false;
1911
+ }
1912
+ }
1913
+ // select nodes that were selected in the mean time
1914
+ for(i = 0, j = s.length; i < j; i++) {
1915
+ if($.inArray(s[i], r) === -1) {
1916
+ m[s[i]].state.selected = true;
1917
+ }
1918
+ }
1919
+ }
1920
+ }
1921
+ if(rslt.add.length) {
1922
+ this._data.core.selected = this._data.core.selected.concat(rslt.add);
1923
+ }
1924
+
1925
+ this.trigger('model', { "nodes" : rslt.dpc, 'parent' : rslt.par });
1926
+
1927
+ if(rslt.par !== $.jstree.root) {
1928
+ this._node_changed(rslt.par);
1929
+ this.redraw();
1930
+ }
1931
+ else {
1932
+ // this.get_container_ul().children('.jstree-initial-node').remove();
1933
+ this.redraw(true);
1934
+ }
1935
+ if(rslt.add.length) {
1936
+ this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
1937
+ }
1938
+ cb.call(this, true);
1939
+ };
1940
+ if(this.settings.core.worker && window.Blob && window.URL && window.Worker) {
1941
+ try {
1942
+ if(this._wrk === null) {
1943
+ this._wrk = window.URL.createObjectURL(
1944
+ new window.Blob(
1945
+ ['self.onmessage = ' + func.toString()],
1946
+ {type:"text/javascript"}
1947
+ )
1948
+ );
1949
+ }
1950
+ if(!this._data.core.working || force_processing) {
1951
+ this._data.core.working = true;
1952
+ w = new window.Worker(this._wrk);
1953
+ w.onmessage = $.proxy(function (e) {
1954
+ rslt.call(this, e.data, true);
1955
+ try { w.terminate(); w = null; } catch(ignore) { }
1956
+ if(this._data.core.worker_queue.length) {
1957
+ this._append_json_data.apply(this, this._data.core.worker_queue.shift());
1958
+ }
1959
+ else {
1960
+ this._data.core.working = false;
1961
+ }
1962
+ }, this);
1963
+ if(!args.par) {
1964
+ if(this._data.core.worker_queue.length) {
1965
+ this._append_json_data.apply(this, this._data.core.worker_queue.shift());
1966
+ }
1967
+ else {
1968
+ this._data.core.working = false;
1969
+ }
1970
+ }
1971
+ else {
1972
+ w.postMessage(args);
1973
+ }
1974
+ }
1975
+ else {
1976
+ this._data.core.worker_queue.push([dom, data, cb, true]);
1977
+ }
1978
+ }
1979
+ catch(e) {
1980
+ rslt.call(this, func(args), false);
1981
+ if(this._data.core.worker_queue.length) {
1982
+ this._append_json_data.apply(this, this._data.core.worker_queue.shift());
1983
+ }
1984
+ else {
1985
+ this._data.core.working = false;
1986
+ }
1987
+ }
1988
+ }
1989
+ else {
1990
+ rslt.call(this, func(args), false);
1991
+ }
1992
+ },
1993
+ /**
1994
+ * parses a node from a jQuery object and appends them to the in memory tree model. Used internally.
1995
+ * @private
1996
+ * @name _parse_model_from_html(d [, p, ps])
1997
+ * @param {jQuery} d the jQuery object to parse
1998
+ * @param {String} p the parent ID
1999
+ * @param {Array} ps list of all parents
2000
+ * @return {String} the ID of the object added to the model
2001
+ */
2002
+ _parse_model_from_html : function (d, p, ps) {
2003
+ if(!ps) { ps = []; }
2004
+ else { ps = [].concat(ps); }
2005
+ if(p) { ps.unshift(p); }
2006
+ var c, e, m = this._model.data,
2007
+ data = {
2008
+ id : false,
2009
+ text : false,
2010
+ icon : true,
2011
+ parent : p,
2012
+ parents : ps,
2013
+ children : [],
2014
+ children_d : [],
2015
+ data : null,
2016
+ state : { },
2017
+ li_attr : { id : false },
2018
+ a_attr : { href : '#' },
2019
+ original : false
2020
+ }, i, tmp, tid;
2021
+ for(i in this._model.default_state) {
2022
+ if(this._model.default_state.hasOwnProperty(i)) {
2023
+ data.state[i] = this._model.default_state[i];
2024
+ }
2025
+ }
2026
+ tmp = $.vakata.attributes(d, true);
2027
+ $.each(tmp, function (i, v) {
2028
+ v = $.trim(v);
2029
+ if(!v.length) { return true; }
2030
+ data.li_attr[i] = v;
2031
+ if(i === 'id') {
2032
+ data.id = v.toString();
2033
+ }
2034
+ });
2035
+ tmp = d.children('a').first();
2036
+ if(tmp.length) {
2037
+ tmp = $.vakata.attributes(tmp, true);
2038
+ $.each(tmp, function (i, v) {
2039
+ v = $.trim(v);
2040
+ if(v.length) {
2041
+ data.a_attr[i] = v;
2042
+ }
2043
+ });
2044
+ }
2045
+ tmp = d.children("a").first().length ? d.children("a").first().clone() : d.clone();
2046
+ tmp.children("ins, i, ul").remove();
2047
+ tmp = tmp.html();
2048
+ tmp = $('<div />').html(tmp);
2049
+ data.text = this.settings.core.force_text ? tmp.text() : tmp.html();
2050
+ tmp = d.data();
2051
+ data.data = tmp ? $.extend(true, {}, tmp) : null;
2052
+ data.state.opened = d.hasClass('jstree-open');
2053
+ data.state.selected = d.children('a').hasClass('jstree-clicked');
2054
+ data.state.disabled = d.children('a').hasClass('jstree-disabled');
2055
+ if(data.data && data.data.jstree) {
2056
+ for(i in data.data.jstree) {
2057
+ if(data.data.jstree.hasOwnProperty(i)) {
2058
+ data.state[i] = data.data.jstree[i];
2059
+ }
2060
+ }
2061
+ }
2062
+ tmp = d.children("a").children(".jstree-themeicon");
2063
+ if(tmp.length) {
2064
+ data.icon = tmp.hasClass('jstree-themeicon-hidden') ? false : tmp.attr('rel');
2065
+ }
2066
+ if(data.state.icon !== undefined) {
2067
+ data.icon = data.state.icon;
2068
+ }
2069
+ if(data.icon === undefined || data.icon === null || data.icon === "") {
2070
+ data.icon = true;
2071
+ }
2072
+ tmp = d.children("ul").children("li");
2073
+ do {
2074
+ tid = 'j' + this._id + '_' + (++this._cnt);
2075
+ } while(m[tid]);
2076
+ data.id = data.li_attr.id ? data.li_attr.id.toString() : tid;
2077
+ if(tmp.length) {
2078
+ tmp.each($.proxy(function (i, v) {
2079
+ c = this._parse_model_from_html($(v), data.id, ps);
2080
+ e = this._model.data[c];
2081
+ data.children.push(c);
2082
+ if(e.children_d.length) {
2083
+ data.children_d = data.children_d.concat(e.children_d);
2084
+ }
2085
+ }, this));
2086
+ data.children_d = data.children_d.concat(data.children);
2087
+ }
2088
+ else {
2089
+ if(d.hasClass('jstree-closed')) {
2090
+ data.state.loaded = false;
2091
+ }
2092
+ }
2093
+ if(data.li_attr['class']) {
2094
+ data.li_attr['class'] = data.li_attr['class'].replace('jstree-closed','').replace('jstree-open','');
2095
+ }
2096
+ if(data.a_attr['class']) {
2097
+ data.a_attr['class'] = data.a_attr['class'].replace('jstree-clicked','').replace('jstree-disabled','');
2098
+ }
2099
+ m[data.id] = data;
2100
+ if(data.state.selected) {
2101
+ this._data.core.selected.push(data.id);
2102
+ }
2103
+ return data.id;
2104
+ },
2105
+ /**
2106
+ * 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.
2107
+ * @private
2108
+ * @name _parse_model_from_flat_json(d [, p, ps])
2109
+ * @param {Object} d the JSON object to parse
2110
+ * @param {String} p the parent ID
2111
+ * @param {Array} ps list of all parents
2112
+ * @return {String} the ID of the object added to the model
2113
+ */
2114
+ _parse_model_from_flat_json : function (d, p, ps) {
2115
+ if(!ps) { ps = []; }
2116
+ else { ps = ps.concat(); }
2117
+ if(p) { ps.unshift(p); }
2118
+ var tid = d.id.toString(),
2119
+ m = this._model.data,
2120
+ df = this._model.default_state,
2121
+ i, j, c, e,
2122
+ tmp = {
2123
+ id : tid,
2124
+ text : d.text || '',
2125
+ icon : d.icon !== undefined ? d.icon : true,
2126
+ parent : p,
2127
+ parents : ps,
2128
+ children : d.children || [],
2129
+ children_d : d.children_d || [],
2130
+ data : d.data,
2131
+ state : { },
2132
+ li_attr : { id : false },
2133
+ a_attr : { href : '#' },
2134
+ original : false
2135
+ };
2136
+ for(i in df) {
2137
+ if(df.hasOwnProperty(i)) {
2138
+ tmp.state[i] = df[i];
2139
+ }
2140
+ }
2141
+ if(d && d.data && d.data.jstree && d.data.jstree.icon) {
2142
+ tmp.icon = d.data.jstree.icon;
2143
+ }
2144
+ if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
2145
+ tmp.icon = true;
2146
+ }
2147
+ if(d && d.data) {
2148
+ tmp.data = d.data;
2149
+ if(d.data.jstree) {
2150
+ for(i in d.data.jstree) {
2151
+ if(d.data.jstree.hasOwnProperty(i)) {
2152
+ tmp.state[i] = d.data.jstree[i];
2153
+ }
2154
+ }
2155
+ }
2156
+ }
2157
+ if(d && typeof d.state === 'object') {
2158
+ for (i in d.state) {
2159
+ if(d.state.hasOwnProperty(i)) {
2160
+ tmp.state[i] = d.state[i];
2161
+ }
2162
+ }
2163
+ }
2164
+ if(d && typeof d.li_attr === 'object') {
2165
+ for (i in d.li_attr) {
2166
+ if(d.li_attr.hasOwnProperty(i)) {
2167
+ tmp.li_attr[i] = d.li_attr[i];
2168
+ }
2169
+ }
2170
+ }
2171
+ if(!tmp.li_attr.id) {
2172
+ tmp.li_attr.id = tid;
2173
+ }
2174
+ if(d && typeof d.a_attr === 'object') {
2175
+ for (i in d.a_attr) {
2176
+ if(d.a_attr.hasOwnProperty(i)) {
2177
+ tmp.a_attr[i] = d.a_attr[i];
2178
+ }
2179
+ }
2180
+ }
2181
+ if(d && d.children && d.children === true) {
2182
+ tmp.state.loaded = false;
2183
+ tmp.children = [];
2184
+ tmp.children_d = [];
2185
+ }
2186
+ m[tmp.id] = tmp;
2187
+ for(i = 0, j = tmp.children.length; i < j; i++) {
2188
+ c = this._parse_model_from_flat_json(m[tmp.children[i]], tmp.id, ps);
2189
+ e = m[c];
2190
+ tmp.children_d.push(c);
2191
+ if(e.children_d.length) {
2192
+ tmp.children_d = tmp.children_d.concat(e.children_d);
2193
+ }
2194
+ }
2195
+ delete d.data;
2196
+ delete d.children;
2197
+ m[tmp.id].original = d;
2198
+ if(tmp.state.selected) {
2199
+ this._data.core.selected.push(tmp.id);
2200
+ }
2201
+ return tmp.id;
2202
+ },
2203
+ /**
2204
+ * parses a node from a JSON object and appends it to the in memory tree model. Used internally.
2205
+ * @private
2206
+ * @name _parse_model_from_json(d [, p, ps])
2207
+ * @param {Object} d the JSON object to parse
2208
+ * @param {String} p the parent ID
2209
+ * @param {Array} ps list of all parents
2210
+ * @return {String} the ID of the object added to the model
2211
+ */
2212
+ _parse_model_from_json : function (d, p, ps) {
2213
+ if(!ps) { ps = []; }
2214
+ else { ps = ps.concat(); }
2215
+ if(p) { ps.unshift(p); }
2216
+ var tid = false, i, j, c, e, m = this._model.data, df = this._model.default_state, tmp;
2217
+ do {
2218
+ tid = 'j' + this._id + '_' + (++this._cnt);
2219
+ } while(m[tid]);
2220
+
2221
+ tmp = {
2222
+ id : false,
2223
+ text : typeof d === 'string' ? d : '',
2224
+ icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
2225
+ parent : p,
2226
+ parents : ps,
2227
+ children : [],
2228
+ children_d : [],
2229
+ data : null,
2230
+ state : { },
2231
+ li_attr : { id : false },
2232
+ a_attr : { href : '#' },
2233
+ original : false
2234
+ };
2235
+ for(i in df) {
2236
+ if(df.hasOwnProperty(i)) {
2237
+ tmp.state[i] = df[i];
2238
+ }
2239
+ }
2240
+ if(d && d.id) { tmp.id = d.id.toString(); }
2241
+ if(d && d.text) { tmp.text = d.text; }
2242
+ if(d && d.data && d.data.jstree && d.data.jstree.icon) {
2243
+ tmp.icon = d.data.jstree.icon;
2244
+ }
2245
+ if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
2246
+ tmp.icon = true;
2247
+ }
2248
+ if(d && d.data) {
2249
+ tmp.data = d.data;
2250
+ if(d.data.jstree) {
2251
+ for(i in d.data.jstree) {
2252
+ if(d.data.jstree.hasOwnProperty(i)) {
2253
+ tmp.state[i] = d.data.jstree[i];
2254
+ }
2255
+ }
2256
+ }
2257
+ }
2258
+ if(d && typeof d.state === 'object') {
2259
+ for (i in d.state) {
2260
+ if(d.state.hasOwnProperty(i)) {
2261
+ tmp.state[i] = d.state[i];
2262
+ }
2263
+ }
2264
+ }
2265
+ if(d && typeof d.li_attr === 'object') {
2266
+ for (i in d.li_attr) {
2267
+ if(d.li_attr.hasOwnProperty(i)) {
2268
+ tmp.li_attr[i] = d.li_attr[i];
2269
+ }
2270
+ }
2271
+ }
2272
+ if(tmp.li_attr.id && !tmp.id) {
2273
+ tmp.id = tmp.li_attr.id.toString();
2274
+ }
2275
+ if(!tmp.id) {
2276
+ tmp.id = tid;
2277
+ }
2278
+ if(!tmp.li_attr.id) {
2279
+ tmp.li_attr.id = tmp.id;
2280
+ }
2281
+ if(d && typeof d.a_attr === 'object') {
2282
+ for (i in d.a_attr) {
2283
+ if(d.a_attr.hasOwnProperty(i)) {
2284
+ tmp.a_attr[i] = d.a_attr[i];
2285
+ }
2286
+ }
2287
+ }
2288
+ if(d && d.children && d.children.length) {
2289
+ for(i = 0, j = d.children.length; i < j; i++) {
2290
+ c = this._parse_model_from_json(d.children[i], tmp.id, ps);
2291
+ e = m[c];
2292
+ tmp.children.push(c);
2293
+ if(e.children_d.length) {
2294
+ tmp.children_d = tmp.children_d.concat(e.children_d);
2295
+ }
2296
+ }
2297
+ tmp.children_d = tmp.children.concat(tmp.children_d);
2298
+ }
2299
+ if(d && d.children && d.children === true) {
2300
+ tmp.state.loaded = false;
2301
+ tmp.children = [];
2302
+ tmp.children_d = [];
2303
+ }
2304
+ delete d.data;
2305
+ delete d.children;
2306
+ tmp.original = d;
2307
+ m[tmp.id] = tmp;
2308
+ if(tmp.state.selected) {
2309
+ this._data.core.selected.push(tmp.id);
2310
+ }
2311
+ return tmp.id;
2312
+ },
2313
+ /**
2314
+ * redraws all nodes that need to be redrawn. Used internally.
2315
+ * @private
2316
+ * @name _redraw()
2317
+ * @trigger redraw.jstree
2318
+ */
2319
+ _redraw : function () {
2320
+ var nodes = this._model.force_full_redraw ? this._model.data[$.jstree.root].children.concat([]) : this._model.changed.concat([]),
2321
+ f = document.createElement('UL'), tmp, i, j, fe = this._data.core.focused;
2322
+ for(i = 0, j = nodes.length; i < j; i++) {
2323
+ tmp = this.redraw_node(nodes[i], true, this._model.force_full_redraw);
2324
+ if(tmp && this._model.force_full_redraw) {
2325
+ f.appendChild(tmp);
2326
+ }
2327
+ }
2328
+ if(this._model.force_full_redraw) {
2329
+ f.className = this.get_container_ul()[0].className;
2330
+ f.setAttribute('role','group');
2331
+ this.element.empty().append(f);
2332
+ //this.get_container_ul()[0].appendChild(f);
2333
+ }
2334
+ if(fe !== null && this.settings.core.restore_focus) {
2335
+ tmp = this.get_node(fe, true);
2336
+ if(tmp && tmp.length && tmp.children('.jstree-anchor')[0] !== document.activeElement) {
2337
+ tmp.children('.jstree-anchor').focus();
2338
+ }
2339
+ else {
2340
+ this._data.core.focused = null;
2341
+ }
2342
+ }
2343
+ this._model.force_full_redraw = false;
2344
+ this._model.changed = [];
2345
+ /**
2346
+ * triggered after nodes are redrawn
2347
+ * @event
2348
+ * @name redraw.jstree
2349
+ * @param {array} nodes the redrawn nodes
2350
+ */
2351
+ this.trigger('redraw', { "nodes" : nodes });
2352
+ },
2353
+ /**
2354
+ * redraws all nodes that need to be redrawn or optionally - the whole tree
2355
+ * @name redraw([full])
2356
+ * @param {Boolean} full if set to `true` all nodes are redrawn.
2357
+ */
2358
+ redraw : function (full) {
2359
+ if(full) {
2360
+ this._model.force_full_redraw = true;
2361
+ }
2362
+ //if(this._model.redraw_timeout) {
2363
+ // clearTimeout(this._model.redraw_timeout);
2364
+ //}
2365
+ //this._model.redraw_timeout = setTimeout($.proxy(this._redraw, this),0);
2366
+ this._redraw();
2367
+ },
2368
+ /**
2369
+ * redraws a single node's children. Used internally.
2370
+ * @private
2371
+ * @name draw_children(node)
2372
+ * @param {mixed} node the node whose children will be redrawn
2373
+ */
2374
+ draw_children : function (node) {
2375
+ var obj = this.get_node(node),
2376
+ i = false,
2377
+ j = false,
2378
+ k = false,
2379
+ d = document;
2380
+ if(!obj) { return false; }
2381
+ if(obj.id === $.jstree.root) { return this.redraw(true); }
2382
+ node = this.get_node(node, true);
2383
+ if(!node || !node.length) { return false; } // TODO: quick toggle
2384
+
2385
+ node.children('.jstree-children').remove();
2386
+ node = node[0];
2387
+ if(obj.children.length && obj.state.loaded) {
2388
+ k = d.createElement('UL');
2389
+ k.setAttribute('role', 'group');
2390
+ k.className = 'jstree-children';
2391
+ for(i = 0, j = obj.children.length; i < j; i++) {
2392
+ k.appendChild(this.redraw_node(obj.children[i], true, true));
2393
+ }
2394
+ node.appendChild(k);
2395
+ }
2396
+ },
2397
+ /**
2398
+ * redraws a single node. Used internally.
2399
+ * @private
2400
+ * @name redraw_node(node, deep, is_callback, force_render)
2401
+ * @param {mixed} node the node to redraw
2402
+ * @param {Boolean} deep should child nodes be redrawn too
2403
+ * @param {Boolean} is_callback is this a recursion call
2404
+ * @param {Boolean} force_render should children of closed parents be drawn anyway
2405
+ */
2406
+ redraw_node : function (node, deep, is_callback, force_render) {
2407
+ var obj = this.get_node(node),
2408
+ par = false,
2409
+ ind = false,
2410
+ old = false,
2411
+ i = false,
2412
+ j = false,
2413
+ k = false,
2414
+ c = '',
2415
+ d = document,
2416
+ m = this._model.data,
2417
+ f = false,
2418
+ s = false,
2419
+ tmp = null,
2420
+ t = 0,
2421
+ l = 0,
2422
+ has_children = false,
2423
+ last_sibling = false;
2424
+ if(!obj) { return false; }
2425
+ if(obj.id === $.jstree.root) { return this.redraw(true); }
2426
+ deep = deep || obj.children.length === 0;
2427
+ 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);
2428
+ if(!node) {
2429
+ deep = true;
2430
+ //node = d.createElement('LI');
2431
+ if(!is_callback) {
2432
+ par = obj.parent !== $.jstree.root ? $('#' + obj.parent.replace($.jstree.idregex,'\\$&'), this.element)[0] : null;
2433
+ if(par !== null && (!par || !m[obj.parent].state.opened)) {
2434
+ return false;
2435
+ }
2436
+ ind = $.inArray(obj.id, par === null ? m[$.jstree.root].children : m[obj.parent].children);
2437
+ }
2438
+ }
2439
+ else {
2440
+ node = $(node);
2441
+ if(!is_callback) {
2442
+ par = node.parent().parent()[0];
2443
+ if(par === this.element[0]) {
2444
+ par = null;
2445
+ }
2446
+ ind = node.index();
2447
+ }
2448
+ // m[obj.id].data = node.data(); // use only node's data, no need to touch jquery storage
2449
+ if(!deep && obj.children.length && !node.children('.jstree-children').length) {
2450
+ deep = true;
2451
+ }
2452
+ if(!deep) {
2453
+ old = node.children('.jstree-children')[0];
2454
+ }
2455
+ f = node.children('.jstree-anchor')[0] === document.activeElement;
2456
+ node.remove();
2457
+ //node = d.createElement('LI');
2458
+ //node = node[0];
2459
+ }
2460
+ node = this._data.core.node.cloneNode(true);
2461
+ // node is DOM, deep is boolean
2462
+
2463
+ c = 'jstree-node ';
2464
+ for(i in obj.li_attr) {
2465
+ if(obj.li_attr.hasOwnProperty(i)) {
2466
+ if(i === 'id') { continue; }
2467
+ if(i !== 'class') {
2468
+ node.setAttribute(i, obj.li_attr[i]);
2469
+ }
2470
+ else {
2471
+ c += obj.li_attr[i];
2472
+ }
2473
+ }
2474
+ }
2475
+ if(!obj.a_attr.id) {
2476
+ obj.a_attr.id = obj.id + '_anchor';
2477
+ }
2478
+ node.setAttribute('aria-selected', !!obj.state.selected);
2479
+ node.setAttribute('aria-level', obj.parents.length);
2480
+ node.setAttribute('aria-labelledby', obj.a_attr.id);
2481
+ if(obj.state.disabled) {
2482
+ node.setAttribute('aria-disabled', true);
2483
+ }
2484
+
2485
+ for(i = 0, j = obj.children.length; i < j; i++) {
2486
+ if(!m[obj.children[i]].state.hidden) {
2487
+ has_children = true;
2488
+ break;
2489
+ }
2490
+ }
2491
+ if(obj.parent !== null && m[obj.parent] && !obj.state.hidden) {
2492
+ i = $.inArray(obj.id, m[obj.parent].children);
2493
+ last_sibling = obj.id;
2494
+ if(i !== -1) {
2495
+ i++;
2496
+ for(j = m[obj.parent].children.length; i < j; i++) {
2497
+ if(!m[m[obj.parent].children[i]].state.hidden) {
2498
+ last_sibling = m[obj.parent].children[i];
2499
+ }
2500
+ if(last_sibling !== obj.id) {
2501
+ break;
2502
+ }
2503
+ }
2504
+ }
2505
+ }
2506
+
2507
+ if(obj.state.hidden) {
2508
+ c += ' jstree-hidden';
2509
+ }
2510
+ if (obj.state.loading) {
2511
+ c += ' jstree-loading';
2512
+ }
2513
+ if(obj.state.loaded && !has_children) {
2514
+ c += ' jstree-leaf';
2515
+ }
2516
+ else {
2517
+ c += obj.state.opened && obj.state.loaded ? ' jstree-open' : ' jstree-closed';
2518
+ node.setAttribute('aria-expanded', (obj.state.opened && obj.state.loaded) );
2519
+ }
2520
+ if(last_sibling === obj.id) {
2521
+ c += ' jstree-last';
2522
+ }
2523
+ node.id = obj.id;
2524
+ node.className = c;
2525
+ c = ( obj.state.selected ? ' jstree-clicked' : '') + ( obj.state.disabled ? ' jstree-disabled' : '');
2526
+ for(j in obj.a_attr) {
2527
+ if(obj.a_attr.hasOwnProperty(j)) {
2528
+ if(j === 'href' && obj.a_attr[j] === '#') { continue; }
2529
+ if(j !== 'class') {
2530
+ node.childNodes[1].setAttribute(j, obj.a_attr[j]);
2531
+ }
2532
+ else {
2533
+ c += ' ' + obj.a_attr[j];
2534
+ }
2535
+ }
2536
+ }
2537
+ if(c.length) {
2538
+ node.childNodes[1].className = 'jstree-anchor ' + c;
2539
+ }
2540
+ if((obj.icon && obj.icon !== true) || obj.icon === false) {
2541
+ if(obj.icon === false) {
2542
+ node.childNodes[1].childNodes[0].className += ' jstree-themeicon-hidden';
2543
+ }
2544
+ else if(obj.icon.indexOf('/') === -1 && obj.icon.indexOf('.') === -1) {
2545
+ node.childNodes[1].childNodes[0].className += ' ' + obj.icon + ' jstree-themeicon-custom';
2546
+ }
2547
+ else {
2548
+ node.childNodes[1].childNodes[0].style.backgroundImage = 'url("'+obj.icon+'")';
2549
+ node.childNodes[1].childNodes[0].style.backgroundPosition = 'center center';
2550
+ node.childNodes[1].childNodes[0].style.backgroundSize = 'auto';
2551
+ node.childNodes[1].childNodes[0].className += ' jstree-themeicon-custom';
2552
+ }
2553
+ }
2554
+
2555
+ if(this.settings.core.force_text) {
2556
+ node.childNodes[1].appendChild(d.createTextNode(obj.text));
2557
+ }
2558
+ else {
2559
+ node.childNodes[1].innerHTML += obj.text;
2560
+ }
2561
+
2562
+
2563
+ if(deep && obj.children.length && (obj.state.opened || force_render) && obj.state.loaded) {
2564
+ k = d.createElement('UL');
2565
+ k.setAttribute('role', 'group');
2566
+ k.className = 'jstree-children';
2567
+ for(i = 0, j = obj.children.length; i < j; i++) {
2568
+ k.appendChild(this.redraw_node(obj.children[i], deep, true));
2569
+ }
2570
+ node.appendChild(k);
2571
+ }
2572
+ if(old) {
2573
+ node.appendChild(old);
2574
+ }
2575
+ if(!is_callback) {
2576
+ // append back using par / ind
2577
+ if(!par) {
2578
+ par = this.element[0];
2579
+ }
2580
+ for(i = 0, j = par.childNodes.length; i < j; i++) {
2581
+ if(par.childNodes[i] && par.childNodes[i].className && par.childNodes[i].className.indexOf('jstree-children') !== -1) {
2582
+ tmp = par.childNodes[i];
2583
+ break;
2584
+ }
2585
+ }
2586
+ if(!tmp) {
2587
+ tmp = d.createElement('UL');
2588
+ tmp.setAttribute('role', 'group');
2589
+ tmp.className = 'jstree-children';
2590
+ par.appendChild(tmp);
2591
+ }
2592
+ par = tmp;
2593
+
2594
+ if(ind < par.childNodes.length) {
2595
+ par.insertBefore(node, par.childNodes[ind]);
2596
+ }
2597
+ else {
2598
+ par.appendChild(node);
2599
+ }
2600
+ if(f) {
2601
+ t = this.element[0].scrollTop;
2602
+ l = this.element[0].scrollLeft;
2603
+ node.childNodes[1].focus();
2604
+ this.element[0].scrollTop = t;
2605
+ this.element[0].scrollLeft = l;
2606
+ }
2607
+ }
2608
+ if(obj.state.opened && !obj.state.loaded) {
2609
+ obj.state.opened = false;
2610
+ setTimeout($.proxy(function () {
2611
+ this.open_node(obj.id, false, 0);
2612
+ }, this), 0);
2613
+ }
2614
+ return node;
2615
+ },
2616
+ /**
2617
+ * opens a node, revealing its children. If the node is not loaded it will be loaded and opened once ready.
2618
+ * @name open_node(obj [, callback, animation])
2619
+ * @param {mixed} obj the node to open
2620
+ * @param {Function} callback a function to execute once the node is opened
2621
+ * @param {Number} animation the animation duration in milliseconds when opening the node (overrides the `core.animation` setting). Use `false` for no animation.
2622
+ * @trigger open_node.jstree, after_open.jstree, before_open.jstree
2623
+ */
2624
+ open_node : function (obj, callback, animation) {
2625
+ var t1, t2, d, t;
2626
+ if($.isArray(obj)) {
2627
+ obj = obj.slice();
2628
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2629
+ this.open_node(obj[t1], callback, animation);
2630
+ }
2631
+ return true;
2632
+ }
2633
+ obj = this.get_node(obj);
2634
+ if(!obj || obj.id === $.jstree.root) {
2635
+ return false;
2636
+ }
2637
+ animation = animation === undefined ? this.settings.core.animation : animation;
2638
+ if(!this.is_closed(obj)) {
2639
+ if(callback) {
2640
+ callback.call(this, obj, false);
2641
+ }
2642
+ return false;
2643
+ }
2644
+ if(!this.is_loaded(obj)) {
2645
+ if(this.is_loading(obj)) {
2646
+ return setTimeout($.proxy(function () {
2647
+ this.open_node(obj, callback, animation);
2648
+ }, this), 500);
2649
+ }
2650
+ this.load_node(obj, function (o, ok) {
2651
+ return ok ? this.open_node(o, callback, animation) : (callback ? callback.call(this, o, false) : false);
2652
+ });
2653
+ }
2654
+ else {
2655
+ d = this.get_node(obj, true);
2656
+ t = this;
2657
+ if(d.length) {
2658
+ if(animation && d.children(".jstree-children").length) {
2659
+ d.children(".jstree-children").stop(true, true);
2660
+ }
2661
+ if(obj.children.length && !this._firstChild(d.children('.jstree-children')[0])) {
2662
+ this.draw_children(obj);
2663
+ //d = this.get_node(obj, true);
2664
+ }
2665
+ if(!animation) {
2666
+ this.trigger('before_open', { "node" : obj });
2667
+ d[0].className = d[0].className.replace('jstree-closed', 'jstree-open');
2668
+ d[0].setAttribute("aria-expanded", true);
2669
+ }
2670
+ else {
2671
+ this.trigger('before_open', { "node" : obj });
2672
+ d
2673
+ .children(".jstree-children").css("display","none").end()
2674
+ .removeClass("jstree-closed").addClass("jstree-open").attr("aria-expanded", true)
2675
+ .children(".jstree-children").stop(true, true)
2676
+ .slideDown(animation, function () {
2677
+ this.style.display = "";
2678
+ if (t.element) {
2679
+ t.trigger("after_open", { "node" : obj });
2680
+ }
2681
+ });
2682
+ }
2683
+ }
2684
+ obj.state.opened = true;
2685
+ if(callback) {
2686
+ callback.call(this, obj, true);
2687
+ }
2688
+ if(!d.length) {
2689
+ /**
2690
+ * 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)
2691
+ * @event
2692
+ * @name before_open.jstree
2693
+ * @param {Object} node the opened node
2694
+ */
2695
+ this.trigger('before_open', { "node" : obj });
2696
+ }
2697
+ /**
2698
+ * triggered when a node is opened (if there is an animation it will not be completed yet)
2699
+ * @event
2700
+ * @name open_node.jstree
2701
+ * @param {Object} node the opened node
2702
+ */
2703
+ this.trigger('open_node', { "node" : obj });
2704
+ if(!animation || !d.length) {
2705
+ /**
2706
+ * triggered when a node is opened and the animation is complete
2707
+ * @event
2708
+ * @name after_open.jstree
2709
+ * @param {Object} node the opened node
2710
+ */
2711
+ this.trigger("after_open", { "node" : obj });
2712
+ }
2713
+ return true;
2714
+ }
2715
+ },
2716
+ /**
2717
+ * opens every parent of a node (node should be loaded)
2718
+ * @name _open_to(obj)
2719
+ * @param {mixed} obj the node to reveal
2720
+ * @private
2721
+ */
2722
+ _open_to : function (obj) {
2723
+ obj = this.get_node(obj);
2724
+ if(!obj || obj.id === $.jstree.root) {
2725
+ return false;
2726
+ }
2727
+ var i, j, p = obj.parents;
2728
+ for(i = 0, j = p.length; i < j; i+=1) {
2729
+ if(i !== $.jstree.root) {
2730
+ this.open_node(p[i], false, 0);
2731
+ }
2732
+ }
2733
+ return $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
2734
+ },
2735
+ /**
2736
+ * closes a node, hiding its children
2737
+ * @name close_node(obj [, animation])
2738
+ * @param {mixed} obj the node to close
2739
+ * @param {Number} animation the animation duration in milliseconds when closing the node (overrides the `core.animation` setting). Use `false` for no animation.
2740
+ * @trigger close_node.jstree, after_close.jstree
2741
+ */
2742
+ close_node : function (obj, animation) {
2743
+ var t1, t2, t, d;
2744
+ if($.isArray(obj)) {
2745
+ obj = obj.slice();
2746
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2747
+ this.close_node(obj[t1], animation);
2748
+ }
2749
+ return true;
2750
+ }
2751
+ obj = this.get_node(obj);
2752
+ if(!obj || obj.id === $.jstree.root) {
2753
+ return false;
2754
+ }
2755
+ if(this.is_closed(obj)) {
2756
+ return false;
2757
+ }
2758
+ animation = animation === undefined ? this.settings.core.animation : animation;
2759
+ t = this;
2760
+ d = this.get_node(obj, true);
2761
+
2762
+ obj.state.opened = false;
2763
+ /**
2764
+ * triggered when a node is closed (if there is an animation it will not be complete yet)
2765
+ * @event
2766
+ * @name close_node.jstree
2767
+ * @param {Object} node the closed node
2768
+ */
2769
+ this.trigger('close_node',{ "node" : obj });
2770
+ if(!d.length) {
2771
+ /**
2772
+ * triggered when a node is closed and the animation is complete
2773
+ * @event
2774
+ * @name after_close.jstree
2775
+ * @param {Object} node the closed node
2776
+ */
2777
+ this.trigger("after_close", { "node" : obj });
2778
+ }
2779
+ else {
2780
+ if(!animation) {
2781
+ d[0].className = d[0].className.replace('jstree-open', 'jstree-closed');
2782
+ d.attr("aria-expanded", false).children('.jstree-children').remove();
2783
+ this.trigger("after_close", { "node" : obj });
2784
+ }
2785
+ else {
2786
+ d
2787
+ .children(".jstree-children").attr("style","display:block !important").end()
2788
+ .removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded", false)
2789
+ .children(".jstree-children").stop(true, true).slideUp(animation, function () {
2790
+ this.style.display = "";
2791
+ d.children('.jstree-children').remove();
2792
+ if (t.element) {
2793
+ t.trigger("after_close", { "node" : obj });
2794
+ }
2795
+ });
2796
+ }
2797
+ }
2798
+ },
2799
+ /**
2800
+ * toggles a node - closing it if it is open, opening it if it is closed
2801
+ * @name toggle_node(obj)
2802
+ * @param {mixed} obj the node to toggle
2803
+ */
2804
+ toggle_node : function (obj) {
2805
+ var t1, t2;
2806
+ if($.isArray(obj)) {
2807
+ obj = obj.slice();
2808
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2809
+ this.toggle_node(obj[t1]);
2810
+ }
2811
+ return true;
2812
+ }
2813
+ if(this.is_closed(obj)) {
2814
+ return this.open_node(obj);
2815
+ }
2816
+ if(this.is_open(obj)) {
2817
+ return this.close_node(obj);
2818
+ }
2819
+ },
2820
+ /**
2821
+ * opens all nodes within a node (or the tree), revealing their children. If the node is not loaded it will be loaded and opened once ready.
2822
+ * @name open_all([obj, animation, original_obj])
2823
+ * @param {mixed} obj the node to open recursively, omit to open all nodes in the tree
2824
+ * @param {Number} animation the animation duration in milliseconds when opening the nodes, the default is no animation
2825
+ * @param {jQuery} reference to the node that started the process (internal use)
2826
+ * @trigger open_all.jstree
2827
+ */
2828
+ open_all : function (obj, animation, original_obj) {
2829
+ if(!obj) { obj = $.jstree.root; }
2830
+ obj = this.get_node(obj);
2831
+ if(!obj) { return false; }
2832
+ var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true), i, j, _this;
2833
+ if(!dom.length) {
2834
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
2835
+ if(this.is_closed(this._model.data[obj.children_d[i]])) {
2836
+ this._model.data[obj.children_d[i]].state.opened = true;
2837
+ }
2838
+ }
2839
+ return this.trigger('open_all', { "node" : obj });
2840
+ }
2841
+ original_obj = original_obj || dom;
2842
+ _this = this;
2843
+ dom = this.is_closed(obj) ? dom.find('.jstree-closed').addBack() : dom.find('.jstree-closed');
2844
+ dom.each(function () {
2845
+ _this.open_node(
2846
+ this,
2847
+ function(node, status) { if(status && this.is_parent(node)) { this.open_all(node, animation, original_obj); } },
2848
+ animation || 0
2849
+ );
2850
+ });
2851
+ if(original_obj.find('.jstree-closed').length === 0) {
2852
+ /**
2853
+ * triggered when an `open_all` call completes
2854
+ * @event
2855
+ * @name open_all.jstree
2856
+ * @param {Object} node the opened node
2857
+ */
2858
+ this.trigger('open_all', { "node" : this.get_node(original_obj) });
2859
+ }
2860
+ },
2861
+ /**
2862
+ * closes all nodes within a node (or the tree), revealing their children
2863
+ * @name close_all([obj, animation])
2864
+ * @param {mixed} obj the node to close recursively, omit to close all nodes in the tree
2865
+ * @param {Number} animation the animation duration in milliseconds when closing the nodes, the default is no animation
2866
+ * @trigger close_all.jstree
2867
+ */
2868
+ close_all : function (obj, animation) {
2869
+ if(!obj) { obj = $.jstree.root; }
2870
+ obj = this.get_node(obj);
2871
+ if(!obj) { return false; }
2872
+ var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true),
2873
+ _this = this, i, j;
2874
+ if(dom.length) {
2875
+ dom = this.is_open(obj) ? dom.find('.jstree-open').addBack() : dom.find('.jstree-open');
2876
+ $(dom.get().reverse()).each(function () { _this.close_node(this, animation || 0); });
2877
+ }
2878
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
2879
+ this._model.data[obj.children_d[i]].state.opened = false;
2880
+ }
2881
+ /**
2882
+ * triggered when an `close_all` call completes
2883
+ * @event
2884
+ * @name close_all.jstree
2885
+ * @param {Object} node the closed node
2886
+ */
2887
+ this.trigger('close_all', { "node" : obj });
2888
+ },
2889
+ /**
2890
+ * checks if a node is disabled (not selectable)
2891
+ * @name is_disabled(obj)
2892
+ * @param {mixed} obj
2893
+ * @return {Boolean}
2894
+ */
2895
+ is_disabled : function (obj) {
2896
+ obj = this.get_node(obj);
2897
+ return obj && obj.state && obj.state.disabled;
2898
+ },
2899
+ /**
2900
+ * enables a node - so that it can be selected
2901
+ * @name enable_node(obj)
2902
+ * @param {mixed} obj the node to enable
2903
+ * @trigger enable_node.jstree
2904
+ */
2905
+ enable_node : function (obj) {
2906
+ var t1, t2;
2907
+ if($.isArray(obj)) {
2908
+ obj = obj.slice();
2909
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2910
+ this.enable_node(obj[t1]);
2911
+ }
2912
+ return true;
2913
+ }
2914
+ obj = this.get_node(obj);
2915
+ if(!obj || obj.id === $.jstree.root) {
2916
+ return false;
2917
+ }
2918
+ obj.state.disabled = false;
2919
+ this.get_node(obj,true).children('.jstree-anchor').removeClass('jstree-disabled').attr('aria-disabled', false);
2920
+ /**
2921
+ * triggered when an node is enabled
2922
+ * @event
2923
+ * @name enable_node.jstree
2924
+ * @param {Object} node the enabled node
2925
+ */
2926
+ this.trigger('enable_node', { 'node' : obj });
2927
+ },
2928
+ /**
2929
+ * disables a node - so that it can not be selected
2930
+ * @name disable_node(obj)
2931
+ * @param {mixed} obj the node to disable
2932
+ * @trigger disable_node.jstree
2933
+ */
2934
+ disable_node : function (obj) {
2935
+ var t1, t2;
2936
+ if($.isArray(obj)) {
2937
+ obj = obj.slice();
2938
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2939
+ this.disable_node(obj[t1]);
2940
+ }
2941
+ return true;
2942
+ }
2943
+ obj = this.get_node(obj);
2944
+ if(!obj || obj.id === $.jstree.root) {
2945
+ return false;
2946
+ }
2947
+ obj.state.disabled = true;
2948
+ this.get_node(obj,true).children('.jstree-anchor').addClass('jstree-disabled').attr('aria-disabled', true);
2949
+ /**
2950
+ * triggered when an node is disabled
2951
+ * @event
2952
+ * @name disable_node.jstree
2953
+ * @param {Object} node the disabled node
2954
+ */
2955
+ this.trigger('disable_node', { 'node' : obj });
2956
+ },
2957
+ /**
2958
+ * determines if a node is hidden
2959
+ * @name is_hidden(obj)
2960
+ * @param {mixed} obj the node
2961
+ */
2962
+ is_hidden : function (obj) {
2963
+ obj = this.get_node(obj);
2964
+ return obj.state.hidden === true;
2965
+ },
2966
+ /**
2967
+ * hides a node - it is still in the structure but will not be visible
2968
+ * @name hide_node(obj)
2969
+ * @param {mixed} obj the node to hide
2970
+ * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
2971
+ * @trigger hide_node.jstree
2972
+ */
2973
+ hide_node : function (obj, skip_redraw) {
2974
+ var t1, t2;
2975
+ if($.isArray(obj)) {
2976
+ obj = obj.slice();
2977
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2978
+ this.hide_node(obj[t1], true);
2979
+ }
2980
+ if (!skip_redraw) {
2981
+ this.redraw();
2982
+ }
2983
+ return true;
2984
+ }
2985
+ obj = this.get_node(obj);
2986
+ if(!obj || obj.id === $.jstree.root) {
2987
+ return false;
2988
+ }
2989
+ if(!obj.state.hidden) {
2990
+ obj.state.hidden = true;
2991
+ this._node_changed(obj.parent);
2992
+ if(!skip_redraw) {
2993
+ this.redraw();
2994
+ }
2995
+ /**
2996
+ * triggered when an node is hidden
2997
+ * @event
2998
+ * @name hide_node.jstree
2999
+ * @param {Object} node the hidden node
3000
+ */
3001
+ this.trigger('hide_node', { 'node' : obj });
3002
+ }
3003
+ },
3004
+ /**
3005
+ * shows a node
3006
+ * @name show_node(obj)
3007
+ * @param {mixed} obj the node to show
3008
+ * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
3009
+ * @trigger show_node.jstree
3010
+ */
3011
+ show_node : function (obj, skip_redraw) {
3012
+ var t1, t2;
3013
+ if($.isArray(obj)) {
3014
+ obj = obj.slice();
3015
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3016
+ this.show_node(obj[t1], true);
3017
+ }
3018
+ if (!skip_redraw) {
3019
+ this.redraw();
3020
+ }
3021
+ return true;
3022
+ }
3023
+ obj = this.get_node(obj);
3024
+ if(!obj || obj.id === $.jstree.root) {
3025
+ return false;
3026
+ }
3027
+ if(obj.state.hidden) {
3028
+ obj.state.hidden = false;
3029
+ this._node_changed(obj.parent);
3030
+ if(!skip_redraw) {
3031
+ this.redraw();
3032
+ }
3033
+ /**
3034
+ * triggered when an node is shown
3035
+ * @event
3036
+ * @name show_node.jstree
3037
+ * @param {Object} node the shown node
3038
+ */
3039
+ this.trigger('show_node', { 'node' : obj });
3040
+ }
3041
+ },
3042
+ /**
3043
+ * hides all nodes
3044
+ * @name hide_all()
3045
+ * @trigger hide_all.jstree
3046
+ */
3047
+ hide_all : function (skip_redraw) {
3048
+ var i, m = this._model.data, ids = [];
3049
+ for(i in m) {
3050
+ if(m.hasOwnProperty(i) && i !== $.jstree.root && !m[i].state.hidden) {
3051
+ m[i].state.hidden = true;
3052
+ ids.push(i);
3053
+ }
3054
+ }
3055
+ this._model.force_full_redraw = true;
3056
+ if(!skip_redraw) {
3057
+ this.redraw();
3058
+ }
3059
+ /**
3060
+ * triggered when all nodes are hidden
3061
+ * @event
3062
+ * @name hide_all.jstree
3063
+ * @param {Array} nodes the IDs of all hidden nodes
3064
+ */
3065
+ this.trigger('hide_all', { 'nodes' : ids });
3066
+ return ids;
3067
+ },
3068
+ /**
3069
+ * shows all nodes
3070
+ * @name show_all()
3071
+ * @trigger show_all.jstree
3072
+ */
3073
+ show_all : function (skip_redraw) {
3074
+ var i, m = this._model.data, ids = [];
3075
+ for(i in m) {
3076
+ if(m.hasOwnProperty(i) && i !== $.jstree.root && m[i].state.hidden) {
3077
+ m[i].state.hidden = false;
3078
+ ids.push(i);
3079
+ }
3080
+ }
3081
+ this._model.force_full_redraw = true;
3082
+ if(!skip_redraw) {
3083
+ this.redraw();
3084
+ }
3085
+ /**
3086
+ * triggered when all nodes are shown
3087
+ * @event
3088
+ * @name show_all.jstree
3089
+ * @param {Array} nodes the IDs of all shown nodes
3090
+ */
3091
+ this.trigger('show_all', { 'nodes' : ids });
3092
+ return ids;
3093
+ },
3094
+ /**
3095
+ * called when a node is selected by the user. Used internally.
3096
+ * @private
3097
+ * @name activate_node(obj, e)
3098
+ * @param {mixed} obj the node
3099
+ * @param {Object} e the related event
3100
+ * @trigger activate_node.jstree, changed.jstree
3101
+ */
3102
+ activate_node : function (obj, e) {
3103
+ if(this.is_disabled(obj)) {
3104
+ return false;
3105
+ }
3106
+ if(!e || typeof e !== 'object') {
3107
+ e = {};
3108
+ }
3109
+
3110
+ // 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
3111
+ 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;
3112
+ if(this._data.core.last_clicked && !this._data.core.last_clicked.state.selected) { this._data.core.last_clicked = null; }
3113
+ 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]); }
3114
+
3115
+ 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 ) )) {
3116
+ if(!this.settings.core.multiple && (e.metaKey || e.ctrlKey || e.shiftKey) && this.is_selected(obj)) {
3117
+ this.deselect_node(obj, false, e);
3118
+ }
3119
+ else {
3120
+ this.deselect_all(true);
3121
+ this.select_node(obj, false, false, e);
3122
+ this._data.core.last_clicked = this.get_node(obj);
3123
+ }
3124
+ }
3125
+ else {
3126
+ if(e.shiftKey) {
3127
+ var o = this.get_node(obj).id,
3128
+ l = this._data.core.last_clicked.id,
3129
+ p = this.get_node(this._data.core.last_clicked.parent).children,
3130
+ c = false,
3131
+ i, j;
3132
+ for(i = 0, j = p.length; i < j; i += 1) {
3133
+ // separate IFs work whem o and l are the same
3134
+ if(p[i] === o) {
3135
+ c = !c;
3136
+ }
3137
+ if(p[i] === l) {
3138
+ c = !c;
3139
+ }
3140
+ if(!this.is_disabled(p[i]) && (c || p[i] === o || p[i] === l)) {
3141
+ if (!this.is_hidden(p[i])) {
3142
+ this.select_node(p[i], true, false, e);
3143
+ }
3144
+ }
3145
+ else {
3146
+ this.deselect_node(p[i], true, e);
3147
+ }
3148
+ }
3149
+ this.trigger('changed', { 'action' : 'select_node', 'node' : this.get_node(obj), 'selected' : this._data.core.selected, 'event' : e });
3150
+ }
3151
+ else {
3152
+ if(!this.is_selected(obj)) {
3153
+ this.select_node(obj, false, false, e);
3154
+ }
3155
+ else {
3156
+ this.deselect_node(obj, false, e);
3157
+ }
3158
+ }
3159
+ }
3160
+ /**
3161
+ * triggered when an node is clicked or intercated with by the user
3162
+ * @event
3163
+ * @name activate_node.jstree
3164
+ * @param {Object} node
3165
+ * @param {Object} event the ooriginal event (if any) which triggered the call (may be an empty object)
3166
+ */
3167
+ this.trigger('activate_node', { 'node' : this.get_node(obj), 'event' : e });
3168
+ },
3169
+ /**
3170
+ * applies the hover state on a node, called when a node is hovered by the user. Used internally.
3171
+ * @private
3172
+ * @name hover_node(obj)
3173
+ * @param {mixed} obj
3174
+ * @trigger hover_node.jstree
3175
+ */
3176
+ hover_node : function (obj) {
3177
+ obj = this.get_node(obj, true);
3178
+ if(!obj || !obj.length || obj.children('.jstree-hovered').length) {
3179
+ return false;
3180
+ }
3181
+ var o = this.element.find('.jstree-hovered'), t = this.element;
3182
+ if(o && o.length) { this.dehover_node(o); }
3183
+
3184
+ obj.children('.jstree-anchor').addClass('jstree-hovered');
3185
+ /**
3186
+ * triggered when an node is hovered
3187
+ * @event
3188
+ * @name hover_node.jstree
3189
+ * @param {Object} node
3190
+ */
3191
+ this.trigger('hover_node', { 'node' : this.get_node(obj) });
3192
+ setTimeout(function () { t.attr('aria-activedescendant', obj[0].id); }, 0);
3193
+ },
3194
+ /**
3195
+ * removes the hover state from a nodecalled when a node is no longer hovered by the user. Used internally.
3196
+ * @private
3197
+ * @name dehover_node(obj)
3198
+ * @param {mixed} obj
3199
+ * @trigger dehover_node.jstree
3200
+ */
3201
+ dehover_node : function (obj) {
3202
+ obj = this.get_node(obj, true);
3203
+ if(!obj || !obj.length || !obj.children('.jstree-hovered').length) {
3204
+ return false;
3205
+ }
3206
+ obj.children('.jstree-anchor').removeClass('jstree-hovered');
3207
+ /**
3208
+ * triggered when an node is no longer hovered
3209
+ * @event
3210
+ * @name dehover_node.jstree
3211
+ * @param {Object} node
3212
+ */
3213
+ this.trigger('dehover_node', { 'node' : this.get_node(obj) });
3214
+ },
3215
+ /**
3216
+ * select a node
3217
+ * @name select_node(obj [, supress_event, prevent_open])
3218
+ * @param {mixed} obj an array can be used to select multiple nodes
3219
+ * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3220
+ * @param {Boolean} prevent_open if set to `true` parents of the selected node won't be opened
3221
+ * @trigger select_node.jstree, changed.jstree
3222
+ */
3223
+ select_node : function (obj, supress_event, prevent_open, e) {
3224
+ var dom, t1, t2, th;
3225
+ if($.isArray(obj)) {
3226
+ obj = obj.slice();
3227
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3228
+ this.select_node(obj[t1], supress_event, prevent_open, e);
3229
+ }
3230
+ return true;
3231
+ }
3232
+ obj = this.get_node(obj);
3233
+ if(!obj || obj.id === $.jstree.root) {
3234
+ return false;
3235
+ }
3236
+ dom = this.get_node(obj, true);
3237
+ if(!obj.state.selected) {
3238
+ obj.state.selected = true;
3239
+ this._data.core.selected.push(obj.id);
3240
+ if(!prevent_open) {
3241
+ dom = this._open_to(obj);
3242
+ }
3243
+ if(dom && dom.length) {
3244
+ dom.attr('aria-selected', true).children('.jstree-anchor').addClass('jstree-clicked');
3245
+ }
3246
+ /**
3247
+ * triggered when an node is selected
3248
+ * @event
3249
+ * @name select_node.jstree
3250
+ * @param {Object} node
3251
+ * @param {Array} selected the current selection
3252
+ * @param {Object} event the event (if any) that triggered this select_node
3253
+ */
3254
+ this.trigger('select_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3255
+ if(!supress_event) {
3256
+ /**
3257
+ * triggered when selection changes
3258
+ * @event
3259
+ * @name changed.jstree
3260
+ * @param {Object} node
3261
+ * @param {Object} action the action that caused the selection to change
3262
+ * @param {Array} selected the current selection
3263
+ * @param {Object} event the event (if any) that triggered this changed event
3264
+ */
3265
+ this.trigger('changed', { 'action' : 'select_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3266
+ }
3267
+ }
3268
+ },
3269
+ /**
3270
+ * deselect a node
3271
+ * @name deselect_node(obj [, supress_event])
3272
+ * @param {mixed} obj an array can be used to deselect multiple nodes
3273
+ * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3274
+ * @trigger deselect_node.jstree, changed.jstree
3275
+ */
3276
+ deselect_node : function (obj, supress_event, e) {
3277
+ var t1, t2, dom;
3278
+ if($.isArray(obj)) {
3279
+ obj = obj.slice();
3280
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3281
+ this.deselect_node(obj[t1], supress_event, e);
3282
+ }
3283
+ return true;
3284
+ }
3285
+ obj = this.get_node(obj);
3286
+ if(!obj || obj.id === $.jstree.root) {
3287
+ return false;
3288
+ }
3289
+ dom = this.get_node(obj, true);
3290
+ if(obj.state.selected) {
3291
+ obj.state.selected = false;
3292
+ this._data.core.selected = $.vakata.array_remove_item(this._data.core.selected, obj.id);
3293
+ if(dom.length) {
3294
+ dom.attr('aria-selected', false).children('.jstree-anchor').removeClass('jstree-clicked');
3295
+ }
3296
+ /**
3297
+ * triggered when an node is deselected
3298
+ * @event
3299
+ * @name deselect_node.jstree
3300
+ * @param {Object} node
3301
+ * @param {Array} selected the current selection
3302
+ * @param {Object} event the event (if any) that triggered this deselect_node
3303
+ */
3304
+ this.trigger('deselect_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3305
+ if(!supress_event) {
3306
+ this.trigger('changed', { 'action' : 'deselect_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3307
+ }
3308
+ }
3309
+ },
3310
+ /**
3311
+ * select all nodes in the tree
3312
+ * @name select_all([supress_event])
3313
+ * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3314
+ * @trigger select_all.jstree, changed.jstree
3315
+ */
3316
+ select_all : function (supress_event) {
3317
+ var tmp = this._data.core.selected.concat([]), i, j;
3318
+ this._data.core.selected = this._model.data[$.jstree.root].children_d.concat();
3319
+ for(i = 0, j = this._data.core.selected.length; i < j; i++) {
3320
+ if(this._model.data[this._data.core.selected[i]]) {
3321
+ this._model.data[this._data.core.selected[i]].state.selected = true;
3322
+ }
3323
+ }
3324
+ this.redraw(true);
3325
+ /**
3326
+ * triggered when all nodes are selected
3327
+ * @event
3328
+ * @name select_all.jstree
3329
+ * @param {Array} selected the current selection
3330
+ */
3331
+ this.trigger('select_all', { 'selected' : this._data.core.selected });
3332
+ if(!supress_event) {
3333
+ this.trigger('changed', { 'action' : 'select_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
3334
+ }
3335
+ },
3336
+ /**
3337
+ * deselect all selected nodes
3338
+ * @name deselect_all([supress_event])
3339
+ * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3340
+ * @trigger deselect_all.jstree, changed.jstree
3341
+ */
3342
+ deselect_all : function (supress_event) {
3343
+ var tmp = this._data.core.selected.concat([]), i, j;
3344
+ for(i = 0, j = this._data.core.selected.length; i < j; i++) {
3345
+ if(this._model.data[this._data.core.selected[i]]) {
3346
+ this._model.data[this._data.core.selected[i]].state.selected = false;
3347
+ }
3348
+ }
3349
+ this._data.core.selected = [];
3350
+ this.element.find('.jstree-clicked').removeClass('jstree-clicked').parent().attr('aria-selected', false);
3351
+ /**
3352
+ * triggered when all nodes are deselected
3353
+ * @event
3354
+ * @name deselect_all.jstree
3355
+ * @param {Object} node the previous selection
3356
+ * @param {Array} selected the current selection
3357
+ */
3358
+ this.trigger('deselect_all', { 'selected' : this._data.core.selected, 'node' : tmp });
3359
+ if(!supress_event) {
3360
+ this.trigger('changed', { 'action' : 'deselect_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
3361
+ }
3362
+ },
3363
+ /**
3364
+ * checks if a node is selected
3365
+ * @name is_selected(obj)
3366
+ * @param {mixed} obj
3367
+ * @return {Boolean}
3368
+ */
3369
+ is_selected : function (obj) {
3370
+ obj = this.get_node(obj);
3371
+ if(!obj || obj.id === $.jstree.root) {
3372
+ return false;
3373
+ }
3374
+ return obj.state.selected;
3375
+ },
3376
+ /**
3377
+ * get an array of all selected nodes
3378
+ * @name get_selected([full])
3379
+ * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
3380
+ * @return {Array}
3381
+ */
3382
+ get_selected : function (full) {
3383
+ return full ? $.map(this._data.core.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.core.selected.slice();
3384
+ },
3385
+ /**
3386
+ * get an array of all top level selected nodes (ignoring children of selected nodes)
3387
+ * @name get_top_selected([full])
3388
+ * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
3389
+ * @return {Array}
3390
+ */
3391
+ get_top_selected : function (full) {
3392
+ var tmp = this.get_selected(true),
3393
+ obj = {}, i, j, k, l;
3394
+ for(i = 0, j = tmp.length; i < j; i++) {
3395
+ obj[tmp[i].id] = tmp[i];
3396
+ }
3397
+ for(i = 0, j = tmp.length; i < j; i++) {
3398
+ for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
3399
+ if(obj[tmp[i].children_d[k]]) {
3400
+ delete obj[tmp[i].children_d[k]];
3401
+ }
3402
+ }
3403
+ }
3404
+ tmp = [];
3405
+ for(i in obj) {
3406
+ if(obj.hasOwnProperty(i)) {
3407
+ tmp.push(i);
3408
+ }
3409
+ }
3410
+ return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
3411
+ },
3412
+ /**
3413
+ * get an array of all bottom level selected nodes (ignoring selected parents)
3414
+ * @name get_bottom_selected([full])
3415
+ * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
3416
+ * @return {Array}
3417
+ */
3418
+ get_bottom_selected : function (full) {
3419
+ var tmp = this.get_selected(true),
3420
+ obj = [], i, j;
3421
+ for(i = 0, j = tmp.length; i < j; i++) {
3422
+ if(!tmp[i].children.length) {
3423
+ obj.push(tmp[i].id);
3424
+ }
3425
+ }
3426
+ return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
3427
+ },
3428
+ /**
3429
+ * gets the current state of the tree so that it can be restored later with `set_state(state)`. Used internally.
3430
+ * @name get_state()
3431
+ * @private
3432
+ * @return {Object}
3433
+ */
3434
+ get_state : function () {
3435
+ var state = {
3436
+ 'core' : {
3437
+ 'open' : [],
3438
+ 'loaded' : [],
3439
+ 'scroll' : {
3440
+ 'left' : this.element.scrollLeft(),
3441
+ 'top' : this.element.scrollTop()
3442
+ },
3443
+ /*!
3444
+ 'themes' : {
3445
+ 'name' : this.get_theme(),
3446
+ 'icons' : this._data.core.themes.icons,
3447
+ 'dots' : this._data.core.themes.dots
3448
+ },
3449
+ */
3450
+ 'selected' : []
3451
+ }
3452
+ }, i;
3453
+ for(i in this._model.data) {
3454
+ if(this._model.data.hasOwnProperty(i)) {
3455
+ if(i !== $.jstree.root) {
3456
+ if(this._model.data[i].state.loaded && this.settings.core.loaded_state) {
3457
+ state.core.loaded.push(i);
3458
+ }
3459
+ if(this._model.data[i].state.opened) {
3460
+ state.core.open.push(i);
3461
+ }
3462
+ if(this._model.data[i].state.selected) {
3463
+ state.core.selected.push(i);
3464
+ }
3465
+ }
3466
+ }
3467
+ }
3468
+ return state;
3469
+ },
3470
+ /**
3471
+ * sets the state of the tree. Used internally.
3472
+ * @name set_state(state [, callback])
3473
+ * @private
3474
+ * @param {Object} state the state to restore. Keep in mind this object is passed by reference and jstree will modify it.
3475
+ * @param {Function} callback an optional function to execute once the state is restored.
3476
+ * @trigger set_state.jstree
3477
+ */
3478
+ set_state : function (state, callback) {
3479
+ if(state) {
3480
+ if(state.core && state.core.selected && state.core.initial_selection === undefined) {
3481
+ state.core.initial_selection = this._data.core.selected.concat([]).sort().join(',');
3482
+ }
3483
+ if(state.core) {
3484
+ var res, n, t, _this, i;
3485
+ if(state.core.loaded) {
3486
+ if(!this.settings.core.loaded_state || !$.isArray(state.core.loaded) || !state.core.loaded.length) {
3487
+ delete state.core.loaded;
3488
+ this.set_state(state, callback);
3489
+ }
3490
+ else {
3491
+ this._load_nodes(state.core.loaded, function (nodes) {
3492
+ delete state.core.loaded;
3493
+ this.set_state(state, callback);
3494
+ });
3495
+ }
3496
+ return false;
3497
+ }
3498
+ if(state.core.open) {
3499
+ if(!$.isArray(state.core.open) || !state.core.open.length) {
3500
+ delete state.core.open;
3501
+ this.set_state(state, callback);
3502
+ }
3503
+ else {
3504
+ this._load_nodes(state.core.open, function (nodes) {
3505
+ this.open_node(nodes, false, 0);
3506
+ delete state.core.open;
3507
+ this.set_state(state, callback);
3508
+ });
3509
+ }
3510
+ return false;
3511
+ }
3512
+ if(state.core.scroll) {
3513
+ if(state.core.scroll && state.core.scroll.left !== undefined) {
3514
+ this.element.scrollLeft(state.core.scroll.left);
3515
+ }
3516
+ if(state.core.scroll && state.core.scroll.top !== undefined) {
3517
+ this.element.scrollTop(state.core.scroll.top);
3518
+ }
3519
+ delete state.core.scroll;
3520
+ this.set_state(state, callback);
3521
+ return false;
3522
+ }
3523
+ if(state.core.selected) {
3524
+ _this = this;
3525
+ if (state.core.initial_selection === undefined ||
3526
+ state.core.initial_selection === this._data.core.selected.concat([]).sort().join(',')
3527
+ ) {
3528
+ this.deselect_all();
3529
+ $.each(state.core.selected, function (i, v) {
3530
+ _this.select_node(v, false, true);
3531
+ });
3532
+ }
3533
+ delete state.core.initial_selection;
3534
+ delete state.core.selected;
3535
+ this.set_state(state, callback);
3536
+ return false;
3537
+ }
3538
+ for(i in state) {
3539
+ if(state.hasOwnProperty(i) && i !== "core" && $.inArray(i, this.settings.plugins) === -1) {
3540
+ delete state[i];
3541
+ }
3542
+ }
3543
+ if($.isEmptyObject(state.core)) {
3544
+ delete state.core;
3545
+ this.set_state(state, callback);
3546
+ return false;
3547
+ }
3548
+ }
3549
+ if($.isEmptyObject(state)) {
3550
+ state = null;
3551
+ if(callback) { callback.call(this); }
3552
+ /**
3553
+ * triggered when a `set_state` call completes
3554
+ * @event
3555
+ * @name set_state.jstree
3556
+ */
3557
+ this.trigger('set_state');
3558
+ return false;
3559
+ }
3560
+ return true;
3561
+ }
3562
+ return false;
3563
+ },
3564
+ /**
3565
+ * refreshes the tree - all nodes are reloaded with calls to `load_node`.
3566
+ * @name refresh()
3567
+ * @param {Boolean} skip_loading an option to skip showing the loading indicator
3568
+ * @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
3569
+ * @trigger refresh.jstree
3570
+ */
3571
+ refresh : function (skip_loading, forget_state) {
3572
+ this._data.core.state = forget_state === true ? {} : this.get_state();
3573
+ if(forget_state && $.isFunction(forget_state)) { this._data.core.state = forget_state.call(this, this._data.core.state); }
3574
+ this._cnt = 0;
3575
+ this._model.data = {};
3576
+ this._model.data[$.jstree.root] = {
3577
+ id : $.jstree.root,
3578
+ parent : null,
3579
+ parents : [],
3580
+ children : [],
3581
+ children_d : [],
3582
+ state : { loaded : false }
3583
+ };
3584
+ this._data.core.selected = [];
3585
+ this._data.core.last_clicked = null;
3586
+ this._data.core.focused = null;
3587
+
3588
+ var c = this.get_container_ul()[0].className;
3589
+ if(!skip_loading) {
3590
+ 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>");
3591
+ this.element.attr('aria-activedescendant','j'+this._id+'_loading');
3592
+ }
3593
+ this.load_node($.jstree.root, function (o, s) {
3594
+ if(s) {
3595
+ this.get_container_ul()[0].className = c;
3596
+ if(this._firstChild(this.get_container_ul()[0])) {
3597
+ this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
3598
+ }
3599
+ this.set_state($.extend(true, {}, this._data.core.state), function () {
3600
+ /**
3601
+ * triggered when a `refresh` call completes
3602
+ * @event
3603
+ * @name refresh.jstree
3604
+ */
3605
+ this.trigger('refresh');
3606
+ });
3607
+ }
3608
+ this._data.core.state = null;
3609
+ });
3610
+ },
3611
+ /**
3612
+ * refreshes a node in the tree (reload its children) all opened nodes inside that node are reloaded with calls to `load_node`.
3613
+ * @name refresh_node(obj)
3614
+ * @param {mixed} obj the node
3615
+ * @trigger refresh_node.jstree
3616
+ */
3617
+ refresh_node : function (obj) {
3618
+ obj = this.get_node(obj);
3619
+ if(!obj || obj.id === $.jstree.root) { return false; }
3620
+ var opened = [], to_load = [], s = this._data.core.selected.concat([]);
3621
+ to_load.push(obj.id);
3622
+ if(obj.state.opened === true) { opened.push(obj.id); }
3623
+ this.get_node(obj, true).find('.jstree-open').each(function() { to_load.push(this.id); opened.push(this.id); });
3624
+ this._load_nodes(to_load, $.proxy(function (nodes) {
3625
+ this.open_node(opened, false, 0);
3626
+ this.select_node(s);
3627
+ /**
3628
+ * triggered when a node is refreshed
3629
+ * @event
3630
+ * @name refresh_node.jstree
3631
+ * @param {Object} node - the refreshed node
3632
+ * @param {Array} nodes - an array of the IDs of the nodes that were reloaded
3633
+ */
3634
+ this.trigger('refresh_node', { 'node' : obj, 'nodes' : nodes });
3635
+ }, this), false, true);
3636
+ },
3637
+ /**
3638
+ * set (change) the ID of a node
3639
+ * @name set_id(obj, id)
3640
+ * @param {mixed} obj the node
3641
+ * @param {String} id the new ID
3642
+ * @return {Boolean}
3643
+ * @trigger set_id.jstree
3644
+ */
3645
+ set_id : function (obj, id) {
3646
+ obj = this.get_node(obj);
3647
+ if(!obj || obj.id === $.jstree.root) { return false; }
3648
+ var i, j, m = this._model.data, old = obj.id;
3649
+ id = id.toString();
3650
+ // update parents (replace current ID with new one in children and children_d)
3651
+ m[obj.parent].children[$.inArray(obj.id, m[obj.parent].children)] = id;
3652
+ for(i = 0, j = obj.parents.length; i < j; i++) {
3653
+ m[obj.parents[i]].children_d[$.inArray(obj.id, m[obj.parents[i]].children_d)] = id;
3654
+ }
3655
+ // update children (replace current ID with new one in parent and parents)
3656
+ for(i = 0, j = obj.children.length; i < j; i++) {
3657
+ m[obj.children[i]].parent = id;
3658
+ }
3659
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
3660
+ m[obj.children_d[i]].parents[$.inArray(obj.id, m[obj.children_d[i]].parents)] = id;
3661
+ }
3662
+ i = $.inArray(obj.id, this._data.core.selected);
3663
+ if(i !== -1) { this._data.core.selected[i] = id; }
3664
+ // update model and obj itself (obj.id, this._model.data[KEY])
3665
+ i = this.get_node(obj.id, true);
3666
+ if(i) {
3667
+ i.attr('id', id); //.children('.jstree-anchor').attr('id', id + '_anchor').end().attr('aria-labelledby', id + '_anchor');
3668
+ if(this.element.attr('aria-activedescendant') === obj.id) {
3669
+ this.element.attr('aria-activedescendant', id);
3670
+ }
3671
+ }
3672
+ delete m[obj.id];
3673
+ obj.id = id;
3674
+ obj.li_attr.id = id;
3675
+ m[id] = obj;
3676
+ /**
3677
+ * triggered when a node id value is changed
3678
+ * @event
3679
+ * @name set_id.jstree
3680
+ * @param {Object} node
3681
+ * @param {String} old the old id
3682
+ */
3683
+ this.trigger('set_id',{ "node" : obj, "new" : obj.id, "old" : old });
3684
+ return true;
3685
+ },
3686
+ /**
3687
+ * get the text value of a node
3688
+ * @name get_text(obj)
3689
+ * @param {mixed} obj the node
3690
+ * @return {String}
3691
+ */
3692
+ get_text : function (obj) {
3693
+ obj = this.get_node(obj);
3694
+ return (!obj || obj.id === $.jstree.root) ? false : obj.text;
3695
+ },
3696
+ /**
3697
+ * set the text value of a node. Used internally, please use `rename_node(obj, val)`.
3698
+ * @private
3699
+ * @name set_text(obj, val)
3700
+ * @param {mixed} obj the node, you can pass an array to set the text on multiple nodes
3701
+ * @param {String} val the new text value
3702
+ * @return {Boolean}
3703
+ * @trigger set_text.jstree
3704
+ */
3705
+ set_text : function (obj, val) {
3706
+ var t1, t2;
3707
+ if($.isArray(obj)) {
3708
+ obj = obj.slice();
3709
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3710
+ this.set_text(obj[t1], val);
3711
+ }
3712
+ return true;
3713
+ }
3714
+ obj = this.get_node(obj);
3715
+ if(!obj || obj.id === $.jstree.root) { return false; }
3716
+ obj.text = val;
3717
+ if(this.get_node(obj, true).length) {
3718
+ this.redraw_node(obj.id);
3719
+ }
3720
+ /**
3721
+ * triggered when a node text value is changed
3722
+ * @event
3723
+ * @name set_text.jstree
3724
+ * @param {Object} obj
3725
+ * @param {String} text the new value
3726
+ */
3727
+ this.trigger('set_text',{ "obj" : obj, "text" : val });
3728
+ return true;
3729
+ },
3730
+ /**
3731
+ * gets a JSON representation of a node (or the whole tree)
3732
+ * @name get_json([obj, options])
3733
+ * @param {mixed} obj
3734
+ * @param {Object} options
3735
+ * @param {Boolean} options.no_state do not return state information
3736
+ * @param {Boolean} options.no_id do not return ID
3737
+ * @param {Boolean} options.no_children do not include children
3738
+ * @param {Boolean} options.no_data do not include node data
3739
+ * @param {Boolean} options.no_li_attr do not include LI attributes
3740
+ * @param {Boolean} options.no_a_attr do not include A attributes
3741
+ * @param {Boolean} options.flat return flat JSON instead of nested
3742
+ * @return {Object}
3743
+ */
3744
+ get_json : function (obj, options, flat) {
3745
+ obj = this.get_node(obj || $.jstree.root);
3746
+ if(!obj) { return false; }
3747
+ if(options && options.flat && !flat) { flat = []; }
3748
+ var tmp = {
3749
+ 'id' : obj.id,
3750
+ 'text' : obj.text,
3751
+ 'icon' : this.get_icon(obj),
3752
+ 'li_attr' : $.extend(true, {}, obj.li_attr),
3753
+ 'a_attr' : $.extend(true, {}, obj.a_attr),
3754
+ 'state' : {},
3755
+ 'data' : options && options.no_data ? false : $.extend(true, $.isArray(obj.data)?[]:{}, obj.data)
3756
+ //( this.get_node(obj, true).length ? this.get_node(obj, true).data() : obj.data ),
3757
+ }, i, j;
3758
+ if(options && options.flat) {
3759
+ tmp.parent = obj.parent;
3760
+ }
3761
+ else {
3762
+ tmp.children = [];
3763
+ }
3764
+ if(!options || !options.no_state) {
3765
+ for(i in obj.state) {
3766
+ if(obj.state.hasOwnProperty(i)) {
3767
+ tmp.state[i] = obj.state[i];
3768
+ }
3769
+ }
3770
+ } else {
3771
+ delete tmp.state;
3772
+ }
3773
+ if(options && options.no_li_attr) {
3774
+ delete tmp.li_attr;
3775
+ }
3776
+ if(options && options.no_a_attr) {
3777
+ delete tmp.a_attr;
3778
+ }
3779
+ if(options && options.no_id) {
3780
+ delete tmp.id;
3781
+ if(tmp.li_attr && tmp.li_attr.id) {
3782
+ delete tmp.li_attr.id;
3783
+ }
3784
+ if(tmp.a_attr && tmp.a_attr.id) {
3785
+ delete tmp.a_attr.id;
3786
+ }
3787
+ }
3788
+ if(options && options.flat && obj.id !== $.jstree.root) {
3789
+ flat.push(tmp);
3790
+ }
3791
+ if(!options || !options.no_children) {
3792
+ for(i = 0, j = obj.children.length; i < j; i++) {
3793
+ if(options && options.flat) {
3794
+ this.get_json(obj.children[i], options, flat);
3795
+ }
3796
+ else {
3797
+ tmp.children.push(this.get_json(obj.children[i], options));
3798
+ }
3799
+ }
3800
+ }
3801
+ return options && options.flat ? flat : (obj.id === $.jstree.root ? tmp.children : tmp);
3802
+ },
3803
+ /**
3804
+ * create a new node (do not confuse with load_node)
3805
+ * @name create_node([par, node, pos, callback, is_loaded])
3806
+ * @param {mixed} par the parent node (to create a root node use either "#" (string) or `null`)
3807
+ * @param {mixed} node the data for the new node (a valid JSON object, or a simple string with the name)
3808
+ * @param {mixed} pos the index at which to insert the node, "first" and "last" are also supported, default is "last"
3809
+ * @param {Function} callback a function to be called once the node is created
3810
+ * @param {Boolean} is_loaded internal argument indicating if the parent node was succesfully loaded
3811
+ * @return {String} the ID of the newly create node
3812
+ * @trigger model.jstree, create_node.jstree
3813
+ */
3814
+ create_node : function (par, node, pos, callback, is_loaded) {
3815
+ if(par === null) { par = $.jstree.root; }
3816
+ par = this.get_node(par);
3817
+ if(!par) { return false; }
3818
+ pos = pos === undefined ? "last" : pos;
3819
+ if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
3820
+ return this.load_node(par, function () { this.create_node(par, node, pos, callback, true); });
3821
+ }
3822
+ if(!node) { node = { "text" : this.get_string('New node') }; }
3823
+ if(typeof node === "string") {
3824
+ node = { "text" : node };
3825
+ } else {
3826
+ node = $.extend(true, {}, node);
3827
+ }
3828
+ if(node.text === undefined) { node.text = this.get_string('New node'); }
3829
+ var tmp, dpc, i, j;
3830
+
3831
+ if(par.id === $.jstree.root) {
3832
+ if(pos === "before") { pos = "first"; }
3833
+ if(pos === "after") { pos = "last"; }
3834
+ }
3835
+ switch(pos) {
3836
+ case "before":
3837
+ tmp = this.get_node(par.parent);
3838
+ pos = $.inArray(par.id, tmp.children);
3839
+ par = tmp;
3840
+ break;
3841
+ case "after" :
3842
+ tmp = this.get_node(par.parent);
3843
+ pos = $.inArray(par.id, tmp.children) + 1;
3844
+ par = tmp;
3845
+ break;
3846
+ case "inside":
3847
+ case "first":
3848
+ pos = 0;
3849
+ break;
3850
+ case "last":
3851
+ pos = par.children.length;
3852
+ break;
3853
+ default:
3854
+ if(!pos) { pos = 0; }
3855
+ break;
3856
+ }
3857
+ if(pos > par.children.length) { pos = par.children.length; }
3858
+ if(!node.id) { node.id = true; }
3859
+ if(!this.check("create_node", node, par, pos)) {
3860
+ this.settings.core.error.call(this, this._data.core.last_error);
3861
+ return false;
3862
+ }
3863
+ if(node.id === true) { delete node.id; }
3864
+ node = this._parse_model_from_json(node, par.id, par.parents.concat());
3865
+ if(!node) { return false; }
3866
+ tmp = this.get_node(node);
3867
+ dpc = [];
3868
+ dpc.push(node);
3869
+ dpc = dpc.concat(tmp.children_d);
3870
+ this.trigger('model', { "nodes" : dpc, "parent" : par.id });
3871
+
3872
+ par.children_d = par.children_d.concat(dpc);
3873
+ for(i = 0, j = par.parents.length; i < j; i++) {
3874
+ this._model.data[par.parents[i]].children_d = this._model.data[par.parents[i]].children_d.concat(dpc);
3875
+ }
3876
+ node = tmp;
3877
+ tmp = [];
3878
+ for(i = 0, j = par.children.length; i < j; i++) {
3879
+ tmp[i >= pos ? i+1 : i] = par.children[i];
3880
+ }
3881
+ tmp[pos] = node.id;
3882
+ par.children = tmp;
3883
+
3884
+ this.redraw_node(par, true);
3885
+ /**
3886
+ * triggered when a node is created
3887
+ * @event
3888
+ * @name create_node.jstree
3889
+ * @param {Object} node
3890
+ * @param {String} parent the parent's ID
3891
+ * @param {Number} position the position of the new node among the parent's children
3892
+ */
3893
+ this.trigger('create_node', { "node" : this.get_node(node), "parent" : par.id, "position" : pos });
3894
+ if(callback) { callback.call(this, this.get_node(node)); }
3895
+ return node.id;
3896
+ },
3897
+ /**
3898
+ * set the text value of a node
3899
+ * @name rename_node(obj, val)
3900
+ * @param {mixed} obj the node, you can pass an array to rename multiple nodes to the same name
3901
+ * @param {String} val the new text value
3902
+ * @return {Boolean}
3903
+ * @trigger rename_node.jstree
3904
+ */
3905
+ rename_node : function (obj, val) {
3906
+ var t1, t2, old;
3907
+ if($.isArray(obj)) {
3908
+ obj = obj.slice();
3909
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3910
+ this.rename_node(obj[t1], val);
3911
+ }
3912
+ return true;
3913
+ }
3914
+ obj = this.get_node(obj);
3915
+ if(!obj || obj.id === $.jstree.root) { return false; }
3916
+ old = obj.text;
3917
+ if(!this.check("rename_node", obj, this.get_parent(obj), val)) {
3918
+ this.settings.core.error.call(this, this._data.core.last_error);
3919
+ return false;
3920
+ }
3921
+ this.set_text(obj, val); // .apply(this, Array.prototype.slice.call(arguments))
3922
+ /**
3923
+ * triggered when a node is renamed
3924
+ * @event
3925
+ * @name rename_node.jstree
3926
+ * @param {Object} node
3927
+ * @param {String} text the new value
3928
+ * @param {String} old the old value
3929
+ */
3930
+ this.trigger('rename_node', { "node" : obj, "text" : val, "old" : old });
3931
+ return true;
3932
+ },
3933
+ /**
3934
+ * remove a node
3935
+ * @name delete_node(obj)
3936
+ * @param {mixed} obj the node, you can pass an array to delete multiple nodes
3937
+ * @return {Boolean}
3938
+ * @trigger delete_node.jstree, changed.jstree
3939
+ */
3940
+ delete_node : function (obj) {
3941
+ var t1, t2, par, pos, tmp, i, j, k, l, c, top, lft;
3942
+ if($.isArray(obj)) {
3943
+ obj = obj.slice();
3944
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3945
+ this.delete_node(obj[t1]);
3946
+ }
3947
+ return true;
3948
+ }
3949
+ obj = this.get_node(obj);
3950
+ if(!obj || obj.id === $.jstree.root) { return false; }
3951
+ par = this.get_node(obj.parent);
3952
+ pos = $.inArray(obj.id, par.children);
3953
+ c = false;
3954
+ if(!this.check("delete_node", obj, par, pos)) {
3955
+ this.settings.core.error.call(this, this._data.core.last_error);
3956
+ return false;
3957
+ }
3958
+ if(pos !== -1) {
3959
+ par.children = $.vakata.array_remove(par.children, pos);
3960
+ }
3961
+ tmp = obj.children_d.concat([]);
3962
+ tmp.push(obj.id);
3963
+ for(i = 0, j = obj.parents.length; i < j; i++) {
3964
+ this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
3965
+ return $.inArray(v, tmp) === -1;
3966
+ });
3967
+ }
3968
+ for(k = 0, l = tmp.length; k < l; k++) {
3969
+ if(this._model.data[tmp[k]].state.selected) {
3970
+ c = true;
3971
+ break;
3972
+ }
3973
+ }
3974
+ if (c) {
3975
+ this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
3976
+ return $.inArray(v, tmp) === -1;
3977
+ });
3978
+ }
3979
+ /**
3980
+ * triggered when a node is deleted
3981
+ * @event
3982
+ * @name delete_node.jstree
3983
+ * @param {Object} node
3984
+ * @param {String} parent the parent's ID
3985
+ */
3986
+ this.trigger('delete_node', { "node" : obj, "parent" : par.id });
3987
+ if(c) {
3988
+ this.trigger('changed', { 'action' : 'delete_node', 'node' : obj, 'selected' : this._data.core.selected, 'parent' : par.id });
3989
+ }
3990
+ for(k = 0, l = tmp.length; k < l; k++) {
3991
+ delete this._model.data[tmp[k]];
3992
+ }
3993
+ if($.inArray(this._data.core.focused, tmp) !== -1) {
3994
+ this._data.core.focused = null;
3995
+ top = this.element[0].scrollTop;
3996
+ lft = this.element[0].scrollLeft;
3997
+ if(par.id === $.jstree.root) {
3998
+ if (this._model.data[$.jstree.root].children[0]) {
3999
+ this.get_node(this._model.data[$.jstree.root].children[0], true).children('.jstree-anchor').focus();
4000
+ }
4001
+ }
4002
+ else {
4003
+ this.get_node(par, true).children('.jstree-anchor').focus();
4004
+ }
4005
+ this.element[0].scrollTop = top;
4006
+ this.element[0].scrollLeft = lft;
4007
+ }
4008
+ this.redraw_node(par, true);
4009
+ return true;
4010
+ },
4011
+ /**
4012
+ * check if an operation is premitted on the tree. Used internally.
4013
+ * @private
4014
+ * @name check(chk, obj, par, pos)
4015
+ * @param {String} chk the operation to check, can be "create_node", "rename_node", "delete_node", "copy_node" or "move_node"
4016
+ * @param {mixed} obj the node
4017
+ * @param {mixed} par the parent
4018
+ * @param {mixed} pos the position to insert at, or if "rename_node" - the new name
4019
+ * @param {mixed} more some various additional information, for example if a "move_node" operations is triggered by DND this will be the hovered node
4020
+ * @return {Boolean}
4021
+ */
4022
+ check : function (chk, obj, par, pos, more) {
4023
+ obj = obj && obj.id ? obj : this.get_node(obj);
4024
+ par = par && par.id ? par : this.get_node(par);
4025
+ var tmp = chk.match(/^move_node|copy_node|create_node$/i) ? par : obj,
4026
+ chc = this.settings.core.check_callback;
4027
+ if(chk === "move_node" || chk === "copy_node") {
4028
+ if((!more || !more.is_multi) && (chk === "move_node" && $.inArray(obj.id, par.children) === pos)) {
4029
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_08', 'reason' : 'Moving node to its current position', 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
4030
+ return false;
4031
+ }
4032
+ 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)) {
4033
+ 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 }) };
4034
+ return false;
4035
+ }
4036
+ }
4037
+ if(tmp && tmp.data) { tmp = tmp.data; }
4038
+ if(tmp && tmp.functions && (tmp.functions[chk] === false || tmp.functions[chk] === true)) {
4039
+ if(tmp.functions[chk] === false) {
4040
+ 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 }) };
4041
+ }
4042
+ return tmp.functions[chk];
4043
+ }
4044
+ if(chc === false || ($.isFunction(chc) && chc.call(this, chk, obj, par, pos, more) === false) || (chc && chc[chk] === false)) {
4045
+ 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 }) };
4046
+ return false;
4047
+ }
4048
+ return true;
4049
+ },
4050
+ /**
4051
+ * get the last error
4052
+ * @name last_error()
4053
+ * @return {Object}
4054
+ */
4055
+ last_error : function () {
4056
+ return this._data.core.last_error;
4057
+ },
4058
+ /**
4059
+ * move a node to a new parent
4060
+ * @name move_node(obj, par [, pos, callback, is_loaded])
4061
+ * @param {mixed} obj the node to move, pass an array to move multiple nodes
4062
+ * @param {mixed} par the new parent
4063
+ * @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`
4064
+ * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
4065
+ * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
4066
+ * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
4067
+ * @param {Boolean} instance internal parameter indicating if the node comes from another instance
4068
+ * @trigger move_node.jstree
4069
+ */
4070
+ move_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
4071
+ var t1, t2, old_par, old_pos, new_par, old_ins, is_multi, dpc, tmp, i, j, k, l, p;
4072
+
4073
+ par = this.get_node(par);
4074
+ pos = pos === undefined ? 0 : pos;
4075
+ if(!par) { return false; }
4076
+ if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
4077
+ return this.load_node(par, function () { this.move_node(obj, par, pos, callback, true, false, origin); });
4078
+ }
4079
+
4080
+ if($.isArray(obj)) {
4081
+ if(obj.length === 1) {
4082
+ obj = obj[0];
4083
+ }
4084
+ else {
4085
+ //obj = obj.slice();
4086
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4087
+ if((tmp = this.move_node(obj[t1], par, pos, callback, is_loaded, false, origin))) {
4088
+ par = tmp;
4089
+ pos = "after";
4090
+ }
4091
+ }
4092
+ this.redraw();
4093
+ return true;
4094
+ }
4095
+ }
4096
+ obj = obj && obj.id ? obj : this.get_node(obj);
4097
+
4098
+ if(!obj || obj.id === $.jstree.root) { return false; }
4099
+
4100
+ old_par = (obj.parent || $.jstree.root).toString();
4101
+ new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
4102
+ old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
4103
+ is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
4104
+ 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;
4105
+ if(old_ins && old_ins._id) {
4106
+ obj = old_ins._model.data[obj.id];
4107
+ }
4108
+
4109
+ if(is_multi) {
4110
+ if((tmp = this.copy_node(obj, par, pos, callback, is_loaded, false, origin))) {
4111
+ if(old_ins) { old_ins.delete_node(obj); }
4112
+ return tmp;
4113
+ }
4114
+ return false;
4115
+ }
4116
+ //var m = this._model.data;
4117
+ if(par.id === $.jstree.root) {
4118
+ if(pos === "before") { pos = "first"; }
4119
+ if(pos === "after") { pos = "last"; }
4120
+ }
4121
+ switch(pos) {
4122
+ case "before":
4123
+ pos = $.inArray(par.id, new_par.children);
4124
+ break;
4125
+ case "after" :
4126
+ pos = $.inArray(par.id, new_par.children) + 1;
4127
+ break;
4128
+ case "inside":
4129
+ case "first":
4130
+ pos = 0;
4131
+ break;
4132
+ case "last":
4133
+ pos = new_par.children.length;
4134
+ break;
4135
+ default:
4136
+ if(!pos) { pos = 0; }
4137
+ break;
4138
+ }
4139
+ if(pos > new_par.children.length) { pos = new_par.children.length; }
4140
+ 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) })) {
4141
+ this.settings.core.error.call(this, this._data.core.last_error);
4142
+ return false;
4143
+ }
4144
+ if(obj.parent === new_par.id) {
4145
+ dpc = new_par.children.concat();
4146
+ tmp = $.inArray(obj.id, dpc);
4147
+ if(tmp !== -1) {
4148
+ dpc = $.vakata.array_remove(dpc, tmp);
4149
+ if(pos > tmp) { pos--; }
4150
+ }
4151
+ tmp = [];
4152
+ for(i = 0, j = dpc.length; i < j; i++) {
4153
+ tmp[i >= pos ? i+1 : i] = dpc[i];
4154
+ }
4155
+ tmp[pos] = obj.id;
4156
+ new_par.children = tmp;
4157
+ this._node_changed(new_par.id);
4158
+ this.redraw(new_par.id === $.jstree.root);
4159
+ }
4160
+ else {
4161
+ // clean old parent and up
4162
+ tmp = obj.children_d.concat();
4163
+ tmp.push(obj.id);
4164
+ for(i = 0, j = obj.parents.length; i < j; i++) {
4165
+ dpc = [];
4166
+ p = old_ins._model.data[obj.parents[i]].children_d;
4167
+ for(k = 0, l = p.length; k < l; k++) {
4168
+ if($.inArray(p[k], tmp) === -1) {
4169
+ dpc.push(p[k]);
4170
+ }
4171
+ }
4172
+ old_ins._model.data[obj.parents[i]].children_d = dpc;
4173
+ }
4174
+ old_ins._model.data[old_par].children = $.vakata.array_remove_item(old_ins._model.data[old_par].children, obj.id);
4175
+
4176
+ // insert into new parent and up
4177
+ for(i = 0, j = new_par.parents.length; i < j; i++) {
4178
+ this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(tmp);
4179
+ }
4180
+ dpc = [];
4181
+ for(i = 0, j = new_par.children.length; i < j; i++) {
4182
+ dpc[i >= pos ? i+1 : i] = new_par.children[i];
4183
+ }
4184
+ dpc[pos] = obj.id;
4185
+ new_par.children = dpc;
4186
+ new_par.children_d.push(obj.id);
4187
+ new_par.children_d = new_par.children_d.concat(obj.children_d);
4188
+
4189
+ // update object
4190
+ obj.parent = new_par.id;
4191
+ tmp = new_par.parents.concat();
4192
+ tmp.unshift(new_par.id);
4193
+ p = obj.parents.length;
4194
+ obj.parents = tmp;
4195
+
4196
+ // update object children
4197
+ tmp = tmp.concat();
4198
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
4199
+ this._model.data[obj.children_d[i]].parents = this._model.data[obj.children_d[i]].parents.slice(0,p*-1);
4200
+ Array.prototype.push.apply(this._model.data[obj.children_d[i]].parents, tmp);
4201
+ }
4202
+
4203
+ if(old_par === $.jstree.root || new_par.id === $.jstree.root) {
4204
+ this._model.force_full_redraw = true;
4205
+ }
4206
+ if(!this._model.force_full_redraw) {
4207
+ this._node_changed(old_par);
4208
+ this._node_changed(new_par.id);
4209
+ }
4210
+ if(!skip_redraw) {
4211
+ this.redraw();
4212
+ }
4213
+ }
4214
+ if(callback) { callback.call(this, obj, new_par, pos); }
4215
+ /**
4216
+ * triggered when a node is moved
4217
+ * @event
4218
+ * @name move_node.jstree
4219
+ * @param {Object} node
4220
+ * @param {String} parent the parent's ID
4221
+ * @param {Number} position the position of the node among the parent's children
4222
+ * @param {String} old_parent the old parent of the node
4223
+ * @param {Number} old_position the old position of the node
4224
+ * @param {Boolean} is_multi do the node and new parent belong to different instances
4225
+ * @param {jsTree} old_instance the instance the node came from
4226
+ * @param {jsTree} new_instance the instance of the new parent
4227
+ */
4228
+ 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 });
4229
+ return obj.id;
4230
+ },
4231
+ /**
4232
+ * copy a node to a new parent
4233
+ * @name copy_node(obj, par [, pos, callback, is_loaded])
4234
+ * @param {mixed} obj the node to copy, pass an array to copy multiple nodes
4235
+ * @param {mixed} par the new parent
4236
+ * @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`
4237
+ * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
4238
+ * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
4239
+ * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
4240
+ * @param {Boolean} instance internal parameter indicating if the node comes from another instance
4241
+ * @trigger model.jstree copy_node.jstree
4242
+ */
4243
+ copy_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
4244
+ var t1, t2, dpc, tmp, i, j, node, old_par, new_par, old_ins, is_multi;
4245
+
4246
+ par = this.get_node(par);
4247
+ pos = pos === undefined ? 0 : pos;
4248
+ if(!par) { return false; }
4249
+ if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
4250
+ return this.load_node(par, function () { this.copy_node(obj, par, pos, callback, true, false, origin); });
4251
+ }
4252
+
4253
+ if($.isArray(obj)) {
4254
+ if(obj.length === 1) {
4255
+ obj = obj[0];
4256
+ }
4257
+ else {
4258
+ //obj = obj.slice();
4259
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4260
+ if((tmp = this.copy_node(obj[t1], par, pos, callback, is_loaded, true, origin))) {
4261
+ par = tmp;
4262
+ pos = "after";
4263
+ }
4264
+ }
4265
+ this.redraw();
4266
+ return true;
4267
+ }
4268
+ }
4269
+ obj = obj && obj.id ? obj : this.get_node(obj);
4270
+ if(!obj || obj.id === $.jstree.root) { return false; }
4271
+
4272
+ old_par = (obj.parent || $.jstree.root).toString();
4273
+ new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
4274
+ old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
4275
+ is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
4276
+
4277
+ if(old_ins && old_ins._id) {
4278
+ obj = old_ins._model.data[obj.id];
4279
+ }
4280
+
4281
+ if(par.id === $.jstree.root) {
4282
+ if(pos === "before") { pos = "first"; }
4283
+ if(pos === "after") { pos = "last"; }
4284
+ }
4285
+ switch(pos) {
4286
+ case "before":
4287
+ pos = $.inArray(par.id, new_par.children);
4288
+ break;
4289
+ case "after" :
4290
+ pos = $.inArray(par.id, new_par.children) + 1;
4291
+ break;
4292
+ case "inside":
4293
+ case "first":
4294
+ pos = 0;
4295
+ break;
4296
+ case "last":
4297
+ pos = new_par.children.length;
4298
+ break;
4299
+ default:
4300
+ if(!pos) { pos = 0; }
4301
+ break;
4302
+ }
4303
+ if(pos > new_par.children.length) { pos = new_par.children.length; }
4304
+ 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) })) {
4305
+ this.settings.core.error.call(this, this._data.core.last_error);
4306
+ return false;
4307
+ }
4308
+ node = old_ins ? old_ins.get_json(obj, { no_id : true, no_data : true, no_state : true }) : obj;
4309
+ if(!node) { return false; }
4310
+ if(node.id === true) { delete node.id; }
4311
+ node = this._parse_model_from_json(node, new_par.id, new_par.parents.concat());
4312
+ if(!node) { return false; }
4313
+ tmp = this.get_node(node);
4314
+ if(obj && obj.state && obj.state.loaded === false) { tmp.state.loaded = false; }
4315
+ dpc = [];
4316
+ dpc.push(node);
4317
+ dpc = dpc.concat(tmp.children_d);
4318
+ this.trigger('model', { "nodes" : dpc, "parent" : new_par.id });
4319
+
4320
+ // insert into new parent and up
4321
+ for(i = 0, j = new_par.parents.length; i < j; i++) {
4322
+ this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(dpc);
4323
+ }
4324
+ dpc = [];
4325
+ for(i = 0, j = new_par.children.length; i < j; i++) {
4326
+ dpc[i >= pos ? i+1 : i] = new_par.children[i];
4327
+ }
4328
+ dpc[pos] = tmp.id;
4329
+ new_par.children = dpc;
4330
+ new_par.children_d.push(tmp.id);
4331
+ new_par.children_d = new_par.children_d.concat(tmp.children_d);
4332
+
4333
+ if(new_par.id === $.jstree.root) {
4334
+ this._model.force_full_redraw = true;
4335
+ }
4336
+ if(!this._model.force_full_redraw) {
4337
+ this._node_changed(new_par.id);
4338
+ }
4339
+ if(!skip_redraw) {
4340
+ this.redraw(new_par.id === $.jstree.root);
4341
+ }
4342
+ if(callback) { callback.call(this, tmp, new_par, pos); }
4343
+ /**
4344
+ * triggered when a node is copied
4345
+ * @event
4346
+ * @name copy_node.jstree
4347
+ * @param {Object} node the copied node
4348
+ * @param {Object} original the original node
4349
+ * @param {String} parent the parent's ID
4350
+ * @param {Number} position the position of the node among the parent's children
4351
+ * @param {String} old_parent the old parent of the node
4352
+ * @param {Number} old_position the position of the original node
4353
+ * @param {Boolean} is_multi do the node and new parent belong to different instances
4354
+ * @param {jsTree} old_instance the instance the node came from
4355
+ * @param {jsTree} new_instance the instance of the new parent
4356
+ */
4357
+ 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 });
4358
+ return tmp.id;
4359
+ },
4360
+ /**
4361
+ * cut a node (a later call to `paste(obj)` would move the node)
4362
+ * @name cut(obj)
4363
+ * @param {mixed} obj multiple objects can be passed using an array
4364
+ * @trigger cut.jstree
4365
+ */
4366
+ cut : function (obj) {
4367
+ if(!obj) { obj = this._data.core.selected.concat(); }
4368
+ if(!$.isArray(obj)) { obj = [obj]; }
4369
+ if(!obj.length) { return false; }
4370
+ var tmp = [], o, t1, t2;
4371
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4372
+ o = this.get_node(obj[t1]);
4373
+ if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
4374
+ }
4375
+ if(!tmp.length) { return false; }
4376
+ ccp_node = tmp;
4377
+ ccp_inst = this;
4378
+ ccp_mode = 'move_node';
4379
+ /**
4380
+ * triggered when nodes are added to the buffer for moving
4381
+ * @event
4382
+ * @name cut.jstree
4383
+ * @param {Array} node
4384
+ */
4385
+ this.trigger('cut', { "node" : obj });
4386
+ },
4387
+ /**
4388
+ * copy a node (a later call to `paste(obj)` would copy the node)
4389
+ * @name copy(obj)
4390
+ * @param {mixed} obj multiple objects can be passed using an array
4391
+ * @trigger copy.jstree
4392
+ */
4393
+ copy : function (obj) {
4394
+ if(!obj) { obj = this._data.core.selected.concat(); }
4395
+ if(!$.isArray(obj)) { obj = [obj]; }
4396
+ if(!obj.length) { return false; }
4397
+ var tmp = [], o, t1, t2;
4398
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4399
+ o = this.get_node(obj[t1]);
4400
+ if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
4401
+ }
4402
+ if(!tmp.length) { return false; }
4403
+ ccp_node = tmp;
4404
+ ccp_inst = this;
4405
+ ccp_mode = 'copy_node';
4406
+ /**
4407
+ * triggered when nodes are added to the buffer for copying
4408
+ * @event
4409
+ * @name copy.jstree
4410
+ * @param {Array} node
4411
+ */
4412
+ this.trigger('copy', { "node" : obj });
4413
+ },
4414
+ /**
4415
+ * get the current buffer (any nodes that are waiting for a paste operation)
4416
+ * @name get_buffer()
4417
+ * @return {Object} an object consisting of `mode` ("copy_node" or "move_node"), `node` (an array of objects) and `inst` (the instance)
4418
+ */
4419
+ get_buffer : function () {
4420
+ return { 'mode' : ccp_mode, 'node' : ccp_node, 'inst' : ccp_inst };
4421
+ },
4422
+ /**
4423
+ * check if there is something in the buffer to paste
4424
+ * @name can_paste()
4425
+ * @return {Boolean}
4426
+ */
4427
+ can_paste : function () {
4428
+ return ccp_mode !== false && ccp_node !== false; // && ccp_inst._model.data[ccp_node];
4429
+ },
4430
+ /**
4431
+ * copy or move the previously cut or copied nodes to a new parent
4432
+ * @name paste(obj [, pos])
4433
+ * @param {mixed} obj the new parent
4434
+ * @param {mixed} pos the position to insert at (besides integer, "first" and "last" are supported), defaults to integer `0`
4435
+ * @trigger paste.jstree
4436
+ */
4437
+ paste : function (obj, pos) {
4438
+ obj = this.get_node(obj);
4439
+ if(!obj || !ccp_mode || !ccp_mode.match(/^(copy_node|move_node)$/) || !ccp_node) { return false; }
4440
+ if(this[ccp_mode](ccp_node, obj, pos, false, false, false, ccp_inst)) {
4441
+ /**
4442
+ * triggered when paste is invoked
4443
+ * @event
4444
+ * @name paste.jstree
4445
+ * @param {String} parent the ID of the receiving node
4446
+ * @param {Array} node the nodes in the buffer
4447
+ * @param {String} mode the performed operation - "copy_node" or "move_node"
4448
+ */
4449
+ this.trigger('paste', { "parent" : obj.id, "node" : ccp_node, "mode" : ccp_mode });
4450
+ }
4451
+ ccp_node = false;
4452
+ ccp_mode = false;
4453
+ ccp_inst = false;
4454
+ },
4455
+ /**
4456
+ * clear the buffer of previously copied or cut nodes
4457
+ * @name clear_buffer()
4458
+ * @trigger clear_buffer.jstree
4459
+ */
4460
+ clear_buffer : function () {
4461
+ ccp_node = false;
4462
+ ccp_mode = false;
4463
+ ccp_inst = false;
4464
+ /**
4465
+ * triggered when the copy / cut buffer is cleared
4466
+ * @event
4467
+ * @name clear_buffer.jstree
4468
+ */
4469
+ this.trigger('clear_buffer');
4470
+ },
4471
+ /**
4472
+ * put a node in edit mode (input field to rename the node)
4473
+ * @name edit(obj [, default_text, callback])
4474
+ * @param {mixed} obj
4475
+ * @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)
4476
+ * @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
4477
+ */
4478
+ edit : function (obj, default_text, callback) {
4479
+ var rtl, w, a, s, t, h1, h2, fn, tmp, cancel = false;
4480
+ obj = this.get_node(obj);
4481
+ if(!obj) { return false; }
4482
+ if(!this.check("edit", obj, this.get_parent(obj))) {
4483
+ this.settings.core.error.call(this, this._data.core.last_error);
4484
+ return false;
4485
+ }
4486
+ tmp = obj;
4487
+ default_text = typeof default_text === 'string' ? default_text : obj.text;
4488
+ this.set_text(obj, "");
4489
+ obj = this._open_to(obj);
4490
+ tmp.text = default_text;
4491
+
4492
+ rtl = this._data.core.rtl;
4493
+ w = this.element.width();
4494
+ this._data.core.focused = tmp.id;
4495
+ a = obj.children('.jstree-anchor').focus();
4496
+ s = $('<span>');
4497
+ /*!
4498
+ oi = obj.children("i:visible"),
4499
+ ai = a.children("i:visible"),
4500
+ w1 = oi.width() * oi.length,
4501
+ w2 = ai.width() * ai.length,
4502
+ */
4503
+ t = default_text;
4504
+ h1 = $("<"+"div />", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo(document.body);
4505
+ h2 = $("<"+"input />", {
4506
+ "value" : t,
4507
+ "class" : "jstree-rename-input",
4508
+ // "size" : t.length,
4509
+ "css" : {
4510
+ "padding" : "0",
4511
+ "border" : "1px solid silver",
4512
+ "box-sizing" : "border-box",
4513
+ "display" : "inline-block",
4514
+ "height" : (this._data.core.li_height) + "px",
4515
+ "lineHeight" : (this._data.core.li_height) + "px",
4516
+ "width" : "150px" // will be set a bit further down
4517
+ },
4518
+ "blur" : $.proxy(function (e) {
4519
+ e.stopImmediatePropagation();
4520
+ e.preventDefault();
4521
+ var i = s.children(".jstree-rename-input"),
4522
+ v = i.val(),
4523
+ f = this.settings.core.force_text,
4524
+ nv;
4525
+ if(v === "") { v = t; }
4526
+ h1.remove();
4527
+ s.replaceWith(a);
4528
+ s.remove();
4529
+ t = f ? t : $('<div></div>').append($.parseHTML(t)).html();
4530
+ obj = this.get_node(obj);
4531
+ this.set_text(obj, t);
4532
+ nv = !!this.rename_node(obj, f ? $('<div></div>').text(v).text() : $('<div></div>').append($.parseHTML(v)).html());
4533
+ if(!nv) {
4534
+ this.set_text(obj, t); // move this up? and fix #483
4535
+ }
4536
+ this._data.core.focused = tmp.id;
4537
+ setTimeout($.proxy(function () {
4538
+ var node = this.get_node(tmp.id, true);
4539
+ if(node.length) {
4540
+ this._data.core.focused = tmp.id;
4541
+ node.children('.jstree-anchor').focus();
4542
+ }
4543
+ }, this), 0);
4544
+ if(callback) {
4545
+ callback.call(this, tmp, nv, cancel);
4546
+ }
4547
+ h2 = null;
4548
+ }, this),
4549
+ "keydown" : function (e) {
4550
+ var key = e.which;
4551
+ if(key === 27) {
4552
+ cancel = true;
4553
+ this.value = t;
4554
+ }
4555
+ if(key === 27 || key === 13 || key === 37 || key === 38 || key === 39 || key === 40 || key === 32) {
4556
+ e.stopImmediatePropagation();
4557
+ }
4558
+ if(key === 27 || key === 13) {
4559
+ e.preventDefault();
4560
+ this.blur();
4561
+ }
4562
+ },
4563
+ "click" : function (e) { e.stopImmediatePropagation(); },
4564
+ "mousedown" : function (e) { e.stopImmediatePropagation(); },
4565
+ "keyup" : function (e) {
4566
+ h2.width(Math.min(h1.text("pW" + this.value).width(),w));
4567
+ },
4568
+ "keypress" : function(e) {
4569
+ if(e.which === 13) { return false; }
4570
+ }
4571
+ });
4572
+ fn = {
4573
+ fontFamily : a.css('fontFamily') || '',
4574
+ fontSize : a.css('fontSize') || '',
4575
+ fontWeight : a.css('fontWeight') || '',
4576
+ fontStyle : a.css('fontStyle') || '',
4577
+ fontStretch : a.css('fontStretch') || '',
4578
+ fontVariant : a.css('fontVariant') || '',
4579
+ letterSpacing : a.css('letterSpacing') || '',
4580
+ wordSpacing : a.css('wordSpacing') || ''
4581
+ };
4582
+ s.attr('class', a.attr('class')).append(a.contents().clone()).append(h2);
4583
+ a.replaceWith(s);
4584
+ h1.css(fn);
4585
+ h2.css(fn).width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select();
4586
+ $(document).one('mousedown.jstree touchstart.jstree dnd_start.vakata', function (e) {
4587
+ if (h2 && e.target !== h2) {
4588
+ $(h2).blur();
4589
+ }
4590
+ });
4591
+ },
4592
+
4593
+
4594
+ /**
4595
+ * changes the theme
4596
+ * @name set_theme(theme_name [, theme_url])
4597
+ * @param {String} theme_name the name of the new theme to apply
4598
+ * @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.
4599
+ * @trigger set_theme.jstree
4600
+ */
4601
+ set_theme : function (theme_name, theme_url) {
4602
+ if(!theme_name) { return false; }
4603
+ if(theme_url === true) {
4604
+ var dir = this.settings.core.themes.dir;
4605
+ if(!dir) { dir = $.jstree.path + '/themes'; }
4606
+ theme_url = dir + '/' + theme_name + '/style.css';
4607
+ }
4608
+ if(theme_url && $.inArray(theme_url, themes_loaded) === -1) {
4609
+ $('head').append('<'+'link rel="stylesheet" href="' + theme_url + '" type="text/css" />');
4610
+ themes_loaded.push(theme_url);
4611
+ }
4612
+ if(this._data.core.themes.name) {
4613
+ this.element.removeClass('jstree-' + this._data.core.themes.name);
4614
+ }
4615
+ this._data.core.themes.name = theme_name;
4616
+ this.element.addClass('jstree-' + theme_name);
4617
+ this.element[this.settings.core.themes.responsive ? 'addClass' : 'removeClass' ]('jstree-' + theme_name + '-responsive');
4618
+ /**
4619
+ * triggered when a theme is set
4620
+ * @event
4621
+ * @name set_theme.jstree
4622
+ * @param {String} theme the new theme
4623
+ */
4624
+ this.trigger('set_theme', { 'theme' : theme_name });
4625
+ },
4626
+ /**
4627
+ * gets the name of the currently applied theme name
4628
+ * @name get_theme()
4629
+ * @return {String}
4630
+ */
4631
+ get_theme : function () { return this._data.core.themes.name; },
4632
+ /**
4633
+ * changes the theme variant (if the theme has variants)
4634
+ * @name set_theme_variant(variant_name)
4635
+ * @param {String|Boolean} variant_name the variant to apply (if `false` is used the current variant is removed)
4636
+ */
4637
+ set_theme_variant : function (variant_name) {
4638
+ if(this._data.core.themes.variant) {
4639
+ this.element.removeClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
4640
+ }
4641
+ this._data.core.themes.variant = variant_name;
4642
+ if(variant_name) {
4643
+ this.element.addClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
4644
+ }
4645
+ },
4646
+ /**
4647
+ * gets the name of the currently applied theme variant
4648
+ * @name get_theme()
4649
+ * @return {String}
4650
+ */
4651
+ get_theme_variant : function () { return this._data.core.themes.variant; },
4652
+ /**
4653
+ * shows a striped background on the container (if the theme supports it)
4654
+ * @name show_stripes()
4655
+ */
4656
+ show_stripes : function () {
4657
+ this._data.core.themes.stripes = true;
4658
+ this.get_container_ul().addClass("jstree-striped");
4659
+ /**
4660
+ * triggered when stripes are shown
4661
+ * @event
4662
+ * @name show_stripes.jstree
4663
+ */
4664
+ this.trigger('show_stripes');
4665
+ },
4666
+ /**
4667
+ * hides the striped background on the container
4668
+ * @name hide_stripes()
4669
+ */
4670
+ hide_stripes : function () {
4671
+ this._data.core.themes.stripes = false;
4672
+ this.get_container_ul().removeClass("jstree-striped");
4673
+ /**
4674
+ * triggered when stripes are hidden
4675
+ * @event
4676
+ * @name hide_stripes.jstree
4677
+ */
4678
+ this.trigger('hide_stripes');
4679
+ },
4680
+ /**
4681
+ * toggles the striped background on the container
4682
+ * @name toggle_stripes()
4683
+ */
4684
+ toggle_stripes : function () { if(this._data.core.themes.stripes) { this.hide_stripes(); } else { this.show_stripes(); } },
4685
+ /**
4686
+ * shows the connecting dots (if the theme supports it)
4687
+ * @name show_dots()
4688
+ */
4689
+ show_dots : function () {
4690
+ this._data.core.themes.dots = true;
4691
+ this.get_container_ul().removeClass("jstree-no-dots");
4692
+ /**
4693
+ * triggered when dots are shown
4694
+ * @event
4695
+ * @name show_dots.jstree
4696
+ */
4697
+ this.trigger('show_dots');
4698
+ },
4699
+ /**
4700
+ * hides the connecting dots
4701
+ * @name hide_dots()
4702
+ */
4703
+ hide_dots : function () {
4704
+ this._data.core.themes.dots = false;
4705
+ this.get_container_ul().addClass("jstree-no-dots");
4706
+ /**
4707
+ * triggered when dots are hidden
4708
+ * @event
4709
+ * @name hide_dots.jstree
4710
+ */
4711
+ this.trigger('hide_dots');
4712
+ },
4713
+ /**
4714
+ * toggles the connecting dots
4715
+ * @name toggle_dots()
4716
+ */
4717
+ toggle_dots : function () { if(this._data.core.themes.dots) { this.hide_dots(); } else { this.show_dots(); } },
4718
+ /**
4719
+ * show the node icons
4720
+ * @name show_icons()
4721
+ */
4722
+ show_icons : function () {
4723
+ this._data.core.themes.icons = true;
4724
+ this.get_container_ul().removeClass("jstree-no-icons");
4725
+ /**
4726
+ * triggered when icons are shown
4727
+ * @event
4728
+ * @name show_icons.jstree
4729
+ */
4730
+ this.trigger('show_icons');
4731
+ },
4732
+ /**
4733
+ * hide the node icons
4734
+ * @name hide_icons()
4735
+ */
4736
+ hide_icons : function () {
4737
+ this._data.core.themes.icons = false;
4738
+ this.get_container_ul().addClass("jstree-no-icons");
4739
+ /**
4740
+ * triggered when icons are hidden
4741
+ * @event
4742
+ * @name hide_icons.jstree
4743
+ */
4744
+ this.trigger('hide_icons');
4745
+ },
4746
+ /**
4747
+ * toggle the node icons
4748
+ * @name toggle_icons()
4749
+ */
4750
+ toggle_icons : function () { if(this._data.core.themes.icons) { this.hide_icons(); } else { this.show_icons(); } },
4751
+ /**
4752
+ * show the node ellipsis
4753
+ * @name show_icons()
4754
+ */
4755
+ show_ellipsis : function () {
4756
+ this._data.core.themes.ellipsis = true;
4757
+ this.get_container_ul().addClass("jstree-ellipsis");
4758
+ /**
4759
+ * triggered when ellisis is shown
4760
+ * @event
4761
+ * @name show_ellipsis.jstree
4762
+ */
4763
+ this.trigger('show_ellipsis');
4764
+ },
4765
+ /**
4766
+ * hide the node ellipsis
4767
+ * @name hide_ellipsis()
4768
+ */
4769
+ hide_ellipsis : function () {
4770
+ this._data.core.themes.ellipsis = false;
4771
+ this.get_container_ul().removeClass("jstree-ellipsis");
4772
+ /**
4773
+ * triggered when ellisis is hidden
4774
+ * @event
4775
+ * @name hide_ellipsis.jstree
4776
+ */
4777
+ this.trigger('hide_ellipsis');
4778
+ },
4779
+ /**
4780
+ * toggle the node ellipsis
4781
+ * @name toggle_icons()
4782
+ */
4783
+ toggle_ellipsis : function () { if(this._data.core.themes.ellipsis) { this.hide_ellipsis(); } else { this.show_ellipsis(); } },
4784
+ /**
4785
+ * set the node icon for a node
4786
+ * @name set_icon(obj, icon)
4787
+ * @param {mixed} obj
4788
+ * @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
4789
+ */
4790
+ set_icon : function (obj, icon) {
4791
+ var t1, t2, dom, old;
4792
+ if($.isArray(obj)) {
4793
+ obj = obj.slice();
4794
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4795
+ this.set_icon(obj[t1], icon);
4796
+ }
4797
+ return true;
4798
+ }
4799
+ obj = this.get_node(obj);
4800
+ if(!obj || obj.id === $.jstree.root) { return false; }
4801
+ old = obj.icon;
4802
+ obj.icon = icon === true || icon === null || icon === undefined || icon === '' ? true : icon;
4803
+ dom = this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon");
4804
+ if(icon === false) {
4805
+ dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
4806
+ this.hide_icon(obj);
4807
+ }
4808
+ else if(icon === true || icon === null || icon === undefined || icon === '') {
4809
+ dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
4810
+ if(old === false) { this.show_icon(obj); }
4811
+ }
4812
+ else if(icon.indexOf("/") === -1 && icon.indexOf(".") === -1) {
4813
+ dom.removeClass(old).css("background","");
4814
+ dom.addClass(icon + ' jstree-themeicon-custom').attr("rel",icon);
4815
+ if(old === false) { this.show_icon(obj); }
4816
+ }
4817
+ else {
4818
+ dom.removeClass(old).css("background","");
4819
+ dom.addClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
4820
+ if(old === false) { this.show_icon(obj); }
4821
+ }
4822
+ return true;
4823
+ },
4824
+ /**
4825
+ * get the node icon for a node
4826
+ * @name get_icon(obj)
4827
+ * @param {mixed} obj
4828
+ * @return {String}
4829
+ */
4830
+ get_icon : function (obj) {
4831
+ obj = this.get_node(obj);
4832
+ return (!obj || obj.id === $.jstree.root) ? false : obj.icon;
4833
+ },
4834
+ /**
4835
+ * hide the icon on an individual node
4836
+ * @name hide_icon(obj)
4837
+ * @param {mixed} obj
4838
+ */
4839
+ hide_icon : function (obj) {
4840
+ var t1, t2;
4841
+ if($.isArray(obj)) {
4842
+ obj = obj.slice();
4843
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4844
+ this.hide_icon(obj[t1]);
4845
+ }
4846
+ return true;
4847
+ }
4848
+ obj = this.get_node(obj);
4849
+ if(!obj || obj === $.jstree.root) { return false; }
4850
+ obj.icon = false;
4851
+ this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon").addClass('jstree-themeicon-hidden');
4852
+ return true;
4853
+ },
4854
+ /**
4855
+ * show the icon on an individual node
4856
+ * @name show_icon(obj)
4857
+ * @param {mixed} obj
4858
+ */
4859
+ show_icon : function (obj) {
4860
+ var t1, t2, dom;
4861
+ if($.isArray(obj)) {
4862
+ obj = obj.slice();
4863
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4864
+ this.show_icon(obj[t1]);
4865
+ }
4866
+ return true;
4867
+ }
4868
+ obj = this.get_node(obj);
4869
+ if(!obj || obj === $.jstree.root) { return false; }
4870
+ dom = this.get_node(obj, true);
4871
+ obj.icon = dom.length ? dom.children(".jstree-anchor").children(".jstree-themeicon").attr('rel') : true;
4872
+ if(!obj.icon) { obj.icon = true; }
4873
+ dom.children(".jstree-anchor").children(".jstree-themeicon").removeClass('jstree-themeicon-hidden');
4874
+ return true;
4875
+ }
4876
+ };
4877
+
4878
+ // helpers
4879
+ $.vakata = {};
4880
+ // collect attributes
4881
+ $.vakata.attributes = function(node, with_values) {
4882
+ node = $(node)[0];
4883
+ var attr = with_values ? {} : [];
4884
+ if(node && node.attributes) {
4885
+ $.each(node.attributes, function (i, v) {
4886
+ if($.inArray(v.name.toLowerCase(),['style','contenteditable','hasfocus','tabindex']) !== -1) { return; }
4887
+ if(v.value !== null && $.trim(v.value) !== '') {
4888
+ if(with_values) { attr[v.name] = v.value; }
4889
+ else { attr.push(v.name); }
4890
+ }
4891
+ });
4892
+ }
4893
+ return attr;
4894
+ };
4895
+ $.vakata.array_unique = function(array) {
4896
+ var a = [], i, j, l, o = {};
4897
+ for(i = 0, l = array.length; i < l; i++) {
4898
+ if(o[array[i]] === undefined) {
4899
+ a.push(array[i]);
4900
+ o[array[i]] = true;
4901
+ }
4902
+ }
4903
+ return a;
4904
+ };
4905
+ // remove item from array
4906
+ $.vakata.array_remove = function(array, from) {
4907
+ array.splice(from, 1);
4908
+ return array;
4909
+ //var rest = array.slice((to || from) + 1 || array.length);
4910
+ //array.length = from < 0 ? array.length + from : from;
4911
+ //array.push.apply(array, rest);
4912
+ //return array;
4913
+ };
4914
+ // remove item from array
4915
+ $.vakata.array_remove_item = function(array, item) {
4916
+ var tmp = $.inArray(item, array);
4917
+ return tmp !== -1 ? $.vakata.array_remove(array, tmp) : array;
4918
+ };
4919
+ $.vakata.array_filter = function(c,a,b,d,e) {
4920
+ if (c.filter) {
4921
+ return c.filter(a, b);
4922
+ }
4923
+ d=[];
4924
+ for (e in c) {
4925
+ if (~~e+''===e+'' && e>=0 && a.call(b,c[e],+e,c)) {
4926
+ d.push(c[e]);
4927
+ }
4928
+ }
4929
+ return d;
4930
+ };
4931
+ }));