forgeos_core 1.9.1 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/COPYING +339 -0
  2. data/COPYING.LESSER +165 -0
  3. data/app/assets/images/forgeos/dataTables/Sorting icons.psd +0 -0
  4. data/app/assets/images/forgeos/dataTables/back_disabled.jpg +0 -0
  5. data/app/assets/images/forgeos/dataTables/back_enabled.jpg +0 -0
  6. data/app/assets/images/forgeos/dataTables/favicon.ico +0 -0
  7. data/app/assets/images/forgeos/dataTables/forward_disabled.jpg +0 -0
  8. data/app/assets/images/forgeos/dataTables/forward_enabled.jpg +0 -0
  9. data/app/assets/images/forgeos/dataTables/sort_asc.png +0 -0
  10. data/app/assets/images/forgeos/dataTables/sort_asc_disabled.png +0 -0
  11. data/app/assets/images/forgeos/dataTables/sort_both.png +0 -0
  12. data/app/assets/images/forgeos/dataTables/sort_desc.png +0 -0
  13. data/app/assets/images/forgeos/dataTables/sort_desc_disabled.png +0 -0
  14. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/bubble-quantity-products.png +0 -0
  15. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/check-checked.png +0 -0
  16. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/check-unchecked.png +0 -0
  17. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/context.gif +0 -0
  18. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/create.png +0 -0
  19. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/dark-blue-minus.png +0 -0
  20. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/dark-blue-plus.png +0 -0
  21. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/dot.gif +0 -0
  22. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/f.png +0 -0
  23. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/fminus.gif +0 -0
  24. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/fminus_rtl.gif +0 -0
  25. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/folder.png +0 -0
  26. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/fplus.gif +0 -0
  27. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/fplus_rtl.gif +0 -0
  28. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/lastli.gif +0 -0
  29. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/lastli_rtl.gif +0 -0
  30. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/li.gif +0 -0
  31. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/remove.png +0 -0
  32. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/rename.png +0 -0
  33. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/association_categories/throbber.gif +0 -0
  34. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/brown-minus.png +0 -0
  35. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/brown-plus.png +0 -0
  36. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/bubble-quantity-elements.png +0 -0
  37. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/context.gif +0 -0
  38. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/create.png +0 -0
  39. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/dot.gif +0 -0
  40. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/f.png +0 -0
  41. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/fminus.gif +0 -0
  42. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/fminus_rtl.gif +0 -0
  43. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/fplus.gif +0 -0
  44. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/fplus_rtl.gif +0 -0
  45. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/images.png +0 -0
  46. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/lastli.gif +0 -0
  47. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/lastli_rtl.gif +0 -0
  48. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/li.gif +0 -0
  49. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/remove.png +0 -0
  50. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/rename.png +0 -0
  51. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/categories/throbber.gif +0 -0
  52. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/marker.gif +0 -0
  53. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/marker_rtl.gif +0 -0
  54. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/plus.gif +0 -0
  55. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/remove.gif +0 -0
  56. data/app/assets/{stylesheets → images}/forgeos/jstree/themes/remove.png +0 -0
  57. data/app/assets/javascripts/forgeos/admin/functions/forgeos_core/commons.js +8 -3
  58. data/app/assets/javascripts/forgeos/admin/functions/forgeos_core/dataTable.js +2 -2
  59. data/app/assets/javascripts/forgeos/admin/functions/forgeos_core/tinyMCE.js +1 -1
  60. data/app/assets/javascripts/forgeos/admin/functions/forgeos_core/trees.js +202 -257
  61. data/app/assets/javascripts/forgeos/admin/inits/forgeos_core/left-sidebar.js +16 -23
  62. data/app/assets/javascripts/forgeos/admin/inits/forgeos_core/settings.js +5 -5
  63. data/app/assets/javascripts/forgeos/admin/inits/forgeos_core/tabs.js +3 -3
  64. data/app/assets/javascripts/forgeos/admin/inits/forgeos_core/trees.js +2 -45
  65. data/app/assets/javascripts/forgeos/jquery.dataTables.min.js +138 -529
  66. data/app/assets/javascripts/forgeos/jstree/jquery.jstree.js +4544 -0
  67. data/app/assets/stylesheets/forgeos/admin/forgeos_core/_lightbox.css.sass +2 -21
  68. data/app/assets/stylesheets/forgeos/admin/forgeos_core/_settings.css.sass +77 -39
  69. data/app/assets/stylesheets/forgeos/dataTables/demo_table.css +150 -27
  70. data/app/assets/stylesheets/forgeos/jstree/themes/association_categories/style.css.sass +36 -154
  71. data/app/assets/stylesheets/forgeos/jstree/themes/categories/style.css.sass +59 -58
  72. data/app/controllers/admin/accounts_controller.rb +1 -1
  73. data/app/controllers/admin/administrators_controller.rb +13 -4
  74. data/app/controllers/admin/attachments_controller.rb +7 -3
  75. data/app/controllers/admin/base_controller.rbc +1305 -0
  76. data/app/controllers/admin/categories_controller.rb +1 -1
  77. data/app/controllers/admin/dashboard_controller.rbc +361 -0
  78. data/app/controllers/admin/person_sessions_controller.rbc +1248 -0
  79. data/app/controllers/admin/rights_controller.rb +6 -6
  80. data/app/controllers/admin/roles_controller.rb +8 -3
  81. data/app/controllers/admin/users_controller.rb +12 -6
  82. data/app/controllers/forgeos/application_controller.rb +1 -2
  83. data/app/controllers/forgeos/application_controller.rbc +2027 -0
  84. data/app/helpers/admin/attachment_helper.rbc +2340 -0
  85. data/app/helpers/admin/base_helper.rb +0 -15
  86. data/app/helpers/admin/base_helper.rbc +2522 -0
  87. data/app/helpers/forgeos/application_helper.rbc +3152 -0
  88. data/app/models/administrator.rbc +415 -0
  89. data/app/models/category.rb +3 -3
  90. data/app/models/person.rb +5 -9
  91. data/app/models/person.rbc +1498 -0
  92. data/app/models/person_session.rbc +142 -0
  93. data/app/models/right.rbc +432 -0
  94. data/app/models/role.rbc +469 -0
  95. data/app/models/setting.rbc +699 -0
  96. data/app/views/admin/accounts/_form.html.haml +1 -1
  97. data/app/views/admin/administrators/activate.js.erb +1 -0
  98. data/app/views/admin/administrators/destroy.js.erb +1 -0
  99. data/app/views/admin/administrators/index.json.erb +10 -12
  100. data/app/views/admin/attachments/_form.html.haml +2 -2
  101. data/app/views/admin/attachments/destroy.js.erb +1 -0
  102. data/app/views/admin/attachments/index.json.erb +4 -5
  103. data/app/views/admin/categories/_associated_elements.html.haml +4 -8
  104. data/app/views/admin/categories/index.json.erb +1 -1
  105. data/app/views/admin/rights/destroy.js.erb +1 -0
  106. data/app/views/admin/rights/index.json.erb +5 -6
  107. data/app/views/admin/roles/activate.js.erb +1 -0
  108. data/app/views/admin/roles/destroy.js.erb +1 -0
  109. data/app/views/admin/roles/index.json.erb +10 -12
  110. data/app/views/admin/settings/_tabs.html.haml +0 -6
  111. data/app/views/admin/settings/edit.html.haml +19 -16
  112. data/app/views/admin/sidebars/_attachments_popups.html.haml +1 -1
  113. data/app/views/admin/sidebars/_left_sidebar.html.haml +2 -2
  114. data/app/views/admin/users/activate.js.erb +1 -0
  115. data/app/views/admin/users/destroy.js.erb +1 -0
  116. data/app/views/admin/users/index.json.erb +8 -11
  117. data/app/views/admin/visual/_visual_popup.html.haml +2 -2
  118. data/app/views/admin/visual/_visuals_popup.html.haml +1 -1
  119. data/app/views/layouts/admin.html.haml +5 -4
  120. data/app/views/layouts/admin_login.html.haml +3 -3
  121. data/config/initializers/load_settings.rbc +330 -0
  122. data/config/routes.rb +5 -8
  123. data/config/routes.rbc +2203 -0
  124. data/lib/extensions/form_helper_extensions.rb +2 -2
  125. data/lib/extensions/form_helper_extensions.rbc +295 -0
  126. data/lib/extensions/i18n_fallbacks_config.rbc +246 -0
  127. data/lib/extensions.rbc +126 -0
  128. data/lib/forgeos/core/engine.rbc +316 -0
  129. data/lib/forgeos/core.rbc +325 -0
  130. data/lib/forgeos.rbc +1942 -0
  131. data/lib/forgeos_core.rbc +53 -0
  132. data/lib/map_fields.rbc +4437 -0
  133. data/lib/sortable_attachments.rbc +1399 -0
  134. data/lib/sphinx_globalize.rbc +785 -0
  135. metadata +286 -53
  136. data/app/assets/javascripts/forgeos/jstree/jquery.tree.js +0 -2061
  137. data/app/assets/javascripts/forgeos/jstree/plugins/jquery.tree.contextmenu.js +0 -129
  138. data/app/assets/javascripts/forgeos/jstree/plugins/jquery.tree.cookie.js +0 -70
  139. data/app/assets/stylesheets/forgeos/jquery.selectbox.css +0 -75
  140. data/app/assets/stylesheets/forgeos/jstree/themes/categories/style.css +0 -106
  141. data/app/assets/stylesheets/forgeos/jstree/tree_component.css.sass +0 -204
