Making a catalog. It was necessary to make a tree of product categories / companies / services with infinite nesting. Each category can be checked by checkbox, so that later you can get a list / array of all selected categories (for example, to search by them).
Wrote this tree here. Implemented as a plugin to your favorite jQuery) ')
What can:
If an empty div is specified, it loads all categories from the specified script and subcategories (nested ul, if li has the folder class and does not have an nested list (ul)) the tree will automatically load this list from the specified script with the specified recursion depth requested data with the required parameters).
If a ready list is specified, then you can collapse / expand subcategories, mark the necessary ones, which will be highlighted with the specified class
Get selected category numbers (value checkboxes) in an array
Ability to search all loaded branches of the tree, displaying the search result in the specified div (indicated by the search div, in which the line for entering the query + div (empty) for outputting the results)
The number of search results can be limited (in parameters)
When you click on one of the results found - the tree opens to display the specified branch and it is highlighted by the class (indicated in the parameters)
You can set that when you click on the parent category - internal also highlighted
You can set a message that is issued when trying to highlight an extra checkbox if their number is limited.
It seems to have not forgotten anything)
Options:
_loadPath - the path to the file from where the categories will be loaded.
_loadLvl - the number of default subcategories - 0 - load all nested
_selectChildren - whether or not to select child subcategories when selecting the parent
_liminSelected - limit the number of marked categories
_limitMessage - message if the number of marked categories is exceeded
_searchDiv - container to search (must be a string and div)
_showResult - how many search results found show 0-all.
_hlClass - class for which the found categories will be highlighted
_checkedClass - class highlighting marked categories.
* This source code was highlighted with Source Code Highlighter .
I will explain a little: the li element which has nested lists must have a folder class, all ul that must be visible have an expanded class. The title of the category is thrust into the span, just by clicking on it and the folding / unfolding of the sub-branch occurs.
Well, everything seems to be ...
Strong beauty has not yet suggested, so do not judge. I will accept constructive criticism;)