diff --git a/README.md b/README.md index 07bb574..053ddcc 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,10 @@ To automate the process of building the css, Grunt is used. To use grunt, switch This will build the css and output it to `bootstrap-combined.min.css` file. You can also use `grunt watch` to watch changes to the less files while you build and test. + +#### Usage + +Just call .bootstrapTree() on the root element of the tree: + + $('.tree').boootstrapTree(); + diff --git a/js/bootstrap-tree.js b/js/bootstrap-tree.js index e69fb46..dd20494 100644 --- a/js/bootstrap-tree.js +++ b/js/bootstrap-tree.js @@ -1,15 +1,36 @@ -$(document).ready(function() { - $('.tree > ul').attr('role', 'tree').find('ul').attr('role', 'group'); - $('.tree').find('li:has(ul)').addClass('parent_li').attr('role', 'treeitem').find(' > span').attr('title', 'Collapse this branch').on('click', function (e) { - var children = $(this).parent('li.parent_li').find(' > ul > li'); - if (children.is(':visible')) { - children.hide('fast'); - $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign'); +!function( $ ) { + var bootstrapTree = { + init: function() { + $(this).find('ul').attr('role', 'tree').find('ul').attr('role', 'group'); + $(this) + .find('li:has(ul)') + .addClass('parent_li') + .attr('role', 'treeitem') + .find(' > span') + .attr('title', 'Collapse this branch') + .on('click', function(e) { + var children = $(this).parent('li.parent_li').find(' > ul > li'); + if (children.is(':visible')) { + children.hide('fast'); + $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign'); + } + else { + children.show('fast'); + $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign'); + } + e.stopPropagation(); + }); } - else { - children.show('fast'); - $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign'); - } - e.stopPropagation(); - }); -}); \ No newline at end of file + }; + + $.fn.bootstrapTree = function(method) { + if (bootstrapTree[method]) { + return bootstrapTree[ method ].apply(this, Array.prototype.slice.call(arguments, 1)); + } else if (typeof method === 'object' || !method) { + return bootstrapTree.init.apply(this, arguments); + } else { + $.error('Method with name ' + method + ' does not exists for jQuery.bootstrapTree'); + } + }; + +}(window.jQuery); diff --git a/less/bootstrap-tree.less b/less/bootstrap-tree.less index e9132d5..e9f4163 100644 --- a/less/bootstrap-tree.less +++ b/less/bootstrap-tree.less @@ -72,7 +72,7 @@ } /*Remove connectors after last child*/ &:last-child::before { - height: 30px; + height: 14px; } } /*Remove connectors before root*/