📄 jquery.agiletreeview.1.0.js
字号:
// Version: 1.0
// Author: Spring.Cheung(spring.cheung@163.com)
// LastChangedDate: 2008-06-02
// Requires: jquery.1.2.3.jsjQuery.fn.agileTreeView = function(options) { options = jQuery.extend( { container: $(this).attr("id"), key: "title", separator: "|", target: "Ids" }, options);
if (options.container != null && options.container != "" && options.target != null && options.target != "")
{
// refresh checked nodes
var target = $("#" + options.target);
$(":checkbox[@id^=" + options.container + "n]", $("#" + options.container)).each(
function()
{
var key = $(this).next().attr(options.key);
var checked = target.val().indexOf(options.separator + key) >= 0;
$(this).attr("checked", checked);
});
$(":checkbox:not(:checked)[@id^=" + options.container + "n]", $("#" + options.container)).each(
function()
{
var checkeds = $(":checkbox:checked[@id^=" + options.container + "n]", $("#" + $(this).attr("id").replace("CheckBox", "Nodes"))).length;
if (checkeds == 0)
{
$(this).attr("checked", false);
$(this).removeAttr("indeterminate");
}
else if (checkeds < $(":checkbox[@id^=" + options.container + "n]", $("#" + $(this).attr("id").replace("CheckBox", "Nodes"))).length)
{
$(this).attr("checked", false);
$(this).attr("indeterminate", true);
}
else
{
$(this).attr("checked", true);
$(this).removeAttr("indeterminate");
}
});
// choose nodes
$(":checkbox", $("#" + options.container)).click(
function()
{
// deal with current node
var key = $(this).next().attr(options.key);
var checked = $(this).attr("checked") != null;
if (checked)
{
target.val(target.val() + options.separator + key);
}
else
{
target.val(target.val().replace(options.separator + key, ""));
}
// deal with child nodes
$(":checkbox[@id^=" + options.container + "n]", $("#" + $(this).attr("id").replace("CheckBox", "Nodes"))).each(
function()
{
key = $(this).next().attr(options.key);
$(this).attr("checked", checked);
$(this).removeAttr("indeterminate");
if (checked)
{
target.val(target.val() + options.separator + key);
}
else
{
target.val(target.val().replace(options.separator + key, ""));
}
});
// deal with parent nodes
$(this).parents("div[@id^=" + options.container + "n]").each(
function()
{
$(":checkbox[@id=" + $(this).attr("id").replace("Nodes", "CheckBox") + "]").each(
function()
{
key = $(this).next().attr(options.key);
var checkeds = $(":checkbox:checked[@id^=" + options.container + "n]", $("#" + $(this).attr("id").replace("CheckBox", "Nodes"))).length;
if (checkeds == 0)
{
$(this).attr("checked", false);
$(this).removeAttr("indeterminate");
target.val(target.val().replace(options.separator + key, ""));
}
else if (checkeds < $(":checkbox[@id^=" + options.container + "n]", $("#" + $(this).attr("id").replace("CheckBox", "Nodes"))).length)
{
$(this).attr("checked", false);
$(this).attr("indeterminate", true);
target.val(target.val().replace(options.separator + key, ""));
}
else
{
$(this).attr("checked", true);
$(this).removeAttr("indeterminate");
target.val(target.val() + options.separator + key);
}
});
});
});
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -