Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/miller-columns.git

Moved breadcrumb and toolbar into HTML. Added hooks for event notifications. Added a few default settings.

AuthorDave Jarvis <email>
Date2014-12-31 04:41:01 GMT-0800
Commit5492ef9bf793c8ef4d4620c8beee815d40d5b248
Parentdf06b17
README.md
1. Create a element for the nested HTML list's columnar version.
1. Add the nested HTML list inside the columnar element.
+1. Optionally, include breadcrumb and toolbar classes on div elements.
1. Add the following code to the HTML document:
```
<script type="text/javascript">
$(document).ready( function() { $("div.columns").millerColumns(); });
</script>
```
-See the example `index.html` for technical details.
+See the example `index.html` for further details.
columns.js
-(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" );
}
index.html
<body>
<div id="container">
+ <div class="breadcrumb"></div>
<div class="columns">
<ul>
</ul>
</div>
+ <div class="toolbar"></div>
</div>
</body>
Delta32 lines added, 17 lines removed, 15-line increase