jstree-rails-4 3.3.8 → 3.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@
13
13
  }(function ($, undefined) {
14
14
  "use strict";
15
15
  /*!
16
- * jsTree 3.3.8
16
+ * jsTree 3.3.17
17
17
  * http://jstree.com/
18
18
  *
19
19
  * Copyright (c) 2014 Ivan Bozhanov (http://vakata.com)
@@ -45,6 +45,15 @@
45
45
  src = $('script:last').attr('src'),
46
46
  document = window.document; // local variable is always faster to access then a global
47
47
 
48
+ var setImmediate = window.setImmediate;
49
+ var Promise = window.Promise;
50
+ if (!setImmediate && Promise) {
51
+ // Good enough approximation of setImmediate
52
+ setImmediate = function (cb, arg) {
53
+ Promise.resolve(arg).then(cb);
54
+ };
55
+ }
56
+
48
57
  /**
49
58
  * holds all jstree related functions and variables, including the actual class and methods to create, access and manipulate instances.
50
59
  * @name $.jstree
@@ -54,7 +63,7 @@
54
63
  * specifies the jstree version in use
55
64
  * @name $.jstree.version
56
65
  */
57
- version : '3.3.8',
66
+ version : '3.3.17',
58
67
  /**
59
68
  * holds all the default options used when creating new instances
60
69
  * @name $.jstree.defaults
@@ -265,7 +274,7 @@
265
274
  * You can also pass in a HTML string or a JSON array here.
266
275
  *
267
276
  * 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.
277
+ * In addition to the standard jQuery ajax options here you can supply 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
278
  *
270
279
  * 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
280
  *
@@ -444,6 +453,12 @@
444
453
  * @name $.jstree.defaults.core.restore_focus
445
454
  */
446
455
  restore_focus : true,
456
+ /**
457
+ * Force to compute and set "aria-setsize" and "aria-posinset" explicitly for each treeitem.
458
+ * Some browsers may compute incorrect elements position and produce wrong announcements for screen readers. Defaults to `false`
459
+ * @name $.jstree.defaults.core.compute_elements_positions
460
+ */
461
+ compute_elements_positions : false,
447
462
  /**
448
463
  * 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
464
  * @name $.jstree.defaults.core.keyboard
@@ -467,31 +482,31 @@
467
482
  }
468
483
  else {
469
484
  var o = this.get_parent(e.currentTarget);
470
- if(o && o.id !== $.jstree.root) { this.get_node(o, true).children('.jstree-anchor').focus(); }
485
+ if(o && o.id !== $.jstree.root) { this.get_node(o, true).children('.jstree-anchor').trigger('focus'); }
471
486
  }
472
487
  },
473
488
  'up': function (e) {
474
489
  // up
475
490
  e.preventDefault();
476
491
  var o = this.get_prev_dom(e.currentTarget);
477
- if(o && o.length) { o.children('.jstree-anchor').focus(); }
492
+ if(o && o.length) { o.children('.jstree-anchor').trigger('focus'); }
478
493
  },
479
494
  'right': function (e) {
480
495
  // right
481
496
  e.preventDefault();
482
497
  if(this.is_closed(e.currentTarget)) {
483
- this.open_node(e.currentTarget, function (o) { this.get_node(o, true).children('.jstree-anchor').focus(); });
498
+ this.open_node(e.currentTarget, function (o) { this.get_node(o, true).children('.jstree-anchor').trigger('focus'); });
484
499
  }
485
500
  else if (this.is_open(e.currentTarget)) {
486
501
  var o = this.get_node(e.currentTarget, true).children('.jstree-children')[0];
487
- if(o) { $(this._firstChild(o)).children('.jstree-anchor').focus(); }
502
+ if(o) { $(this._firstChild(o)).children('.jstree-anchor').trigger('focus'); }
488
503
  }
489
504
  },
490
505
  'down': function (e) {
491
506
  // down
492
507
  e.preventDefault();
493
508
  var o = this.get_next_dom(e.currentTarget);
494
- if(o && o.length) { o.children('.jstree-anchor').focus(); }
509
+ if(o && o.length) { o.children('.jstree-anchor').trigger('focus'); }
495
510
  },
496
511
  '*': function (e) {
497
512
  // aria defines * on numpad as open_all - not very common
@@ -501,19 +516,24 @@
501
516
  // home
502
517
  e.preventDefault();
503
518
  var o = this._firstChild(this.get_container_ul()[0]);
504
- if(o) { $(o).children('.jstree-anchor').filter(':visible').focus(); }
519
+ if(o) { $(o).children('.jstree-anchor').filter(':visible').trigger('focus'); }
505
520
  },
506
521
  'end': function (e) {
507
522
  // end
508
523
  e.preventDefault();
509
- this.element.find('.jstree-anchor').filter(':visible').last().focus();
524
+ this.element.find('.jstree-anchor').filter(':visible').last().trigger('focus');
510
525
  },
511
526
  'f2': function (e) {
512
527
  // f2 - safe to include - if check_callback is false it will fail
513
528
  e.preventDefault();
514
529
  this.edit(e.currentTarget);
515
530
  }
516
- }
531
+ },
532
+ /**
533
+ * Should reselecting an already selected node trigger the select and changed callbacks
534
+ * @name $.jstree.defaults.core.allow_reselect
535
+ */
536
+ allow_reselect : false
517
537
  };
518
538
  $.jstree.core.prototype = {
519
539
  /**
@@ -593,7 +613,7 @@
593
613
  return this.nodeType === 3 && (!this.nodeValue || /^\s+$/.test(this.nodeValue));
594
614
  })
595
615
  .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>");
616
+ 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='none'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' role='treeitem' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
597
617
  this.element.attr('aria-activedescendant','j' + this._id + '_loading');
598
618
  this._data.core.li_height = this.get_container_ul().children("li").first().outerHeight() || 24;
599
619
  this._data.core.node = this._create_prototype_node();
@@ -634,7 +654,7 @@
634
654
  */
635
655
  _create_prototype_node : function () {
636
656
  var _node = document.createElement('LI'), _temp1, _temp2;
637
- _node.setAttribute('role', 'treeitem');
657
+ _node.setAttribute('role', 'none');
638
658
  _temp1 = document.createElement('I');
639
659
  _temp1.className = 'jstree-icon jstree-ocl';
640
660
  _temp1.setAttribute('role', 'presentation');
@@ -643,6 +663,7 @@
643
663
  _temp1.className = 'jstree-anchor';
644
664
  _temp1.setAttribute('href','#');
645
665
  _temp1.setAttribute('tabindex','-1');
666
+ _temp1.setAttribute('role', 'treeitem');
646
667
  _temp2 = document.createElement('I');
647
668
  _temp2.className = 'jstree-icon jstree-themeicon';
648
669
  _temp2.setAttribute('role', 'presentation');
@@ -675,9 +696,12 @@
675
696
  var parts = [];
676
697
  if (e.ctrlKey) { parts.push('ctrl'); }
677
698
  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();
699
+ if (e.shiftKey) { parts.push('shift'); }
700
+ parts.push(keys[e.which] ? keys[e.which].toLowerCase() : e.which);
701
+ parts = parts.sort().join('-').toLowerCase();
702
+ if (parts === 'shift-shift' || parts === 'ctrl-ctrl' || parts === 'alt-alt') {
703
+ return null;
704
+ }
681
705
 
682
706
  var kb = this.settings.core.keyboard, i, tmp;
683
707
  for (i in kb) {
@@ -734,30 +758,30 @@
734
758
  }
735
759
  }
736
760
  })
737
- .on("mousedown.jstree", $.proxy(function (e) {
761
+ .on("mousedown.jstree", function (e) {
738
762
  if(e.target === this.element[0]) {
739
763
  e.preventDefault(); // prevent losing focus when clicking scroll arrows (FF, Chrome)
740
764
  was_click = +(new Date()); // ie does not allow to prevent losing focus
741
765
  }
742
- }, this))
766
+ }.bind(this))
743
767
  .on("mousedown.jstree", ".jstree-ocl", function (e) {
744
768
  e.preventDefault(); // prevent any node inside from losing focus when clicking the open/close icon
745
769
  })
746
- .on("click.jstree", ".jstree-ocl", $.proxy(function (e) {
770
+ .on("click.jstree", ".jstree-ocl", function (e) {
747
771
  this.toggle_node(e.target);
748
- }, this))
749
- .on("dblclick.jstree", ".jstree-anchor", $.proxy(function (e) {
772
+ }.bind(this))
773
+ .on("dblclick.jstree", ".jstree-anchor", function (e) {
750
774
  if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
751
775
  if(this.settings.core.dblclick_toggle) {
752
776
  this.toggle_node(e.target);
753
777
  }
754
- }, this))
755
- .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
778
+ }.bind(this))
779
+ .on("click.jstree", ".jstree-anchor", function (e) {
756
780
  e.preventDefault();
757
- if(e.currentTarget !== document.activeElement) { $(e.currentTarget).focus(); }
781
+ if(e.currentTarget !== document.activeElement) { $(e.currentTarget).trigger('focus'); }
758
782
  this.activate_node(e.currentTarget, e);
759
- }, this))
760
- .on('keydown.jstree', '.jstree-anchor', $.proxy(function (e) {
783
+ }.bind(this))
784
+ .on('keydown.jstree', '.jstree-anchor', function (e) {
761
785
  if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
762
786
  if(this._data.core.rtl) {
763
787
  if(e.which === 37) { e.which = 39; }
@@ -770,8 +794,8 @@
770
794
  return r;
771
795
  }
772
796
  }
773
- }, this))
774
- .on("load_node.jstree", $.proxy(function (e, data) {
797
+ }.bind(this))
798
+ .on("load_node.jstree", function (e, data) {
775
799
  if(data.status) {
776
800
  if(data.node.id === $.jstree.root && !this._data.core.loaded) {
777
801
  this._data.core.loaded = true;
@@ -786,7 +810,7 @@
786
810
  this.trigger("loaded");
787
811
  }
788
812
  if(!this._data.core.ready) {
789
- setTimeout($.proxy(function() {
813
+ setTimeout(function() {
790
814
  if(this.element && !this.get_container_ul().find('.jstree-loading').length) {
791
815
  this._data.core.ready = true;
792
816
  if(this._data.core.selected.length) {
@@ -809,12 +833,12 @@
809
833
  */
810
834
  this.trigger("ready");
811
835
  }
812
- }, this), 0);
836
+ }.bind(this), 0);
813
837
  }
814
838
  }
815
- }, this))
839
+ }.bind(this))
816
840
  // quick searching when the tree is focused
