Jquery folding menu code

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.