@@ -1,2061 +0,0 @@
1
- /*
2
- * jsTree 0.9.9a
3
- * http://jstree.com/
4
- *
5
- * Copyright (c) 2009 Ivan Bozhanov (vakata.com)
6
- *
7
- * Dual licensed under the MIT and GPL licenses:
8
- * http://www.opensource.org/licenses/mit-license.php
9
- * http://www.gnu.org/licenses/gpl.html
10
- *
11
- * Date: 2009-10-06
12
- *
13
- */
14
-
15
- (function($) {
16
- // jQuery plugin
17
- $.tree = {
18
- datastores : { },
19
- plugins : { },
20
- defaults : {
21
- data : {
22
- async : false, // Are async requests used to load open_branch contents
23
- type : "html", // One of included datastores
24
- opts : { method: "GET", url: false } // Options passed to datastore
25
- },
26
- selected : false, // FALSE or STRING or ARRAY
27
- opened : [], // ARRAY OF INITIALLY OPENED NODES
28
- languages : [], // ARRAY of string values (which will be used as CSS classes - so they must be valid)
29
- ui : {
30
- dots : true, // BOOL - dots or no dots
31
- animation : 0, // INT - duration of open/close animations in miliseconds
32
- scroll_spd : 4,
33
- theme_path : false, // Path to the theme CSS file - if set to false and theme_name is not false - will lookup jstree-path-here/themes/theme-name-here/style.css
34
- theme_name : "default",// if set to false no theme will be loaded
35
- selected_parent_close : "select_parent", // false, "deselect", "select_parent"
36
- selected_delete : "select_previous" // false, "select_previous"
37
- },
38
- types : {
39
- "default" : {
40
- clickable : true, // can be function
41
- renameable : true, // can be function
42
- deletable : true, // can be function
43
- creatable : true, // can be function
44
- draggable : true, // can be function
45
- max_children : -1, // -1 - not set, 0 - no children, 1 - one child, etc // can be function
46
- max_depth : -1, // -1 - not set, 0 - no children, 1 - one level of children, etc // can be function
47
- valid_children : "all", // all, none, array of values // can be function
48
- icon : {
49
- image : false,
50
- position : false
51
- }
52
- }
53
- },
54
- rules : {
55
- multiple : false, // FALSE | CTRL | ON - multiple selection off/ with or without holding Ctrl
56
- multitree : "none", // all, none, array of tree IDs to accept from
57
- type_attr : "rel", // STRING attribute name (where is the type stored as string)
58
- createat : "bottom", // STRING (top or bottom) new nodes get inserted at top or bottom
59
- drag_copy : "ctrl", // FALSE | CTRL | ON - drag to copy off/ with or without holding Ctrl
60
- drag_button : "left", // left, right or both
61
- use_max_children : true,
62
- use_max_depth : true,
63
-
64
- max_children: -1,
65
- max_depth : -1,
66
- valid_children : "all"
67
- },
68
- lang : {
69
- new_node : "New folder",
70
- loading : "Loading ..."
71
- },
72
- callback : {
73
- beforechange: function(NODE,TREE_OBJ) { return true },
74
- beforeopen : function(NODE,TREE_OBJ) { return true },
75
- beforeclose : function(NODE,TREE_OBJ) { return true },
76
- beforemove : function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true },
77
- beforecreate: function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true },
78
- beforerename: function(NODE,LANG,TREE_OBJ) { return true },
79
- beforedelete: function(NODE,TREE_OBJ) { return true },
80
- beforedata : function(NODE,TREE_OBJ) { return { id : $(NODE).attr("id") || 0 } }, // PARAMETERS PASSED TO SERVER
81
- ondata : function(DATA,TREE_OBJ) { return DATA; }, // modify data before parsing it
82
- onparse : function(STR,TREE_OBJ) { return STR; }, // modify string before visualizing it
83
- onhover : function(NODE,TREE_OBJ) { }, // node hovered
84
- onselect : function(NODE,TREE_OBJ) { }, // node selected
85
- ondeselect : function(NODE,TREE_OBJ) { }, // node deselected
86
- onchange : function(NODE,TREE_OBJ) { }, // focus changed
87
- onrename : function(NODE,TREE_OBJ,RB) { }, // node renamed
88
- onmove : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // move completed
89
- oncopy : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // copy completed
90
- oncreate : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // node created
91
- ondelete : function(NODE,TREE_OBJ,RB) { }, // node deleted
92
- onopen : function(NODE,TREE_OBJ) { }, // node opened
93
- onopen_all : function(TREE_OBJ) { }, // all nodes opened
94
- onclose_all : function(TREE_OBJ) { }, // all nodes closed
95
- onclose : function(NODE,TREE_OBJ) { }, // node closed
96
- error : function(TEXT,TREE_OBJ) { }, // error occured
97
- ondblclk : function(NODE,TREE_OBJ) { TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE); },
98
- onrgtclk : function(NODE,TREE_OBJ,EV) { }, // right click - to prevent use: EV.preventDefault(); EV.stopPropagation(); return false
99
- onload : function(TREE_OBJ) { },
100
- oninit : function(TREE_OBJ) { },
101
- onfocus : function(TREE_OBJ) { },
102
- ondestroy : function(TREE_OBJ) { },
103
- onsearch : function(NODES, TREE_OBJ) { NODES.addClass("search"); },
104
- ondrop : function(NODE,REF_NODE,TYPE,TREE_OBJ) { },
105
- check : function(RULE,NODE,VALUE,TREE_OBJ) { return VALUE; },
106
- check_move : function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true; }
107
- },
108
- plugins : { }
109
- },
110
-
111
- create : function () { return new tree_component(); },
112
- focused : function () { return tree_component.inst[tree_component.focused]; },
113
- reference : function (obj) {
114
- var o = $(obj);
115
- if(!o.size()) o = $("#" + obj);
116
- if(!o.size()) return null;
117
- o = (o.is(".tree")) ? o.attr("id") : o.parents(".tree:eq(0)").attr("id");
118
- return tree_component.inst[o] || null;
119
- },
120
- rollback : function (data) {
121
- for(var i in data) {
122
- if(!data.hasOwnProperty(i)) continue;
123
- var tmp = tree_component.inst[i];
124
- var lock = !tmp.locked;
125
-
126
- // if not locked - lock the tree
127
- if(lock) tmp.lock(true);
128
- // Cancel ongoing rename
129
- tmp.inp = false;
130
- tmp.container.html(data[i].html).find(".dragged").removeClass("dragged").end().find(".hover").removeClass("hover");
131
-
132
- if(data[i].selected) {
133
- tmp.selected = $("#" + data[i].selected);
134
- tmp.selected_arr = [];
135
- tmp.container
136
- .find("a.clicked").each( function () {
137
- tmp.selected_arr.push(tmp.get_node(this));
138
- });
139
- }
140
- // if this function set the lock - unlock
141
- if(lock) tmp.lock(false);
142
-
143
- delete lock;
144
- delete tmp;
145
- }
146
- },
147
- drop_mode : function (opts) {
148
- opts = $.extend(opts, { show : false, type : "default", str : "Foreign node" });
149
- tree_component.drag_drop.foreign = true;
150
- tree_component.drag_drop.isdown = true;
151
- tree_component.drag_drop.moving = true;
152
- tree_component.drag_drop.appended = false;
153
- tree_component.drag_drop.f_type = opts.type;
154
- tree_component.drag_drop.f_data = opts;
155
-
156
-
157
- if(!opts.show) {
158
- tree_component.drag_drop.drag_help = false;
159
- tree_component.drag_drop.drag_node = false;
160
- }
161
- else {
162
- tree_component.drag_drop.drag_help = $("<div id='jstree-dragged' class='tree tree-default'><ul><li class='last dragged foreign'><a href='#'><ins>&nbsp;</ins>" + opts.str + "</a></li></ul></div>");
163
- tree_component.drag_drop.drag_node = tree_component.drag_drop.drag_help.find("li:eq(0)");
164
- }
165
- if($.tree.drag_start !== false) $.tree.drag_start.call(null, false);
166
- },
167
- drag_start : false,
168
- drag : false,
169
- drag_end : false
170
- };
171
- $.fn.tree = function (opts) {
172
- return this.each(function() {
173
- var conf = $.extend({},opts);
174
- if(tree_component.inst && tree_component.inst[$(this).attr('id')]) tree_component.inst[$(this).attr('id')].destroy();
175
- if(conf !== false) new tree_component().init(this, conf);
176
- });
177
- };
178
-
179
- // core
180
- function tree_component () {
181
- return {
182
- cntr : ++tree_component.cntr,
183
- settings : $.extend({},$.tree.defaults),
184
-
185
- init : function(elem, conf) {
186
- var _this = this;
187
- this.container = $(elem);
188
- if(this.container.size == 0) return false;
189
- tree_component.inst[this.cntr] = this;
190
- if(!this.container.attr("id")) this.container.attr("id","jstree_" + this.cntr);
191
- tree_component.inst[this.container.attr("id")] = tree_component.inst[this.cntr];
192
- tree_component.focused = this.cntr;
193
- this.settings = $.extend(true, {}, this.settings, conf);
194
-
195
- // DEAL WITH LANGUAGE VERSIONS
196
- if(this.settings.languages && this.settings.languages.length) {
197
- this.current_lang = this.settings.languages[0];
198
- var st = false;
199
- var id = "#" + this.container.attr("id");
200
- for(var ln = 0; ln < this.settings.languages.length; ln++) {
201
- st = tree_component.add_css(id + " ." + this.settings.languages[ln]);
202
- if(st !== false) st.style.display = (this.settings.languages[ln] == this.current_lang) ? "" : "none";
203
- }
204
- }
205
- else this.current_lang = false;
206
- // THEMES
207
- this.container.addClass("tree");
208
- if(this.settings.ui.theme_name !== false) {
209
- if(this.settings.ui.theme_path === false) {
210
- $("script").each(function () {
211
- if(this.src.toString().match(/jquery\.tree.*?js$/)) { _this.settings.ui.theme_path = this.src.toString().replace(/jquery\.tree.*?js$/, "") + "themes/" + _this.settings.ui.theme_name + "/style.css"; return false; }
212
- });
213
- }
214
- if(this.settings.ui.theme_path != "" && $.inArray(this.settings.ui.theme_path, tree_component.themes) == -1) {
215
- //By webpulser
216
- this.settings.ui.theme_path = this.settings.ui.theme_path+this.settings.ui.theme_name+'/style.css'
217
- //
218
- tree_component.add_sheet({ url : this.settings.ui.theme_path });
219
- tree_component.themes.push(this.settings.ui.theme_path);
220
- }
221
- this.container.addClass("tree-" + this.settings.ui.theme_name);
222
- }
223
- // TYPE ICONS
224
- var type_icons = "";
225
- for(var t in this.settings.types) {
226
- if(!this.settings.types.hasOwnProperty(t)) continue;
227
- if(!this.settings.types[t].icon) continue;
228
- if( this.settings.types[t].icon.image || this.settings.types[t].icon.position) {
229
- if(t == "default") type_icons += "#" + this.container.attr("id") + " li > a ins { ";
230
- else type_icons += "#" + this.container.attr("id") + " li[rel=" + t + "] > a ins { ";
231
- if(this.settings.types[t].icon.image) type_icons += " background-image:url(" + this.settings.types[t].icon.image + "); ";
232
- if(this.settings.types[t].icon.position) type_icons += " background-position:" + this.settings.types[t].icon.position + "; ";
233
- type_icons += "} ";
234
- }
235
- }
236
- if(type_icons != "") tree_component.add_sheet({ str : type_icons });
237
-
238
- if(this.settings.rules.multiple) this.selected_arr = [];
239
- this.offset = false;
240
- this.hovered = false;
241
- this.locked = false;
242
-
243
- if(tree_component.drag_drop.marker === false) tree_component.drag_drop.marker = $("<div>").attr({ id : "jstree-marker" }).hide().appendTo("body");
244
- this.callback("oninit", [this]);
245
- this.refresh();
246
- this.attach_events();
247
- this.focus();
248
- },
249
- refresh : function (obj) {
250
- if(this.locked) return this.error("LOCKED");
251
- var _this = this;
252
- if(obj && !this.settings.data.async) obj = false;
253
- this.is_partial_refresh = obj ? true : false;
254
-
255
- // SAVE OPENED
256
- this.opened = Array();
257
- if(this.settings.opened != false) {
258
- $.each(this.settings.opened, function (i, item) {
259
- if(this.replace(/^#/,"").length > 0) { _this.opened.push("#" + this.replace(/^#/,"")); }
260
- });
261
- this.settings.opened = false;
262
- }
263
- else {
264
- this.container.find("li.open").each(function (i) { if(this.id) { _this.opened.push("#" + this.id); } });
265
- }
266
-
267
- // SAVE SELECTED
268
- if(this.selected) {
269
- this.settings.selected = Array();
270
- if(obj) {
271
- $(obj).find("li:has(a.clicked)").each(function () {
272
- if(this.id) _this.settings.selected.push("#" + this.id);
273
- });
274
- }
275
- else {
276
- if(this.selected_arr) {
277
- $.each(this.selected_arr, function () {
278
- if(this.attr("id")) _this.settings.selected.push("#" + this.attr("id"));
279
- });
280
- }
281
- else {
282
- if(this.selected.attr("id")) this.settings.selected.push("#" + this.selected.attr("id"));
283
- }
284
- }
285
- }
286
- else if(this.settings.selected !== false) {
287
- var tmp = Array();
288
- if((typeof this.settings.selected).toLowerCase() == "object") {
289
- $.each(this.settings.selected, function () {
290
- if(this.replace(/^#/,"").length > 0) tmp.push("#" + this.replace(/^#/,""));
291
- });
292
- }
293
- else {
294
- if(this.settings.selected.replace(/^#/,"").length > 0) tmp.push("#" + this.settings.selected.replace(/^#/,""));
295
- }
296
- this.settings.selected = tmp;
297
- }
298
-
299
- if(obj && this.settings.data.async) {
300
- this.opened = Array();
301
- obj = this.get_node(obj);
302
- obj.find("li.open").each(function (i) { _this.opened.push("#" + this.id); });
303
- if(obj.hasClass("open")) obj.removeClass("open").addClass("closed");
304
- if(obj.hasClass("leaf")) obj.removeClass("leaf");
305
- obj.children("ul:eq(0)").html("");
306
- return this.open_branch(obj, true, function () { _this.reselect.apply(_this); });
307
- }
308
-
309
- var _this = this;
310
- var _datastore = new $.tree.datastores[this.settings.data.type]();
311
- if(this.container.children("ul").size() == 0) {
312
- this.container.html("<ul class='ltr' style='direction:ltr;'><li class='last'><a class='loading' href='#'><ins>&nbsp;</ins>" + (this.settings.lang.loading || "Loading ...") + "</a></li></ul>");
313
- }
314
- _datastore.load(this.callback("beforedata",[false,this]),this,this.settings.data.opts,function(data) {
315
- data = _this.callback("ondata",[data, _this]);
316
- _datastore.parse(data,_this,_this.settings.data.opts,function(str) {
317
- str = _this.callback("onparse", [str, _this]);
318
- _this.container.empty().append($("<ul class='ltr'>").html(str));
319
- _this.container.find("li:last-child").addClass("last").end().find("li:has(ul)").not(".open").addClass("closed");
320
- _this.container.find("li").not(".open").not(".closed").addClass("leaf");
321
- _this.reselect();
322
- });
323
- });
324
- },
325
- reselect : function (is_callback) {
326
- var _this = this;
327
-
328
- if(!is_callback) this.cl_count = 0;
329
- else this.cl_count --;
330
- // REOPEN BRANCHES
331
- if(this.opened && this.opened.length) {
332
- var opn = false;
333
- for(var j = 0; this.opened && j < this.opened.length; j++) {
334
- if(this.settings.data.async) {
335
- var tmp = this.get_node(this.opened[j]);
336
- if(tmp.size() && tmp.hasClass("closed") > 0) {
337
- opn = true;
338
- var tmp = this.opened[j].toString().replace('/','\\/');
339
- delete this.opened[j];
340
- this.open_branch(tmp, true, function () { _this.reselect.apply(_this, [true]); } );
341
- this.cl_count ++;
342
- }
343
- }
344
- else this.open_branch(this.opened[j], true);
345
- }
346
- if(this.settings.data.async && opn) return;
347
- if(this.cl_count > 0) return;
348
- delete this.opened;
349
- }
350
- if(this.cl_count > 0) return;
351
-
352
- // DOTS and RIGHT TO LEFT
353
- this.container.css("direction","ltr").children("ul:eq(0)").addClass("ltr");
354
- if(this.settings.ui.dots == false) this.container.children("ul:eq(0)").addClass("no_dots");
355
-
356
- // REPOSITION SCROLL
357
- if(this.scrtop) {
358
- this.container.scrollTop(_this.scrtop);
359
- delete this.scrtop;
360
- }
361
- // RESELECT PREVIOUSLY SELECTED
362
- if(this.settings.selected !== false) {
363
- $.each(this.settings.selected, function (i) {
364
- if(_this.is_partial_refresh) _this.select_branch($(_this.settings.selected[i].toString().replace('/','\\/'), _this.container), (_this.settings.rules.multiple !== false) );
365
- else _this.select_branch($(_this.settings.selected[i].toString().replace('/','\\/'), _this.container), (_this.settings.rules.multiple !== false && i > 0) );
366
- });
367
- this.settings.selected = false;
368
- }
369
- this.callback("onload", [_this]);
370
- },
371
-
372
- get : function (obj, format, opts) {
373
- if(!format) format = this.settings.data.type;
374
- if(!opts) opts = this.settings.data.opts;
375
- return new $.tree.datastores[format]().get(obj, this, opts);
376
- },
377
-
378
- attach_events : function () {
379
- var _this = this;
380
-
381
- this.container
382
- .bind("mousedown.jstree", function (event) {
383
- if(tree_component.drag_drop.isdown) {
384
- tree_component.drag_drop.move_type = false;
385
- event.preventDefault();
386
- event.stopPropagation();
387
- event.stopImmediatePropagation();
388
- return false;
389
- }
390
- })
391
- .bind("mouseup.jstree", function (event) {
392
- setTimeout( function() { _this.focus.apply(_this); }, 5);
393
- })
394
- .bind("click.jstree", function (event) {
395
- //event.stopPropagation();
396
- return true;
397
- });
398
- $("#" + this.container.attr("id") + " li")
399
- .live("click", function(event) { // WHEN CLICK IS ON THE ARROW
400
- if(event.target.tagName != "LI") return true;
401
- _this.off_height();
402
- if(event.pageY - $(event.target).offset().top > _this.li_height) return true;
403
- _this.toggle_branch.apply(_this, [event.target]);
404
- event.stopPropagation();
405
- return false;
406
- });
407
- $("#" + this.container.attr("id") + " li a")
408
- .live("click.jstree", function (event) { // WHEN CLICK IS ON THE TEXT OR ICON
409
- if(event.which && event.which == 3) return true;
410
- if(_this.locked) {
411
- event.preventDefault();
412
- event.target.blur();
413
- return _this.error("LOCKED");
414
- }
415
- _this.select_branch.apply(_this, [event.target, event.ctrlKey || _this.settings.rules.multiple == "on"]);
416
- if(_this.inp) { _this.inp.blur(); }
417
- event.preventDefault();
418
- event.target.blur();
419
- return false;
420
- })
421
- .live("dblclick.jstree", function (event) { // WHEN DOUBLECLICK ON TEXT OR ICON
422
- if(_this.locked) {
423
- event.preventDefault();
424
- event.stopPropagation();
425
- event.target.blur();
426
- return _this.error("LOCKED");
427
- }
428
- _this.callback("ondblclk", [_this.get_node(event.target).get(0), _this]);
429
- event.preventDefault();
430
- event.stopPropagation();
431
- event.target.blur();
432
- })
433
- .live("contextmenu.jstree", function (event) {
434
- if(_this.locked) {
435
- event.target.blur();
436
- return _this.error("LOCKED");
437
- }
438
- return _this.callback("onrgtclk", [_this.get_node(event.target).get(0), _this, event]);
439
- })
440
- .live("mouseover.jstree", function (event) {
441
- if(_this.locked) {
442
- event.preventDefault();
443
- event.stopPropagation();
444
- return _this.error("LOCKED");
445
- }
446
- if(_this.hovered !== false && (event.target.tagName == "A" || event.target.tagName == "INS")) {
447
- _this.hovered.children("a").removeClass("hover");
448
- _this.hovered = false;
449
- }
450
- _this.callback("onhover",[_this.get_node(event.target).get(0), _this]);
451
- })
452
- .live("mousedown.jstree", function (event) {
453
- if(_this.settings.rules.drag_button == "left" && event.which && event.which != 1) return true;
454
- if(_this.settings.rules.drag_button == "right" && event.which && event.which != 3) return true;
455
- _this.focus.apply(_this);
456
- if(_this.locked) return _this.error("LOCKED");
457
- // SELECT LIST ITEM NODE
458
- var obj = _this.get_node(event.target);
459
- // IF ITEM IS DRAGGABLE
460
- if(_this.settings.rules.multiple != false && _this.selected_arr.length > 1 && obj.children("a:eq(0)").hasClass("clicked")) {
461
- var counter = 0;
462
- for(var i in _this.selected_arr) {
463
- if(!_this.selected_arr.hasOwnProperty(i)) continue;
464
- if(_this.check("draggable", _this.selected_arr[i])) {
465
- _this.selected_arr[i].addClass("dragged");
466
- tree_component.drag_drop.origin_tree = _this;
467
- counter ++;
468
- }
469
- }
470
- if(counter > 0) {
471
- if(_this.check("draggable", obj)) tree_component.drag_drop.drag_node = obj;
472
- else tree_component.drag_drop.drag_node = _this.container.find("li.dragged:eq(0)");
473
- tree_component.drag_drop.isdown = true;
474
- tree_component.drag_drop.drag_help = $("<div id='jstree-dragged' class='tree " + ( _this.settings.ui.theme_name != "" ? " tree-" + _this.settings.ui.theme_name : "" ) + "' />").append("<ul class='" + _this.container.children("ul:eq(0)").get(0).className + "' />");
475
- var tmp = tree_component.drag_drop.drag_node.clone();
476
- if(_this.settings.languages.length > 0) tmp.find("a").not("." + _this.current_lang).hide();
477
- tree_component.drag_drop.drag_help.children("ul:eq(0)").append(tmp);
478
- tree_component.drag_drop.drag_help.find("li:eq(0)").removeClass("last").addClass("last").children("a").html("<ins>&nbsp;</ins>Multiple selection").end().children("ul").remove();
479
-
480
- tree_component.drag_drop.dragged = _this.container.find("li.dragged");
481
- }
482
- }
483
- else {
484
- if(_this.check("draggable", obj)) {
485
- tree_component.drag_drop.drag_node = obj;
486
- tree_component.drag_drop.drag_help = $("<div id='jstree-dragged' class='tree " + ( _this.settings.ui.theme_name != "" ? " tree-" + _this.settings.ui.theme_name : "" ) + "' />").append("<ul class='" + _this.container.children("ul:eq(0)").get(0).className + "' />");
487
- var tmp = obj.clone();
488
- if(_this.settings.languages.length > 0) tmp.find("a").not("." + _this.current_lang).hide();
489
- tree_component.drag_drop.drag_help.children("ul:eq(0)").append(tmp);
490
- tree_component.drag_drop.drag_help.find("li:eq(0)").removeClass("last").addClass("last");
491
- tree_component.drag_drop.isdown = true;
492
- tree_component.drag_drop.foreign = false;
493
- tree_component.drag_drop.origin_tree = _this;
494
- obj.addClass("dragged");
495
-
496
- tree_component.drag_drop.dragged = _this.container.find("li.dragged");
497
- }
498
- }
499
- tree_component.drag_drop.init_x = event.pageX;
500
- tree_component.drag_drop.init_y = event.pageY;
501
- obj.blur();
502
- event.preventDefault();
503
- event.stopPropagation();
504
- return false;
505
- });
506
- },
507
- focus : function () {
508
- if(this.locked) return false;
509
- if(tree_component.focused != this.cntr) {
510
- tree_component.focused = this.cntr;
511
- this.callback("onfocus",[this]);
512
- }
513
- },
514
-
515
- off_height : function () {
516
- if(this.offset === false) {
517
- this.container.css({ position : "relative" });
518
- this.offset = this.container.offset();
519
- var tmp = 0;
520
- tmp = parseInt($.curCSS(this.container.get(0), "paddingTop", true),10);
521
- if(tmp) this.offset.top += tmp;
522
- tmp = parseInt($.curCSS(this.container.get(0), "borderTopWidth", true),10);
523
- if(tmp) this.offset.top += tmp;
524
- this.container.css({ position : "" });
525
- }
526
- if(!this.li_height) {
527
- var tmp = this.container.find("ul li.closed, ul li.leaf").eq(0);
528
- this.li_height = tmp.height();
529
- if(tmp.children("ul:eq(0)").size()) this.li_height -= tmp.children("ul:eq(0)").height();
530
- if(!this.li_height) this.li_height = 18;
531
- }
532
- },
533
- scroll_check : function (x,y) {
534
- var _this = this;
535
- var cnt = _this.container;
536
- var off = _this.container.offset();
537
-
538
- var st = cnt.scrollTop();
539
- var sl = cnt.scrollLeft();
540
- // DETECT HORIZONTAL SCROLL
541
- var h_cor = (cnt.get(0).scrollWidth > cnt.width()) ? 40 : 20;
542
-
543
- if(y - off.top < 20) cnt.scrollTop(Math.max( (st - _this.settings.ui.scroll_spd) ,0)); // NEAR TOP
544
- if(cnt.height() - (y - off.top) < h_cor) cnt.scrollTop(st + _this.settings.ui.scroll_spd); // NEAR BOTTOM
545
- if(x - off.left < 20) cnt.scrollLeft(Math.max( (sl - _this.settings.ui.scroll_spd),0)); // NEAR LEFT
546
- if(cnt.width() - (x - off.left) < 40) cnt.scrollLeft(sl + _this.settings.ui.scroll_spd); // NEAR RIGHT
547
-
548
- if(cnt.scrollLeft() != sl || cnt.scrollTop() != st) {
549
- tree_component.drag_drop.move_type = false;
550
- tree_component.drag_drop.ref_node = false;
551
- tree_component.drag_drop.marker.hide();
552
- }
553
- tree_component.drag_drop.scroll_time = setTimeout( function() { _this.scroll_check(x,y); }, 50);
554
- },
555
- scroll_into_view : function (obj) {
556
- obj = obj ? this.get_node(obj) : this.selected;
557
- if(!obj) return false;
558
- var off_t = obj.offset().top;
559
- var beg_t = this.container.offset().top;
560
- var end_t = beg_t + this.container.height();
561
- var h_cor = (this.container.get(0).scrollWidth > this.container.width()) ? 40 : 20;
562
- if(off_t + 5 < beg_t) this.container.scrollTop(this.container.scrollTop() - (beg_t - off_t + 5) );
563
- if(off_t + h_cor > end_t) this.container.scrollTop(this.container.scrollTop() + (off_t + h_cor - end_t) );
564
- },
565
-
566
- get_node : function (obj) {
567
- return $(obj).closest("li");
568
- },
569
- get_type : function (obj) {
570
- obj = !obj ? this.selected : this.get_node(obj);
571
- if(!obj) return;
572
- var tmp = obj.attr(this.settings.rules.type_attr);
573
- return tmp || "default";
574
- },
575
- set_type : function (str, obj) {
576
- obj = !obj ? this.selected : this.get_node(obj);
577
- if(!obj || !str) return;
578
- obj.attr(this.settings.rules.type_attr, str);
579
- },
580
- get_text : function (obj, lang) {
581
- obj = this.get_node(obj);
582
- if(!obj || obj.size() == 0) return "";
583
- if(this.settings.languages && this.settings.languages.length) {
584
- lang = lang ? lang : this.current_lang;
585
- obj = obj.children("a." + lang);
586
- }
587
- else obj = obj.children("a:visible");
588
- var val = "";
589
- obj.contents().each(function () {
590
- if(this.nodeType == 3) { val = this.data; return false; }
591
- });
592
- return val;
593
- },
594
-
595
- check : function (rule, obj) {
596
- if(this.locked) return false;
597
- var v = false;
598
- // if root node
599
- if(obj === -1) { if(typeof this.settings.rules[rule] != "undefined") v = this.settings.rules[rule]; }
600
- else {
601
- obj = !obj ? this.selected : this.get_node(obj);
602
- if(!obj) return;
603
- var t = this.get_type(obj);
604
- if(typeof this.settings.types[t] != "undefined" && typeof this.settings.types[t][rule] != "undefined") v = this.settings.types[t][rule];
605
- else if(typeof this.settings.types["default"] != "undefined" && typeof this.settings.types["default"][rule] != "undefined") v = this.settings.types["default"][rule];
606
- }
607
- if(typeof v == "function") v = v.call(null, obj, this);
608
- v = this.callback("check", [rule, obj, v, this]);
609
- return v;
610
- },
611
- check_move : function (nod, ref_node, how) {
612
- if(this.locked) return false;
613
- if($(ref_node).closest("li.dragged").size()) return false;
614
-
615
- var tree1 = nod.parents(".tree:eq(0)").get(0);
616
- var tree2 = ref_node.parents(".tree:eq(0)").get(0);
617
- // if different trees
618
- if(tree1 && tree1 != tree2) {
619
- var m = $.tree.reference(tree2.id).settings.rules.multitree;
620
- if(m == "none" || ($.isArray(m) && $.inArray(tree1.id, m) == -1)) return false;
621
- }
622
-
623
- var p = (how != "inside") ? this.parent(ref_node) : this.get_node(ref_node);
624
- nod = this.get_node(nod);
625
- if(p == false) return false;
626
- var r = {
627
- max_depth : this.settings.rules.use_max_depth ? this.check("max_depth", p) : -1,
628
- max_children : this.settings.rules.use_max_children ? this.check("max_children", p) : -1,
629
- valid_children : this.check("valid_children", p)
630
- };
631
- var nod_type = (typeof nod == "string") ? nod : this.get_type(nod);
632
- if(typeof r.valid_children != "undefined" && (r.valid_children == "none" || (typeof r.valid_children == "object" && $.inArray(nod_type, $.makeArray(r.valid_children)) == -1))) return false;
633
-
634
- if(this.settings.rules.use_max_children) {
635
- if(typeof r.max_children != "undefined" && r.max_children != -1) {
636
- if(r.max_children == 0) return false;
637
- var c_count = 1;
638
- if(tree_component.drag_drop.moving == true && tree_component.drag_drop.foreign == false) {
639
- c_count = tree_component.drag_drop.dragged.size();
640
- c_count = c_count - p.find('> ul > li.dragged').size();
641
- }
642
- if(r.max_children < p.find('> ul > li').size() + c_count) return false;
643
- }
644
- }
645
-
646
- if(this.settings.rules.use_max_depth) {
647
- if(typeof r.max_depth != "undefined" && r.max_depth === 0) return this.error("MOVE: MAX-DEPTH REACHED");
648
- // check for max_depth up the chain
649
- var mx = (r.max_depth > 0) ? r.max_depth : false;
650
- var i = 0;
651
- var t = p;
652
- while(t !== -1) {
653
- t = this.parent(t);
654
- i ++;
655
- var m = this.check("max_depth",t);
656
- if(m >= 0) {
657
- mx = (mx === false) ? (m - i) : Math.min(mx, m - i);
658
- }
659
- if(mx !== false && mx <= 0) return this.error("MOVE: MAX-DEPTH REACHED");
660
- }
661
- if(mx !== false && mx <= 0) return this.error("MOVE: MAX-DEPTH REACHED");
662
- if(mx !== false) {
663
- var incr = 1;
664
- if(typeof nod != "string") {
665
- var t = nod;
666
- // possible async problem - when nodes are not all loaded down the chain
667
- while(t.size() > 0) {
668
- if(mx - incr < 0) return this.error("MOVE: MAX-DEPTH REACHED");
669
- t = t.children("ul").children("li");
670
- incr ++;
671
- }
672
- }
673
- }
674
- }
675
- if(this.callback("check_move", [nod, ref_node, how, this]) == false) return false;
676
- return true;
677
- },
678
-
679
- hover_branch : function (obj) {
680
- if(this.locked) return this.error("LOCKED");
681
- var _this = this;
682
- var obj = _this.get_node(obj);
683
- if(!obj.size()) return this.error("HOVER: NOT A VALID NODE");
684
- if(!_this.check("clickable", obj)) return this.error("SELECT: NODE NOT SELECTABLE");
685
- if(this.hovered) this.hovered.children("A").removeClass("hover");
686
- this.hovered = obj;
687
- this.hovered.children("a").addClass("hover");
688
- this.scroll_into_view(this.hovered);
689
- },
690
- select_branch : function (obj, multiple) {
691
- if(this.locked) return this.error("LOCKED");
692
- if(!obj && this.hovered !== false) obj = this.hovered;
693
- var _this = this;
694
- obj = _this.get_node(obj);
695
- if(!obj.size()) return this.error("SELECT: NOT A VALID NODE");
696
- obj.children("a").removeClass("hover");
697
- // CHECK AGAINST RULES FOR SELECTABLE NODES
698
- if(!_this.check("clickable", obj)) return this.error("SELECT: NODE NOT SELECTABLE");
699
- if(_this.callback("beforechange",[obj.get(0),_this]) === false) return this.error("SELECT: STOPPED BY USER");
700
- // IF multiple AND obj IS ALREADY SELECTED - DESELECT IT
701
- if(this.settings.rules.multiple != false && multiple && obj.children("a.clicked").size() > 0) {
702
- return this.deselect_branch(obj);
703
- }
704
- if(this.settings.rules.multiple != false && multiple) {
705
- this.selected_arr.push(obj);
706
- }
707
- if(this.settings.rules.multiple != false && !multiple) {
708
- for(var i in this.selected_arr) {
709
- if(!this.selected_arr.hasOwnProperty(i)) continue;
710
- this.selected_arr[i].children("A").removeClass("clicked");
711
- this.callback("ondeselect", [this.selected_arr[i].get(0), _this]);
712
- }
713
- this.selected_arr = [];
714
- this.selected_arr.push(obj);
715
- if(this.selected && this.selected.children("A").hasClass("clicked")) {
716
- this.selected.children("A").removeClass("clicked");
717
- this.callback("ondeselect", [this.selected.get(0), _this]);
718
- }
719
- }
720
- if(!this.settings.rules.multiple) {
721
- if(this.selected) {
722
- this.selected.children("A").removeClass("clicked");
723
- this.callback("ondeselect", [this.selected.get(0), _this]);
724
- }
725
- }
726
- // SAVE NEWLY SELECTED
727
- this.selected = obj;
728
- if(this.hovered !== false) {
729
- this.hovered.children("A").removeClass("hover");
730
- this.hovered = obj;
731
- }
732
-
733
- // FOCUS NEW NODE AND OPEN ALL PARENT NODES IF CLOSED
734
- this.selected.children("a").addClass("clicked").end().parents("li.closed").each( function () { _this.open_branch(this, true); });
735
-
736
- // SCROLL SELECTED NODE INTO VIEW
737
- this.scroll_into_view(this.selected);
738
-
739
- this.callback("onselect", [this.selected.get(0), _this]);
740
- this.callback("onchange", [this.selected.get(0), _this]);
741
- },
742
- deselect_branch : function (obj) {
743
- if(this.locked) return this.error("LOCKED");
744
- var _this = this;
745
- var obj = this.get_node(obj);
746
- if(obj.children("a.clicked").size() == 0) return this.error("DESELECT: NODE NOT SELECTED");
747
-
748
- obj.children("a").removeClass("clicked");
749
- this.callback("ondeselect", [obj.get(0), _this]);
750
- if(this.settings.rules.multiple != false && this.selected_arr.length > 1) {
751
- this.selected_arr = [];
752
- this.container.find("a.clicked").filter(":first-child").parent().each(function () {
753
- _this.selected_arr.push($(this));
754
- });
755
- if(obj.get(0) == this.selected.get(0)) {
756
- this.selected = this.selected_arr[0];
757
- }
758
- }
759
- else {
760
- if(this.settings.rules.multiple != false) this.selected_arr = [];
761
- this.selected = false;
762
- }
763
- this.callback("onchange", [obj.get(0), _this]);
764
- },
765
- toggle_branch : function (obj) {
766
- if(this.locked) return this.error("LOCKED");
767
- var obj = this.get_node(obj);
768
- if(obj.hasClass("closed")) return this.open_branch(obj);
769
- if(obj.hasClass("open")) return this.close_branch(obj);
770
- },
771
- open_branch : function (obj, disable_animation, callback) {
772
- var _this = this;
773
-
774
- if(this.locked) return this.error("LOCKED");
775
- var obj = this.get_node(obj);
776
- if(!obj.size()) return this.error("OPEN: NO SUCH NODE");
777
- if(obj.hasClass("leaf")) return this.error("OPEN: OPENING LEAF NODE");
778
- if(this.settings.data.async && obj.find("li").size() == 0) {
779
-
780
- if(this.callback("beforeopen",[obj.get(0),this]) === false) return this.error("OPEN: STOPPED BY USER");
781
-
782
- obj.children("ul:eq(0)").remove().end().append("<ul><li class='last'><a class='loading' href='#'><ins>&nbsp;</ins>" + (_this.settings.lang.loading || "Loading ...") + "</a></li></ul>");
783
- obj.removeClass("closed").addClass("open");
784
-
785
- var _datastore = new $.tree.datastores[this.settings.data.type]();
786
- _datastore.load(this.callback("beforedata",[obj,this]),this,this.settings.data.opts,function(data){
787
- data = _this.callback("ondata", [data, _this]);
788
- if(!data || data.length == 0) {
789
- obj.removeClass("closed").removeClass("open").addClass("leaf").children("ul").remove();
790
- if(callback) callback.call();
791
- return;
792
- }
793
- _datastore.parse(data,_this,_this.settings.data.opts,function(str){
794
- str = _this.callback("onparse", [str, _this]);
795
- // if(obj.children('ul:eq(0)').children('li').size() > 1) obj.children("ul").find('.loaading').parent().replaceWith(str); else
796
- obj.children("ul:eq(0)").replaceWith($("<ul>").html(str));
797
- obj.find("li:last-child").addClass("last").end().find("li:has(ul)").not(".open").addClass("closed");
798
- obj.find("li").not(".open").not(".closed").addClass("leaf");
799
- _this.open_branch.apply(_this, [obj]);
800
- if(callback) callback.call();
801
- });
802
- });
803
- return true;
804
- }
805
- else {
806
- if(!this.settings.data.async) {
807
- if(this.callback("beforeopen",[obj.get(0),this]) === false) return this.error("OPEN: STOPPED BY USER");
808
- }
809
- if(parseInt(this.settings.ui.animation) > 0 && !disable_animation ) {
810
- obj.children("ul:eq(0)").css("display","none");
811
- obj.removeClass("closed").addClass("open");
812
- obj.children("ul:eq(0)").slideDown(parseInt(this.settings.ui.animation), function() {
813
- $(this).css("display","");
814
- if(callback) callback.call();
815
- });
816
- } else {
817
- obj.removeClass("closed").addClass("open");
818
- if(callback) callback.call();
819
- }
820
- this.callback("onopen", [obj.get(0), this]);
821
- return true;
822
- }
823
- },
824
- close_branch : function (obj, disable_animation) {
825
- if(this.locked) return this.error("LOCKED");
826
- var _this = this;
827
- var obj = this.get_node(obj);
828
- if(!obj.size()) return this.error("CLOSE: NO SUCH NODE");
829
- if(_this.callback("beforeclose",[obj.get(0),_this]) === false) return this.error("CLOSE: STOPPED BY USER");
830
- if(parseInt(this.settings.ui.animation) > 0 && !disable_animation && obj.children("ul:eq(0)").size() == 1) {
831
- obj.children("ul:eq(0)").slideUp(parseInt(this.settings.ui.animation), function() {
832
- if(obj.hasClass("open")) obj.removeClass("open").addClass("closed");
833
- $(this).css("display","");
834
- });
835
- }
836
- else {
837
- if(obj.hasClass("open")) obj.removeClass("open").addClass("closed");
838
- }
839
- if(this.selected && this.settings.ui.selected_parent_close !== false && obj.children("ul:eq(0)").find("a.clicked").size() > 0) {
840
- obj.find("li:has(a.clicked)").each(function() {
841
- _this.deselect_branch(this);
842
- });
843
- if(this.settings.ui.selected_parent_close == "select_parent" && obj.children("a.clicked").size() == 0) this.select_branch(obj, (this.settings.rules.multiple != false && this.selected_arr.length > 0) );
844
- }
845
- this.callback("onclose", [obj.get(0), this]);
846
- },
847
- open_all : function (obj, callback) {
848
- if(this.locked) return this.error("LOCKED");
849
- var _this = this;
850
- obj = obj ? this.get_node(obj) : this.container;
851
-
852
- var s = obj.find("li.closed").size();
853
- if(!callback) this.cl_count = 0;
854
- else this.cl_count --;
855
- if(s > 0) {
856
- this.cl_count += s;
857
- // maybe add .andSelf()
858
- obj.find("li.closed").each( function () { var __this = this; _this.open_branch.apply(_this, [this, true, function() { _this.open_all.apply(_this, [__this, true]); } ]); });
859
- }
860
- else if(this.cl_count == 0) this.callback("onopen_all",[this]);
861
- },
862
- close_all : function (obj) {
863
- if(this.locked) return this.error("LOCKED");
864
- var _this = this;
865
- obj = obj ? this.get_node(obj) : this.container;
866
- // maybe add .andSelf()
867
- obj.find("li.open").each( function () { _this.close_branch(this, true); });
868
- this.callback("onclose_all",[this]);
869
- },
870
-
871
- set_lang : function (i) {
872
- if(!$.isArray(this.settings.languages) || this.settings.languages.length == 0) return false;
873
- if(this.locked) return this.error("LOCKED");
874
- if(!$.inArray(i,this.settings.languages) && typeof this.settings.languages[i] != "undefined") i = this.settings.languages[i];
875
- if(typeof i == "undefined") return false;
876
- if(i == this.current_lang) return true;
877
- var st = false;
878
- var id = "#" + this.container.attr("id");
879
- st = tree_component.get_css(id + " ." + this.current_lang);
880
- if(st !== false) st.style.display = "none";
881
- st = tree_component.get_css(id + " ." + i);
882
- if(st !== false) st.style.display = "";
883
- this.current_lang = i;
884
- return true;
885
- },
886
- get_lang : function () {
887
- if(!$.isArray(this.settings.languages) || this.settings.languages.length == 0) return false;
888
- return this.current_lang;
889
- },
890
-
891
- create : function (obj, ref_node, position) {
892
- if(this.locked) return this.error("LOCKED");
893
-
894
- var root = false;
895
- if(ref_node == -1) { root = true; ref_node = this.container; }
896
- else ref_node = ref_node ? this.get_node(ref_node) : this.selected;
897
-
898
- if(!root && (!ref_node || !ref_node.size())) return this.error("CREATE: NO NODE SELECTED");
899
-
900
- var pos = position;
901
-
902
- var tmp = ref_node; // for type calculation
903
- if(position == "before") {
904
- position = ref_node.parent().children().index(ref_node);
905
- ref_node = ref_node.parents("li:eq(0)");
906
- }
907
- if(position == "after") {
908
- position = ref_node.parent().children().index(ref_node) + 1;
909
- ref_node = ref_node.parents("li:eq(0)");
910
- }
911
- if(!root && ref_node.size() == 0) { root = true; ref_node = this.container; }
912
-
913
- if(!root) {
914
- if(!this.check("creatable", ref_node)) return this.error("CREATE: CANNOT CREATE IN NODE");
915
- if(ref_node.hasClass("closed")) {
916
- if(this.settings.data.async && ref_node.children("ul").size() == 0) {
917
- var _this = this;
918
- return this.open_branch(ref_node, true, function () { _this.create.apply(_this, [obj, ref_node, position]); } );
919
- }
920
- else this.open_branch(ref_node, true);
921
- }
922
- }
923
-
924
- // creating new object to pass to parseJSON
925
- var torename = false;
926
- if(!obj) obj = {};
927
- else obj = $.extend(true, {}, obj);
928
- if(!obj.attributes) obj.attributes = {};
929
- if(!obj.attributes[this.settings.rules.type_attr]) obj.attributes[this.settings.rules.type_attr] = this.get_type(tmp) || "default";
930
- if(this.settings.languages.length) {
931
- if(!obj.data) { obj.data = {}; torename = true; }
932
- for(var i = 0; i < this.settings.languages.length; i++) {
933
- if(!obj.data[this.settings.languages[i]]) obj.data[this.settings.languages[i]] = ((typeof this.settings.lang.new_node).toLowerCase() != "string" && this.settings.lang.new_node[i]) ? this.settings.lang.new_node[i] : this.settings.lang.new_node;
934
- }
935
- }
936
- else {
937
- if(!obj.data) { obj.data = this.settings.lang.new_node; torename = true; }
938
- }
939
-
940
- obj = this.callback("ondata",[obj, this]);
941
- var obj_s = $.tree.datastores.json().parse(obj,this);
942
- obj_s = this.callback("onparse", [obj_s, this]);
943
- var $li = $(obj_s);
944
-
945
- if($li.children("ul").size()) {
946
- if(!$li.is(".open")) $li.addClass("closed");
947
- }
948
- else $li.addClass("leaf");
949
- $li.find("li:last-child").addClass("last").end().find("li:has(ul)").not(".open").addClass("closed");
950
- $li.find("li").not(".open").not(".closed").addClass("leaf");
951
-
952
- var r = {
953
- max_depth : this.settings.rules.use_max_depth ? this.check("max_depth", (root ? -1 : ref_node) ) : -1,
954
- max_children : this.settings.rules.use_max_children ? this.check("max_children", (root ? -1 : ref_node) ) : -1,
955
- valid_children : this.check("valid_children", (root ? -1 : ref_node) )
956
- };
957
- var nod_type = this.get_type($li);
958
- if(typeof r.valid_children != "undefined" && (r.valid_children == "none" || ($.isArray(r.valid_children) && $.inArray(nod_type, r.valid_children) == -1))) return this.error("CREATE: NODE NOT A VALID CHILD");
959
-
960
- if(this.settings.rules.use_max_children) {
961
- if(typeof r.max_children != "undefined" && r.max_children != -1 && r.max_children >= this.children(ref_node).size()) return this.error("CREATE: MAX_CHILDREN REACHED");
962
- }
963
-
964
- if(this.settings.rules.use_max_depth) {
965
- if(typeof r.max_depth != "undefined" && r.max_depth === 0) return this.error("CREATE: MAX-DEPTH REACHED");
966
- // check for max_depth up the chain
967
- var mx = (r.max_depth > 0) ? r.max_depth : false;
968
- var i = 0;
969
- var t = ref_node;
970
-
971
- while(t !== -1 && !root) {
972
- t = this.parent(t);
973
- i ++;
974
- var m = this.check("max_depth",t);
975
- if(m >= 0) {
976
- mx = (mx === false) ? (m - i) : Math.min(mx, m - i);
977
- }
978
- if(mx !== false && mx <= 0) return this.error("CREATE: MAX-DEPTH REACHED");
979
- }
980
- if(mx !== false && mx <= 0) return this.error("CREATE: MAX-DEPTH REACHED");
981
- if(mx !== false) {
982
- var incr = 1;
983
- var t = $li;
984
- while(t.size() > 0) {
985
- if(mx - incr < 0) return this.error("CREATE: MAX-DEPTH REACHED");
986
- t = t.children("ul").children("li");
987
- incr ++;
988
- }
989
- }
990
- }
991
-
992
- if((typeof position).toLowerCase() == "undefined" || position == "inside")
993
- position = (this.settings.rules.createat == "top") ? 0 : ref_node.children("ul:eq(0)").children("li").size();
994
- if(ref_node.children("ul").size() == 0 || (root == true && ref_node.children("ul").children("li").size() == 0) ) {
995
- if(!root) var a = this.moved($li,ref_node.children("a:eq(0)"),"inside", true);
996
- else var a = this.moved($li,this.container.children("ul:eq(0)"),"inside", true);
997
- }
998
- else if(pos == "before" && ref_node.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
999
- var a = this.moved($li,ref_node.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before", true);
1000
- else if(pos == "after" && ref_node.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").size())
1001
- var a = this.moved($li,ref_node.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").children("a:eq(0)"),"after", true);
1002
- else if(ref_node.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
1003
- var a = this.moved($li,ref_node.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before", true);
1004
- else
1005
- var a = this.moved($li,ref_node.children("ul:eq(0)").children("li:last").children("a:eq(0)"),"after",true);
1006
-
1007
- if(a === false) return this.error("CREATE: ABORTED");
1008
-
1009
- if(torename) {
1010
- this.select_branch($li.children("a:eq(0)"));
1011
- this.rename();
1012
- }
1013
- return $li;
1014
- },
1015
- rename : function (obj, new_name) {
1016
- if(this.locked) return this.error("LOCKED");
1017
- obj = obj ? this.get_node(obj) : this.selected;
1018
- var _this = this;
1019
- if(!obj || !obj.size()) return this.error("RENAME: NO NODE SELECTED");
1020
- if(!this.check("renameable", obj)) return this.error("RENAME: NODE NOT RENAMABLE");
1021
- if(!this.callback("beforerename",[obj.get(0), _this.current_lang, _this])) return this.error("RENAME: STOPPED BY USER");
1022
-
1023
- obj.parents("li.closed").each(function () { _this.open_branch(this) });
1024
- if(this.current_lang) obj = obj.find("a." + this.current_lang);
1025
- else obj = obj.find("a:first");
1026
-
1027
- // Rollback
1028
- var rb = {};
1029
- rb[this.container.attr("id")] = this.get_rollback();
1030
-
1031
- var icn = obj.children("ins").clone();
1032
- if((typeof new_name).toLowerCase() == "string") {
1033
- obj.text(new_name).prepend(icn);
1034
- _this.callback("onrename", [_this.get_node(obj).get(0), _this, rb]);
1035
- }
1036
- else {
1037
- var last_value = "";
1038
- obj.contents().each(function () {
1039
- if(this.nodeType == 3) { last_value = this.data; return false; }
1040
- });
1041
- _this.inp = $("<input type='text' autocomplete='off' />");
1042
- _this.inp
1043
- .val(last_value.replace(/&amp;/g,"&").replace(/&gt;/g,">").replace(/&lt;/g,"<"))
1044
- .bind("mousedown", function (event) { event.stopPropagation(); })
1045
- .bind("mouseup", function (event) { event.stopPropagation(); })
1046
- .bind("click", function (event) { event.stopPropagation(); })
1047
- .bind("keyup", function (event) {
1048
- var key = event.keyCode || event.which;
1049
- if(key == 27) { this.value = last_value; this.blur(); return }
1050
- if(key == 13) { this.blur(); return; }
1051
- });
1052
- _this.inp.blur(function(event) {
1053
- if(this.value == "") this.value = last_value;
1054
- obj.text(this.value).prepend(icn);
1055
- obj.get(0).style.display = "";
1056
- obj.prevAll("span").remove();
1057
- _this.inp = false;
1058
- _this.callback("onrename", [_this.get_node(obj).get(0), _this, rb]);
1059
- });
1060
-
1061
- var spn = $("<span />").addClass(obj.attr("class")).append(icn).append(_this.inp);
1062
- obj.get(0).style.display = "none";
1063
- obj.parent().prepend(spn);
1064
- _this.inp.get(0).focus();
1065
- _this.inp.get(0).select();
1066
- }
1067
- },
1068
- remove : function(obj) {
1069
- if(this.locked) return this.error("LOCKED");
1070
- var _this = this;
1071
-
1072
- // Rollback
1073
- var rb = {};
1074
- rb[this.container.attr("id")] = this.get_rollback();
1075
-
1076
- if(obj && (!this.selected || this.get_node(obj).get(0) != this.selected.get(0) )) {
1077
- obj = this.get_node(obj);
1078
- if(obj.size()) {
1079
- if(!this.check("deletable", obj)) return this.error("DELETE: NODE NOT DELETABLE");
1080
- if(!this.callback("beforedelete",[obj.get(0), _this])) return this.error("DELETE: STOPPED BY USER");
1081
- $parent = obj.parent();
1082
- if(obj.find("a.clicked").size()) {
1083
- var reset_selected = false;
1084
- _this.selected_arr = [];
1085
- this.container.find("a.clicked").filter(":first-child").parent().each(function () {
1086
- if(!reset_selected && this == _this.selected.get(0)) reset_selected = true;
1087
- if($(this).parents().index(obj) != -1) return true;
1088
- _this.selected_arr.push($(this));
1089
- });
1090
- if(reset_selected) this.selected = this.selected_arr[0] || false;
1091
- }
1092
- obj = obj.remove();
1093
- $parent.children("li:last").addClass("last");
1094
- if($parent.children("li").size() == 0) {
1095
- $li = $parent.parents("li:eq(0)");
1096
- $li.removeClass("open").removeClass("closed").addClass("leaf").children("ul").remove();
1097
- }
1098
- this.callback("ondelete", [obj.get(0), this, rb]);
1099
- }
1100
- }
1101
- else if(this.selected) {
1102
- if(!this.check("deletable", this.selected)) return this.error("DELETE: NODE NOT DELETABLE");
1103
- if(!this.callback("beforedelete",[this.selected.get(0), _this])) return this.error("DELETE: STOPPED BY USER");
1104
- $parent = this.selected.parent();
1105
- var obj = this.selected;
1106
- if(this.settings.rules.multiple == false || this.selected_arr.length == 1) {
1107
- var stop = true;
1108
- var tmp = this.settings.ui.selected_delete == "select_previous" ? this.prev(this.selected) : false;
1109
- }
1110
- obj = obj.remove();
1111
- $parent.children("li:last").addClass("last");
1112
- if($parent.children("li").size() == 0) {
1113
- $li = $parent.parents("li:eq(0)");
1114
- $li.removeClass("open").removeClass("closed").addClass("leaf").children("ul").remove();
1115
- }
1116
- if(!stop && this.settings.rules.multiple != false) {
1117
- var _this = this;
1118
- this.selected_arr = [];
1119
- this.container.find("a.clicked").filter(":first-child").parent().each(function () {
1120
- _this.selected_arr.push($(this));
1121
- });
1122
- if(this.selected_arr.length > 0) {
1123
- this.selected = this.selected_arr[0];
1124
- this.remove();
1125
- }
1126
- }
1127
- if(stop && tmp) this.select_branch(tmp);
1128
- this.callback("ondelete", [obj.get(0), this, rb]);
1129
- }
1130
- else return this.error("DELETE: NO NODE SELECTED");
1131
- },
1132
-
1133
- next : function (obj, strict) {
1134
- obj = this.get_node(obj);
1135
- if(!obj.size()) return false;
1136
- if(strict) return (obj.nextAll("li").size() > 0) ? obj.nextAll("li:eq(0)") : false;
1137
-
1138
- if(obj.hasClass("open")) return obj.find("li:eq(0)");
1139
- else if(obj.nextAll("li").size() > 0) return obj.nextAll("li:eq(0)");
1140
- else return obj.parents("li").next("li").eq(0);
1141
- },
1142
- prev : function(obj, strict) {
1143
- obj = this.get_node(obj);
1144
- if(!obj.size()) return false;
1145
- if(strict) return (obj.prevAll("li").size() > 0) ? obj.prevAll("li:eq(0)") : false;
1146
-
1147
- if(obj.prev("li").size()) {
1148
- var obj = obj.prev("li").eq(0);
1149
- while(obj.hasClass("open")) obj = obj.children("ul:eq(0)").children("li:last");
1150
- return obj;
1151
- }
1152
- else return obj.parents("li:eq(0)").size() ? obj.parents("li:eq(0)") : false;
1153
- },
1154
- parent : function(obj) {
1155
- obj = this.get_node(obj);
1156
- if(!obj.size()) return false;
1157
- return obj.parents("li:eq(0)").size() ? obj.parents("li:eq(0)") : -1;
1158
- },
1159
- children : function(obj) {
1160
- if(obj === -1) return this.container.children("ul:eq(0)").children("li");
1161
-
1162
- obj = this.get_node(obj);
1163
- if(!obj.size()) return false;
1164
- return obj.children("ul:eq(0)").children("li");
1165
- },
1166
-
1167
- toggle_dots : function () {
1168
- if(this.settings.ui.dots) {
1169
- this.settings.ui.dots = false;
1170
- this.container.children("ul:eq(0)").addClass("no_dots");
1171
- }
1172
- else {
1173
- this.settings.ui.dots = true;
1174
- this.container.children("ul:eq(0)").removeClass("no_dots");
1175
- }
1176
- },
1177
-
1178
- callback : function (cb, args) {
1179
- var p = false;
1180
- var r = null;
1181
- for(var i in this.settings.plugins) {
1182
- if(typeof $.tree.plugins[i] != "object") continue;
1183
- p = $.tree.plugins[i];
1184
- if(p.callbacks && typeof p.callbacks[cb] == "function") r = p.callbacks[cb].apply(this, args);
1185
- if(typeof r !== "undefined" && r !== null) {
1186
- if(cb == "ondata" || cb == "onparse") args[0] = r; // keep the chain if data or parse
1187
- else return r;
1188
- }
1189
- }
1190
- p = this.settings.callback[cb];
1191
- if(typeof p == "function") return p.apply(null, args);
1192
- },
1193
- get_rollback : function () {
1194
- var rb = {};
1195
- rb.html = this.container.html();
1196
- rb.selected = this.selected ? this.selected.attr("id") : false;
1197
- return rb;
1198
- },
1199
- moved : function (what, where, how, is_new, is_copy, rb) {
1200
- var what = $(what);
1201
- var $parent = $(what).parents("ul:eq(0)");
1202
- var $where = $(where);
1203
- if($where.is("ins")) $where = $where.parent();
1204
-
1205
- // Rollback
1206
- if(!rb) {
1207
- var rb = {};
1208
- rb[this.container.attr("id")] = this.get_rollback();
1209
- if(!is_new) {
1210
- var tmp = what.size() > 1 ? what.eq(0).parents(".tree:eq(0)") : what.parents(".tree:eq(0)");
1211
- if(tmp.get(0) != this.container.get(0)) {
1212
- tmp = tree_component.inst[tmp.attr("id")];
1213
- rb[tmp.container.attr("id")] = tmp.get_rollback();
1214
- }
1215
- delete tmp;
1216
- }
1217
- }
1218
-
1219
- if(how == "inside" && this.settings.data.async) {
1220
- var _this = this;
1221
- if(this.get_node($where).hasClass("closed")) {
1222
- return this.open_branch(this.get_node($where), true, function () { _this.moved.apply(_this, [what, where, how, is_new, is_copy, rb]); });
1223
- }
1224
- if(this.get_node($where).find("> ul > li > a.loading").size() == 1) {
1225
- setTimeout(function () { _this.moved.apply(_this, [what, where, how, is_new, is_copy]); }, 200);
1226
- return;
1227
- }
1228
- }
1229
-
1230
-
1231
- // IF MULTIPLE
1232
- if(what.size() > 1) {
1233
- var _this = this;
1234
- var tmp = this.moved(what.eq(0), where, how, false, is_copy, rb);
1235
- what.each(function (i) {
1236
- if(i == 0) return;
1237
- if(tmp) { // if tmp is false - the previous move was a no-go
1238
- tmp = _this.moved(this, tmp.children("a:eq(0)"), "after", false, is_copy, rb);
1239
- }
1240
- });
1241
- return what;
1242
- }
1243
-
1244
- if(is_copy) {
1245
- _what = what.clone();
1246
- _what.each(function (i) {
1247
- this.id = this.id + "_copy";
1248
- $(this).find("li").each(function () {
1249
- this.id = this.id + "_copy";
1250
- });
1251
- $(this).removeClass("dragged").find("a.clicked").removeClass("clicked").end().find("li.dragged").removeClass("dragged");
1252
- });
1253
- }
1254
- else _what = what;
1255
- if(is_new) {
1256
- if(!this.callback("beforecreate", [this.get_node(what).get(0), this.get_node(where).get(0),how,this])) return false;
1257
- }
1258
- else {
1259
- if(!this.callback("beforemove", [this.get_node(what).get(0), this.get_node(where).get(0),how,this])) return false;
1260
- }
1261
-
1262
- if(!is_new) {
1263
- var tmp = what.parents(".tree:eq(0)");
1264
- // if different trees
1265
- if(tmp.get(0) != this.container.get(0)) {
1266
- tmp = tree_component.inst[tmp.attr("id")];
1267
-
1268
- // if there are languages - otherwise - no cleanup needed
1269
- if(tmp.settings.languages.length) {
1270
- var res = [];
1271
- // if new tree has no languages - use current visible
1272
- if(this.settings.languages.length == 0) res.push("." + tmp.current_lang);
1273
- else {
1274
- for(var i in this.settings.languages) {
1275
- if(!this.settings.languages.hasOwnProperty(i)) continue;
1276
- for(var j in tmp.settings.languages) {
1277
- if(!tmp.settings.languages.hasOwnProperty(j)) continue;
1278
- if(this.settings.languages[i] == tmp.settings.languages[j]) res.push("." + this.settings.languages[i]);
1279
- }
1280
- }
1281
- }
1282
- if(res.length == 0) return this.error("MOVE: NO COMMON LANGUAGES");
1283
- _what.find("a").not(res.join(",")).remove();
1284
- }
1285
- _what.find("a.clicked").removeClass("clicked");
1286
- }
1287
- }
1288
- what = _what;
1289
-
1290
- // ADD NODE TO NEW PLACE
1291
- switch(how) {
1292
- case "before":
1293
- $where.parents("ul:eq(0)").children("li.last").removeClass("last");
1294
- $where.parent().before(what.removeClass("last"));
1295
- $where.parents("ul:eq(0)").children("li:last").addClass("last");
1296
- break;
1297
- case "after":
1298
- $where.parents("ul:eq(0)").children("li.last").removeClass("last");
1299
- $where.parent().after(what.removeClass("last"));
1300
- $where.parents("ul:eq(0)").children("li:last").addClass("last");
1301
- break;
1302
- case "inside":
1303
- if($where.parent().children("ul:first").size()) {
1304
- if(this.settings.rules.createat == "top") {
1305
- $where.parent().children("ul:first").prepend(what.removeClass("last")).children("li:last").addClass("last");
1306
-
1307
- // restored this section
1308
- var tmp_node = $where.parent().children("ul:first").children("li:first");
1309
- if(tmp_node.size()) {
1310
- how = "before";
1311
- where = tmp_node;
1312
- }
1313
- }
1314
- else {
1315
- // restored this section
1316
- var tmp_node = $where.parent().children("ul:first").children(".last");
1317
- if(tmp_node.size()) {
1318
- how = "after";
1319
- where = tmp_node;
1320
- }
1321
-
1322
- $where.parent().children("ul:first").children(".last").removeClass("last").end().append(what.removeClass("last")).children("li:last").addClass("last");
1323
- }
1324
- }
1325
- else {
1326
- what.addClass("last");
1327
- $where.parent().removeClass("leaf").append("<ul/>");
1328
- if(!$where.parent().hasClass("open")) $where.parent().addClass("closed");
1329
- $where.parent().children("ul:first").prepend(what);
1330
- }
1331
- if($where.parent().hasClass("closed")) { this.open_branch($where); }
1332
- break;
1333
- default:
1334
- break;
1335
- }
1336
- // CLEANUP OLD PARENT
1337
- if($parent.find("li").size() == 0) {
1338
- var $li = $parent.parent();
1339
- $li.removeClass("open").removeClass("closed").addClass("leaf");
1340
- if(!$li.is(".tree")) $li.children("ul").remove();
1341
- $li.parents("ul:eq(0)").children("li.last").removeClass("last").end().children("li:last").addClass("last");
1342
- }
1343
- else {
1344
- $parent.children("li.last").removeClass("last");
1345
- $parent.children("li:last").addClass("last");
1346
- }
1347
-
1348
- // NO LONGER CORRECT WITH position PARAM - if(is_new && how != "inside") where = this.get_node(where).parents("li:eq(0)");
1349
- if(is_copy) this.callback("oncopy", [this.get_node(what).get(0), this.get_node(where).get(0), how, this, rb]);
1350
- else if(is_new) this.callback("oncreate", [this.get_node(what).get(0), ($where.is("ul") ? -1 : this.get_node(where).get(0) ), how, this, rb]);
1351
- else this.callback("onmove", [this.get_node(what).get(0), this.get_node(where).get(0), how, this, rb]);
1352
- return what;
1353
- },
1354
- error : function (code) {
1355
- this.callback("error",[code,this]);
1356
- return false;
1357
- },
1358
- lock : function (state) {
1359
- this.locked = state;
1360
- if(this.locked) this.container.children("ul:eq(0)").addClass("locked");
1361
- else this.container.children("ul:eq(0)").removeClass("locked");
1362
- },
1363
- cut : function (obj) {
1364
- if(this.locked) return this.error("LOCKED");
1365
- obj = obj ? this.get_node(obj) : this.container.find("a.clicked").filter(":first-child").parent();
1366
- if(!obj || !obj.size()) return this.error("CUT: NO NODE SELECTED");
1367
- tree_component.cut_copy.copy_nodes = false;
1368
- tree_component.cut_copy.cut_nodes = obj;
1369
- },
1370
- copy : function (obj) {
1371
- if(this.locked) return this.error("LOCKED");
1372
- obj = obj ? this.get_node(obj) : this.container.find("a.clicked").filter(":first-child").parent();
1373
- if(!obj || !obj.size()) return this.error("COPY: NO NODE SELECTED");
1374
- tree_component.cut_copy.copy_nodes = obj;
1375
- tree_component.cut_copy.cut_nodes = false;
1376
- },
1377
- paste : function (obj, position) {
1378
- if(this.locked) return this.error("LOCKED");
1379
-
1380
- var root = false;
1381
- if(obj == -1) { root = true; obj = this.container; }
1382
- else obj = obj ? this.get_node(obj) : this.selected;
1383
-
1384
- if(!root && (!obj || !obj.size())) return this.error("PASTE: NO NODE SELECTED");
1385
- if(!tree_component.cut_copy.copy_nodes && !tree_component.cut_copy.cut_nodes) return this.error("PASTE: NOTHING TO DO");
1386
-
1387
- var _this = this;
1388
-
1389
- var pos = position;
1390
-
1391
- if(position == "before") {
1392
- position = obj.parent().children().index(obj);
1393
- obj = obj.parents("li:eq(0)");
1394
- }
1395
- else if(position == "after") {
1396
- position = obj.parent().children().index(obj) + 1;
1397
- obj = obj.parents("li:eq(0)");
1398
- }
1399
- else if((typeof position).toLowerCase() == "undefined" || position == "inside") {
1400
- position = (this.settings.rules.createat == "top") ? 0 : obj.children("ul:eq(0)").children("li").size();
1401
- }
1402
- if(!root && obj.size() == 0) { root = true; obj = this.container; }
1403
-
1404
- if(tree_component.cut_copy.copy_nodes && tree_component.cut_copy.copy_nodes.size()) {
1405
- var ok = true;
1406
- if(!root && !this.check_move(tree_component.cut_copy.copy_nodes, obj.children("a:eq(0)"), "inside")) return false;
1407
-
1408
- if(obj.children("ul").size() == 0 || (root == true && obj.children("ul").children("li").size() == 0) ) {
1409
- if(!root) var a = this.moved(tree_component.cut_copy.copy_nodes,obj.children("a:eq(0)"),"inside", false, true);
1410
- else var a = this.moved(tree_component.cut_copy.copy_nodes,this.container.children("ul:eq(0)"),"inside", false, true);
1411
- }
1412
- else if(pos == "before" && obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
1413
- var a = this.moved(tree_component.cut_copy.copy_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before", false, true);
1414
- else if(pos == "after" && obj.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").size())
1415
- var a = this.moved(tree_component.cut_copy.copy_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").children("a:eq(0)"),"after", false, true);
1416
- else if(obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
1417
- var a = this.moved(tree_component.cut_copy.copy_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before", false, true);
1418
- else
1419
- var a = this.moved(tree_component.cut_copy.copy_nodes,obj.children("ul:eq(0)").children("li:last").children("a:eq(0)"),"after", false, true);
1420
- tree_component.cut_copy.copy_nodes = false;
1421
- }
1422
- if(tree_component.cut_copy.cut_nodes && tree_component.cut_copy.cut_nodes.size()) {
1423
- var ok = true;
1424
- obj.parents().andSelf().each(function () {
1425
- if(tree_component.cut_copy.cut_nodes.index(this) != -1) {
1426
- ok = false;
1427
- return false;
1428
- }
1429
- });
1430
- if(!ok) return this.error("Invalid paste");
1431
- if(!root && !this.check_move(tree_component.cut_copy.cut_nodes, obj.children("a:eq(0)"), "inside")) return false;
1432
-
1433
- if(obj.children("ul").size() == 0 || (root == true && obj.children("ul").children("li").size() == 0) ) {
1434
- if(!root) var a = this.moved(tree_component.cut_copy.cut_nodes,obj.children("a:eq(0)"),"inside");
1435
- else var a = this.moved(tree_component.cut_copy.cut_nodes,this.container.children("ul:eq(0)"),"inside");
1436
- }
1437
- else if(pos == "before" && obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
1438
- var a = this.moved(tree_component.cut_copy.cut_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before");
1439
- else if(pos == "after" && obj.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").size())
1440
- var a = this.moved(tree_component.cut_copy.cut_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").children("a:eq(0)"),"after");
1441
- else if(obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
1442
- var a = this.moved(tree_component.cut_copy.cut_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before");
1443
- else
1444
- var a = this.moved(tree_component.cut_copy.cut_nodes,obj.children("ul:eq(0)").children("li:last").children("a:eq(0)"),"after");
1445
- tree_component.cut_copy.cut_nodes = false;
1446
- }
1447
- },
1448
- search : function(str, func) {
1449
- var _this = this;
1450
- if(!str || (this.srch && str != this.srch) ) {
1451
- this.srch = "";
1452
- this.srch_opn = false;
1453
- this.container.find("a.search").removeClass("search");
1454
- }
1455
- this.srch = str;
1456
- if(!str) return;
1457
-
1458
- if(!func) func = "contains";
1459
- if(this.settings.data.async) {
1460
- if(!this.srch_opn) {
1461
- var dd = $.extend( { "search" : str } , this.callback("beforedata", [false, this] ) );
1462
- $.ajax({
1463
- type : this.settings.data.opts.method,
1464
- url : this.settings.data.opts.url,
1465
- data : dd,
1466
- dataType : "text",
1467
- success : function (data) {
1468
- _this.srch_opn = $.unique(data.split(","));
1469
- _this.search.apply(_this,[str, func]);
1470
- }
1471
- });
1472
- }
1473
- else if(this.srch_opn.length) {
1474
- if(this.srch_opn && this.srch_opn.length) {
1475
- var opn = false;
1476
- for(var j = 0; j < this.srch_opn.length; j++) {
1477
- if(this.get_node("#" + this.srch_opn[j]).size() > 0) {
1478
- opn = true;
1479
- var tmp = "#" + this.srch_opn[j];
1480
- delete this.srch_opn[j];
1481
- this.open_branch(tmp, true, function () { _this.search.apply(_this,[str, func]); } );
1482
- }
1483
- }
1484
- if(!opn) {
1485
- this.srch_opn = [];
1486
- _this.search.apply(_this,[str, func]);
1487
- }
1488
- }
1489
- }
1490
- else {
1491
- this.srch_opn = false;
1492
- var selector = "a";
1493
- // IF LANGUAGE VERSIONS
1494
- if(this.settings.languages.length) selector += "." + this.current_lang;
1495
- this.callback("onsearch", [this.container.find(selector + ":" + func + "('" + str + "')"), this]);
1496
- }
1497
- }
1498
- else {
1499
- var selector = "a";
1500
- // IF LANGUAGE VERSIONS
1501
- if(this.settings.languages.length) selector += "." + this.current_lang;
1502
- var nn = this.container.find(selector + ":" + func + "('" + str + "')");
1503
- nn.parents("li.closed").each( function () { _this.open_branch(this, true); });
1504
- this.callback("onsearch", [nn, this]);
1505
- }
1506
- },
1507
- add_sheet : tree_component.add_sheet,
1508
-
1509
- destroy : function() {
1510
- this.callback("ondestroy", [this]);
1511
-
1512
- this.container.unbind(".jstree");
1513
- $("#" + this.container.attr("id")).die("click.jstree").die("dblclick.jstree").die("mouseover.jstree").die("mouseout.jstree").die("mousedown.jstree");
1514
- this.container.removeClass("tree ui-widget ui-widget-content tree-default tree-" + this.settings.ui.theme_name).children("ul").removeClass("no_dots ltr locked").find("li").removeClass("leaf").removeClass("open").removeClass("closed").removeClass("last").children("a").removeClass("clicked hover search");
1515
-
1516
- if(this.cntr == tree_component.focused) {
1517
- for(var i in tree_component.inst) {
1518
- if(i != this.cntr && i != this.container.attr("id")) {
1519
- tree_component.inst[i].focus();
1520
- break;
1521
- }
1522
- }
1523
- }
1524
-
1525
- tree_component.inst[this.cntr] = false;
1526
- tree_component.inst[this.container.attr("id")] = false;
1527
- delete tree_component.inst[this.cntr];
1528
- delete tree_component.inst[this.container.attr("id")];
1529
- tree_component.cntr --;
1530
- }
1531
- }
1532
- };
1533
-
1534
- // instance manager
1535
- tree_component.cntr = 0;
1536
- tree_component.inst = {};
1537
-
1538
- // themes
1539
- tree_component.themes = [];
1540
-
1541
- // drag'n'drop stuff
1542
- tree_component.drag_drop = {
1543
- isdown : false, // Is there a drag
1544
- drag_node : false, // The actual node
1545
- drag_help : false, // The helper
1546
- dragged : false,
1547
-
1548
- init_x : false,
1549
- init_y : false,
1550
- moving : false,
1551
-
1552
- origin_tree : false,
1553
- marker : false,
1554
-
1555
- move_type : false, // before, after or inside
1556
- ref_node : false, // reference node
1557
- appended : false, // is helper appended
1558
-
1559
- foreign : false, // Is the dragged node a foreign one
1560
- droppable : [], // Array of classes that can be dropped onto the tree
1561
-
1562
- open_time : false, // Timeout for opening nodes
1563
- scroll_time : false // Timeout for scrolling
1564
- };
1565
- tree_component.mouseup = function(event) {
1566
- var tmp = tree_component.drag_drop;
1567
- if(tmp.open_time) clearTimeout(tmp.open_time);
1568
- if(tmp.scroll_time) clearTimeout(tmp.scroll_time);
1569
-
1570
- if(tmp.moving && $.tree.drag_end !== false) $.tree.drag_end.call(null, event, tmp);
1571
-
1572
- if(tmp.foreign === false && tmp.drag_node && tmp.drag_node.size()) {
1573
- tmp.drag_help.remove();
1574
- if(tmp.move_type) {
1575
- var tree1 = tree_component.inst[tmp.ref_node.parents(".tree:eq(0)").attr("id")];
1576
- if(tree1) tree1.moved(tmp.dragged, tmp.ref_node, tmp.move_type, false, (tmp.origin_tree.settings.rules.drag_copy == "on" || (tmp.origin_tree.settings.rules.drag_copy == "ctrl" && event.ctrlKey) ) );
1577
- }
1578
- tmp.move_type = false;
1579
- tmp.ref_node = false;
1580
- }
1581
- if(tmp.foreign !== false) {
1582
- if(tmp.drag_help) tmp.drag_help.remove();
1583
- if(tmp.move_type) {
1584
- var tree1 = tree_component.inst[tmp.ref_node.parents(".tree:eq(0)").attr("id")];
1585
- if(tree1) tree1.callback("ondrop",[tmp.f_data, tree1.get_node(tmp.ref_node).get(0), tmp.move_type, tree1]);
1586
- }
1587
- tmp.foreign = false;
1588
- tmp.move_type = false;
1589
- tmp.ref_node = false;
1590
- }
1591
- // RESET EVERYTHING
1592
- if(tree_component.drag_drop.marker) tree_component.drag_drop.marker.hide();
1593
- if(tmp.dragged && tmp.dragged.size()) tmp.dragged.removeClass("dragged");
1594
- tmp.dragged = false;
1595
- tmp.drag_help = false;
1596
- tmp.drag_node = false;
1597
- tmp.f_type = false;
1598
- tmp.f_data = false;
1599
- tmp.init_x = false;
1600
- tmp.init_y = false;
1601
- tmp.moving = false;
1602
- tmp.appended = false;
1603
- tmp.origin_tree = false;
1604
- if(tmp.isdown) {
1605
- tmp.isdown = false;
1606
- event.preventDefault();
1607
- event.stopPropagation();
1608
- return false;
1609
- }
1610
- };
1611
- tree_component.mousemove = function(event) {
1612
- var tmp = tree_component.drag_drop;
1613
- var is_start = false;
1614
-
1615
- if(tmp.isdown) {
1616
- if(!tmp.moving && Math.abs(tmp.init_x - event.pageX) < 5 && Math.abs(tmp.init_y - event.pageY) < 5) {
1617
- event.preventDefault();
1618
- event.stopPropagation();
1619
- return false;
1620
- }
1621
- else {
1622
- if(!tmp.moving) {
1623
- tree_component.drag_drop.moving = true;
1624
- is_start = true;
1625
- }
1626
- }
1627
-
1628
- if(tmp.open_time) clearTimeout(tmp.open_time);
1629
-
1630
- if(tmp.drag_help !== false) {
1631
- if(!tmp.appended) {
1632
- if(tmp.foreign !== false) tmp.origin_tree = $.tree.focused();
1633
- $("body").append(tmp.drag_help);
1634
- tmp.w = tmp.drag_help.width();
1635
- tmp.appended = true;
1636
- }
1637
- tmp.drag_help.css({ "left" : (event.pageX + 5 ), "top" : (event.pageY + 15) });
1638
- }
1639
-
1640
- if(is_start && $.tree.drag_start !== false) $.tree.drag_start.call(null, event, tmp);
1641
- if($.tree.drag !== false) $.tree.drag.call(null, event, tmp);
1642
-
1643
- if(event.target.tagName == "DIV" && event.target.id == "jstree-marker") return false;
1644
-
1645
- var et = $(event.target);
1646
- if(et.is("ins")) et = et.parent();
1647
- var cnt = et.is(".tree") ? et : et.parents(".tree:eq(0)");
1648
-
1649
- // if not moving over a tree
1650
- if(cnt.size() == 0 || !tree_component.inst[cnt.attr("id")]) {
1651
- if(tmp.scroll_time) clearTimeout(tmp.scroll_time);
1652
- if(tmp.drag_help !== false) tmp.drag_help.find("li:eq(0) ins").addClass("forbidden");
1653
- tmp.move_type = false;
1654
- tmp.ref_node = false;
1655
- tree_component.drag_drop.marker.hide();
1656
- return false;
1657
- }
1658
-
1659
- var tree2 = tree_component.inst[cnt.attr("id")];
1660
- tree2.off_height();
1661
-
1662
- if(tmp.scroll_time) clearTimeout(tmp.scroll_time);
1663
- tmp.scroll_time = setTimeout( function() { tree2.scroll_check(event.pageX,event.pageY); }, 50);
1664
-
1665
- var mov = false;
1666
- var st = cnt.scrollTop();
1667
-
1668
- if(event.target.tagName == "A" || event.target.tagName == "INS") {
1669
- // just in case if hover is over the draggable
1670
- if(et.is("#jstree-dragged")) return false;
1671
- if(tree2.get_node(event.target).hasClass("closed")) {
1672
- tmp.open_time = setTimeout( function () { tree2.open_branch(et); }, 500);
1673
- }
1674
-
1675
- var et_off = et.offset();
1676
- var goTo = {
1677
- x : (et_off.left - 1),
1678
- y : (event.pageY - et_off.top)
1679
- };
1680
-
1681
- var arr = [];
1682
- if(goTo.y < tree2.li_height/3 + 1 ) arr = ["before","inside","after"];
1683
- else if(goTo.y > tree2.li_height*2/3 - 1 ) arr = ["after","inside","before"];
1684
- else {
1685
- if(goTo.y < tree2.li_height/2) arr = ["inside","before","after"];
1686
- else arr = ["inside","after","before"];
1687
- }
1688
- var ok = false;
1689
- var nn = (tmp.foreign == false) ? tmp.origin_tree.container.find("li.dragged") : tmp.f_type;
1690
- $.each(arr, function(i, val) {
1691
- if(tree2.check_move(nn, et, val)) {
1692
- mov = val;
1693
- ok = true;
1694
- return false;
1695
- }
1696
- });
1697
- if(ok) {
1698
- switch(mov) {
1699
- case "before":
1700
- goTo.y = et_off.top - 2;
1701
- tree_component.drag_drop.marker.attr("class","marker");
1702
- break;
1703
- case "after":
1704
- goTo.y = et_off.top - 2 + tree2.li_height;
1705
- tree_component.drag_drop.marker.attr("class","marker");
1706
- break;
1707
- case "inside":
1708
- goTo.x -= 2;
1709
- goTo.y = et_off.top - 2 + tree2.li_height/2;
1710
- tree_component.drag_drop.marker.attr("class","marker_plus");
1711
- break;
1712
- }
1713
- tmp.move_type = mov;
1714
- tmp.ref_node = $(event.target);
1715
- if(tmp.drag_help !== false) tmp.drag_help.find(".forbidden").removeClass("forbidden");
1716
- tree_component.drag_drop.marker.css({ "left" : goTo.x , "top" : goTo.y }).show();
1717
- }
1718
- }
1719
-
1720
- if( (et.is(".tree") || et.is("ul") ) && et.find("li:eq(0)").size() == 0) {
1721
- var et_off = et.offset();
1722
- tmp.move_type = "inside";
1723
- tmp.ref_node = cnt.children("ul:eq(0)");
1724
- if(tmp.drag_help !== false) tmp.drag_help.find(".forbidden").removeClass("forbidden");
1725
- tree_component.drag_drop.marker.attr("class","marker_plus");
1726
- tree_component.drag_drop.marker.css({ "left" : (et_off.left + 10) , "top" : et_off.top + 15 }).show();
1727
- }
1728
- else if( (event.target.tagName != "A" && event.target.tagName != "INS") || !ok) {
1729
- if(tmp.drag_help !== false) tmp.drag_help.find("li:eq(0) ins").addClass("forbidden");
1730
- tmp.move_type = false;
1731
- tmp.ref_node = false;
1732
- tree_component.drag_drop.marker.hide();
1733
- }
1734
- event.preventDefault();
1735
- event.stopPropagation();
1736
- return false;
1737
- }
1738
- return true;
1739
- };
1740
- $(function () {
1741
- $(document).bind("mousemove.jstree", tree_component.mousemove);
1742
- $(document).bind("mouseup.jstree", tree_component.mouseup);
1743
- });
1744
-
1745
- // cut, copy, paste stuff
1746
- tree_component.cut_copy = {
1747
- copy_nodes : false,
1748
- cut_nodes : false
1749
- };
1750
-
1751
- // css stuff
1752
- tree_component.css = false;
1753
- tree_component.get_css = function(rule_name, delete_flag) {
1754
- rule_name = rule_name.toLowerCase();
1755
- var css_rules = tree_component.css.cssRules || tree_component.css.rules;
1756
- var j = 0;
1757
- do {
1758
- if(css_rules.length && j > css_rules.length + 5) return false;
1759
- if(css_rules[j].selectorText && css_rules[j].selectorText.toLowerCase() == rule_name) {
1760
- if(delete_flag == true) {
1761
- if(tree_component.css.removeRule) document.styleSheets[i].removeRule(j);
1762
- if(tree_component.css.deleteRule) document.styleSheets[i].deleteRule(j);
1763
- return true;
1764
- }
1765
- else return css_rules[j];
1766
- }
1767
- }
1768
- while (css_rules[++j]);
1769
- return false;
1770
- };
1771
- tree_component.add_css = function(rule_name) {
1772
- if(tree_component.get_css(rule_name)) return false;
1773
- (tree_component.css.insertRule) ? tree_component.css.insertRule(rule_name + ' { }', 0) : tree_component.css.addRule(rule_name, null, 0);
1774
- return tree_component.get_css(rule_name);
1775
- };
1776
- tree_component.remove_css = function(rule_name) {
1777
- return tree_component.get_css(rule_name, true);
1778
- };
1779
- tree_component.add_sheet = function(opts) {
1780
- if(opts.str) {
1781
- var tmp = document.createElement("style");
1782
- tmp.type = "text/css";
1783
- if(tmp.styleSheet) tmp.styleSheet.cssText = opts.str;
1784
- else tmp.appendChild(document.createTextNode(opts.str));
1785
- document.getElementsByTagName("head")[0].appendChild(tmp);
1786
- return tmp.sheet;
1787
- }
1788
- if(opts.url) {
1789
- if(document.createStyleSheet) {
1790
- try { document.createStyleSheet(opts.url); } catch (e) { };
1791
- }
1792
- else {
1793
- var newSS = document.createElement('link');
1794
- newSS.rel = 'stylesheet';
1795
- newSS.type = 'text/css';
1796
- newSS.media = "all";
1797
- newSS.href = opts.url;
1798
- // var styles = "@import url(' " + url + " ');";
1799
- // newSS.href ='data:text/css,'+escape(styles);
1800
- document.getElementsByTagName("head")[0].appendChild(newSS);
1801
- return newSS.styleSheet;
1802
- }
1803
- }
1804
- };
1805
- $(function () {
1806
- var u = navigator.userAgent.toLowerCase();
1807
- var v = (u.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1];
1808
- var css = '/* TREE LAYOUT */ .tree ul { margin:0 0 0 5px; padding:0 0 0 0; list-style-type:none; } .tree li { display:block; min-height:18px; line-height:18px; padding:0 0 0 15px; margin:0 0 0 0; /* Background fix */ clear:both; } .tree li ul { display:none; } .tree li a, .tree li span { display:inline-block;line-height:16px;height:16px;color:black;white-space:nowrap;text-decoration:none;padding:1px 4px 1px 4px;margin:0; } .tree li a:focus { outline: none; } .tree li a input, .tree li span input { margin:0;padding:0 0;display:inline-block;height:12px !important;border:1px solid white;background:white;font-size:10px;font-family:Verdana; } .tree li a input:not([class="xxx"]), .tree li span input:not([class="xxx"]) { padding:1px 0; } /* FOR DOTS */ .tree .ltr li.last { float:left; } .tree > ul li.last { overflow:visible; } /* OPEN OR CLOSE */ .tree li.open ul { display:block; } .tree li.closed ul { display:none !important; } /* FOR DRAGGING */ #jstree-dragged { position:absolute; top:-10px; left:-10px; margin:0; padding:0; } #jstree-dragged ul ul ul { display:none; } #jstree-marker { padding:0; margin:0; line-height:5px; font-size:1px; overflow:hidden; height:5px; position:absolute; left:-45px; top:-30px; z-index:1000; background-color:transparent; background-repeat:no-repeat; display:none; } #jstree-marker.marker { width:45px; background-position:-32px top; } #jstree-marker.marker_plus { width:5px; background-position:right top; } /* BACKGROUND DOTS */ .tree li li { overflow:hidden; } .tree > .ltr > li { display:table; } /* ICONS */ .tree ul ins { display:inline-block; text-decoration:none; width:16px; height:16px; } .tree .ltr ins { margin:0 4px 0 0px; } ';
1809
- if(/msie/.test(u) && !/opera/.test(u)) {
1810
- if(parseInt(v) == 6) css += '.tree li { height:18px; zoom:1; } .tree li li { overflow:visible; } .tree .ltr li.last { margin-top: expression( (this.previousSibling && /open/.test(this.previousSibling.className) ) ? "-2px" : "0"); } .marker { width:45px; background-position:-32px top; } .marker_plus { width:5px; background-position:right top; }';
1811
- if(parseInt(v) == 7) css += '.tree li li { overflow:visible; } .tree .ltr li.last { margin-top: expression( (this.previousSibling && /open/.test(this.previousSibling.className) ) ? "-2px" : "0"); }';
1812
- }
1813
- if(/opera/.test(u)) css += '.tree > ul > li.last:after { content:"."; display: block; height:1px; clear:both; visibility:hidden; }';
1814
- if(/mozilla/.test(u) && !/(compatible|webkit)/.test(u) && v.indexOf("1.8") == 0) css += '.tree .ltr li a { display:inline; float:left; } .tree li ul { clear:both; }';
1815
- tree_component.css = tree_component.add_sheet({ str : css });
1816
- });
1817
- })(jQuery);
1818
-
1819
- // Datastores
1820
- // HTML and JSON are included here by default
1821
- (function ($) {
1822
- $.extend($.tree.datastores, {
1823
- "html" : function () {
1824
- return {
1825
- get : function(obj, tree, opts) {
1826
- return obj && $(obj).size() ? $('<div>').append(tree.get_node(obj).clone()).html() : tree.container.children("ul:eq(0)").html();
1827
- },
1828
- parse : function(data, tree, opts, callback) {
1829
- if(callback) callback.call(null, data);
1830
- return data;
1831
- },
1832
- load : function(data, tree, opts, callback) {
1833
- if(opts.url) {
1834
- $.ajax({
1835
- 'type' : opts.method,
1836
- 'url' : opts.url,
1837
- 'data' : data,
1838
- 'dataType' : "html",
1839
- 'success' : function (d, textStatus) {
1840
- callback.call(null, d);
1841
- },
1842
- 'error' : function (xhttp, textStatus, errorThrown) {
1843
- callback.call(null, false);
1844
- tree.error(errorThrown + " " + textStatus);
1845
- }
1846
- });
1847
- }
1848
- else {
1849
- callback.call(null, opts.static || tree.container.children("ul:eq(0)").html());
1850
- }
1851
- }
1852
- };
1853
- },
1854
- "json" : function () {
1855
- return {
1856
- get : function(obj, tree, opts) {
1857
- var _this = this;
1858
- if(!obj || $(obj).size() == 0) obj = tree.container.children("ul").children("li");
1859
- else obj = $(obj);
1860
-
1861
- if(!opts) opts = {};
1862
- if(!opts.outer_attrib) opts.outer_attrib = [ "id", "rel", "class" ];
1863
- if(!opts.inner_attrib) opts.inner_attrib = [ ];
1864
-
1865
- if(obj.size() > 1) {
1866
- var arr = [];
1867
- obj.each(function () {
1868
- arr.push(_this.get(this, tree, opts));
1869
- });
1870
- return arr;
1871
- }
1872
- if(obj.size() == 0) return [];
1873
-
1874
- var json = { attributes : {}, data : {} };
1875
- if(obj.hasClass("open")) json.data.state = "open";
1876
- if(obj.hasClass("closed")) json.data.state = "closed";
1877
-
1878
- for(var i in opts.outer_attrib) {
1879
- if(!opts.outer_attrib.hasOwnProperty(i)) continue;
1880
- var val = (opts.outer_attrib[i] == "class") ? obj.attr(opts.outer_attrib[i]).replace(/(^| )last( |$)/ig," ").replace(/(^| )(leaf|closed|open)( |$)/ig," ") : obj.attr(opts.outer_attrib[i]);
1881
- if(typeof val != "undefined" && val.toString().replace(" ","").length > 0) json.attributes[opts.outer_attrib[i]] = val;
1882
- delete val;
1883
- }
1884
-
1885
- if(tree.settings.languages.length) {
1886
- for(var i in tree.settings.languages) {
1887
- if(!tree.settings.languages.hasOwnProperty(i)) continue;
1888
- var a = obj.children("a." + tree.settings.languages[i]);
1889
- if(opts.force || opts.inner_attrib.length || a.children("ins").get(0).style.backgroundImage.toString().length || a.children("ins").get(0).className.length) {
1890
- json.data[tree.settings.languages[i]] = {};
1891
- json.data[tree.settings.languages[i]].title = tree.get_text(obj,tree.settings.languages[i]);
1892
- if(a.children("ins").get(0).style.className.length) {
1893
- json.data[tree.settings.languages[i]].icon = a.children("ins").get(0).style.className;
1894
- }
1895
- if(a.children("ins").get(0).style.backgroundImage.length) {
1896
- json.data[tree.settings.languages[i]].icon = a.children("ins").get(0).style.backgroundImage.replace("url(","").replace(")","");
1897
- }
1898
- if(opts.inner_attrib.length) {
1899
- json.data[tree.settings.languages[i]].attributes = {};
1900
- for(var j in opts.inner_attrib) {
1901
- if(!opts.inner_attrib.hasOwnProperty(j)) continue;
1902
- var val = a.attr(opts.inner_attrib[j]);
1903
- if(typeof val != "undefined" && val.toString().replace(" ","").length > 0) json.data[tree.settings.languages[i]].attributes[opts.inner_attrib[j]] = val;
1904
- delete val;
1905
- }
1906
- }
1907
- }
1908
- else {
1909
- json.data[tree.settings.languages[i]] = tree.get_text(obj,tree.settings.languages[i]);
1910
- }
1911
- }
1912
- }
1913
- else {
1914
- var a = obj.children("a");
1915
- json.data.title = tree.get_text(obj);
1916
-
1917
- if(a.children("ins").size() && a.children("ins").get(0).className.length) {
1918
- json.data.icon = a.children("ins").get(0).className;
1919
- }
1920
- if(a.children("ins").size() && a.children("ins").get(0).style.backgroundImage.length) {
1921
- json.data.icon = a.children("ins").get(0).style.backgroundImage.replace("url(","").replace(")","");
1922
- }
1923
-
1924
- if(opts.inner_attrib.length) {
1925
- json.data.attributes = {};
1926
- for(var j in opts.inner_attrib) {
1927
- if(!opts.inner_attrib.hasOwnProperty(j)) continue;
1928
- var val = a.attr(opts.inner_attrib[j]);
1929
- if(typeof val != "undefined" && val.toString().replace(" ","").length > 0) json.data.attributes[opts.inner_attrib[j]] = val;
1930
- delete val;
1931
- }
1932
- }
1933
- }
1934
-
1935
- if(obj.children("ul").size() > 0) {
1936
- json.children = [];
1937
- obj.children("ul").children("li").each(function () {
1938
- json.children.push(_this.get(this, tree, opts));
1939
- });
1940
- }
1941
- return json;
1942
- },
1943
- parse : function(data, tree, opts, callback) {
1944
- if(Object.prototype.toString.apply(data) === "[object Array]") {
1945
- var str = '';
1946
- for(var i = 0; i < data.length; i ++) {
1947
- if(typeof data[i] == "function") continue;
1948
- str += this.parse(data[i], tree, opts);
1949
- }
1950
- if(callback) callback.call(null, str);
1951
- return str;
1952
- }
1953
-
1954
- if(!data || !data.data) {
1955
- if(callback) callback.call(null, false);
1956
- return "";
1957
- }
1958
-
1959
- var str = '';
1960
- str += "<li ";
1961
- var cls = false;
1962
- if(data.attributes) {
1963
- for(var i in data.attributes) {
1964
- if(!data.attributes.hasOwnProperty(i)) continue;
1965
- if(i == "class") {
1966
- str += " class='" + data.attributes[i] + " ";
1967
- if(data.state == "closed" || data.state == "open") str += " " + data.state + " ";
1968
- str += "' ";
1969
- cls = true;
1970
- }
1971
- else str += " " + i + "='" + data.attributes[i] + "' ";
1972
- }
1973
- }
1974
- if(!cls && (data.state == "closed" || data.state == "open")) str += " class='" + data.state + "' ";
1975
- str += ">";
1976
-
1977
- if(tree.settings.languages.length) {
1978
- for(var i = 0; i < tree.settings.languages.length; i++) {
1979
- var attr = {};
1980
- attr["href"] = "";
1981
- attr["style"] = "";
1982
- attr["class"] = tree.settings.languages[i];
1983
- if(data.data[tree.settings.languages[i]] && (typeof data.data[tree.settings.languages[i]].attributes).toLowerCase() != "undefined") {
1984
- for(var j in data.data[tree.settings.languages[i]].attributes) {
1985
- if(!data.data[tree.settings.languages[i]].attributes.hasOwnProperty(j)) continue;
1986
- if(j == "style" || j == "class") attr[j] += " " + data.data[tree.settings.languages[i]].attributes[j];
1987
- else attr[j] = data.data[tree.settings.languages[i]].attributes[j];
1988
- }
1989
- }
1990
- str += "<a";
1991
- for(var j in attr) {
1992
- if(!attr.hasOwnProperty(j)) continue;
1993
- str += ' ' + j + '="' + attr[j] + '" ';
1994
- }
1995
- str += ">";
1996
- if(data.data[tree.settings.languages[i]] && data.data[tree.settings.languages[i]].icon) {
1997
- str += "<ins " + (data.data[tree.settings.languages[i]].icon.indexOf("/") == -1 ? " class='" + data.data[tree.settings.languages[i]].icon + "' " : " style='background-image:url(\"" + data.data[tree.settings.languages[i]].icon + "\");' " ) + ">&nbsp;</ins>";
1998
- }
1999
- else str += "<ins>&nbsp;</ins>";
2000
- str += ( (typeof data.data[tree.settings.languages[i]].title).toLowerCase() != "undefined" ? data.data[tree.settings.languages[i]].title : data.data[tree.settings.languages[i]] ) + "</a>";
2001
- }
2002
- }
2003
- else {
2004
- var attr = {};
2005
- attr["href"] = "";
2006
- attr["style"] = "";
2007
- attr["class"] = "";
2008
- if((typeof data.data.attributes).toLowerCase() != "undefined") {
2009
- for(var i in data.data.attributes) {
2010
- if(!data.data.attributes.hasOwnProperty(i)) continue;
2011
- if(i == "style" || i == "class") attr[i] += " " + data.data.attributes[i];
2012
- else attr[i] = data.data.attributes[i];
2013
- }
2014
- }
2015
- str += "<a";
2016
- for(var i in attr) {
2017
- if(!attr.hasOwnProperty(i)) continue;
2018
- str += ' ' + i + '="' + attr[i] + '" ';
2019
- }
2020
- str += ">";
2021
- if(data.data.icon) {
2022
- str += "<ins " + (data.data.icon.indexOf("/") == -1 ? " class='" + data.data.icon + "' " : " style='background-image:url(\"" + data.data.icon + "\");' " ) + ">&nbsp;</ins>";
2023
- }
2024
- else str += "<ins>&nbsp;</ins>";
2025
- str += ( (typeof data.data.title).toLowerCase() != "undefined" ? data.data.title : data.data ) + "</a>";
2026
- }
2027
- if(data.children && data.children.length) {
2028
- str += '<ul>';
2029
- for(var i = 0; i < data.children.length; i++) {
2030
- str += this.parse(data.children[i], tree, opts);
2031
- }
2032
- str += '</ul>';
2033
- }
2034
- str += "</li>";
2035
- if(callback) callback.call(null, str);
2036
- return str;
2037
- },
2038
- load : function(data, tree, opts, callback) {
2039
- if(opts.static) {
2040
- callback.call(null, opts.static);
2041
- }
2042
- else {
2043
- $.ajax({
2044
- 'type' : opts.method,
2045
- 'url' : opts.url,
2046
- 'data' : data,
2047
- 'dataType' : "json",
2048
- 'success' : function (d, textStatus) {
2049
- callback.call(null, d);
2050
- },
2051
- 'error' : function (xhttp, textStatus, errorThrown) {
2052
- callback.call(null, false);
2053
- tree.error(errorThrown + " " + textStatus);
2054
- }
2055
- });
2056
- }
2057
- }
2058
- }
2059
- }
2060
- });
2061
- })(jQuery);