Jquery jsTree上下文菜单翻译
我需要翻译jsTree中的contextmenu,它在您单击右键时显示,此时我创建了新文件jsTree.contextmenu.pl.js,并从jquery.jsTree.js复制了一些代码,并进行了自己的更改。这是可行的,但我不确定这是不是最好的选择Jquery jsTree上下文菜单翻译,jquery,jstree,Jquery,Jstree,我需要翻译jsTree中的contextmenu,它在您单击右键时显示,此时我创建了新文件jsTree.contextmenu.pl.js,并从jquery.jsTree.js复制了一些代码,并进行了自己的更改。这是可行的,但我不确定这是不是最好的选择 $.jstree.plugin("contextmenu", { __init : function () { this.get_container() .delegate("a", "co
$.jstree.plugin("contextmenu", {
__init : function () {
this.get_container()
.delegate("a", "contextmenu.jstree", $.proxy(function (e) {
e.preventDefault();
if(!$(e.currentTarget).hasClass("jstree-loading")) {
this.show_contextmenu(e.currentTarget, e.pageX, e.pageY);
}
}, this))
.delegate("a", "click.jstree", $.proxy(function (e) {
if(this.data.contextmenu) {
$.vakata.context.hide();
}
}, this))
.bind("destroy.jstree", $.proxy(function () {
// TODO: move this to descruct method
if(this.data.contextmenu) {
$.vakata.context.hide();
}
}, this));
$(document).bind("context_hide.vakata", $.proxy(function () { this.data.contextmenu = false; }, this));
},
defaults : {
select_node : false, // requires UI plugin
show_at_node : true,
items : { // Could be a function that should return an object like this one
"create" : {
"separator_before" : false,
"separator_after" : true,
"label" : "Utwórz nowy",
"action" : function (obj) { this.create(obj); }
},
"rename" : {
"separator_before" : false,
"separator_after" : false,
"label" : "Zmień nazwę",
"action" : function (obj) { this.rename(obj); }
},
"remove" : {
"separator_before" : false,
"icon" : false,
"separator_after" : false,
"label" : "Usuń",
"action" : function (obj) { if(this.is_selected(obj)) { this.remove(); } else { this.remove(obj); } }
},
"ccp" : {
"separator_before" : true,
"icon" : false,
"separator_after" : false,
"label" : "Edytuj",
"action" : false,
"submenu" : {
"cut" : {
"separator_before" : false,
"separator_after" : false,
"label" : "Wytnij",
"action" : function (obj) { this.cut(obj); }
},
"copy" : {
"separator_before" : false,
"icon" : false,
"separator_after" : false,
"label" : "Kopiuj",
"action" : function (obj) { this.copy(obj); }
},
"paste" : {
"separator_before" : false,
"icon" : false,
"separator_after" : false,
"label" : "Wklej",
"action" : function (obj) { this.paste(obj); }
}
}
}
}
},
_fn : {
show_contextmenu : function (obj, x, y) {
obj = this._get_node(obj);
var s = this.get_settings().contextmenu,
a = obj.children("a:visible:eq(0)"),
o = false,
i = false;
if(s.select_node && this.data.ui && !this.is_selected(obj)) {
this.deselect_all();
this.select_node(obj, true);
}
if(s.show_at_node || typeof x === "undefined" || typeof y === "undefined") {
o = a.offset();
x = o.left;
y = o.top + this.data.core.li_height;
}
i = obj.data("jstree") && obj.data("jstree").contextmenu ? obj.data("jstree").contextmenu : s.items;
if($.isFunction(i)) { i = i.call(this, obj); }
this.data.contextmenu = true;
$.vakata.context.show(i, a, x, y, this, obj, this._get_settings().core.rtl);
if(this.data.themes) { $.vakata.context.cnt.attr("class", "jstree-" + this.data.themes.theme + "-context"); }
}
}
});
如何正确地使用它 绝对不需要修改定义上下文菜单选项的jstree。您可以修改特定树实例的菜单,如下所示
$("#jstreediv").jstree({
contextmenu:{
items:{
"create" : {
"separator_before" : false,
"separator_after" : true,
"label" : "Utwórz nowy",
"action" : function (obj) { this.create(obj); }
},
"rename" : {
"separator_before" : false,
"separator_after" : false,
"label" : "Zmień nazwę",
"action" : function (obj) { this.rename(obj); }
},
"remove" : {
"separator_before" : false,
"icon" : false,
"separator_after" : false,
"label" : "Usuń",
"action" : function (obj) {
if(this.is_selected(obj)) {
this.remove();
}
else {
this.remove(obj);
}
}
}
}
},
plugins: ["contextmenu"]
});
或者,如果要将整个上下文菜单配置移动到其他新文件,则
编写一个函数,返回上下文菜单项,如下所示
function yourContextMenu() {
var items = {
"create" : {
"separator_before" : false,
"separator_after" : true,
"label" : "Utwórz nowy",
"action" : function (obj) { this.create(obj); }
},
"rename" : {
"separator_before" : false,
"separator_after" : false,
"label" : "Zmień nazwę",
"action" : function (obj) { this.rename(obj); }
},
"remove" : {
"separator_before" : false,
"icon" : false,
"separator_after" : false,
"label" : "Usuń",
"action" : function (obj) {
if(this.is_selected(obj)) {
this.remove();
}
else {
this.remove(obj);
}
}
}
//add as many context menu items as you want here
};
return items;
}
将此函数保存在javascript文件somename.js中
并将其包含在您的页面中
<script src="somename.js"></script>
绝对不需要修改定义上下文菜单选项的jstree。您可以修改特定树实例的菜单,如下所示
$("#jstreediv").jstree({
contextmenu:{
items:{
"create" : {
"separator_before" : false,
"separator_after" : true,
"label" : "Utwórz nowy",
"action" : function (obj) { this.create(obj); }
},
"rename" : {
"separator_before" : false,
"separator_after" : false,
"label" : "Zmień nazwę",
"action" : function (obj) { this.rename(obj); }
},
"remove" : {
"separator_before" : false,
"icon" : false,
"separator_after" : false,
"label" : "Usuń",
"action" : function (obj) {
if(this.is_selected(obj)) {
this.remove();
}
else {
this.remove(obj);
}
}
}
}
},
plugins: ["contextmenu"]
});
或者,如果要将整个上下文菜单配置移动到其他新文件,则
编写一个函数,返回上下文菜单项,如下所示
function yourContextMenu() {
var items = {
"create" : {
"separator_before" : false,
"separator_after" : true,
"label" : "Utwórz nowy",
"action" : function (obj) { this.create(obj); }
},
"rename" : {
"separator_before" : false,
"separator_after" : false,
"label" : "Zmień nazwę",
"action" : function (obj) { this.rename(obj); }
},
"remove" : {
"separator_before" : false,
"icon" : false,
"separator_after" : false,
"label" : "Usuń",
"action" : function (obj) {
if(this.is_selected(obj)) {
this.remove();
}
else {
this.remove(obj);
}
}
}
//add as many context menu items as you want here
};
return items;
}
将此函数保存在javascript文件somename.js中
并将其包含在您的页面中
<script src="somename.js"></script>
由于项目可以是一个函数,因此现在可以通过以下方式进行翻译: $'jstreediv'.jstree{ //... “上下文菜单”:{ “项”:函数n{ var tmp=$.jstree.defaults.contextmenu.items; tmp.create.label='Créer'; tmp.rename.label='Renommer'; tmp.remove.label='supplimer'; 返回tmp; } } };
由于项目可以是一个函数,因此现在可以通过以下方式进行翻译: $'jstreediv'.jstree{ //... “上下文菜单”:{ “项”:函数n{ var tmp=$.jstree.defaults.contextmenu.items; tmp.create.label='Créer'; tmp.rename.label='Renommer'; tmp.remove.label='supplimer'; 返回tmp; } } };
如何将其移动到一个配置文件?如果我在我的项目中使用jstree multiply?@Warthel4578我已经编辑了答案。退房你说的jstree乘法是什么意思?非常感谢!我不知道如何正确地做这件事。我想说我在几个地方使用了jstree,我想将配置移动到一个文件中。如何将其移动到一个配置文件中?如果我在我的项目中使用jstree multiply?@Warthel4578我已经编辑了答案。退房你说的jstree乘法是什么意思?非常感谢!我不知道如何正确地做这件事。我想说的是,我在几个地方使用了jstree,我想将配置移动到一个文件中。我已经搜索了一个小时来寻找覆盖默认值的方法,谢谢!我已经花了一个小时寻找一种方法来覆盖默认值,谢谢!