|
3 | 3 | */
|
4 | 4 | var SelectTree = (function () {
|
5 | 5 |
|
| 6 | + 'use strict'; |
| 7 | + |
6 | 8 | var my = {};
|
7 | 9 |
|
8 | 10 | my.initTree = function (config) {
|
9 |
| - if (! 'rootNode' in config) { |
10 |
| - config.rootNode = "/"; |
11 |
| - } |
12 |
| - jQuery(config.selector).jstree({ |
13 |
| - "core": { |
14 |
| - "initially_load": config.path.expanded, |
15 |
| - "initially_open": config.path.preloaded |
16 |
| - }, |
17 |
| - "plugins": [ "themes", "types", "ui", "json_data"], |
18 |
| - "json_data": { |
19 |
| - "ajax": { |
20 |
| - "url": config.ajax.children_url, |
21 |
| - "data": function (node) { |
22 |
| - if (node == -1) { |
23 |
| - return { 'root' : config.rootNode }; |
24 |
| - } else { |
25 |
| - return { 'root' : jQuery(node).attr('id') }; |
| 11 | + jQuery.extend({ |
| 12 | + rootNode: '/', |
| 13 | + }, config); |
| 14 | + |
| 15 | + jQuery(config.selector) |
| 16 | + .jstree({ |
| 17 | + "core": { |
| 18 | + "initially_load": config.path.expanded, |
| 19 | + "initially_open": config.path.preloaded |
| 20 | + }, |
| 21 | + "plugins": ["themes", "types", "ui", "json_data"], |
| 22 | + "json_data": { |
| 23 | + "ajax": { |
| 24 | + "url": config.ajax.children_url, |
| 25 | + "data": function (node) { |
| 26 | + if (-1 === node) { |
| 27 | + return { 'root' : config.rootNode }; |
| 28 | + } else { |
| 29 | + return { 'root' : jQuery(node).attr('id') }; |
| 30 | + } |
26 | 31 | }
|
27 | 32 | }
|
| 33 | + }, |
| 34 | + "types": { |
| 35 | + "max_depth": -1, |
| 36 | + "max_children": -1, |
| 37 | + "valid_children": ["all"], |
| 38 | + "types": config.types |
| 39 | + }, |
| 40 | + "ui": { |
| 41 | + "initially_select" : [config.selected] |
28 | 42 | }
|
29 |
| - }, |
30 |
| - "types": { |
31 |
| - "max_depth": -1, |
32 |
| - "max_children": -1, |
33 |
| - "valid_children": [ "all"], |
34 |
| - "types": config.types |
35 |
| - }, |
36 |
| - "ui": { |
37 |
| - "initially_select" : [ config.selected ] |
38 |
| - } |
39 | 43 |
|
40 |
| - }) |
41 |
| - .bind("select_node.jstree", function (event, data) { |
42 |
| - jQuery(config.output).val(data.rslt.obj.attr("id")); |
43 |
| - jQuery(config.output).trigger('change'); |
44 |
| - }) |
45 |
| - .delegate("a", "click", function (event, data) { event.preventDefault(); }); |
| 44 | + }) |
| 45 | + .bind("select_node.jstree", function (event, data) { |
| 46 | + jQuery(config.output).val(data.rslt.obj.attr("id")); |
| 47 | + jQuery(config.output).trigger('change'); |
| 48 | + }) |
| 49 | + .on("click", "a", function (event, data) { |
| 50 | + event.preventDefault(); |
| 51 | + }) |
| 52 | + ; |
| 53 | + |
| 54 | + jQuery(config.reset).on("click", function (e) { |
| 55 | + e.preventDefault(); |
46 | 56 |
|
47 |
| - jQuery(config.reset).bind("click", function(e) { |
48 | 57 | jQuery(config.selector).jstree("deselect_all");
|
49 | 58 | jQuery(config.output).val("");
|
| 59 | + |
50 | 60 | if (config.selectRootNode) {
|
51 | 61 | jQuery(config.selector).jstree("select", config.rootNode);
|
52 | 62 | jQuery(config.output).val(config.rootNode);
|
53 | 63 | }
|
54 |
| - e.preventDefault(); |
55 | 64 | });
|
56 | 65 | };
|
57 | 66 |
|
|
0 commit comments