Skip to content

Commit

Permalink
fixed type icons setting and major bugs in set_icon - close #454
Browse files Browse the repository at this point in the history
  • Loading branch information
vakata committed Jan 9, 2014
1 parent 2e4132b commit 03c32e7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 27 deletions.
22 changes: 15 additions & 7 deletions dist/jstree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,7 @@
* @param {String} icon the new icon - can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class
*/
set_icon : function (obj, icon) {
var t1, t2, dom;
var t1, t2, dom, old;
if($.isArray(obj)) {
obj = obj.slice();
for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
Expand All @@ -3273,16 +3273,22 @@
}
obj = this.get_node(obj);
if(!obj || obj.id === '#') { return false; }
old = obj.icon;
obj.icon = icon;
dom = this.get_node(obj, true).children("jstree-anchor").children(".jstree-themeicon");
dom = this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon");
if(icon === false) {
this.removeClass('jstree-themeicon-custom').hide_icon(obj);
this.hide_icon(obj);
}
else if(icon === true) {
dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
}
else if(icon.indexOf("/") === -1 && icon.indexOf(".") === -1) {
dom.removeClass(old).css("background","");
dom.addClass(icon + ' jstree-themeicon-custom').attr("rel",icon);
}
else {
dom.removeClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
dom.removeClass(old).css("background","");
dom.addClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
}
return true;
},
Expand Down Expand Up @@ -5678,7 +5684,7 @@
* @plugin types
*/
this.set_type = function (obj, type) {
var t, t1, t2;
var t, t1, t2, old_type, old_icon;
if($.isArray(obj)) {
obj = obj.slice();
for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
Expand All @@ -5689,9 +5695,11 @@
t = this.settings.types;
obj = this.get_node(obj);
if(!t[type] || !obj) { return false; }
old_type = obj.type;
old_icon = this.get_icon(obj);
obj.type = type;
if(t[type].icon && this.get_icon(obj) === true) {
this.set_icon(obj, t[type].icon);
if(old_icon === true || (t[old_type] && t[old_type].icon && old_icon === t[old_type].icon)) {
this.set_icon(obj, t[type].icon || true);
}
return true;
};
Expand Down
4 changes: 2 additions & 2 deletions dist/jstree.min.js

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions docs/assets/dist/jstree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,7 @@
* @param {String} icon the new icon - can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class
*/
set_icon : function (obj, icon) {
var t1, t2, dom;
var t1, t2, dom, old;
if($.isArray(obj)) {
obj = obj.slice();
for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
Expand All @@ -3273,16 +3273,22 @@
}
obj = this.get_node(obj);
if(!obj || obj.id === '#') { return false; }
old = obj.icon;
obj.icon = icon;
dom = this.get_node(obj, true).children("jstree-anchor").children(".jstree-themeicon");
dom = this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon");
if(icon === false) {
this.removeClass('jstree-themeicon-custom').hide_icon(obj);
this.hide_icon(obj);
}
else if(icon === true) {
dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
}
else if(icon.indexOf("/") === -1 && icon.indexOf(".") === -1) {
dom.removeClass(old).css("background","");
dom.addClass(icon + ' jstree-themeicon-custom').attr("rel",icon);
}
else {
dom.removeClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
dom.removeClass(old).css("background","");
dom.addClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
}
return true;
},
Expand Down Expand Up @@ -5678,7 +5684,7 @@
* @plugin types
*/
this.set_type = function (obj, type) {
var t, t1, t2;
var t, t1, t2, old_type, old_icon;
if($.isArray(obj)) {
obj = obj.slice();
for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
Expand All @@ -5689,9 +5695,11 @@
t = this.settings.types;
obj = this.get_node(obj);
if(!t[type] || !obj) { return false; }
old_type = obj.type;
old_icon = this.get_icon(obj);
obj.type = type;
if(t[type].icon && this.get_icon(obj) === true) {
this.set_icon(obj, t[type].icon);
if(old_icon === true || (t[old_type] && t[old_type].icon && old_icon === t[old_type].icon)) {
this.set_icon(obj, t[type].icon || true);
}
return true;
};
Expand Down
4 changes: 2 additions & 2 deletions docs/assets/dist/jstree.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/jstree.json
Original file line number Diff line number Diff line change
Expand Up @@ -4580,7 +4580,7 @@
},
"isPrivate": false,
"ignore": false,
"code": "set_icon : function (obj, icon) {\n\t\t\tvar t1, t2, dom;\n\t\t\tif($.isArray(obj)) {\n\t\t\t\tobj = obj.slice();\n\t\t\t\tfor(t1 = 0, t2 = obj.length; t1 < t2; t1++) {\n\t\t\t\t\tthis.set_icon(obj[t1], icon);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tobj = this.get_node(obj);\n\t\t\tif(!obj || obj.id === '#') { return false; }\n\t\t\tobj.icon = icon;\n\t\t\tdom = this.get_node(obj, true).children(\"jstree-anchor\").children(\".jstree-themeicon\");\n\t\t\tif(icon === false) {\n\t\t\t\tthis.removeClass('jstree-themeicon-custom').hide_icon(obj);\n\t\t\t}\n\t\t\telse if(icon.indexOf(\"/\") === -1 && icon.indexOf(\".\") === -1) {\n\t\t\t\tdom.addClass(icon + ' jstree-themeicon-custom').attr(\"rel\",icon);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdom.removeClass('jstree-themeicon-custom').css(\"background\", \"url('\" + icon + \"') center center no-repeat\").attr(\"rel\",icon);\n\t\t\t}\n\t\t\treturn true;\n\t\t},"
"code": "set_icon : function (obj, icon) {\n\t\t\tvar t1, t2, dom, old;\n\t\t\tif($.isArray(obj)) {\n\t\t\t\tobj = obj.slice();\n\t\t\t\tfor(t1 = 0, t2 = obj.length; t1 < t2; t1++) {\n\t\t\t\t\tthis.set_icon(obj[t1], icon);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tobj = this.get_node(obj);\n\t\t\tif(!obj || obj.id === '#') { return false; }\n\t\t\told = obj.icon;\n\t\t\tobj.icon = icon;\n\t\t\tdom = this.get_node(obj, true).children(\".jstree-anchor\").children(\".jstree-themeicon\");\n\t\t\tif(icon === false) {\n\t\t\t\tthis.hide_icon(obj);\n\t\t\t}\n\t\t\telse if(icon === true) {\n\t\t\t\tdom.removeClass('jstree-themeicon-custom ' + old).css(\"background\",\"\").removeAttr(\"rel\");\n\t\t\t}\n\t\t\telse if(icon.indexOf(\"/\") === -1 && icon.indexOf(\".\") === -1) {\n\t\t\t\tdom.removeClass(old).css(\"background\",\"\");\n\t\t\t\tdom.addClass(icon + ' jstree-themeicon-custom').attr(\"rel\",icon);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdom.removeClass(old).css(\"background\",\"\");\n\t\t\t\tdom.addClass('jstree-themeicon-custom').css(\"background\", \"url('\" + icon + \"') center center no-repeat\").attr(\"rel\",icon);\n\t\t\t}\n\t\t\treturn true;\n\t\t},"
},
{
"tags": [
Expand Down Expand Up @@ -6074,7 +6074,7 @@
},
"isPrivate": false,
"ignore": false,
"code": "this.set_type = function (obj, type) {\n\t\t\tvar t, t1, t2;\n\t\t\tif($.isArray(obj)) {\n\t\t\t\tobj = obj.slice();\n\t\t\t\tfor(t1 = 0, t2 = obj.length; t1 < t2; t1++) {\n\t\t\t\t\tthis.set_type(obj[t1], type);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tt = this.settings.types;\n\t\t\tobj = this.get_node(obj);\n\t\t\tif(!t[type] || !obj) { return false; }\n\t\t\tobj.type = type;\n\t\t\tif(t[type].icon && this.get_icon(obj) === true) {\n\t\t\t\tthis.set_icon(obj, t[type].icon);\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t};\n\t// include the types plugin by default\n\t// $.jstree.defaults.plugins.push(\"types\");",
"code": "this.set_type = function (obj, type) {\n\t\t\tvar t, t1, t2, old_type, old_icon;\n\t\t\tif($.isArray(obj)) {\n\t\t\t\tobj = obj.slice();\n\t\t\t\tfor(t1 = 0, t2 = obj.length; t1 < t2; t1++) {\n\t\t\t\t\tthis.set_type(obj[t1], type);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tt = this.settings.types;\n\t\t\tobj = this.get_node(obj);\n\t\t\tif(!t[type] || !obj) { return false; }\n\t\t\told_type = obj.type;\n\t\t\told_icon = this.get_icon(obj);\n\t\t\tobj.type = type;\n\t\t\tif(old_icon === true || (t[old_type] && t[old_type].icon && old_icon === t[old_type].icon)) {\n\t\t\t\tthis.set_icon(obj, t[type].icon || true);\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t};\n\t// include the types plugin by default\n\t// $.jstree.defaults.plugins.push(\"types\");",
"ctx": {
"type": "method",
"receiver": "this",
Expand Down
14 changes: 10 additions & 4 deletions src/jstree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,7 @@
* @param {String} icon the new icon - can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class
*/
set_icon : function (obj, icon) {
var t1, t2, dom;
var t1, t2, dom, old;
if($.isArray(obj)) {
obj = obj.slice();
for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
Expand All @@ -3273,16 +3273,22 @@
}
obj = this.get_node(obj);
if(!obj || obj.id === '#') { return false; }
old = obj.icon;
obj.icon = icon;
dom = this.get_node(obj, true).children("jstree-anchor").children(".jstree-themeicon");
dom = this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon");
if(icon === false) {
this.removeClass('jstree-themeicon-custom').hide_icon(obj);
this.hide_icon(obj);
}
else if(icon === true) {
dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
}
else if(icon.indexOf("/") === -1 && icon.indexOf(".") === -1) {
dom.removeClass(old).css("background","");
dom.addClass(icon + ' jstree-themeicon-custom').attr("rel",icon);
}
else {
dom.removeClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
dom.removeClass(old).css("background","");
dom.addClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
}
return true;
},
Expand Down
8 changes: 5 additions & 3 deletions src/jstree.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
* @plugin types
*/
this.set_type = function (obj, type) {
var t, t1, t2;
var t, t1, t2, old_type, old_icon;
if($.isArray(obj)) {
obj = obj.slice();
for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
Expand All @@ -169,9 +169,11 @@
t = this.settings.types;
obj = this.get_node(obj);
if(!t[type] || !obj) { return false; }
old_type = obj.type;
old_icon = this.get_icon(obj);
obj.type = type;
if(t[type].icon && this.get_icon(obj) === true) {
this.set_icon(obj, t[type].icon);
if(old_icon === true || (t[old_type] && t[old_type].icon && old_icon === t[old_type].icon)) {
this.set_icon(obj, t[type].icon || true);
}
return true;
};
Expand Down

0 comments on commit 03c32e7

Please sign in to comment.