Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/delibero.git

Removed duplicated code. Fixed bug with automatic scrolling to selected column.

AuthorDave Jarvis <email>
Date2014-12-29 04:39:02 GMT-0800
Commit923f88c7892dbfe36e7252a1903099da833b231b
Parent58b21e8
xml/js/tags.js
$.fn.millerColumns = function() {
return this.each( function() {
- $(this).before( $("<div>").addClass( "breadcrumb" ) );
- $(this).after( $("<div>").addClass( "toolbar" ) );
- unnest( $(this) );
+ var $columns = $(this);
+ $columns.before( $("<div>").addClass( "breadcrumb" ) );
+ $columns.after( $("<div>").addClass( "toolbar" ) );
+ unnest( $columns );
collapse();
// Expand the requested child node on click.
- $(this).find( "li" ).on( "click", function() {
+ $columns.find( "li" ).on( "click", function() {
collapse();
$(this).addClass( "selection" ).siblings().removeClass( "selection" );
- var $descendant = $(this).data( "descendants" );
+ var $descendants = $(this).data( "descendants" );
- if( $descendant !== undefined ) {
- $descendant.removeClass( "collapsed" );
- $descendant.children().removeClass( "selection" );
+ if( $descendants !== undefined ) {
+ $descendants.removeClass( "collapsed" );
+ $descendants.children().removeClass( "selection" );
}
// Ensure the viewport shows the entire newly expanded item.
- $column.parent().parent().animate(
- { scrollLeft: $column.offset().left },
- 500 );
+ $columns.animate( { scrollLeft: $(this).offset().left }, 500 );
});
});
}
+ /** Determine the breadcrumb path via the selected items. */
function breadcrumb() {
var $breadcrumb = $("div.breadcrumb").empty();
// Add the breadcrumb trail.
$("li.selection").each( function( _, crumb ) {
$breadcrumb.append( "<span>" + $(crumb).text() + "</span>" );
});
}
- /* Convert nested lists into columns using breadth-first traversal. */
+ /** Convert nested lists into columns using breadth-first traversal. */
function unnest( $columns ) {
var queue = [];
if( $descendants.length > 0 ) {
queue.push( $descendants );
- $(this).data( "descendants", $descendants );
- $(this).addClass( "parent" );
+ $(this).data( "descendants", $descendants ).addClass( "parent" );
}
// Causes item siblings to have a flattened DOM lineage.
$(this).parent().detach().appendTo( $columns ).addClass( "column" );
});
}
}
- /** Hide all the columns and deselect selected items. */
+ /** Hide all columns, except the first. */
function collapse() {
$(".column:gt(0)").addClass( "collapsed" );
Delta14 lines added, 15 lines removed, 1-line decrease