You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 lines
1.3 KiB

  1. /**
  2. * ### Conditionalselect plugin
  3. *
  4. * This plugin allows defining a callback to allow or deny node selection by user input (activate node method).
  5. */
  6. /*globals jQuery, define, exports, require, document */
  7. (function (factory) {
  8. "use strict";
  9. if (typeof define === 'function' && define.amd) {
  10. define('jstree.conditionalselect', ['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.conditionalselect) { return; }
  21. /**
  22. * a callback (function) which is invoked in the instance's scope and receives two arguments - the node and the event that triggered the `activate_node` call. Returning false prevents working with the node, returning true allows invoking activate_node. Defaults to returning `true`.
  23. * @name $.jstree.defaults.checkbox.visible
  24. * @plugin checkbox
  25. */
  26. $.jstree.defaults.conditionalselect = function () { return true; };
  27. $.jstree.plugins.conditionalselect = function (options, parent) {
  28. // own function
  29. this.activate_node = function (obj, e) {
  30. if(this.settings.conditionalselect.call(this, this.get_node(obj), e)) {
  31. return parent.activate_node.call(this, obj, e);
  32. }
  33. };
  34. };
  35. }));