25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

123 lines
5.1 KiB

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