817
- .on('keypress.jstree', $.proxy(function (e) {
841
+ .on('keypress.jstree', function (e) {
818
842
  if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
819
843
  if(tout) { clearTimeout(tout); }
820
844
  tout = setTimeout(function () {
@@ -829,50 +853,50 @@
829
853
 
830
854
  // match for whole word from current node down (including the current node)
831
855
  if(word.length > 1) {
832
- col.slice(ind).each($.proxy(function (i, v) {
856
+ col.slice(ind).each(function (i, v) {
833
857
  if($(v).text().toLowerCase().indexOf(word) === 0) {
834
- $(v).focus();
858
+ $(v).trigger('focus');
835
859
  end = true;
836
860
  return false;
837
861
  }
838
- }, this));
862
+ }.bind(this));
839
863
  if(end) { return; }
840
864
 
841
865
  // match for whole word from the beginning of the tree
842
- col.slice(0, ind).each($.proxy(function (i, v) {
866
+ col.slice(0, ind).each(function (i, v) {
843
867
  if($(v).text().toLowerCase().indexOf(word) === 0) {
844
- $(v).focus();
868
+ $(v).trigger('focus');
845
869
  end = true;
846
870
  return false;
847
871
  }
848
- }, this));
872
+ }.bind(this));
849
873
  if(end) { return; }
850
874
  }
851
875
  // list nodes that start with that letter (only if word consists of a single char)
852
876
  if(new RegExp('^' + chr.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '+$').test(word)) {
853
877
  // search for the next node starting with that letter
854
- col.slice(ind + 1).each($.proxy(function (i, v) {
878
+ col.slice(ind + 1).each(function (i, v) {
855
879
  if($(v).text().toLowerCase().charAt(0) === chr) {
856
- $(v).focus();
880
+ $(v).trigger('focus');
857
881
  end = true;
858
882
  return false;
859
883
  }
860
- }, this));
884
+ }.bind(this));
861
885
  if(end) { return; }
862
886
 
863
887
  // search from the beginning
864
- col.slice(0, ind + 1).each($.proxy(function (i, v) {
888
+ col.slice(0, ind + 1).each(function (i, v) {
865
889
  if($(v).text().toLowerCase().charAt(0) === chr) {
866
- $(v).focus();
890
+ $(v).trigger('focus');
867
891
  end = true;
868
892
  return false;
869
893
  }
870
- }, this));
894
+ }.bind(this));
871
895
  if(end) { return; }
872
896
  }
873
- }, this))
897
+ }.bind(this))
874
898
  // THEME RELATED
875
- .on("init.jstree", $.proxy(function () {
899
+ .on("init.jstree", function () {
876
900
  var s = this.settings.core.themes;
877
901
  this._data.core.themes.dots = s.dots;
878
902
  this._data.core.themes.stripes = s.stripes;
@@ -880,42 +904,44 @@
880
904
  this._data.core.themes.ellipsis = s.ellipsis;
881
905
  this.set_theme(s.name || "default", s.url);
882
906
  this.set_theme_variant(s.variant);
883
- }, this))
884
- .on("loading.jstree", $.proxy(function () {
907
+ }.bind(this))
908
+ .on("loading.jstree", function () {
885
909
  this[ this._data.core.themes.dots ? "show_dots" : "hide_dots" ]();
886
910
  this[ this._data.core.themes.icons ? "show_icons" : "hide_icons" ]();
887
911
  this[ this._data.core.themes.stripes ? "show_stripes" : "hide_stripes" ]();
888
912
  this[ this._data.core.themes.ellipsis ? "show_ellipsis" : "hide_ellipsis" ]();
889
- }, this))
890
- .on('blur.jstree', '.jstree-anchor', $.proxy(function (e) {
913
+ }.bind(this))
914
+ .on('blur.jstree', '.jstree-anchor', function (e) {
891
915
  this._data.core.focused = null;
892
916
  $(e.currentTarget).filter('.jstree-hovered').trigger('mouseleave');
893
917
  this.element.attr('tabindex', '0');
894
- }, this))
895
- .on('focus.jstree', '.jstree-anchor', $.proxy(function (e) {
918
+ $(e.currentTarget).attr('tabindex', '-1');
919
+ }.bind(this))
920
+ .on('focus.jstree', '.jstree-anchor', function (e) {
896
921
  var tmp = this.get_node(e.currentTarget);
897
- if(tmp && tmp.id) {
922
+ if(tmp && (tmp.id || tmp.id === 0)) {
898
923
  this._data.core.focused = tmp.id;
899
924
  }
900
925
  this.element.find('.jstree-hovered').not(e.currentTarget).trigger('mouseleave');
901
926
  $(e.currentTarget).trigger('mouseenter');
902
927
  this.element.attr('tabindex', '-1');
903
- }, this))
904
- .on('focus.jstree', $.proxy(function () {
928
+ $(e.currentTarget).attr('tabindex', '0');
929
+ }.bind(this))
930
+ .on('focus.jstree', function () {
905
931
  if(+(new Date()) - was_click > 500 && !this._data.core.focused && this.settings.core.restore_focus) {
906
932
  was_click = 0;
907
933
  var act = this.get_node(this.element.attr('aria-activedescendant'), true);
908
934
  if(act) {
909
- act.find('> .jstree-anchor').focus();
935
+ act.find('> .jstree-anchor').trigger('focus');
910
936
  }
911
937
  }
912
- }, this))
913
- .on('mouseenter.jstree', '.jstree-anchor', $.proxy(function (e) {
938
+ }.bind(this))
939
+ .on('mouseenter.jstree', '.jstree-anchor', function (e) {
914
940
  this.hover_node(e.currentTarget);
915
- }, this))
916
- .on('mouseleave.jstree', '.jstree-anchor', $.proxy(function (e) {
941
+ }.bind(this))
942
+ .on('mouseleave.jstree', '.jstree-anchor', function (e) {
917
943
  this.dehover_node(e.currentTarget);
918
- }, this));
944
+ }.bind(this));
919
945
  },
920
946
  /**
921
947
  * part of the destroying of an instance. Used internally.
@@ -966,7 +992,7 @@
966
992
  */
967
993
  get_string : function (key) {
968
994
  var a = this.settings.core.strings;
969
- if($.isFunction(a)) { return a.call(this, key); }
995
+ if($.vakata.is_function(a)) { return a.call(this, key); }
970
996
  if(a && a[key]) { return a[key]; }
971
997
  return key;
972
998
  },
@@ -1020,7 +1046,7 @@
1020
1046
  * @return {Object|jQuery}
1021
1047
  */
1022
1048
  get_node : function (obj, as_dom) {
1023
- if(obj && obj.id) {
1049
+ if(obj && (obj.id || obj.id === 0)) {
1024
1050
  obj = obj.id;
1025
1051
  }
1026
1052
  if (obj instanceof $ && obj.length && obj[0].id) {
@@ -1257,8 +1283,8 @@
1257
1283
  * @trigger load_node.jstree
1258
1284
  */
1259
1285
  load_node : function (obj, callback) {
1260
- var k, l, i, j, c;
1261
- if($.isArray(obj)) {
1286
+ var dom = this.get_node(obj, true), k, l, i, j, c;
1287
+ if($.vakata.is_array(obj)) {
1262
1288
  this._load_nodes(obj.slice(), callback);
1263
1289
  return true;
1264
1290
  }
@@ -1294,8 +1320,13 @@
1294
1320
  }
1295
1321
  obj.state.failed = false;
1296
1322
  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) {
1323
+ if (obj.id !== $.jstree.root) {
1324
+ dom.children(".jstree-anchor").attr('aria-busy', true);
1325
+ } else {
1326
+ dom.attr('aria-busy', true);
1327
+ }
1328
+ dom.addClass("jstree-loading");
1329
+ this._load_node(obj, function (status) {
1299
1330
  obj = this._model.data[obj.id];
1300
1331
  obj.state.loading = false;
1301
1332
  obj.state.loaded = status;
@@ -1318,7 +1349,12 @@
1318
1349
  }
1319
1350
  }
1320
1351
  }
1321
- dom.removeClass("jstree-loading").attr('aria-busy',false);
1352
+ if (obj.id !== $.jstree.root) {
1353
+ dom.children(".jstree-anchor").attr('aria-busy', false);
1354
+ } else {
1355
+ dom.attr('aria-busy', false);
1356
+ }
1357
+ dom.removeClass("jstree-loading");
1322
1358
  /**
1323
1359
  * triggered after a node is loaded
1324
1360
  * @event
@@ -1330,7 +1366,7 @@
1330
1366
  if(callback) {
1331
1367
  callback.call(this, obj, status);
1332
1368
  }
1333
- }, this));
1369
+ }.bind(this));
1334
1370
  return true;
1335
1371
  },
1336
1372
  /**
@@ -1428,8 +1464,8 @@
1428
1464
  }
1429
1465
  // return callback.call(this, obj.id === $.jstree.root ? this._append_html_data(obj, this._data.core.original_container_html.clone(true)) : false);
1430
1466
  }
1431
- if($.isFunction(s)) {
1432
- return s.call(this, obj, $.proxy(function (d) {
1467
+ if($.vakata.is_function(s)) {
1468
+ return s.call(this, obj, function (d) {
1433
1469
  if(d === false) {
1434
1470
  callback.call(this, false);
1435
1471
  }
@@ -1439,19 +1475,19 @@
1439
1475
  });
1440
1476
  }
1441
1477
  // 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));
1478
+ }.bind(this));
1443
1479
  }
1444
1480
  if(typeof s === 'object') {
1445
1481
  if(s.url) {
1446
1482
  s = $.extend(true, {}, s);
1447
- if($.isFunction(s.url)) {
1483
+ if($.vakata.is_function(s.url)) {
1448
1484
  s.url = s.url.call(this, obj);
1449
1485
  }
1450
- if($.isFunction(s.data)) {
1486
+ if($.vakata.is_function(s.data)) {
1451
1487
  s.data = s.data.call(this, obj);
1452
1488
  }
1453
1489
  return $.ajax(s)
1454
- .done($.proxy(function (d,t,x) {
1490
+ .done(function (d,t,x) {
1455
1491
  var type = x.getResponseHeader('Content-Type');
1456
1492
  if((type && type.indexOf('json') !== -1) || typeof d === "object") {
1457
1493
  return this._append_json_data(obj, d, function (status) { callback.call(this, status); });
@@ -1464,14 +1500,14 @@
1464
1500
  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
1501
  this.settings.core.error.call(this, this._data.core.last_error);
1466
1502
  return callback.call(this, false);
1467
- }, this))
1468
- .fail($.proxy(function (f) {
1503
+ }.bind(this))
1504
+ .fail(function (f) {
1469
1505
  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
1506
  callback.call(this, false);
1471
1507
  this.settings.core.error.call(this, this._data.core.last_error);
1472
- }, this));
1508
+ }.bind(this));
1473
1509
  }
1474
- if ($.isArray(s)) {
1510
+ if ($.vakata.is_array(s)) {
1475
1511
  t = $.extend(true, [], s);
1476
1512
  } else if ($.isPlainObject(s)) {
1477
1513
  t = $.extend(true, {}, s);
@@ -1537,7 +1573,7 @@
1537
1573
  p = m[par],
1538
1574
  s = this._data.core.selected.length,
1539
1575
  tmp, i, j;
1540
- dat.each($.proxy(function (i, v) {
1576
+ dat.each(function (i, v) {
1541
1577
  tmp = this._parse_model_from_html($(v), par, p.parents.concat());
1542
1578
  if(tmp) {
1543
1579
  chd.push(tmp);
@@ -1546,7 +1582,7 @@
1546
1582
  dpc = dpc.concat(m[tmp].children_d);
1547
1583
  }
1548
1584
  }
1549
- }, this));
1585
+ }.bind(this));
1550
1586
  p.children = chd;
1551
1587
  p.children_d = dpc;
1552
1588
  for(i = 0, j = p.parents.length; i < j; i++) {
@@ -1594,7 +1630,7 @@
1594
1630
  data = JSON.parse(data);
1595
1631
  }
1596
1632
  }
1597
- if(!$.isArray(data)) { data = [data]; }
1633
+ if(!$.vakata.is_array(data)) { data = [data]; }
1598
1634
  var w = null,
1599
1635
  args = {
1600
1636
  'df' : this._model.default_state,
@@ -1735,7 +1771,7 @@
1735
1771
  tmp.state[i] = df[i];
1736
1772
  }
1737
1773
  }
1738
- if(d && d.id) { tmp.id = d.id.toString(); }
1774
+ if(d && (d.id || d.id === 0)) { tmp.id = d.id.toString(); }
1739
1775
  if(d && d.text) { tmp.text = d.text; }
1740
1776
  if(d && d.data && d.data.jstree && d.data.jstree.icon) {
1741
1777
  tmp.icon = d.data.jstree.icon;
@@ -1767,10 +1803,10 @@
1767
1803
  }
1768
1804
  }
1769
1805
  }
1770
- if(tmp.li_attr.id && !tmp.id) {
1806
+ if(tmp.li_attr.id && !(tmp.id || tmp.id === 0)) {
1771
1807
  tmp.id = tmp.li_attr.id.toString();
1772
1808
  }
1773
- if(!tmp.id) {
1809
+ if(!(tmp.id || tmp.id === 0)) {
1774
1810
  tmp.id = tid;
1775
1811
  }
1776
1812
  if(!tmp.li_attr.id) {
@@ -1935,7 +1971,16 @@
1935
1971
  if(rslt.add.length) {
1936
1972
  this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
1937
1973
  }
1938
- cb.call(this, true);
1974
+
1975
+ // If no worker, try to mimic worker behavioour, by invoking cb asynchronously
1976
+ if (!worker && setImmediate) {
1977
+ setImmediate(function(){
1978
+ cb.call(inst, true);
1979
+ });
1980
+ }
1981
+ else {
1982
+ cb.call(inst, true);
1983
+ }
1939
1984
  };
1940
1985
  if(this.settings.core.worker && window.Blob && window.URL && window.Worker) {
1941
1986
  try {
@@ -1950,7 +1995,7 @@
1950
1995
  if(!this._data.core.working || force_processing) {
1951
1996
  this._data.core.working = true;
1952
1997
  w = new window.Worker(this._wrk);
1953
- w.onmessage = $.proxy(function (e) {
1998
+ w.onmessage = function (e) {
1954
1999
  rslt.call(this, e.data, true);
1955
2000
  try { w.terminate(); w = null; } catch(ignore) { }
1956
2001
  if(this._data.core.worker_queue.length) {
@@ -1959,7 +2004,16 @@
1959
2004
  else {
1960
2005
  this._data.core.working = false;
1961
2006
  }
1962
- }, this);
2007
+ }.bind(this);
2008
+ w.onerror = function (e) {
2009
+ rslt.call(this, func(args), false);
2010
+ if(this._data.core.worker_queue.length) {
2011
+ this._append_json_data.apply(this, this._data.core.worker_queue.shift());
2012
+ }
2013
+ else {
2014
+ this._data.core.working = false;
2015
+ }
2016
+ }.bind(this);
1963
2017
  if(!args.par) {
1964
2018
  if(this._data.core.worker_queue.length) {
1965
2019
  this._append_json_data.apply(this, this._data.core.worker_queue.shift());
@@ -2025,7 +2079,7 @@
2025
2079
  }
2026
2080
  tmp = $.vakata.attributes(d, true);
2027
2081
  $.each(tmp, function (i, v) {
2028
- v = $.trim(v);
2082
+ v = $.vakata.trim(v);
2029
2083
  if(!v.length) { return true; }
2030
2084
  data.li_attr[i] = v;
2031
2085
  if(i === 'id') {
@@ -2036,7 +2090,7 @@
2036
2090
  if(tmp.length) {
2037
2091
  tmp = $.vakata.attributes(tmp, true);
2038
2092
  $.each(tmp, function (i, v) {
2039
- v = $.trim(v);
2093
+ v = $.vakata.trim(v);
2040
2094
  if(v.length) {
2041
2095
  data.a_attr[i] = v;
2042
2096
  }
@@ -2045,7 +2099,7 @@
2045
2099
  tmp = d.children("a").first().length ? d.children("a").first().clone() : d.clone();
2046
2100
  tmp.children("ins, i, ul").remove();
2047
2101
  tmp = tmp.html();
2048
- tmp = $('<div />').html(tmp);
2102
+ tmp = $('<div></div>').html(tmp);
2049
2103
  data.text = this.settings.core.force_text ? tmp.text() : tmp.html();
2050
2104
  tmp = d.data();
2051
2105
  data.data = tmp ? $.extend(true, {}, tmp) : null;
@@ -2075,14 +2129,14 @@
2075
2129
  } while(m[tid]);
2076
2130
  data.id = data.li_attr.id ? data.li_attr.id.toString() : tid;
2077
2131
  if(tmp.length) {
2078
- tmp.each($.proxy(function (i, v) {
2132
+ tmp.each(function (i, v) {
2079
2133
  c = this._parse_model_from_html($(v), data.id, ps);
2080
2134
  e = this._model.data[c];
2081
2135
  data.children.push(c);
2082
2136
  if(e.children_d.length) {
2083
2137
  data.children_d = data.children_d.concat(e.children_d);
2084
2138
  }
2085
- }, this));
2139
+ }.bind(this));
2086
2140
  data.children_d = data.children_d.concat(data.children);
2087
2141
  }
2088
2142
  else {
@@ -2237,7 +2291,7 @@
2237
2291
  tmp.state[i] = df[i];
2238
2292
  }
2239
2293
  }
2240
- if(d && d.id) { tmp.id = d.id.toString(); }
2294
+ if(d && (d.id || d.id === 0)) { tmp.id = d.id.toString(); }
2241
2295
  if(d && d.text) { tmp.text = d.text; }
2242
2296
  if(d && d.data && d.data.jstree && d.data.jstree.icon) {
2243
2297
  tmp.icon = d.data.jstree.icon;
@@ -2269,10 +2323,10 @@
2269
2323
  }
2270
2324
  }
2271
2325
  }
2272
- if(tmp.li_attr.id && !tmp.id) {
2326
+ if(tmp.li_attr.id && !(tmp.id || tmp.id === 0)) {
2273
2327
  tmp.id = tmp.li_attr.id.toString();
2274
2328
  }
2275
- if(!tmp.id) {
2329
+ if(!(tmp.id || tmp.id === 0)) {
2276
2330
  tmp.id = tid;
2277
2331
  }
2278
2332
  if(!tmp.li_attr.id) {
@@ -2327,14 +2381,14 @@
2327
2381
  }
2328
2382
  if(this._model.force_full_redraw) {
2329
2383
  f.className = this.get_container_ul()[0].className;
2330
- f.setAttribute('role','group');
2384
+ f.setAttribute('role','presentation');
2331
2385
  this.element.empty().append(f);
2332
2386
  //this.get_container_ul()[0].appendChild(f);
2333
2387
  }
2334
2388
  if(fe !== null && this.settings.core.restore_focus) {
2335
2389
  tmp = this.get_node(fe, true);
2336
2390
  if(tmp && tmp.length && tmp.children('.jstree-anchor')[0] !== document.activeElement) {
2337
- tmp.children('.jstree-anchor').focus();
2391
+ tmp.children('.jstree-anchor').trigger('focus');
2338
2392
  }
2339
2393
  else {
2340
2394
  this._data.core.focused = null;
@@ -2475,11 +2529,14 @@
2475
2529
  if(!obj.a_attr.id) {
2476
2530
  obj.a_attr.id = obj.id + '_anchor';
2477
2531
  }
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);
2532
+ node.childNodes[1].setAttribute('aria-selected', !!obj.state.selected);
2533
+ node.childNodes[1].setAttribute('aria-level', obj.parents.length);
2534
+ if(this.settings.core.compute_elements_positions) {
2535
+ node.childNodes[1].setAttribute('aria-setsize', m[obj.parent].children.length);
2536
+ node.childNodes[1].setAttribute('aria-posinset', m[obj.parent].children.indexOf(obj.id) + 1);
2537
+ }
2481
2538
  if(obj.state.disabled) {
2482
- node.setAttribute('aria-disabled', true);
2539
+ node.childNodes[1].setAttribute('aria-disabled', true);
2483
2540
  }
2484
2541
 
2485
2542
  for(i = 0, j = obj.children.length; i < j; i++) {
@@ -2515,7 +2572,7 @@
2515
2572
  }
2516
2573
  else {
2517
2574
  c += obj.state.opened && obj.state.loaded ? ' jstree-open' : ' jstree-closed';
2518
- node.setAttribute('aria-expanded', (obj.state.opened && obj.state.loaded) );
2575
+ node.childNodes[1].setAttribute('aria-expanded', (obj.state.opened && obj.state.loaded) );
2519
2576
  }
2520
2577
  if(last_sibling === obj.id) {
2521
2578
  c += ' jstree-last';
@@ -2607,9 +2664,9 @@
2607
2664
  }
2608
2665
  if(obj.state.opened && !obj.state.loaded) {
2609
2666
  obj.state.opened = false;
2610
- setTimeout($.proxy(function () {
2667
+ setTimeout(function () {
2611
2668
  this.open_node(obj.id, false, 0);
2612
- }, this), 0);
2669
+ }.bind(this), 0);
2613
2670
  }
2614
2671
  return node;
2615
2672
  },
@@ -2623,7 +2680,7 @@
2623
2680
  */
2624
2681
  open_node : function (obj, callback, animation) {
2625
2682
  var t1, t2, d, t;
2626
- if($.isArray(obj)) {
2683
+ if($.vakata.is_array(obj)) {
2627
2684
  obj = obj.slice();
2628
2685
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2629
2686
  this.open_node(obj[t1], callback, animation);
@@ -2643,9 +2700,9 @@
2643
2700
  }
2644
2701
  if(!this.is_loaded(obj)) {
2645
2702
  if(this.is_loading(obj)) {
2646
- return setTimeout($.proxy(function () {
2703
+ return setTimeout(function () {
2647
2704
  this.open_node(obj, callback, animation);
2648
- }, this), 500);
2705
+ }.bind(this), 500);
2649
2706
  }
2650
2707
  this.load_node(obj, function (o, ok) {
2651
2708
  return ok ? this.open_node(o, callback, animation) : (callback ? callback.call(this, o, false) : false);
@@ -2665,13 +2722,14 @@
2665
2722
  if(!animation) {
2666
2723
  this.trigger('before_open', { "node" : obj });
2667
2724
  d[0].className = d[0].className.replace('jstree-closed', 'jstree-open');
2668
- d[0].setAttribute("aria-expanded", true);
2725
+ d[0].childNodes[1].setAttribute("aria-expanded", true);
2669
2726
  }
2670
2727
  else {
2671
2728
  this.trigger('before_open', { "node" : obj });
2672
2729
  d
2673
2730
  .children(".jstree-children").css("display","none").end()
2674
- .removeClass("jstree-closed").addClass("jstree-open").attr("aria-expanded", true)
2731
+ .removeClass("jstree-closed").addClass("jstree-open")
2732
+ .children('.jstree-anchor').attr("aria-expanded", true).end()
2675
2733
  .children(".jstree-children").stop(true, true)
2676
2734
  .slideDown(animation, function () {
2677
2735
  this.style.display = "";
@@ -2741,7 +2799,7 @@
2741
2799
  */
2742
2800
  close_node : function (obj, animation) {
2743
2801
  var t1, t2, t, d;
2744
- if($.isArray(obj)) {
2802
+ if($.vakata.is_array(obj)) {
2745
2803
  obj = obj.slice();
2746
2804
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2747
2805
  this.close_node(obj[t1], animation);
@@ -2779,13 +2837,15 @@
2779
2837
  else {
2780
2838
  if(!animation) {
2781
2839
  d[0].className = d[0].className.replace('jstree-open', 'jstree-closed');
2782
- d.attr("aria-expanded", false).children('.jstree-children').remove();
2840
+ d.children('.jstree-anchor').attr("aria-expanded", false);
2841
+ d.children('.jstree-children').remove();
2783
2842
  this.trigger("after_close", { "node" : obj });
2784
2843
  }
2785
2844
  else {
2786
2845
  d
2787
2846
  .children(".jstree-children").attr("style","display:block !important").end()
2788
- .removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded", false)
2847
+ .removeClass("jstree-open").addClass("jstree-closed")
2848
+ .children('.jstree-anchor').attr("aria-expanded", false).end()
2789
2849
  .children(".jstree-children").stop(true, true).slideUp(animation, function () {
2790
2850
  this.style.display = "";
2791
2851
  d.children('.jstree-children').remove();
@@ -2803,7 +2863,7 @@
2803
2863
  */
2804
2864
  toggle_node : function (obj) {
2805
2865
  var t1, t2;
2806
- if($.isArray(obj)) {
2866
+ if($.vakata.is_array(obj)) {
2807
2867
  obj = obj.slice();
2808
2868
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2809
2869
  this.toggle_node(obj[t1]);
@@ -2904,7 +2964,7 @@
2904
2964
  */
2905
2965
  enable_node : function (obj) {
2906
2966
  var t1, t2;
2907
- if($.isArray(obj)) {
2967
+ if($.vakata.is_array(obj)) {
2908
2968
  obj = obj.slice();
2909
2969
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2910
2970
  this.enable_node(obj[t1]);
@@ -2933,7 +2993,7 @@
2933
2993
  */
2934
2994
  disable_node : function (obj) {
2935
2995
  var t1, t2;
2936
- if($.isArray(obj)) {
2996
+ if($.vakata.is_array(obj)) {
2937
2997
  obj = obj.slice();
2938
2998
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2939
2999
  this.disable_node(obj[t1]);
@@ -2972,7 +3032,7 @@
2972
3032
  */
2973
3033
  hide_node : function (obj, skip_redraw) {
2974
3034
  var t1, t2;
2975
- if($.isArray(obj)) {
3035
+ if($.vakata.is_array(obj)) {
2976
3036
  obj = obj.slice();
2977
3037
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2978
3038
  this.hide_node(obj[t1], true);
@@ -3010,7 +3070,7 @@
3010
3070
  */
3011
3071
  show_node : function (obj, skip_redraw) {
3012
3072
  var t1, t2;
3013
- if($.isArray(obj)) {
3073
+ if($.vakata.is_array(obj)) {
3014
3074
  obj = obj.slice();
3015
3075
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3016
3076
  this.show_node(obj[t1], true);
@@ -3117,8 +3177,10 @@
3117
3177
  this.deselect_node(obj, false, e);
3118
3178
  }
3119
3179
  else {
3120
- this.deselect_all(true);
3121
- this.select_node(obj, false, false, e);
3180
+ if (this.settings.core.allow_reselect || !this.is_selected(obj) || this._data.core.selected.length !== 1) {
3181
+ this.deselect_all(true);
3182
+ this.select_node(obj, false, false, e);
3183
+ }
3122
3184
  this._data.core.last_clicked = this.get_node(obj);
3123
3185
  }
3124
3186
  }
@@ -3143,13 +3205,18 @@
3143
3205
  }
3144
3206
  }
3145
3207
  else {
3146
- this.deselect_node(p[i], true, e);
3208
+ if (!e.ctrlKey) {
3209
+ this.deselect_node(p[i], true, e);
3210
+ }
3147
3211
  }
3148
3212
  }
3149
3213
  this.trigger('changed', { 'action' : 'select_node', 'node' : this.get_node(obj), 'selected' : this._data.core.selected, 'event' : e });
3150
3214
  }
3151
3215
  else {
3152
3216
  if(!this.is_selected(obj)) {
3217
+ if (e.ctrlKey) {
3218
+ this._data.core.last_clicked = this.get_node(obj);
3219
+ }
3153
3220
  this.select_node(obj, false, false, e);
3154
3221
  }
3155
3222
  else {
@@ -3222,7 +3289,7 @@
3222
3289
  */
3223
3290
  select_node : function (obj, supress_event, prevent_open, e) {
3224
3291
  var dom, t1, t2, th;
3225
- if($.isArray(obj)) {
3292
+ if($.vakata.is_array(obj)) {
3226
3293
  obj = obj.slice();
3227
3294
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3228
3295
  this.select_node(obj[t1], supress_event, prevent_open, e);
@@ -3241,7 +3308,7 @@
3241
3308
  dom = this._open_to(obj);
3242
3309
  }
3243
3310
  if(dom && dom.length) {
3244
- dom.attr('aria-selected', true).children('.jstree-anchor').addClass('jstree-clicked');
3311
+ dom.children('.jstree-anchor').addClass('jstree-clicked').attr('aria-selected', true);
3245
3312
  }
3246
3313
  /**
3247
3314
  * triggered when an node is selected
@@ -3275,7 +3342,7 @@
3275
3342
  */
3276
3343
  deselect_node : function (obj, supress_event, e) {
3277
3344
  var t1, t2, dom;
3278
- if($.isArray(obj)) {
3345
+ if($.vakata.is_array(obj)) {
3279
3346
  obj = obj.slice();
3280
3347
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3281
3348
  this.deselect_node(obj[t1], supress_event, e);
@@ -3291,7 +3358,7 @@
3291
3358
  obj.state.selected = false;
3292
3359
  this._data.core.selected = $.vakata.array_remove_item(this._data.core.selected, obj.id);
3293
3360
  if(dom.length) {
3294
- dom.attr('aria-selected', false).children('.jstree-anchor').removeClass('jstree-clicked');
3361
+ dom.children('.jstree-anchor').removeClass('jstree-clicked').attr('aria-selected', false);
3295
3362
  }
3296
3363
  /**
3297
3364
  * triggered when an node is deselected
@@ -3347,7 +3414,7 @@
3347
3414
  }
3348
3415
  }
3349
3416
  this._data.core.selected = [];
3350
- this.element.find('.jstree-clicked').removeClass('jstree-clicked').parent().attr('aria-selected', false);
3417
+ this.element.find('.jstree-clicked').removeClass('jstree-clicked').attr('aria-selected', false);
3351
3418
  /**
3352
3419
  * triggered when all nodes are deselected
3353
3420
  * @event
@@ -3380,7 +3447,7 @@
3380
3447
  * @return {Array}
3381
3448
  */
3382
3449
  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();
3450
+ return full ? $.map(this._data.core.selected, function (i) { return this.get_node(i); }.bind(this)) : this._data.core.selected.slice();
3384
3451
  },
3385
3452
  /**
3386
3453
  * get an array of all top level selected nodes (ignoring children of selected nodes)
@@ -3407,7 +3474,7 @@
3407
3474
  tmp.push(i);
3408
3475
  }
3409
3476
  }
3410
- return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
3477
+ return full ? $.map(tmp, function (i) { return this.get_node(i); }.bind(this)) : tmp;
3411
3478
  },
3412
3479
  /**
3413
3480
  * get an array of all bottom level selected nodes (ignoring selected parents)
@@ -3423,7 +3490,7 @@
3423
3490
  obj.push(tmp[i].id);
3424
3491
  }
3425
3492
  }
3426
- return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
3493
+ return full ? $.map(obj, function (i) { return this.get_node(i); }.bind(this)) : obj;
3427
3494
  },
3428
3495
  /**
3429
3496
  * gets the current state of the tree so that it can be restored later with `set_state(state)`. Used internally.
@@ -3483,7 +3550,7 @@
3483
3550
  if(state.core) {
3484
3551
  var res, n, t, _this, i;
3485
3552
  if(state.core.loaded) {
3486
- if(!this.settings.core.loaded_state || !$.isArray(state.core.loaded) || !state.core.loaded.length) {
3553
+ if(!this.settings.core.loaded_state || !$.vakata.is_array(state.core.loaded) || !state.core.loaded.length) {
3487
3554
  delete state.core.loaded;
3488
3555
  this.set_state(state, callback);
3489
3556
  }
@@ -3496,7 +3563,7 @@
3496
3563
  return false;
3497
3564
  }
3498
3565
  if(state.core.open) {
3499
- if(!$.isArray(state.core.open) || !state.core.open.length) {
3566
+ if(!$.vakata.is_array(state.core.open) || !state.core.open.length) {
3500
3567
  delete state.core.open;
3501
3568
  this.set_state(state, callback);
3502
3569
  }
@@ -3570,7 +3637,7 @@
3570
3637
  */
3571
3638
  refresh : function (skip_loading, forget_state) {
3572
3639
  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); }
3640
+ if(forget_state && $.vakata.is_function(forget_state)) { this._data.core.state = forget_state.call(this, this._data.core.state); }
3574
3641
  this._cnt = 0;
3575
3642
  this._model.data = {};
3576
3643
  this._model.data[$.jstree.root] = {
@@ -3587,7 +3654,7 @@
3587
3654
 
3588
3655
  var c = this.get_container_ul()[0].className;
3589
3656
  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>");
3657
+ this.element.html("<"+"ul class='"+c+"' role='group'><"+"li class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='none' id='j"+this._id+"_loading'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' role='treeitem' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
3591
3658
  this.element.attr('aria-activedescendant','j'+this._id+'_loading');
3592
3659
  }
3593
3660
  this.load_node($.jstree.root, function (o, s) {
@@ -3621,7 +3688,7 @@
3621
3688
  to_load.push(obj.id);
3622
3689
  if(obj.state.opened === true) { opened.push(obj.id); }
3623
3690
  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) {
3691
+ this._load_nodes(to_load, function (nodes) {
3625
3692
  this.open_node(opened, false, 0);
3626
3693
  this.select_node(s);
3627
3694
  /**
@@ -3632,7 +3699,7 @@
3632
3699
  * @param {Array} nodes - an array of the IDs of the nodes that were reloaded
3633
3700
  */
3634
3701
  this.trigger('refresh_node', { 'node' : obj, 'nodes' : nodes });
3635
- }, this), false, true);
3702
+ }.bind(this), false, true);
3636
3703
  },
3637
3704
  /**
3638
3705
  * set (change) the ID of a node
@@ -3704,7 +3771,7 @@
3704
3771
  */
3705
3772
  set_text : function (obj, val) {
3706
3773
  var t1, t2;
3707
- if($.isArray(obj)) {
3774
+ if($.vakata.is_array(obj)) {
3708
3775
  obj = obj.slice();
3709
3776
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3710
3777
  this.set_text(obj[t1], val);
@@ -3752,7 +3819,7 @@
3752
3819
  'li_attr' : $.extend(true, {}, obj.li_attr),
3753
3820
  'a_attr' : $.extend(true, {}, obj.a_attr),
3754
3821
  'state' : {},
3755
- 'data' : options && options.no_data ? false : $.extend(true, $.isArray(obj.data)?[]:{}, obj.data)
3822
+ 'data' : options && options.no_data ? false : $.extend(true, $.vakata.is_array(obj.data)?[]:{}, obj.data)
3756
3823
  //( this.get_node(obj, true).length ? this.get_node(obj, true).data() : obj.data ),
3757
3824
  }, i, j;
3758
3825
  if(options && options.flat) {
@@ -3855,7 +3922,7 @@
3855
3922
  break;
3856
3923
  }
3857
3924
  if(pos > par.children.length) { pos = par.children.length; }
3858
- if(!node.id) { node.id = true; }
3925
+ if(node.id === undefined) { node.id = true; }
3859
3926
  if(!this.check("create_node", node, par, pos)) {
3860
3927
  this.settings.core.error.call(this, this._data.core.last_error);
3861
3928
  return false;
@@ -3904,7 +3971,7 @@
3904
3971
  */
3905
3972
  rename_node : function (obj, val) {
3906
3973
  var t1, t2, old;
3907
- if($.isArray(obj)) {
3974
+ if($.vakata.is_array(obj)) {
3908
3975
  obj = obj.slice();
3909
3976
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3910
3977
  this.rename_node(obj[t1], val);
@@ -3939,7 +4006,7 @@
3939
4006
  */
3940
4007
  delete_node : function (obj) {
3941
4008
  var t1, t2, par, pos, tmp, i, j, k, l, c, top, lft;
3942
- if($.isArray(obj)) {
4009
+ if($.vakata.is_array(obj)) {
3943
4010
  obj = obj.slice();
3944
4011
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3945
4012
  this.delete_node(obj[t1]);
@@ -3996,11 +4063,11 @@
3996
4063
  lft = this.element[0].scrollLeft;
3997
4064
  if(par.id === $.jstree.root) {
3998
4065
  if (this._model.data[$.jstree.root].children[0]) {
3999
- this.get_node(this._model.data[$.jstree.root].children[0], true).children('.jstree-anchor').focus();
4066
+ this.get_node(this._model.data[$.jstree.root].children[0], true).children('.jstree-anchor').trigger('focus');
4000
4067
  }
4001
4068
  }
4002
4069
  else {
4003
- this.get_node(par, true).children('.jstree-anchor').focus();
4070
+ this.get_node(par, true).children('.jstree-anchor').trigger('focus');
4004
4071
  }
4005
4072
  this.element[0].scrollTop = top;
4006
4073
  this.element[0].scrollLeft = lft;
@@ -4022,7 +4089,7 @@
4022
4089
  check : function (chk, obj, par, pos, more) {
4023
4090
  obj = obj && obj.id ? obj : this.get_node(obj);
4024
4091
  par = par && par.id ? par : this.get_node(par);
4025
- var tmp = chk.match(/^move_node|copy_node|create_node$/i) ? par : obj,
4092
+ var tmp = chk.match(/^(move_node|copy_node|create_node)$/i) ? par : obj,
4026
4093
  chc = this.settings.core.check_callback;
4027
4094
  if(chk === "move_node" || chk === "copy_node") {
4028
4095
  if((!more || !more.is_multi) && (chk === "move_node" && $.inArray(obj.id, par.children) === pos)) {
@@ -4041,7 +4108,7 @@
4041
4108
  }
4042
4109
  return tmp.functions[chk];
4043
4110
  }
4044
- if(chc === false || ($.isFunction(chc) && chc.call(this, chk, obj, par, pos, more) === false) || (chc && chc[chk] === false)) {
4111
+ if(chc === false || ($.vakata.is_function(chc) && chc.call(this, chk, obj, par, pos, more) === false) || (chc && chc[chk] === false)) {
4045
4112
  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
4113
  return false;
4047
4114
  }
@@ -4077,7 +4144,7 @@
4077
4144
  return this.load_node(par, function () { this.move_node(obj, par, pos, callback, true, false, origin); });
4078
4145
  }
4079
4146
 
4080
- if($.isArray(obj)) {
4147
+ if($.vakata.is_array(obj)) {
4081
4148
  if(obj.length === 1) {
4082
4149
  obj = obj[0];
4083
4150
  }
@@ -4093,7 +4160,7 @@
4093
4160
  return true;
4094
4161
  }
4095
4162
  }
4096
- obj = obj && obj.id ? obj : this.get_node(obj);
4163
+ obj = obj && (obj.id !== undefined) ? obj : this.get_node(obj);
4097
4164
 
4098
4165
  if(!obj || obj.id === $.jstree.root) { return false; }
4099
4166
 
@@ -4250,7 +4317,7 @@
4250
4317
  return this.load_node(par, function () { this.copy_node(obj, par, pos, callback, true, false, origin); });
4251
4318
  }
4252
4319
 
4253
- if($.isArray(obj)) {
4320
+ if($.vakata.is_array(obj)) {
4254
4321
  if(obj.length === 1) {
4255
4322
  obj = obj[0];
4256
4323
  }
@@ -4266,7 +4333,7 @@
4266
4333
  return true;
4267
4334
  }
4268
4335
  }
4269
- obj = obj && obj.id ? obj : this.get_node(obj);
4336
+ obj = obj && (obj.id !== undefined) ? obj : this.get_node(obj);
4270
4337
  if(!obj || obj.id === $.jstree.root) { return false; }
4271
4338
 
4272
4339
  old_par = (obj.parent || $.jstree.root).toString();
@@ -4365,12 +4432,12 @@
4365
4432
  */
4366
4433
  cut : function (obj) {
4367
4434
  if(!obj) { obj = this._data.core.selected.concat(); }
4368
- if(!$.isArray(obj)) { obj = [obj]; }
4435
+ if(!$.vakata.is_array(obj)) { obj = [obj]; }
4369
4436
  if(!obj.length) { return false; }
4370
4437
  var tmp = [], o, t1, t2;
4371
4438
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4372
4439
  o = this.get_node(obj[t1]);
4373
- if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
4440
+ if(o && (o.id || o.id === 0) && o.id !== $.jstree.root) { tmp.push(o); }
4374
4441
  }
4375
4442
  if(!tmp.length) { return false; }
4376
4443
  ccp_node = tmp;
@@ -4392,12 +4459,12 @@
4392
4459
  */
4393
4460
  copy : function (obj) {
4394
4461
  if(!obj) { obj = this._data.core.selected.concat(); }
4395
- if(!$.isArray(obj)) { obj = [obj]; }
4462
+ if(!$.vakata.is_array(obj)) { obj = [obj]; }
4396
4463
  if(!obj.length) { return false; }
4397
4464
  var tmp = [], o, t1, t2;
4398
4465
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4399
4466
  o = this.get_node(obj[t1]);
4400
- if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
4467
+ if(o && (o.id !== undefined) && o.id !== $.jstree.root) { tmp.push(o); }
4401
4468
  }
4402
4469
  if(!tmp.length) { return false; }
4403
4470
  ccp_node = tmp;
@@ -4473,7 +4540,7 @@
4473
4540
  * @name edit(obj [, default_text, callback])
4474
4541
  * @param {mixed} obj
4475
4542
  * @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
4543
+ * @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), a boolean indicating if the user cancelled the edit and the original unescaped value provided by the user. You can also access the node's title using .text
4477
4544
  */
4478
4545
  edit : function (obj, default_text, callback) {
4479
4546
  var rtl, w, a, s, t, h1, h2, fn, tmp, cancel = false;
@@ -4492,8 +4559,8 @@
4492
4559
  rtl = this._data.core.rtl;
4493
4560
  w = this.element.width();
4494
4561
  this._data.core.focused = tmp.id;
4495
- a = obj.children('.jstree-anchor').focus();
4496
- s = $('<span>');
4562
+ a = obj.children('.jstree-anchor').trigger('focus');
4563
+ s = $('<span></span>');
4497
4564
  /*!
4498
4565
  oi = obj.children("i:visible"),
4499
4566
  ai = a.children("i:visible"),
@@ -4501,7 +4568,7 @@
4501
4568
  w2 = ai.width() * ai.length,
4502
4569
  */
4503
4570
  t = default_text;
4504
- h1 = $("<"+"div />", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo(document.body);
4571
+ h1 = $("<"+"div></div>", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo(document.body);
4505
4572
  h2 = $("<"+"input />", {
4506
4573
  "value" : t,
4507
4574
  "class" : "jstree-rename-input",
@@ -4515,58 +4582,60 @@
4515
4582
  "lineHeight" : (this._data.core.li_height) + "px",
4516
4583
  "width" : "150px" // will be set a bit further down
4517
4584
  },
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) {
4585
+ "on" : {
4586
+ "blur" : function (e) {
4556
4587
  e.stopImmediatePropagation();
4557
- }
4558
- if(key === 27 || key === 13) {
4559
4588
  e.preventDefault();
4560
- this.blur();
4589
+ var i = s.children(".jstree-rename-input"),
4590
+ v = i.val(),
4591
+ f = this.settings.core.force_text,
4592
+ nv;
4593
+ if(v === "") { v = t; }
4594
+ h1.remove();
4595
+ s.replaceWith(a);
4596
+ s.remove();
4597
+ t = f ? t : $('<div></div>').append($.parseHTML(t)).html();
4598
+ obj = this.get_node(obj);
4599
+ this.set_text(obj, t);
4600
+ nv = !!this.rename_node(obj, f ? $('<div></div>').text(v).text() : $('<div></div>').append($.parseHTML(v)).html());
4601
+ if(!nv) {
4602
+ this.set_text(obj, t); // move this up? and fix #483
4603
+ }
4604
+ this._data.core.focused = tmp.id;
4605
+ setTimeout(function () {
4606
+ var node = this.get_node(tmp.id, true);
4607
+ if(node.length) {
4608
+ this._data.core.focused = tmp.id;
4609
+ node.children('.jstree-anchor').trigger('focus');
4610
+ }
4611
+ }.bind(this), 0);
4612
+ if(callback) {
4613
+ callback.call(this, tmp, nv, cancel, v);
4614
+ }
4615
+ h2 = null;
4616
+ }.bind(this),
4617
+ "keydown" : function (e) {
4618
+ var key = e.which;
4619
+ if(key === 27) {
4620
+ cancel = true;
4621
+ this.value = t;
4622
+ }
4623
+ if(key === 27 || key === 13 || key === 37 || key === 38 || key === 39 || key === 40 || key === 32) {
4624
+ e.stopImmediatePropagation();
4625
+ }
4626
+ if(key === 27 || key === 13) {
4627
+ e.preventDefault();
4628
+ this.blur();
4629
+ }
4630
+ },
4631
+ "click" : function (e) { e.stopImmediatePropagation(); },
4632
+ "mousedown" : function (e) { e.stopImmediatePropagation(); },
4633
+ "keyup" : function (e) {
4634
+ h2.width(Math.min(h1.text("pW" + this.value).width(),w));
4635
+ },
4636
+ "keypress" : function(e) {
4637
+ if(e.which === 13) { return false; }
4561
4638
  }
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
4639
  }
4571
4640
  });
4572
4641
  fn = {
@@ -4585,7 +4654,7 @@
4585
4654
  h2.css(fn).width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select();
4586
4655
  $(document).one('mousedown.jstree touchstart.jstree dnd_start.vakata', function (e) {
4587
4656
  if (h2 && e.target !== h2) {
4588
- $(h2).blur();
4657
+ $(h2).trigger('blur');
4589
4658
  }
4590
4659
  });
4591
4660
  },
@@ -4789,7 +4858,7 @@
4789
4858
  */
4790
4859
  set_icon : function (obj, icon) {
4791
4860
  var t1, t2, dom, old;
4792
- if($.isArray(obj)) {
4861
+ if($.vakata.is_array(obj)) {
4793
4862
  obj = obj.slice();
4794
4863
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4795
4864
  this.set_icon(obj[t1], icon);
@@ -4838,7 +4907,7 @@
4838
4907
  */
4839
4908
  hide_icon : function (obj) {
4840
4909
  var t1, t2;
4841
- if($.isArray(obj)) {
4910
+ if($.vakata.is_array(obj)) {
4842
4911
  obj = obj.slice();
4843
4912
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4844
4913
  this.hide_icon(obj[t1]);
@@ -4858,7 +4927,7 @@
4858
4927
  */
4859
4928
  show_icon : function (obj) {
4860
4929
  var t1, t2, dom;
4861
- if($.isArray(obj)) {
4930
+ if($.vakata.is_array(obj)) {
4862
4931
  obj = obj.slice();
4863
4932
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4864
4933
  this.show_icon(obj[t1]);
@@ -4884,7 +4953,7 @@
4884
4953
  if(node && node.attributes) {
4885
4954
  $.each(node.attributes, function (i, v) {
4886
4955
  if($.inArray(v.name.toLowerCase(),['style','contenteditable','hasfocus','tabindex']) !== -1) { return; }
4887
- if(v.value !== null && $.trim(v.value) !== '') {
4956
+ if(v.value !== null && $.vakata.trim(v.value) !== '') {
4888
4957
  if(with_values) { attr[v.name] = v.value; }
4889
4958
  else { attr.push(v.name); }
4890
4959
  }
@@ -4928,6 +4997,34 @@
4928
4997
  }
4929
4998
  return d;
4930
4999
  };
5000
+ $.vakata.trim = function (text) {
5001
+ return String.prototype.trim ?
5002
+ String.prototype.trim.call(text.toString()) :
5003
+ text.toString().replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
5004
+ };
5005
+ $.vakata.is_function = function(obj) {
5006
+ return typeof obj === "function" && typeof obj.nodeType !== "number";
5007
+ };
5008
+ $.vakata.is_array = Array.isArray || function (obj) {
5009
+ return Object.prototype.toString.call(obj) === "[object Array]";
5010
+ };
5011
+
5012
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind#polyfill
5013
+ if (!Function.prototype.bind) {
5014
+ Function.prototype.bind = function () {
5015
+ var thatFunc = this, thatArg = arguments[0];
5016
+ var args = Array.prototype.slice.call(arguments, 1);
5017
+ if (typeof thatFunc !== 'function') {
5018
+ // closest thing possible to the ECMAScript 5
5019
+ // internal IsCallable function
5020
+ throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
5021
+ }
5022
+ return function(){
5023
+ var funcArgs = args.concat(Array.prototype.slice.call(arguments));
5024
+ return thatFunc.apply(thatArg, funcArgs);
5025
+ };
5026
+ };
5027
+ }
4931
5028
 
4932
5029
 
4933
5030
  /**
@@ -5061,7 +5158,7 @@
5061
5158
  this.settings.checkbox.cascade = 'up+down+undetermined';
5062
5159
  }
5063
5160
  this.element
5064
- .on("init.jstree", $.proxy(function () {
5161
+ .on("init.jstree", function () {
5065
5162
  this._data.checkbox.visible = this.settings.checkbox.visible;
5066
5163
  if(!this.settings.checkbox.keep_selected_style) {
5067
5164
  this.element.addClass('jstree-checkbox-no-clicked');
@@ -5069,21 +5166,21 @@
5069
5166
  if(this.settings.checkbox.tie_selection) {
5070
5167
  this.element.addClass('jstree-checkbox-selection');
5071
5168
  }
5072
- }, this))
5073
- .on("loading.jstree", $.proxy(function () {
5169
+ }.bind(this))
5170
+ .on("loading.jstree", function () {
5074
5171
  this[ this._data.checkbox.visible ? 'show_checkboxes' : 'hide_checkboxes' ]();
5075
- }, this));
5172
+ }.bind(this));
5076
5173
  if(this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
5077
5174
  this.element
5078
- .on('changed.jstree uncheck_node.jstree check_node.jstree uncheck_all.jstree check_all.jstree move_node.jstree copy_node.jstree redraw.jstree open_node.jstree', $.proxy(function () {
5175
+ .on('changed.jstree uncheck_node.jstree check_node.jstree uncheck_all.jstree check_all.jstree move_node.jstree copy_node.jstree redraw.jstree open_node.jstree', function () {
5079
5176
  // only if undetermined is in setting
5080
5177
  if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
5081
- this._data.checkbox.uto = setTimeout($.proxy(this._undetermined, this), 50);
5082
- }, this));
5178
+ this._data.checkbox.uto = setTimeout(this._undetermined.bind(this), 50);
5179
+ }.bind(this));
5083
5180
  }
5084
5181
  if(!this.settings.checkbox.tie_selection) {
5085
5182
  this.element
5086
- .on('model.jstree', $.proxy(function (e, data) {
5183
+ .on('model.jstree', function (e, data) {
5087
5184
  var m = this._model.data,
5088
5185
  p = m[data.parent],
5089
5186
  dpc = data.nodes,
@@ -5094,11 +5191,11 @@
5094
5191
  this._data.checkbox.selected.push(dpc[i]);
5095
5192
  }
5096
5193
  }
5097
- }, this));
5194
+ }.bind(this));
5098
5195
  }
5099
5196
  if(this.settings.checkbox.cascade.indexOf('up') !== -1 || this.settings.checkbox.cascade.indexOf('down') !== -1) {
5100
5197
  this.element
5101
- .on('model.jstree', $.proxy(function (e, data) {
5198
+ .on('model.jstree', function (e, data) {
5102
5199
  var m = this._model.data,
5103
5200
  p = m[data.parent],
5104
5201
  dpc = data.nodes,
@@ -5146,7 +5243,7 @@
5146
5243
  this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5147
5244
  tmp = this.get_node(p, true);
5148
5245
  if(tmp && tmp.length) {
5149
- tmp.attr('aria-selected', true).children('.jstree-anchor').addClass( t ? 'jstree-clicked' : 'jstree-checked');
5246
+ tmp.children('.jstree-anchor').attr('aria-selected', true).addClass( t ? 'jstree-clicked' : 'jstree-checked');
5150
5247
  }
5151
5248
  }
5152
5249
  else {
@@ -5158,8 +5255,8 @@
5158
5255
  }
5159
5256
 
5160
5257
  this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_unique(this._data[ t ? 'core' : 'checkbox' ].selected);
5161
- }, this))
5162
- .on(this.settings.checkbox.tie_selection ? 'select_node.jstree' : 'check_node.jstree', $.proxy(function (e, data) {
5258
+ }.bind(this))
5259
+ .on(this.settings.checkbox.tie_selection ? 'select_node.jstree' : 'check_node.jstree', function (e, data) {
5163
5260
  var self = this,
5164
5261
  obj = data.node,
5165
5262
  m = this._model.data,
@@ -5199,7 +5296,7 @@
5199
5296
  //this._data[ t ? 'core' : 'checkbox' ].selected.push(par.id);
5200
5297
  tmp = this.get_node(par, true);
5201
5298
  if(tmp && tmp.length) {
5202
- tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5299
+ tmp.children('.jstree-anchor').attr('aria-selected', true).addClass(t ? 'jstree-clicked' : 'jstree-checked');
5203
5300
  }
5204
5301
  }
5205
5302
  else {
@@ -5216,8 +5313,8 @@
5216
5313
  }
5217
5314
  }
5218
5315
  this._data[ t ? 'core' : 'checkbox' ].selected = cur;
5219
- }, this))
5220
- .on(this.settings.checkbox.tie_selection ? 'deselect_all.jstree' : 'uncheck_all.jstree', $.proxy(function (e, data) {
5316
+ }.bind(this))
5317
+ .on(this.settings.checkbox.tie_selection ? 'deselect_all.jstree' : 'uncheck_all.jstree', function (e, data) {
5221
5318
  var obj = this.get_node($.jstree.root),
5222
5319
  m = this._model.data,
5223
5320
  i, j, tmp;
@@ -5227,8 +5324,8 @@
5227
5324
  tmp.original.state.undetermined = false;
5228
5325
  }
5229
5326
  }
5230
- }, this))
5231
- .on(this.settings.checkbox.tie_selection ? 'deselect_node.jstree' : 'uncheck_node.jstree', $.proxy(function (e, data) {
5327
+ }.bind(this))
5328
+ .on(this.settings.checkbox.tie_selection ? 'deselect_node.jstree' : 'uncheck_node.jstree', function (e, data) {
5232
5329
  var self = this,
5233
5330
  obj = data.node,
5234
5331
  dom = this.get_node(obj, true),
@@ -5257,7 +5354,7 @@
5257
5354
  }
5258
5355
  tmp = this.get_node(obj.parents[i], true);
5259
5356
  if(tmp && tmp.length) {
5260
- tmp.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5357
+ tmp.children('.jstree-anchor').attr('aria-selected', false).removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5261
5358
  }
5262
5359
  }
5263
5360
 
@@ -5267,11 +5364,11 @@
5267
5364
  }
5268
5365
 
5269
5366
  this._data[ t ? 'core' : 'checkbox' ].selected = cur;
5270
- }, this));
5367
+ }.bind(this));
5271
5368
  }
5272
5369
  if(this.settings.checkbox.cascade.indexOf('up') !== -1) {
5273
5370
  this.element
5274
- .on('delete_node.jstree', $.proxy(function (e, data) {
5371
+ .on('delete_node.jstree', function (e, data) {
5275
5372
  // apply up (whole handler)
5276
5373
  var p = this.get_node(data.parent),
5277
5374
  m = this._model.data,
@@ -5286,7 +5383,7 @@
5286
5383
  this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5287
5384
  tmp = this.get_node(p, true);
5288
5385
  if(tmp && tmp.length) {
5289
- tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5386
+ tmp.children('.jstree-anchor').attr('aria-selected', true).addClass(t ? 'jstree-clicked' : 'jstree-checked');
5290
5387
  }
5291
5388
  }
5292
5389
  else {
@@ -5294,8 +5391,8 @@
5294
5391
  }
5295
5392
  p = this.get_node(p.parent);
5296
5393
  }
5297
- }, this))
5298
- .on('move_node.jstree', $.proxy(function (e, data) {
5394
+ }.bind(this))
5395
+ .on('move_node.jstree', function (e, data) {
5299
5396
  // apply up (whole handler)
5300
5397
  var is_multi = data.is_multi,
5301
5398
  old_par = data.old_parent,
@@ -5314,7 +5411,7 @@
5314
5411
  this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5315
5412
  tmp = this.get_node(p, true);
5316
5413
  if(tmp && tmp.length) {
5317
- tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5414
+ tmp.children('.jstree-anchor').attr('aria-selected', true).addClass(t ? 'jstree-clicked' : 'jstree-checked');
5318
5415
  }
5319
5416
  }
5320
5417
  else {
@@ -5335,7 +5432,7 @@
5335
5432
  this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5336
5433
  tmp = this.get_node(p, true);
5337
5434
  if(tmp && tmp.length) {
5338
- tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5435
+ tmp.children('.jstree-anchor').attr('aria-selected', true).addClass(t ? 'jstree-clicked' : 'jstree-checked');
5339
5436
  }
5340
5437
  }
5341
5438
  }
@@ -5345,7 +5442,7 @@
5345
5442
  this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_remove_item(this._data[ t ? 'core' : 'checkbox' ].selected, p.id);
5346
5443
  tmp = this.get_node(p, true);
5347
5444
  if(tmp && tmp.length) {
5348
- tmp.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5445
+ tmp.children('.jstree-anchor').attr('aria-selected', false).removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5349
5446
  }
5350
5447
  }
5351
5448
  else {
@@ -5354,7 +5451,7 @@
5354
5451
  }
5355
5452
  p = this.get_node(p.parent);
5356
5453
  }
5357
- }, this));
5454
+ }.bind(this));
5358
5455
  }
5359
5456
  };
5360
5457
  /**
@@ -5465,7 +5562,7 @@
5465
5562
  }
5466
5563
  if(!is_callback && this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
5467
5564
  if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
5468
- this._data.checkbox.uto = setTimeout($.proxy(this._undetermined, this), 50);
5565
+ this._data.checkbox.uto = setTimeout(this._undetermined.bind(this), 50);
5469
5566
  }
5470
5567
  return obj;
5471
5568
  };
@@ -5518,7 +5615,7 @@
5518
5615
  */
5519
5616
  this.disable_checkbox = function (obj) {
5520
5617
  var t1, t2, dom;
5521
- if($.isArray(obj)) {
5618
+ if($.vakata.is_array(obj)) {
5522
5619
  obj = obj.slice();
5523
5620
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5524
5621
  this.disable_checkbox(obj[t1]);
@@ -5554,7 +5651,7 @@
5554
5651
  */
5555
5652
  this.enable_checkbox = function (obj) {
5556
5653
  var t1, t2, dom;
5557
- if($.isArray(obj)) {
5654
+ if($.vakata.is_array(obj)) {
5558
5655
  obj = obj.slice();
5559
5656
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5560
5657
  this.enable_checkbox(obj[t1]);
@@ -5603,11 +5700,34 @@
5603
5700
  }
5604
5701
  this.trigger('activate_node', { 'node' : this.get_node(obj) });
5605
5702
  };
5703
+ this.delete_node = function (obj) {
5704
+ if(this.settings.checkbox.tie_selection || $.vakata.is_array(obj)) {
5705
+ return parent.delete_node.call(this, obj);
5706
+ }
5707
+ var tmp, k, l, c = false;
5708
+ obj = this.get_node(obj);
5709
+ if(!obj || obj.id === $.jstree.root) { return false; }
5710
+ tmp = obj.children_d.concat([]);
5711
+ tmp.push(obj.id);
5712
+ for(k = 0, l = tmp.length; k < l; k++) {
5713
+ if(this._model.data[tmp[k]].state.checked) {
5714
+ c = true;
5715
+ break;
5716
+ }
5717
+ }
5718
+ if (c) {
5719
+ this._data.checkbox.selected = $.vakata.array_filter(this._data.checkbox.selected, function (v) {
5720
+ return $.inArray(v, tmp) === -1;
5721
+ });
5722
+ }
5723
+ return parent.delete_node.call(this, obj);
5724
+ };
5606
5725
 
5607
5726
  /**
5608
5727
  * Cascades checked state to a node and all its descendants. This function does NOT affect hidden and disabled nodes (or their descendants).
5609
5728
  * However if these unaffected nodes are already selected their ids will be included in the returned array.
5610
5729
  * @private
5730
+ * @name _cascade_new_checked_state(id, checkedState)
5611
5731
  * @param {string} id the node ID
5612
5732
  * @param {bool} checkedState should the nodes be checked or not
5613
5733
  * @returns {Array} Array of all node id's (in this tree branch) that are checked.
@@ -5647,7 +5767,7 @@
5647
5767
  //If a node is undetermined then remove selected class
5648
5768
  if (undetermined) {
5649
5769
  node.state[ t ? 'selected' : 'checked' ] = false;
5650
- dom.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5770
+ dom.children('.jstree-anchor').attr('aria-selected', false).removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5651
5771
  }
5652
5772
  //Otherwise, if the checkedState === true (i.e. the node is being checked now) and all of the node's children are checked (if it has any children),
5653
5773
  //check the node and style it correctly.
@@ -5655,11 +5775,11 @@
5655
5775
  node.state[ t ? 'selected' : 'checked' ] = checkedState;
5656
5776
  selectedNodeIds.push(node.id);
5657
5777
 
5658
- dom.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5778
+ dom.children('.jstree-anchor').attr('aria-selected', true).addClass(t ? 'jstree-clicked' : 'jstree-checked');
5659
5779
  }
5660
5780
  else {
5661
5781
  node.state[ t ? 'selected' : 'checked' ] = false;
5662
- dom.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5782
+ dom.children('.jstree-anchor').attr('aria-selected', false).removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5663
5783
  }
5664
5784
  }
5665
5785
  else {
@@ -5702,7 +5822,7 @@
5702
5822
  this.check_node = function (obj, e) {
5703
5823
  if(this.settings.checkbox.tie_selection) { return this.select_node(obj, false, true, e); }
5704
5824
  var dom, t1, t2, th;
5705
- if($.isArray(obj)) {
5825
+ if($.vakata.is_array(obj)) {
5706
5826
  obj = obj.slice();
5707
5827
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5708
5828
  this.check_node(obj[t1], e);
@@ -5742,7 +5862,7 @@
5742
5862
  this.uncheck_node = function (obj, e) {
5743
5863
  if(this.settings.checkbox.tie_selection) { return this.deselect_node(obj, false, e); }
5744
5864
  var t1, t2, dom;
5745
- if($.isArray(obj)) {
5865
+ if($.vakata.is_array(obj)) {
5746
5866
  obj = obj.slice();
5747
5867
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5748
5868
  this.uncheck_node(obj[t1], e);
@@ -5846,7 +5966,7 @@
5846
5966
  */
5847
5967
  this.get_checked = function (full) {
5848
5968
  if(this.settings.checkbox.tie_selection) { return this.get_selected(full); }
5849
- return full ? $.map(this._data.checkbox.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.checkbox.selected.slice();
5969
+ return full ? $.map(this._data.checkbox.selected, function (i) { return this.get_node(i); }.bind(this)) : this._data.checkbox.selected.slice();
5850
5970
  };
5851
5971
  /**
5852
5972
  * get an array of all top level checked nodes (ignoring children of checked nodes) (if tie_selection is on in the settings this function will return the same as get_top_selected)
@@ -5875,7 +5995,7 @@
5875
5995
  tmp.push(i);
5876
5996
  }
5877
5997
  }
5878
- return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
5998
+ return full ? $.map(tmp, function (i) { return this.get_node(i); }.bind(this)) : tmp;
5879
5999
  };
5880
6000
  /**
5881
6001
  * get an array of all bottom level checked nodes (ignoring selected parents) (if tie_selection is on in the settings this function will return the same as get_bottom_selected)
@@ -5893,11 +6013,11 @@
5893
6013
  obj.push(tmp[i].id);
5894
6014
  }
5895
6015
  }
5896
- return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
6016
+ return full ? $.map(obj, function (i) { return this.get_node(i); }.bind(this)) : obj;
5897
6017
  };
5898
6018
  this.load_node = function (obj, callback) {
5899
6019
  var k, l, i, j, c, tmp;
5900
- if(!$.isArray(obj) && !this.settings.checkbox.tie_selection) {
6020
+ if(!$.vakata.is_array(obj) && !this.settings.checkbox.tie_selection) {
5901
6021
  tmp = this.get_node(obj);
5902
6022
  if(tmp && tmp.state.loaded) {
5903
6023
  for(k = 0, l = tmp.children_d.length; k < l; k++) {
@@ -6125,10 +6245,10 @@
6125
6245
 
6126
6246
  var last_ts = 0, cto = null, ex, ey;
6127
6247
  this.element
6128
- .on("init.jstree loading.jstree ready.jstree", $.proxy(function () {
6248
+ .on("init.jstree loading.jstree ready.jstree", function () {
6129
6249
  this.get_container_ul().addClass('jstree-contextmenu');
6130
- }, this))
6131
- .on("contextmenu.jstree", ".jstree-anchor", $.proxy(function (e, data) {
6250
+ }.bind(this))
6251
+ .on("contextmenu.jstree", ".jstree-anchor", function (e, data) {
6132
6252
  if (e.target.tagName.toLowerCase() === 'input') {
6133
6253
  return;
6134
6254
  }
@@ -6143,13 +6263,13 @@
6143
6263
  if(!this.is_loading(e.currentTarget)) {
6144
6264
  this.show_contextmenu(e.currentTarget, e.pageX, e.pageY, e);
6145
6265
  }
6146
- }, this))
6147
- .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
6266
+ }.bind(this))
6267
+ .on("click.jstree", ".jstree-anchor", function (e) {
6148
6268
  if(this._data.contextmenu.visible && (!last_ts || (+new Date()) - last_ts > 250)) { // work around safari & macOS ctrl+click
6149
6269
  $.vakata.context.hide();
6150
6270
  }
6151
6271
  last_ts = 0;
6152
- }, this))
6272
+ }.bind(this))
6153
6273
  .on("touchstart.jstree", ".jstree-anchor", function (e) {
6154
6274
  if(!e.originalEvent || !e.originalEvent.changedTouches || !e.originalEvent.changedTouches[0]) {
6155
6275
  return;
@@ -6193,15 +6313,16 @@
6193
6313
  });
6194
6314
  }
6195
6315
  */
6196
- $(document).on("context_hide.vakata.jstree", $.proxy(function (e, data) {
6316
+ $(document).on("context_hide.vakata.jstree", function (e, data) {
6197
6317
  this._data.contextmenu.visible = false;
6198
6318
  $(data.reference).removeClass('jstree-context');
6199
- }, this));
6319
+ }.bind(this));
6200
6320
  };
6201
6321
  this.teardown = function () {
6202
6322
  if(this._data.contextmenu.visible) {
6203
6323
  $.vakata.context.hide();
6204
6324
  }
6325
+ $(document).off("context_hide.vakata.jstree");
6205
6326
  parent.teardown.call(this);
6206
6327
  };
6207
6328
 
@@ -6233,10 +6354,10 @@
6233
6354
  }
6234
6355
 
6235
6356
  i = s.items;
6236
- if($.isFunction(i)) {
6237
- i = i.call(this, obj, $.proxy(function (i) {
6357
+ if($.vakata.is_function(i)) {
6358
+ i = i.call(this, obj, function (i) {
6238
6359
  this._show_contextmenu(obj, x, y, i);
6239
- }, this));
6360
+ }.bind(this));
6240
6361
  }
6241
6362
  if($.isPlainObject(i)) {
6242
6363
  this._show_contextmenu(obj, x, y, i);
@@ -6256,11 +6377,11 @@
6256
6377
  this._show_contextmenu = function (obj, x, y, i) {
6257
6378
  var d = this.get_node(obj, true),
6258
6379
  a = d.children(".jstree-anchor");
6259
- $(document).one("context_show.vakata.jstree", $.proxy(function (e, data) {
6380
+ $(document).one("context_show.vakata.jstree", function (e, data) {
6260
6381
  var cls = 'jstree-contextmenu jstree-' + this.get_theme() + '-contextmenu';
6261
6382
  $(data.element).addClass(cls);
6262
6383
  a.addClass('jstree-context');
6263
- }, this));
6384
+ }.bind(this));
6264
6385
  this._data.contextmenu.visible = true;
6265
6386
  $.vakata.context.show(a, { 'x' : x, 'y' : y }, i);
6266
6387
  /**
@@ -6306,7 +6427,7 @@
6306
6427
  },
6307
6428
  _execute : function (i) {
6308
6429
  i = vakata_context.items[i];
6309
- return i && (!i._disabled || ($.isFunction(i._disabled) && !i._disabled({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }))) && i.action ? i.action.call(null, {
6430
+ return i && (!i._disabled || ($.vakata.is_function(i._disabled) && !i._disabled({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }))) && i.action ? i.action.call(null, {
6310
6431
  "item" : i,
6311
6432
  "reference" : vakata_context.reference,
6312
6433
  "element" : vakata_context.element,
@@ -6331,10 +6452,10 @@
6331
6452
  if(!val) { return true; }
6332
6453
  vakata_context.items.push(val);
6333
6454
  if(!sep && val.separator_before) {
6334
- str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
6455
+ str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'class="vakata-context-no-icons"') + ">&#160;<"+"/a><"+"/li>";
6335
6456
  }
6336
6457
  sep = false;
6337
- str += "<"+"li class='" + (val._class || "") + (val._disabled === true || ($.isFunction(val._disabled) && val._disabled({ "item" : val, "reference" : vakata_context.reference, "element" : vakata_context.element })) ? " vakata-contextmenu-disabled " : "") + "' "+(val.shortcut?" data-shortcut='"+val.shortcut+"' ":'')+">";
6458
+ str += "<"+"li class='" + (val._class || "") + (val._disabled === true || ($.vakata.is_function(val._disabled) && val._disabled({ "item" : val, "reference" : vakata_context.reference, "element" : vakata_context.element })) ? " vakata-contextmenu-disabled " : "") + "' "+(val.shortcut?" data-shortcut='"+val.shortcut+"' ":'')+">";
6338
6459
  str += "<"+"a href='#' rel='" + (vakata_context.items.length - 1) + "' " + (val.title ? "title='" + val.title + "'" : "") + ">";
6339
6460
  if($.vakata.context.settings.icons) {
6340
6461
  str += "<"+"i ";
@@ -6344,14 +6465,14 @@
6344
6465
  }
6345
6466
  str += "><"+"/i><"+"span class='vakata-contextmenu-sep'>&#160;<"+"/span>";
6346
6467
  }
6347
- str += ($.isFunction(val.label) ? val.label({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }) : val.label) + (val.shortcut?' <span class="vakata-contextmenu-shortcut vakata-contextmenu-shortcut-'+val.shortcut+'">'+ (val.shortcut_label || '') +'</span>':'') + "<"+"/a>";
6468
+ str += ($.vakata.is_function(val.label) ? val.label({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }) : val.label) + (val.shortcut?' <span class="vakata-contextmenu-shortcut vakata-contextmenu-shortcut-'+val.shortcut+'">'+ (val.shortcut_label || '') +'</span>':'') + "<"+"/a>";
6348
6469
  if(val.submenu) {
6349
6470
  tmp = $.vakata.context._parse(val.submenu, true);
6350
6471
  if(tmp) { str += tmp; }
6351
6472
  }
6352
6473
  str += "<"+"/li>";
6353
6474
  if(val.separator_after) {
6354
- str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
6475
+ str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'class="vakata-context-no-icons"') + ">&#160;<"+"/a><"+"/li>";
6355
6476
  sep = true;
6356
6477
  }
6357
6478
  });
@@ -6459,7 +6580,7 @@
6459
6580
  vakata_context.element
6460
6581
  .css({ "left" : x, "top" : y })
6461
6582
  .show()
6462
- .find('a').first().focus().parent().addClass("vakata-context-hover");
6583
+ .find('a').first().trigger('focus').parent().addClass("vakata-context-hover");
6463
6584
  vakata_context.is_visible = true;
6464
6585
  /**
6465
6586
  * triggered on the document when the contextmenu is shown
@@ -6475,7 +6596,7 @@
6475
6596
  },
6476
6597
  hide : function () {
6477
6598
  if(vakata_context.is_visible) {
6478
- vakata_context.element.hide().find("ul").hide().end().find(':focus').blur().end().detach();
6599
+ vakata_context.element.hide().find("ul").hide().end().find(':focus').trigger('blur').end().detach();
6479
6600
  vakata_context.is_visible = false;
6480
6601
  /**
6481
6602
  * triggered on the document when the contextmenu is hidden
@@ -6531,7 +6652,7 @@
6531
6652
  e.preventDefault();
6532
6653
  //})
6533
6654
  //.on("mouseup", "a", function (e) {
6534
- if(!$(this).blur().parent().hasClass("vakata-context-disabled") && $.vakata.context._execute($(this).attr("rel")) !== false) {
6655
+ if(!$(this).trigger('blur').parent().hasClass("vakata-context-disabled") && $.vakata.context._execute($(this).attr("rel")) !== false) {
6535
6656
  $.vakata.context.hide();
6536
6657
  }
6537
6658
  })
@@ -6546,7 +6667,7 @@
6546
6667
  break;
6547
6668
  case 37:
6548
6669
  if(vakata_context.is_visible) {
6549
- vakata_context.element.find(".vakata-context-hover").last().closest("li").first().find("ul").hide().find(".vakata-context-hover").removeClass("vakata-context-hover").end().end().children('a').focus();
6670
+ vakata_context.element.find(".vakata-context-hover").last().closest("li").first().find("ul").hide().find(".vakata-context-hover").removeClass("vakata-context-hover").end().end().children('a').trigger('focus');
6550
6671
  e.stopImmediatePropagation();
6551
6672
  e.preventDefault();
6552
6673
  }
@@ -6555,14 +6676,14 @@
6555
6676
  if(vakata_context.is_visible) {
6556
6677
  o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").prevAll("li:not(.vakata-context-separator)").first();
6557
6678
  if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").last(); }
6558
- o.addClass("vakata-context-hover").children('a').focus();
6679
+ o.addClass("vakata-context-hover").children('a').trigger('focus');
6559
6680
  e.stopImmediatePropagation();
6560
6681
  e.preventDefault();
6561
6682
  }
6562
6683
  break;
6563
6684
  case 39:
6564
6685
  if(vakata_context.is_visible) {
6565
- vakata_context.element.find(".vakata-context-hover").last().children("ul").show().children("li:not(.vakata-context-separator)").removeClass("vakata-context-hover").first().addClass("vakata-context-hover").children('a').focus();
6686
+ vakata_context.element.find(".vakata-context-hover").last().children("ul").show().children("li:not(.vakata-context-separator)").removeClass("vakata-context-hover").first().addClass("vakata-context-hover").children('a').trigger('focus');
6566
6687
  e.stopImmediatePropagation();
6567
6688
  e.preventDefault();
6568
6689
  }
@@ -6571,7 +6692,7 @@
6571
6692
  if(vakata_context.is_visible) {
6572
6693
  o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").nextAll("li:not(.vakata-context-separator)").first();
6573
6694
  if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").first(); }
6574
- o.addClass("vakata-context-hover").children('a').focus();
6695
+ o.addClass("vakata-context-hover").children('a').trigger('focus');
6575
6696
  e.stopImmediatePropagation();
6576
6697
  e.preventDefault();
6577
6698
  }
@@ -6589,7 +6710,7 @@
6589
6710
  e.preventDefault();
6590
6711
  var a = vakata_context.element.find('.vakata-contextmenu-shortcut-' + e.which).parent();
6591
6712
  if(a.parent().not('.vakata-context-disabled')) {
6592
- a.click();
6713
+ a.trigger('click');
6593
6714
  }
6594
6715
  });
6595
6716
 
@@ -6690,7 +6811,13 @@
6690
6811
  * @name $.jstree.defaults.dnd.use_html5
6691
6812
  * @plugin dnd
6692
6813
  */
6693
- use_html5: false
6814
+ use_html5: false,
6815
+ /**
6816
+ * controls whether items can be dropped anywhere on the tree.
6817
+ * @name $.jstree.defaults.dnd.blank_space_drop
6818
+ * @plugin dnd
6819
+ */
6820
+ blank_space_drop: false
6694
6821
  };
6695
6822
  var drg, elm;
6696
6823
  // TODO: now check works by checking for each node individually, how about max_children, unique, etc?
@@ -6703,7 +6830,7 @@
6703
6830
  parent.bind.call(this);
6704
6831
 
6705
6832
  this.element
6706
- .on(this.settings.dnd.use_html5 ? 'dragstart.jstree' : 'mousedown.jstree touchstart.jstree', this.settings.dnd.large_drag_target ? '.jstree-node' : '.jstree-anchor', $.proxy(function (e) {
6833
+ .on(this.settings.dnd.use_html5 ? 'dragstart.jstree' : 'mousedown.jstree touchstart.jstree', this.settings.dnd.large_drag_target ? '.jstree-node' : '.jstree-anchor', function (e) {
6707
6834
  if(this.settings.dnd.large_drag_target && $(e.target).closest('.jstree-node')[0] !== e.currentTarget) {
6708
6835
  return true;
6709
6836
  }
@@ -6716,8 +6843,8 @@
6716
6843
  if(this.settings.core.force_text) {
6717
6844
  txt = $.vakata.html.escape(txt);
6718
6845
  }
6719
- if(obj && obj.id && obj.id !== $.jstree.root && (e.which === 1 || e.type === "touchstart" || e.type === "dragstart") &&
6720
- (this.settings.dnd.is_draggable === true || ($.isFunction(this.settings.dnd.is_draggable) && this.settings.dnd.is_draggable.call(this, (mlt > 1 ? this.get_top_selected(true) : [obj]), e)))
6846
+ if(obj && (obj.id || obj.id === 0) && obj.id !== $.jstree.root && (e.which === 1 || e.type === "touchstart" || e.type === "dragstart") &&
6847
+ (this.settings.dnd.is_draggable === true || ($.vakata.is_function(this.settings.dnd.is_draggable) && this.settings.dnd.is_draggable.call(this, (mlt > 1 ? this.get_top_selected(true) : [obj]), e)))
6721
6848
  ) {
6722
6849
  drg = { 'jstree' : true, 'origin' : this, 'obj' : this.get_node(obj,true), 'nodes' : mlt > 1 ? this.get_top_selected() : [obj.id] };
6723
6850
  elm = e.currentTarget;
@@ -6725,10 +6852,10 @@
6725
6852
  $.vakata.dnd._trigger('start', e, { 'helper': $(), 'element': elm, 'data': drg });
6726
6853
  } else {
6727
6854
  this.element.trigger('mousedown.jstree');
6728
- return $.vakata.dnd.start(e, drg, '<div id="jstree-dnd" class="jstree-' + this.get_theme() + ' jstree-' + this.get_theme() + '-' + this.get_theme_variant() + ' ' + ( this.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ) + '"><i class="jstree-icon jstree-er"></i>' + txt + '<ins class="jstree-copy" style="display:none;">+</ins></div>');
6855
+ return $.vakata.dnd.start(e, drg, '<div id="jstree-dnd" class="jstree-' + this.get_theme() + ' jstree-' + this.get_theme() + '-' + this.get_theme_variant() + ' ' + ( this.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ) + '"><i class="jstree-icon jstree-er"></i>' + txt + '<ins class="jstree-copy">+</ins></div>');
6729
6856
  }
6730
6857
  }
6731
- }, this));
6858
+ }.bind(this));
6732
6859
  if (this.settings.dnd.use_html5) {
6733
6860
  this.element
6734
6861
  .on('dragover.jstree', function (e) {
@@ -6741,11 +6868,11 @@
6741
6868
  // $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
6742
6869
  // return false;
6743
6870
  // }, this))
6744
- .on('drop.jstree', $.proxy(function (e) {
6871
+ .on('drop.jstree', function (e) {
6745
6872
  e.preventDefault();
6746
6873
  $.vakata.dnd._trigger('stop', e, { 'helper': $(), 'element': elm, 'data': drg });
6747
6874
  return false;
6748
- }, this));
6875
+ }.bind(this));
6749
6876
  }
6750
6877
  };
6751
6878
  this.redraw_node = function(obj, deep, callback, force_render) {
@@ -6816,7 +6943,7 @@
6816
6943
  ref = false,
6817
6944
  off = false,
6818
6945
  rel = false,
6819
- tmp, l, t, h, p, i, o, ok, t1, t2, op, ps, pr, ip, tm, is_copy, pn;
6946
+ tmp, l, t, h, p, i, o, ok, t1, t2, op, ps, pr, ip, tm, is_copy, pn, c;
6820
6947
  // if we are over an instance
6821
6948
  if(ins && ins._data && ins._data.dnd) {
6822
6949
  marker.attr('class', 'jstree-' + ins.get_theme() + ( ins.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ));
@@ -6827,7 +6954,7 @@
6827
6954
 
6828
6955
  // if are hovering the container itself add a new root node
6829
6956
  //console.log(data.event);
6830
- if( (data.event.target === ins.element[0] || data.event.target === ins.get_container_ul()[0]) && ins.get_container_ul().children().length === 0) {
6957
+ if( (data.event.target === ins.element[0] || data.event.target === ins.get_container_ul()[0]) && (ins.get_container_ul().children().length === 0 || ins.settings.dnd.blank_space_drop)) {
6831
6958
  ok = true;
6832
6959
  for(t1 = 0, t2 = data.data.nodes.length; t1 < t2; t1++) {
6833
6960
  ok = ok && ins.check( (data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey)) ) ? "copy_node" : "move_node"), (data.data.origin && data.data.origin !== ins ? data.data.origin.get_node(data.data.nodes[t1]) : data.data.nodes[t1]), $.jstree.root, 'last', { 'dnd' : true, 'ref' : ins.get_node($.jstree.root), 'pos' : 'i', 'origin' : data.data.origin, 'is_multi' : (data.data.origin && data.data.origin !== ins), 'is_foreign' : (!data.data.origin) });
@@ -6846,6 +6973,7 @@
6846
6973
  else {
6847
6974
  // if we are hovering a tree node
6848
6975
  ref = ins.settings.dnd.large_drop_target ? $(data.event.target).closest('.jstree-node').children('.jstree-anchor') : $(data.event.target).closest('.jstree-anchor');
6976
+
6849
6977
  if(ref && ref.length && ref.parent().is('.jstree-closed, .jstree-open, .jstree-leaf')) {
6850
6978
  off = ref.offset();
6851
6979
  rel = (data.event.pageY !== undefined ? data.event.pageY : data.event.originalEvent.pageY) - off.top;
@@ -6866,6 +6994,7 @@
6866
6994
  t = off.top;
6867
6995
  p = ins.get_parent(ref);
6868
6996
  i = ref.parent().index();
6997
+ c = 'jstree-below';
6869
6998
  break;
6870
6999
  case 'i':
6871
7000
  ip = ins.settings.dnd.inside_pos;
@@ -6874,12 +7003,14 @@
6874
7003
  t = off.top + h / 2 + 1;
6875
7004
  p = tm.id;
6876
7005
  i = ip === 'first' ? 0 : (ip === 'last' ? tm.children.length : Math.min(ip, tm.children.length));
7006
+ c = 'jstree-inside';
6877
7007
  break;
6878
7008
  case 'a':
6879
7009
  l = off.left - 6;
6880
7010
  t = off.top + h;
6881
7011
  p = ins.get_parent(ref);
6882
7012
  i = ref.parent().index() + 1;
7013
+ c = 'jstree-above';
6883
7014
  break;
6884
7015
  }
6885
7016
  ok = true;
@@ -6912,6 +7043,7 @@
6912
7043
  }
6913
7044
  lastmv = { 'ins' : ins, 'par' : p, 'pos' : v === 'i' && ip === 'last' && i === 0 && !ins.is_loaded(tm) ? 'last' : i };
6914
7045
  marker.css({ 'left' : l + 'px', 'top' : t + 'px' }).show();
7046
+ marker.removeClass('jstree-above jstree-inside jstree-below').addClass(c);
6915
7047
  data.helper.find('.jstree-icon').first().removeClass('jstree-er').addClass('jstree-ok');
6916
7048
  if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
6917
7049
  data.event.originalEvent.dataTransfer.dropEffect = is_copy ? 'copy' : 'move';
@@ -6990,7 +7122,7 @@
6990
7122
  // helpers
6991
7123
  (function ($) {
6992
7124
  $.vakata.html = {
6993
- div : $('<div />'),
7125
+ div : $('<div></div>'),
6994
7126
  escape : function (str) {
6995
7127
  return $.vakata.html.div.text(str).html();
6996
7128
  },
@@ -7057,6 +7189,7 @@
7057
7189
  scroll_i: false,
7058
7190
  is_touch: false
7059
7191
  };
7192
+ elm = null;
7060
7193
  $(document).off("mousemove.vakata.jstree touchmove.vakata.jstree", $.vakata.dnd.drag);
7061
7194
  $(document).off("mouseup.vakata.jstree touchend.vakata.jstree", $.vakata.dnd.stop);
7062
7195
  },
@@ -7171,7 +7304,7 @@
7171
7304
  vakata_dnd.scroll_e = false;
7172
7305
  $($(e.target).parentsUntil("body").addBack().get().reverse())
7173
7306
  .filter(function () {
7174
- return (/^auto|scroll$/).test($(this).css("overflow")) &&
7307
+ return this.ownerDocument && (/^auto|scroll$/).test($(this).css("overflow")) &&
7175
7308
  (this.scrollHeight > this.offsetHeight || this.scrollWidth > this.offsetWidth);
7176
7309
  })
7177
7310
  .each(function () {
@@ -7252,7 +7385,7 @@
7252
7385
  }
7253
7386
  else {
7254
7387
  if(e.type === "touchend" && e.target === vakata_dnd.target) {
7255
- var to = setTimeout(function () { $(e.target).click(); }, 100);
7388
+ var to = setTimeout(function () { $(e.target).trigger('click'); }, 100);
7256
7389
  $(e.target).one('click', function() { if(to) { clearTimeout(to); } });
7257
7390
  }
7258
7391
  }
@@ -7297,8 +7430,7 @@
7297
7430
  parent.init.call(this, el, options);
7298
7431
  };
7299
7432
  this._load_nodes = function (nodes, callback, is_callback, force_reload) {
7300
- var s = this.settings.massload,
7301
- nodesString = JSON.stringify(nodes),
7433
+ var s = this.settings.massload,
7302
7434
  toLoad = [],
7303
7435
  m = this._model.data,
7304
7436
  i, j, dom;
@@ -7314,8 +7446,8 @@
7314
7446
  }
7315
7447
  this._data.massload = {};
7316
7448
  if (toLoad.length) {
7317
- if($.isFunction(s)) {
7318
- return s.call(this, toLoad, $.proxy(function (data) {
7449
+ if($.vakata.is_function(s)) {
7450
+ return s.call(this, toLoad, function (data) {
7319
7451
  var i, j;
7320
7452
  if(data) {
7321
7453
  for(i in data) {
@@ -7331,18 +7463,18 @@
7331
7463
  }
7332
7464
  }
7333
7465
  parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
7334
- }, this));
7466
+ }.bind(this));
7335
7467
  }
7336
7468
  if(typeof s === 'object' && s && s.url) {
7337
7469
  s = $.extend(true, {}, s);
7338
- if($.isFunction(s.url)) {
7470
+ if($.vakata.is_function(s.url)) {
7339
7471
  s.url = s.url.call(this, toLoad);
7340
7472
  }
7341
- if($.isFunction(s.data)) {
7473
+ if($.vakata.is_function(s.data)) {
7342
7474
  s.data = s.data.call(this, toLoad);
7343
7475
  }
7344
7476
  return $.ajax(s)
7345
- .done($.proxy(function (data,t,x) {
7477
+ .done(function (data,t,x) {
7346
7478
  var i, j;
7347
7479
  if(data) {
7348
7480
  for(i in data) {
@@ -7358,10 +7490,10 @@
7358
7490
  }
7359
7491
  }
7360
7492
  parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
7361
- }, this))
7362
- .fail($.proxy(function (f) {
7493
+ }.bind(this))
7494
+ .fail(function (f) {
7363
7495
  parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
7364
- }, this));
7496
+ }.bind(this));
7365
7497
  }
7366
7498
  }
7367
7499
  }
@@ -7387,6 +7519,7 @@
7387
7519
  };
7388
7520
  };
7389
7521
 
7522
+
7390
7523
  /**
7391
7524
  * ### Search plugin
7392
7525
  *
@@ -7468,7 +7601,7 @@
7468
7601
  this._data.search.hdn = [];
7469
7602
 
7470
7603
  this.element
7471
- .on("search.jstree", $.proxy(function (e, data) {
7604
+ .on("search.jstree", function (e, data) {
7472
7605
  if(this._data.search.som && data.res.length) {
7473
7606
  var m = this._model.data, i, j, p = [], k, l;
7474
7607
  for(i = 0, j = data.res.length; i < j; i++) {
@@ -7489,13 +7622,13 @@
7489
7622
  this.show_node(p, true);
7490
7623
  this.redraw(true);
7491
7624
  }
7492
- }, this))
7493
- .on("clear_search.jstree", $.proxy(function (e, data) {
7625
+ }.bind(this))
7626
+ .on("clear_search.jstree", function (e, data) {
7494
7627
  if(this._data.search.som && data.res.length) {
7495
7628
  this.show_node(this._data.search.hdn, true);
7496
7629
  this.redraw(true);
7497
7630
  }
7498
- }, this));
7631
+ }.bind(this));
7499
7632
  };
7500
7633
  /**
7501
7634
  * used to search the tree nodes for a given string
@@ -7509,11 +7642,11 @@
7509
7642
  * @trigger search.jstree
7510
7643
  */
7511
7644
  this.search = function (str, skip_async, show_only_matches, inside, append, show_only_matches_children) {
7512
- if(str === false || $.trim(str.toString()) === "") {
7645
+ if(str === false || $.vakata.trim(str.toString()) === "") {
7513
7646
  return this.clear_search();
7514
7647
  }
7515
7648
  inside = this.get_node(inside);
7516
- inside = inside && inside.id ? inside.id : null;
7649
+ inside = inside && (inside.id || inside.id === 0) ? inside.id : null;
7517
7650
  str = str.toString();
7518
7651
  var s = this.settings.search,
7519
7652
  a = s.ajax ? s.ajax : false,
@@ -7531,13 +7664,13 @@
7531
7664
  show_only_matches_children = s.show_only_matches_children;
7532
7665
  }
7533
7666
  if(!skip_async && a !== false) {
7534
- if($.isFunction(a)) {
7535
- return a.call(this, str, $.proxy(function (d) {
7667
+ if($.vakata.is_function(a)) {
7668
+ return a.call(this, str, function (d) {
7536
7669
  if(d && d.d) { d = d.d; }
7537
- this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
7670
+ this._load_nodes(!$.vakata.is_array(d) ? [] : $.vakata.array_unique(d), function () {
7538
7671
  this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
7539
7672
  });
7540
- }, this), inside);
7673
+ }.bind(this), inside);
7541
7674
  }
7542
7675
  else {
7543
7676
  a = $.extend({}, a);
@@ -7550,16 +7683,16 @@
7550
7683
  this._data.search.lastRequest.abort();
7551
7684
  }
7552
7685
  this._data.search.lastRequest = $.ajax(a)
7553
- .fail($.proxy(function () {
7686
+ .fail(function () {
7554
7687
  this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'search', 'id' : 'search_01', 'reason' : 'Could not load search parents', 'data' : JSON.stringify(a) };
7555
7688
  this.settings.core.error.call(this, this._data.core.last_error);
7556
- }, this))
7557
- .done($.proxy(function (d) {
7689
+ }.bind(this))
7690
+ .done(function (d) {
7558
7691
  if(d && d.d) { d = d.d; }
7559
- this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
7692
+ this._load_nodes(!$.vakata.is_array(d) ? [] : $.vakata.array_unique(d), function () {
7560
7693
  this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
7561
7694
  });
7562
- }, this));
7695
+ }.bind(this));
7563
7696
  return this._data.search.lastRequest;
7564
7697
  }
7565
7698
  }
@@ -7701,7 +7834,7 @@
7701
7834
  };
7702
7835
  }
7703
7836
  search = function (text) {
7704
- text = options.caseSensitive ? text : text.toLowerCase();
7837
+ text = options.caseSensitive ? text.toString() : text.toString().toLowerCase();
7705
7838
  if(pattern === text || text.indexOf(pattern) !== -1) {
7706
7839
  return {
7707
7840
  isMatch: true,
@@ -7813,17 +7946,17 @@
7813
7946
  this.bind = function () {
7814
7947
  parent.bind.call(this);
7815
7948
  this.element
7816
- .on("model.jstree", $.proxy(function (e, data) {
7949
+ .on("model.jstree", function (e, data) {
7817
7950
  this.sort(data.parent, true);
7818
- }, this))
7819
- .on("rename_node.jstree create_node.jstree", $.proxy(function (e, data) {
7951
+ }.bind(this))
7952
+ .on("rename_node.jstree create_node.jstree", function (e, data) {
7820
7953
  this.sort(data.parent || data.node.parent, false);
7821
7954
  this.redraw_node(data.parent || data.node.parent, true);
7822
- }, this))
7823
- .on("move_node.jstree copy_node.jstree", $.proxy(function (e, data) {
7955
+ }.bind(this))
7956
+ .on("move_node.jstree copy_node.jstree", function (e, data) {
7824
7957
  this.sort(data.parent, false);
7825
7958
  this.redraw_node(data.parent, true);
7826
- }, this));
7959
+ }.bind(this));
7827
7960
  };
7828
7961
  /**
7829
7962
  * used to sort a node's children
@@ -7838,7 +7971,7 @@
7838
7971
  var i, j;
7839
7972
  obj = this.get_node(obj);
7840
7973
  if(obj && obj.children && obj.children.length) {
7841
- obj.children.sort($.proxy(this.settings.sort, this));
7974
+ obj.children.sort(this.settings.sort.bind(this));
7842
7975
  if(deep) {
7843
7976
  for(i = 0, j = obj.children_d.length; i < j; i++) {
7844
7977
  this.sort(obj.children_d[i], false);
@@ -7898,11 +8031,11 @@
7898
8031
  $.jstree.plugins.state = function (options, parent) {
7899
8032
  this.bind = function () {
7900
8033
  parent.bind.call(this);
7901
- var bind = $.proxy(function () {
7902
- this.element.on(this.settings.state.events, $.proxy(function () {
8034
+ var bind = function () {
8035
+ this.element.on(this.settings.state.events, function () {
7903
8036
  if(to) { clearTimeout(to); }
7904
- to = setTimeout($.proxy(function () { this.save_state(); }, this), 100);
7905
- }, this));
8037
+ to = setTimeout(function () { this.save_state(); }.bind(this), 100);
8038
+ }.bind(this));
7906
8039
  /**
7907
8040
  * triggered when the state plugin is finished restoring the state (and immediately after ready if there is no state to restore).
7908
8041
  * @event
@@ -7910,12 +8043,12 @@
7910
8043
  * @plugin state
7911
8044
  */
7912
8045
  this.trigger('state_ready');
7913
- }, this);
8046
+ }.bind(this);
7914
8047
  this.element
7915
- .on("ready.jstree", $.proxy(function (e, data) {
8048
+ .on("ready.jstree", function (e, data) {
7916
8049
  this.element.one("restore_state.jstree", bind);
7917
8050
  if(!this.restore_state()) { bind(); }
7918
- }, this));
8051
+ }.bind(this));
7919
8052
  };
7920
8053
  /**
7921
8054
  * save the state
@@ -7940,7 +8073,7 @@
7940
8073
  if(!!k) { try { k = JSON.parse(k); } catch(ex) { return false; } }
7941
8074
  if(!!k && k.ttl && k.sec && +(new Date()) - k.sec > k.ttl) { return false; }
7942
8075
  if(!!k && k.state) { k = k.state; }
7943
- if(!!k && $.isFunction(this.settings.state.filter)) { k = this.settings.state.filter.call(this, k); }
8076
+ if(!!k && $.vakata.is_function(this.settings.state.filter)) { k = this.settings.state.filter.call(this, k); }
7944
8077
  if(!!k) {
7945
8078
  if (!this.settings.state.preserve_loaded) {
7946
8079
  delete k.core.loaded;
@@ -8025,7 +8158,7 @@
8025
8158
  };
8026
8159
  this.bind = function () {
8027
8160
  this.element
8028
- .on('model.jstree', $.proxy(function (e, data) {
8161
+ .on('model.jstree', function (e, data) {
8029
8162
  var m = this._model.data,
8030
8163
  dpc = data.nodes,
8031
8164
  t = this.settings.types,
@@ -8077,7 +8210,7 @@
8077
8210
  }
8078
8211
  }
8079
8212
  m[$.jstree.root].type = $.jstree.root;
8080
- }, this));
8213
+ }.bind(this));
8081
8214
  parent.bind.call(this);
8082
8215
  };
8083
8216
  this.get_json = function (obj, options, flat) {
@@ -8086,9 +8219,9 @@
8086
8219
  opt = options ? $.extend(true, {}, options, {no_id:false}) : {},
8087
8220
  tmp = parent.get_json.call(this, obj, opt, flat);
8088
8221
  if(tmp === false) { return false; }
8089
- if($.isArray(tmp)) {
8222
+ if($.vakata.is_array(tmp)) {
8090
8223
  for(i = 0, j = tmp.length; i < j; i++) {
8091
- tmp[i].type = tmp[i].id && m[tmp[i].id] && m[tmp[i].id].type ? m[tmp[i].id].type : "default";
8224
+ tmp[i].type = (tmp[i].id || tmp[i].id === 0) && m[tmp[i].id] && m[tmp[i].id].type ? m[tmp[i].id].type : "default";
8092
8225
  if(options && options.no_id) {
8093
8226
  delete tmp[i].id;
8094
8227
  if(tmp[i].li_attr && tmp[i].li_attr.id) {
@@ -8101,7 +8234,7 @@
8101
8234
  }
8102
8235
  }
8103
8236
  else {
8104
- tmp.type = tmp.id && m[tmp.id] && m[tmp.id].type ? m[tmp.id].type : "default";
8237
+ tmp.type = (tmp.id || tmp.id === 0) && m[tmp.id] && m[tmp.id].type ? m[tmp.id].type : "default";
8105
8238
  if(options && options.no_id) {
8106
8239
  tmp = this._delete_ids(tmp);
8107
8240
  }
@@ -8109,7 +8242,7 @@
8109
8242
  return tmp;
8110
8243
  };
8111
8244
  this._delete_ids = function (tmp) {
8112
- if($.isArray(tmp)) {
8245
+ if($.vakata.is_array(tmp)) {
8113
8246
  for(var i = 0, j = tmp.length; i < j; i++) {
8114
8247
  tmp[i] = this._delete_ids(tmp[i]);
8115
8248
  }
@@ -8122,16 +8255,16 @@
8122
8255
  if(tmp.a_attr && tmp.a_attr.id) {
8123
8256
  delete tmp.a_attr.id;
8124
8257
  }
8125
- if(tmp.children && $.isArray(tmp.children)) {
8258
+ if(tmp.children && $.vakata.is_array(tmp.children)) {
8126
8259
  tmp.children = this._delete_ids(tmp.children);
8127
8260
  }
8128
8261
  return tmp;
8129
8262
  };
8130
8263
  this.check = function (chk, obj, par, pos, more) {
8131
8264
  if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
8132
- obj = obj && obj.id ? obj : this.get_node(obj);
8133
- par = par && par.id ? par : this.get_node(par);
8134
- var m = obj && obj.id ? (more && more.origin ? more.origin : $.jstree.reference(obj.id)) : null, tmp, d, i, j;
8265
+ obj = obj && (obj.id || obj.id === 0) ? obj : this.get_node(obj);
8266
+ par = par && (par.id || par.id === 0) ? par : this.get_node(par);
8267
+ var m = obj && (obj.id || obj.id === 0) ? (more && more.origin ? more.origin : $.jstree.reference(obj.id)) : null, tmp, d, i, j;
8135
8268
  m = m && m._model && m._model.data ? m._model.data : null;
8136
8269
  switch(chk) {
8137
8270
  case "create_node":
@@ -8140,11 +8273,11 @@
8140
8273
  if(chk !== 'move_node' || $.inArray(obj.id, par.children) === -1) {
8141
8274
  tmp = this.get_rules(par);
8142
8275
  if(tmp.max_children !== undefined && tmp.max_children !== -1 && tmp.max_children === par.children.length) {
8143
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_01', 'reason' : 'max_children prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8276
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_01', 'reason' : 'max_children prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && (obj.id || obj.id === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
8144
8277
  return false;
8145
8278
  }
8146
8279
  if(tmp.valid_children !== undefined && tmp.valid_children !== -1 && $.inArray((obj.type || 'default'), tmp.valid_children) === -1) {
8147
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_02', 'reason' : 'valid_children prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8280
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_02', 'reason' : 'valid_children prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && (obj.id || obj.id === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
8148
8281
  return false;
8149
8282
  }
8150
8283
  if(m && obj.children_d && obj.parents) {
@@ -8157,7 +8290,7 @@
8157
8290
  if(d <= 0 || d === undefined) { d = 1; }
8158
8291
  do {
8159
8292
  if(tmp.max_depth !== undefined && tmp.max_depth !== -1 && tmp.max_depth < d) {
8160
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_03', 'reason' : 'max_depth prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8293
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_03', 'reason' : 'max_depth prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && (obj.id || obj.id === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
8161
8294
  return false;
8162
8295
  }
8163
8296
  par = this.get_node(par.parent);
@@ -8206,7 +8339,7 @@
8206
8339
  */
8207
8340
  this.set_type = function (obj, type) {
8208
8341
  var m = this._model.data, t, t1, t2, old_type, old_icon, k, d, a;
8209
- if($.isArray(obj)) {
8342
+ if($.vakata.is_array(obj)) {
8210
8343
  obj = obj.slice();
8211
8344
  for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
8212
8345
  this.set_type(obj[t1], type);
@@ -8355,7 +8488,7 @@
8355
8488
  */
8356
8489
  trim_whitespace : false,
8357
8490
  /**
8358
- * A callback executed in the instance's scope when a new node is created and the name is already taken, the two arguments are the conflicting name and the counter. The default will produce results like `New node (2)`.
8491
+ * A callback executed in the instance's scope when a new node is created with no name and a node with the default name already exists, the two arguments are the conflicting name and the counter. The default will produce results like `New node (2)`.
8359
8492
  * @name $.jstree.defaults.unique.duplicate
8360
8493
  * @plugin unique
8361
8494
  */
@@ -8367,8 +8500,8 @@
8367
8500
  $.jstree.plugins.unique = function (options, parent) {
8368
8501
  this.check = function (chk, obj, par, pos, more) {
8369
8502
  if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
8370
- obj = obj && obj.id ? obj : this.get_node(obj);
8371
- par = par && par.id ? par : this.get_node(par);
8503
+ obj = obj && (obj.id || obj.id === 0) ? obj : this.get_node(obj);
8504
+ par = par && (par.id || par.id === 0) ? par : this.get_node(par);
8372
8505
  if(!par || !par.children) { return true; }
8373
8506
  var n = chk === "rename_node" ? pos : obj.text,
8374
8507
  c = [],
@@ -8400,32 +8533,32 @@
8400
8533
  }
8401
8534
  i = ($.inArray(n, c) === -1 || (obj.text && t === n));
8402
8535
  if(!i) {
8403
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_01', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8536
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_01', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && (obj.id || obj.id === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
8404
8537
  }
8405
8538
  return i;
8406
8539
  case "create_node":
8407
8540
  i = ($.inArray(n, c) === -1);
8408
8541
  if(!i) {
8409
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_04', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8542
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_04', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && (obj.id || obj.id === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
8410
8543
  }
8411
8544
  return i;
8412
8545
  case "copy_node":
8413
8546
  i = ($.inArray(n, c) === -1);
8414
8547
  if(!i) {
8415
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_02', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8548
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_02', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && (obj.id || obj.id === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
8416
8549
  }
8417
8550
  return i;
8418
8551
  case "move_node":
8419
8552
  i = ( (obj.parent === par.id && (!more || !more.is_multi)) || $.inArray(n, c) === -1);
8420
8553
  if(!i) {
8421
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_03', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8554
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_03', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && (obj.id || obj.id === 0) ? obj.id : false, 'par' : par && (par.id || par.id === 0) ? par.id : false }) };
8422
8555
  }
8423
8556
  return i;
8424
8557
  }
8425
8558
  return true;
8426
8559
  };
8427
8560
  this.create_node = function (par, node, pos, callback, is_loaded) {
8428
- if(!node || node.text === undefined) {
8561
+ if(!node || (typeof node === 'object' && node.text === undefined)) {
8429
8562
  if(par === null) {
8430
8563
  par = $.jstree.root;
8431
8564
  }
@@ -8495,17 +8628,17 @@
8495
8628
  parent.bind.call(this);
8496
8629
 
8497
8630
  this.element
8498
- .on('ready.jstree set_state.jstree', $.proxy(function () {
8631
+ .on('ready.jstree set_state.jstree', function () {
8499
8632
  this.hide_dots();
8500
- }, this))
8501
- .on("init.jstree loading.jstree ready.jstree", $.proxy(function () {
8633
+ }.bind(this))
8634
+ .on("init.jstree loading.jstree ready.jstree", function () {
8502
8635
  //div.style.height = this._data.core.li_height + 'px';
8503
8636
  this.get_container_ul().addClass('jstree-wholerow-ul');
8504
- }, this))
8505
- .on("deselect_all.jstree", $.proxy(function (e, data) {
8637
+ }.bind(this))
8638
+ .on("deselect_all.jstree", function (e, data) {
8506
8639
  this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
8507
- }, this))
8508
- .on("changed.jstree", $.proxy(function (e, data) {
8640
+ }.bind(this))
8641
+ .on("changed.jstree", function (e, data) {
8509
8642
  this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
8510
8643
  var tmp = false, i, j;
8511
8644
  for(i = 0, j = data.selected.length; i < j; i++) {
@@ -8514,21 +8647,21 @@
8514
8647
  tmp.children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
8515
8648
  }
8516
8649
  }
8517
- }, this))
8518
- .on("open_node.jstree", $.proxy(function (e, data) {
8650
+ }.bind(this))
8651
+ .on("open_node.jstree", function (e, data) {
8519
8652
  this.get_node(data.node, true).find('.jstree-clicked').parent().children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
8520
- }, this))
8521
- .on("hover_node.jstree dehover_node.jstree", $.proxy(function (e, data) {
8653
+ }.bind(this))
8654
+ .on("hover_node.jstree dehover_node.jstree", function (e, data) {
8522
8655
  if(e.type === "hover_node" && this.is_disabled(data.node)) { return; }
8523
8656
  this.get_node(data.node, true).children('.jstree-wholerow')[e.type === "hover_node"?"addClass":"removeClass"]('jstree-wholerow-hovered');
8524
- }, this))
8525
- .on("contextmenu.jstree", ".jstree-wholerow", $.proxy(function (e) {
8657
+ }.bind(this))
8658
+ .on("contextmenu.jstree", ".jstree-wholerow", function (e) {
8526
8659
  if (this._data.contextmenu) {
8527
8660
  e.preventDefault();
8528
8661
  var tmp = $.Event('contextmenu', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey, pageX : e.pageX, pageY : e.pageY });
8529
8662
  $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp);
8530
8663
  }
8531
- }, this))
8664
+ }.bind(this))
8532
8665
  /*!
8533
8666
  .on("mousedown.jstree touchstart.jstree", ".jstree-wholerow", function (e) {
8534
8667
  if(e.target === e.currentTarget) {
@@ -8541,28 +8674,28 @@
8541
8674
  .on("click.jstree", ".jstree-wholerow", function (e) {
8542
8675
  e.stopImmediatePropagation();
8543
8676
  var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
8544
- $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
8677
+ $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).trigger('focus');
8545
8678
  })
8546
8679
  .on("dblclick.jstree", ".jstree-wholerow", function (e) {
8547
8680
  e.stopImmediatePropagation();
8548
8681
  var tmp = $.Event('dblclick', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
8549
- $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
8682
+ $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).trigger('focus');
8550
8683
  })
8551
- .on("click.jstree", ".jstree-leaf > .jstree-ocl", $.proxy(function (e) {
8684
+ .on("click.jstree", ".jstree-leaf > .jstree-ocl", function (e) {
8552
8685
  e.stopImmediatePropagation();
8553
8686
  var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
8554
- $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
8555
- }, this))
8556
- .on("mouseover.jstree", ".jstree-wholerow, .jstree-icon", $.proxy(function (e) {
8687
+ $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).trigger('focus');
8688
+ }.bind(this))
8689
+ .on("mouseover.jstree", ".jstree-wholerow, .jstree-icon", function (e) {
8557
8690
  e.stopImmediatePropagation();
8558
8691
  if(!this.is_disabled(e.currentTarget)) {
8559
8692
  this.hover_node(e.currentTarget);
8560
8693
  }
8561
8694
  return false;
8562
- }, this))
8563
- .on("mouseleave.jstree", ".jstree-node", $.proxy(function (e) {
8695
+ }.bind(this))
8696
+ .on("mouseleave.jstree", ".jstree-node", function (e) {
8564
8697
  this.dehover_node(e.currentTarget);
8565
- }, this));
8698
+ }.bind(this));
8566
8699
  };
8567
8700
  this.teardown = function () {
8568
8701
  if(this.settings.wholerow) {