Skip to content

Commit

Permalink
fixed a bug with get_parent
Browse files Browse the repository at this point in the history
disabled hiding selected nodes with progressive render / unload
  • Loading branch information
vakata committed Mar 21, 2013
1 parent b47adc0 commit cdb5bf9
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/jstree.sublime-project
/jstree.sublime-workspace
/node_modules
/documentation.bat
/favicon.ico
27 changes: 13 additions & 14 deletions dist/jstree.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@
if(obj === -1 || !obj || !obj.length) {
return false;
}
var o = obj.parentNode.parentNode;
var o = obj[0].parentNode.parentNode;

return o.tagName === 'LI' ? $(o) : -1;
},
/**
Expand Down Expand Up @@ -2437,7 +2438,7 @@
var t = $(v),
d = t.data('jstree');
if(d && d.children && t.children('ul').length === 0) {
this._progressive_data_clean(d.children);
this._progressive_data_clean(d.children, e.type === 'select_node');
}
}, this));
}, this));
Expand Down Expand Up @@ -2524,7 +2525,7 @@
}, this));
}
};
this._progressive_data_clean = function (data) {
this._progressive_data_clean = function (data, is_select) {
if(!this.settings.checkbox.three_state) { return false; }
for(var i = 0, j = data.length; i < j; i++) {
if(data[i].data && data[i].data.jstree) {
Expand All @@ -2535,7 +2536,7 @@
delete data[i].data.jstree.undetermined;
}
if(data[i].children) {
this._progressive_data_clean(data[i].children);
this._progressive_data_clean(data[i].children, is_select);
}
}
}
Expand Down Expand Up @@ -3609,7 +3610,7 @@
this.element
.bind("after_close.jstree", $.proxy(function (e, data) {
var t = $(data.node);
if(this.settings.json.progressive_unload) {
if(this.settings.json.progressive_unload && t.find('.jstree-clicked:eq(0)').length === 0) {
t.data('jstree').children = this.get_json(t)[0].children;
t.children("ul").remove();
}
Expand All @@ -3618,24 +3619,22 @@
};
this.parse_json = function (node) {
var s = this.settings.json;
if($.isArray(node.children) && (this._data.core.ready || !this.settings.core.expand_selected_onload || !this._has_selected(node.children))) {
if(s.progressive_render) {
if(!node.data) { node.data = {}; }
if(!node.data.jstree) { node.data.jstree = {}; }
node.data.jstree.children = node.children;
node.children = true;
}
if(s.progressive_render && $.isArray(node.children) && !this._json_has_selected(node.children)) {
if(!node.data) { node.data = {}; }
if(!node.data.jstree) { node.data.jstree = {}; }
node.data.jstree.children = node.children;
node.children = true;
}
return parent.parse_json.call(this, node);
};
this._has_selected = function (data) {
this._json_has_selected = function (data) {
var r = false;
for(var i = 0, j = data.length; i < j; i++) {
if(data[i].data && data[i].data.jstree && data[i].data.jstree.selected) {
r = true;
}
else if(data[i].children) {
r = r || this._has_selected(data[i].children);
r = r || this._json_has_selected(data[i].children);
}
else {
r = false;
Expand Down
6 changes: 3 additions & 3 deletions dist/jstree.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/jstree.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/jstree.checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
var t = $(v),
d = t.data('jstree');
if(d && d.children && t.children('ul').length === 0) {
this._progressive_data_clean(d.children);
this._progressive_data_clean(d.children, e.type === 'select_node');
}
}, this));
}, this));
Expand Down Expand Up @@ -137,7 +137,7 @@
}, this));
}
};
this._progressive_data_clean = function (data) {
this._progressive_data_clean = function (data, is_select) {
if(!this.settings.checkbox.three_state) { return false; }
for(var i = 0, j = data.length; i < j; i++) {
if(data[i].data && data[i].data.jstree) {
Expand All @@ -148,7 +148,7 @@
delete data[i].data.jstree.undetermined;
}
if(data[i].children) {
this._progressive_data_clean(data[i].children);
this._progressive_data_clean(data[i].children, is_select);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/jstree.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@
if(obj === -1 || !obj || !obj.length) {
return false;
}
var o = obj.parentNode.parentNode;
var o = obj[0].parentNode.parentNode;

return o.tagName === 'LI' ? $(o) : -1;
},
/**
Expand Down
18 changes: 8 additions & 10 deletions src/jstree.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
this.element
.bind("after_close.jstree", $.proxy(function (e, data) {
var t = $(data.node);
if(this.settings.json.progressive_unload) {
if(this.settings.json.progressive_unload && t.find('.jstree-clicked:eq(0)').length === 0) {
t.data('jstree').children = this.get_json(t)[0].children;
t.children("ul").remove();
}
Expand All @@ -26,24 +26,22 @@
};
this.parse_json = function (node) {
var s = this.settings.json;
if($.isArray(node.children) && (this._data.core.ready || !this.settings.core.expand_selected_onload || !this._has_selected(node.children))) {
if(s.progressive_render) {
if(!node.data) { node.data = {}; }
if(!node.data.jstree) { node.data.jstree = {}; }
node.data.jstree.children = node.children;
node.children = true;
}
if(s.progressive_render && $.isArray(node.children) && !this._json_has_selected(node.children)) {
if(!node.data) { node.data = {}; }
if(!node.data.jstree) { node.data.jstree = {}; }
node.data.jstree.children = node.children;
node.children = true;
}
return parent.parse_json.call(this, node);
};
this._has_selected = function (data) {
this._json_has_selected = function (data) {
var r = false;
for(var i = 0, j = data.length; i < j; i++) {
if(data[i].data && data[i].data.jstree && data[i].data.jstree.selected) {
r = true;
}
else if(data[i].children) {
r = r || this._has_selected(data[i].children);
r = r || this._json_has_selected(data[i].children);
}
else {
r = false;
Expand Down

0 comments on commit cdb5bf9

Please sign in to comment.