| | -(function( $ ) { |
| | - $.fn.millerColumns = function() { |
| | +;(function( $, window, document, undefined ) { |
| | + var settings; |
| | + |
| | + $.fn.millerColumns = function( options ) { |
| | + var defaults = { |
| | + selection: function( $item ) {}, |
| | + breadcrumb: $.fn.millerColumns.breadcrumb, |
| | + animation: $.fn.millerColumns.animation, |
| | + delay: 500 |
| | + }; |
| | + |
| | + settings = $.extend( defaults, options ); |
| | + |
| | return this.each( function() { |
| | var $columns = $(this); |
| | - $columns.before( $("<div/>").addClass( "breadcrumb" ) ); |
| | - $columns.after( $("<div/>").addClass( "toolbar" ) ); |
| | - unnest( $columns ); |
| | - collapse(); |
| | + $.fn.millerColumns.unnest( $columns ); |
| | + $.fn.millerColumns.collapse(); |
| | |
| | // Expand the requested child node on click. |
| | $columns.find( "li" ).on( "click", function() { |
| | - collapse(); |
| | + $.fn.millerColumns.collapse(); |
| | $(".selected").removeClass( "selected" ); |
| | |
 |
| | $ancestor = $ancestor.data( "ancestor" ); |
| | } |
| | - |
| | - breadcrumb(); |
| | |
| | - // Ensure the viewport shows the entire newly expanded item. |
| | - $columns.animate( { scrollLeft: $(this).offset().left }, 500 ); |
| | + settings.animation.call( this, $columns, $(this) ); |
| | + settings.breadcrumb.call( this ); |
| | + settings.selection.call( this, $(this) ); |
| | }); |
| | }); |
| | } |
| | |
| | - /** Determine the breadcrumb path via the selected items. */ |
| | - function breadcrumb() { |
| | + /** Ensure the viewport shows the entire newly expanded item. */ |
| | + $.fn.millerColumns.animation = function( $columns, $column ) { |
| | + $columns.animate( { scrollLeft: $column.offset().left }, settings.delay ); |
| | + } |
| | + |
| | + /** Add the breadcrumb path using the chain of selected items. */ |
| | + $.fn.millerColumns.breadcrumb = function() { |
| | var $breadcrumb = $("div.breadcrumb").empty(); |
| | |
| | - // Add the breadcrumb trail. |
| | $("li.selected").each( function( _, crumb ) { |
| | $("<span/>").text( $(crumb).text().trim() ).appendTo( $breadcrumb ); |
| | }); |
| | } |
| | |
| | /** Convert nested lists into columns using breadth-first traversal. */ |
| | - function unnest( $columns ) { |
| | + $.fn.millerColumns.unnest = function( $columns ) { |
| | var queue = []; |
| | |
 |
| | |
| | /** Hide all columns, except the first. */ |
| | - function collapse() { |
| | + $.fn.millerColumns.collapse = function() { |
| | $(".column:gt(0)").addClass( "collapse" ); |
| | } |