Firstly you should show the original Simple jQuery Tree site jQuery Simple TreeView Plugin
after you briefly review the options for the plugin as
now we will describe the customized method that will add accordion effect to the first level of the tree
and here the sample implementation
and you can find complete sample from here
keep commenting.
after you briefly review the options for the plugin as
- open: "▼", // HTML string to display for the opened handle
- close: "►", // HTML string to display for the closed handle
- slide: false, // Boolean flag to indicate if node should slide open/close
- speed: 'normal', // Speed of the slide. Can be a string: 'slow', 'fast', or a number of milliseconds: 1000
- collapsed: false, // Boolean to indicate if the tree should be collapsed on build
- collapse: null, // A node to collapse on build. Can be a string with indexes: '0.1.2' or a jQuery ul: $("#tree ul:eq(1)")
- expand: null // A node to expand on build. Can be a string with indexes: '0.1.2' or a jQuery ul: $("#tree ul:eq(1)")
$(document).ready(
function
() {
$(
"ul#sitemap"
).simpletreeview();
});
now we will describe the customized method that will add accordion effect to the first level of the tree
- function toggle($ul, method, callback)
- // this method customized by Ahmed Gouda to support accordion effect
- // only for first level and also highlighting anchor elements
- // Set callback to empty function if undefined
- if (callback === undefined) callback = function() { };
- var $handle = $ul.parent("li").children("span.handle");
- var $anchor = $ul.parent("li").children("a");
- if ($ul.is(':hidden') && $ul.hasClass('SecondLevelUL')) {
- $(this).parent("li").children("span.handle").html(settings.close);
- $(this).parent("li").children("a").css('font-weight', 'normal');
- $(this).slideUp(settings.speed, callback);
- });
- }
- if (method == "open") {
- $handle.html(settings.open);
- $anchor.css('font-weight', 'bold');
- if (settings.slide) { $ul.slideDown(settings.speed, callback); }
- else { $ul.show(); callback(); }
- }
- else if (method == "close") {
- $handle.html(settings.close);
- $anchor.css('font-weight', 'normal');
- if (settings.slide) { $ul.slideUp(settings.speed, callback); }
- else { $ul.hide(); callback(); }
- }
- else {
- $handle.html($ul.is(':hidden') ? settings.open : settings.close);
- if ($ul.is(':hidden'))
- $anchor.css('font-weight', 'bold');
- else
- $anchor.css('font-weight', 'normal');
- if (settings.slide) { $ul.slideToggle(settings.speed, callback); }
- else { $ul.toggle(); callback(); }
- }
- }
- <script type="text/javascript">
- var sitemap = $("#sitemap").simpletreeview({
- open: '<span style="color: #900;">↓</span>',
- close: '<span style="color: #090;">→</span>',
- slide: true,
- speed: 'fast',
- collapsed: true,
- expand: '0'
- });
- });
- });
- });
- </script>
keep commenting.