This is the folding menu effect code of the online help manual implemented by jquery.
; (Function ($ ){
Function load (settings, root, child, container ){
$. GetJSON (settings. url, {root: root}, function (response ){
Function createNode (parent ){
Var current = $ ("<li/> "). attr ("id", this. id | "" ).html ("<span>" + this. text + "</span> "). appendTo (parent );
If (this. classes ){
Current. children ("span"). addClass (this. classes );
}
If (this. expanded ){
Current. addClass ("open ");
}
If (this. hasChildren | this. children & this. children. length ){
Var branch = $ ("<ul/>"). appendTo (current );
If (this. hasChildren ){
Current. addClass ("hasChildren ");
CreateNode. call ({
Text: "placeholder ",
Id: "placeholder ",
Children: []
}, Branch );
}
If (this. children & this. children. length ){
$. Each (this. children, createNode, [branch])
}
}
}
$. Each (response, createNode, [child]);
$ (Container). treeview ({add: child });
});
}
Var proxied = $. fn. treeview;
$. Fn. treeview = function (settings ){
If (! Settings. url ){
Return proxied. apply (this, arguments );
}
Var container = this;
Load (settings, "source", this, container );
Var userToggle = settings. toggle;
Return proxied. call (this, $. extend ({}, settings ,{
Collapsed: true,
Toggle: function (){
Var $ this = $ (this );
If ($ this. hasClass ("hasChildren ")){
Var childList = $ this. removeClass ("hasChildren"). find ("ul ");
ChildList. empty ();
Load (settings, this. id, childList, container );
}
If (userToggle ){
UserToggle. apply (this, arguments );
}
}
}));
};
}) (JQuery );