| $.fn.millerColumns = function( options ) { | ||
| var defaults = { | ||
| - selection: function( $item ) {}, | ||
| + current: function( $item ) {}, | ||
| breadcrumb: breadcrumb, | ||
| animation: animation, | ||
| settings.animation.call( this, $columns, $(this) ); | ||
| settings.breadcrumb.call( this ); | ||
| - settings.selection.call( this, $(this) ); | ||
| + settings.current.call( this, $(this) ); | ||
| // Don't allow the underlying DIV to receive the click event. | ||
| var $breadcrumb = $("div.breadcrumb").empty(); | ||
| - $(".column > .selected").each( function( _, crumb ) { | ||
| + chain().each( function( _, crumb ) { | ||
| $("<span/>").text( $(crumb).text().trim() ).appendTo( $breadcrumb ); | ||
| }); | ||
| reset = function() { | ||
| collapse(); | ||
| - $(".column > .selected").removeClass( "selected" ); | ||
| + chain().removeClass( "selected" ); | ||
| breadcrumb(); | ||
| + | ||
| + // Upon reset ensure no value is returned to the calling code. | ||
| + settings.current( undefined ); | ||
| } | ||
| keypress = function( event ) { | ||
| + // Was an attempt made to move the currently selected item (the cursor)? | ||
| var moved = false; | ||
| break; | ||
| } | ||
| - | ||
| - if( moved ) { | ||
| - var $current = current(); | ||
| - // If no item is selected, then jump to the first item. | ||
| - if( $current.length == 0 ) { | ||
| - $(".column").first().children().first().click(); | ||
| - } | ||
| + // If no item is selected, then jump to the first item. | ||
| + if( moved && (current().length == 0) ) { | ||
| + $(".column").first().children().first().click(); | ||
| } | ||
| + } | ||
| + | ||
| + /** Returns a list of the currently selected items. */ | ||
| + chain = function() { | ||
| + return $(".column > .selected"); | ||
| } | ||
| /** Returns the last selected item (i.e., the current cursor). */ | ||
| - current = function () { | ||
| - return $(".column > .selected").last(); | ||
| + current = function() { | ||
| + return chain().last(); | ||
| } | ||
| + /** Select item above current selection. */ | ||
| moveU = function() { | ||
| current().prev().click(); | ||
| } | ||
| + /** Select item below current selection. */ | ||
| moveD = function() { | ||
| current().next().click(); | ||
| } | ||
| + /** Select item left of the current selection. */ | ||
| moveL = function() { | ||
| var $ancestor = current().data( "ancestor" ); | ||
| if( $ancestor !== undefined ) { | ||
| $ancestor.click(); | ||
| } | ||
| } | ||
| + /** Select item right of the current selection, or down if no right item. */ | ||
| moveR = function() { | ||
| var $child = current().data( "child" ); | ||
| - if( $child !== undefined ) { | ||
| - $child.children().first().click(); | ||
| - } | ||
| - else { | ||
| - moveD(); | ||
| - } | ||
| + ($child === undefined) ? moveD() : $child.children().first().click(); | ||
| } | ||
| })(jQuery); | ||
| -(function(a,k,l,e){var f;a.fn.millerColumns=function(c){f=a.extend({selection:function(a){},breadcrumb:breadcrumb,animation:animation,delay:500},c);return this.each(function(){var b=a(this);unnest(b);collapse();b.find("li").on("click",function(c){reset();var d=a(this).data("child");d!==e&&d.removeClass("collapse").children().removeClass("selected");for(d=a(this);d!==e;)d.addClass("selected").parent().removeClass("collapse"),d=d.data("ancestor");f.animation.call(this,b,a(this));f.breadcrumb.call(this); | ||
| -f.selection.call(this,a(this));c.stopPropagation()});b.bind("keypress",keypress);b.on("click",function(){reset()});b.focus()})};animation=function(a,b){a.animate({scrollLeft:b.offset().left},f.delay)};breadcrumb=function(){var c=a("div.breadcrumb").empty();a(".column > .selected").each(function(b,e){a("<span/>").text(a(e).text().trim()).appendTo(c)})};unnest=function(c){var b=[];for(b.push(c.children());b.length;)b.shift().children().each(function(f,d){var g=a(this).children(),h=a(this).parent().parent(); | ||
| -h.length&&a(this).data("ancestor")===e&&a(this).siblings().addBack().data("ancestor",h);0<g.length&&(b.push(g),a(this).data("child",g).addClass("parent"));a(this).parent().appendTo(c).addClass("column")})};collapse=function(){a(".column:gt(0)").addClass("collapse")};reset=function(){collapse();a(".column > .selected").removeClass("selected");breadcrumb()};keypress=function(c){var b=!1;switch(c.keyCode){case 27:reset();break;case 38:moveU();b=!0;break;case 40:moveD();b=!0;break;case 37:moveL();b=!0; | ||
| -break;case 39:moveR(),b=!0}b&&0==current().length&&a(".column").first().children().first().click()};current=function(){return a(".column > .selected").last()};moveU=function(){current().prev().click()};moveD=function(){current().next().click()};moveL=function(){var a=current().data("ancestor");a!==e&&a.click()};moveR=function(){var a=current().data("child");a!==e?a.children().first().click():moveD()}})(jQuery); | ||
| +(function(a,k,l,d){var f;a.fn.millerColumns=function(c){f=a.extend({current:function(b){},breadcrumb:breadcrumb,animation:animation,delay:500},c);return this.each(function(){var b=a(this);unnest(b);collapse();b.find("li").on("click",function(c){reset();var e=a(this).data("child");e!==d&&e.removeClass("collapse").children().removeClass("selected");for(e=a(this);e!==d;)e.addClass("selected").parent().removeClass("collapse"),e=e.data("ancestor");f.animation.call(this,b,a(this));f.breadcrumb.call(this); | ||
| +f.current.call(this,a(this));c.stopPropagation()});b.bind("keypress",keypress);b.on("click",function(){reset()});b.focus()})};animation=function(a,b){a.animate({scrollLeft:b.offset().left},f.delay)};breadcrumb=function(){var c=a("div.breadcrumb").empty();chain().each(function(b,d){a("<span/>").text(a(d).text().trim()).appendTo(c)})};unnest=function(c){var b=[];for(b.push(c.children());b.length;)b.shift().children().each(function(f,e){var g=a(this).children(),h=a(this).parent().parent();h.length&& | ||
| +a(this).data("ancestor")===d&&a(this).siblings().addBack().data("ancestor",h);0<g.length&&(b.push(g),a(this).data("child",g).addClass("parent"));a(this).parent().appendTo(c).addClass("column")})};collapse=function(){a(".column:gt(0)").addClass("collapse")};reset=function(){collapse();chain().removeClass("selected");breadcrumb();f.current(d)};keypress=function(c){var b=!1;switch(c.keyCode){case 27:reset();break;case 38:moveU();b=!0;break;case 40:moveD();b=!0;break;case 37:moveL();b=!0;break;case 39:moveR(), | ||
| +b=!0}b&&0==current().length&&a(".column").first().children().first().click()};chain=function(){return a(".column > .selected")};current=function(){return chain().last()};moveU=function(){current().prev().click()};moveD=function(){current().next().click()};moveL=function(){var a=current().data("ancestor");a!==d&&a.click()};moveR=function(){var a=current().data("child");a===d?moveD():a.children().first().click()}})(jQuery); | ||
| Author | Dave Jarvis <email> |
|---|---|
| Date | 2015-01-01 04:00:34 GMT-0800 |
| Commit | 3b74f980227c8ae03dec27a311d26c0736a33be0 |
| Parent | bc78f82 |
| Delta | 27 lines added, 23 lines removed, 4-line increase |