diff --git a/blocks/navigation/renderer.php b/blocks/navigation/renderer.php index 3c8932c306b..131c559ec4a 100644 --- a/blocks/navigation/renderer.php +++ b/blocks/navigation/renderer.php @@ -140,7 +140,8 @@ class block_navigation_renderer extends plugin_renderer_base { $liclasses[] = 'contains_branch'; if ($depth == 1) { $liexpandable = array( - 'data-expandable' => 'false' + 'data-expandable' => 'false', + 'data-collapsible' => 'false' ); } else { $liexpandable = array( diff --git a/lib/amd/build/tree.min.js b/lib/amd/build/tree.min.js index abc9f1d60b6..f29cc28ee04 100644 --- a/lib/amd/build/tree.min.js +++ b/lib/amd/build/tree.min.js @@ -1 +1 @@ -define(["jquery"],function(a){var b={ITEM:"[role=treeitem]",GROUP:"[role=treeitem]:has([role=group]), [role=treeitem][data-requires-ajax=true]",CLOSED_GROUP:"[role=treeitem]:has([role=group])[aria-expanded=false], [role=treeitem][data-requires-ajax=true][aria-expanded=false]",FIRST_ITEM:"[role=treeitem]:first",VISIBLE_ITEM:"[role=treeitem]:visible",UNLOADED_AJAX_ITEM:"[role=treeitem][data-requires-ajax=true][data-loaded=false][aria-expanded=true]"},c=function(c,d){this.treeRoot=a(c),this.treeRoot.data("activeItem",null),this.selectCallback=d,this.keys={tab:9,enter:13,space:32,pageup:33,pagedown:34,end:35,home:36,left:37,up:38,right:39,down:40,asterisk:106},this.initialiseNodes(this.treeRoot),this.setActiveItem(this.treeRoot.find(b.FIRST_ITEM)),this.refreshVisibleItemsCache(),this.bindEventHandlers()};return c.prototype.refreshVisibleItemsCache=function(){this.treeRoot.data("visibleItems",this.treeRoot.find(b.VISIBLE_ITEM))},c.prototype.getVisibleItems=function(){return this.treeRoot.data("visibleItems")},c.prototype.setActiveItem=function(a){var b=this.treeRoot.data("activeItem");a!==b&&(null!==b&&(b.attr("tabindex","-1"),b.attr("aria-selected","false")),a.attr("tabindex","0"),a.attr("aria-selected","true"),this.treeRoot.data("activeItem",a),"function"==typeof this.selectCallback&&this.selectCallback(a))},c.prototype.isGroupItem=function(a){return a.is(b.GROUP)},c.prototype.initialiseNodes=function(c){this.removeAllFromTabOrder(c),this.setAriaSelectedFalseOnItems(c);var d=this;c.find(b.UNLOADED_AJAX_ITEM).each(function(){var b=a(this);d.collapseGroup(b),d.expandGroup(b)})},c.prototype.removeAllFromTabOrder=function(a){a.find("*").attr("tabindex","-1")},c.prototype.setAriaSelectedFalseOnItems=function(a){a.find(b.ITEM).attr("aria-selected","false")},c.prototype.expandAllGroups=function(){this.expandAllChildGroups(this.treeRoot)},c.prototype.expandAllChildGroups=function(c){var d=this;c.find(b.CLOSED_GROUP).each(function(){var b=a(this);d.expandGroup(b).done(function(){d.expandAllChildGroups(b)})})},c.prototype.expandGroup=function(b){var c=a.Deferred();if("false"!==b.attr("data-expandable")&&"true"!==b.attr("aria-expanded"))if("true"===b.attr("data-requires-ajax")&&"true"!==b.attr("data-loaded")){b.attr("data-loaded",!1);var d=b.closest("[data-ajax-loader]").attr("data-ajax-loader"),e=this;b.addClass("loading"),require([d],function(a){a.load(b).done(function(){b.attr("data-loaded",!0),e.initialiseNodes(b),e.finishExpandingGroup(b),b.removeClass("loading"),c.resolve()})})}else this.finishExpandingGroup(b),c.resolve();else c.resolve();return c},c.prototype.finishExpandingGroup=function(a){var c=a.children(b.GROUP);c.show().attr("aria-hidden","false"),a.attr("aria-expanded","true"),this.refreshVisibleItemsCache()},c.prototype.collapseGroup=function(a){if("false"!==a.attr("aria-expanded")){var c=a.children(b.GROUP);c.hide().attr("aria-hidden","true"),a.attr("aria-expanded","false"),this.refreshVisibleItemsCache()}},c.prototype.toggleGroup=function(a){"true"===a.attr("aria-expanded")?this.collapseGroup(a):this.expandGroup(a)},c.prototype.handleKeyDown=function(a,c){var d=this.getVisibleItems().index(a);if(c.altKey||c.ctrlKey||c.shiftKey&&c.keyCode!=this.keys.tab)return!0;switch(c.keyCode){case this.keys.home:return this.getVisibleItems().first().focus(),c.stopPropagation(),!1;case this.keys.end:return this.getVisibleItems().last().focus(),c.stopPropagation(),!1;case this.keys.enter:var e=a.children().not(b.GROUP).children("a");return e.length?window.location.href=e.first().attr("href"):this.isGroupItem(a)&&this.toggleGroup(a,!0),c.stopPropagation(),!1;case this.keys.space:return this.isGroupItem(a)&&this.toggleGroup(a,!0),c.stopPropagation(),!1;case this.keys.left:if(this.isGroupItem(a)){this.collapseGroup(a);var f=this.getVisibleItems().filter(b.GROUP),g=f.index(a),h=g-1>0?g-1:0;f.eq(h).focus()}return c.stopPropagation(),!1;case this.keys.right:return this.isGroupItem(a)&&this.expandGroup(a).done(function(){a.find(b.ITEM).first().focus()}),c.stopPropagation(),!1;case this.keys.up:if(d>0){var i=this.getVisibleItems().eq(d-1);i.focus()}return c.stopPropagation(),!1;case this.keys.down:if(d0){var g=this.getVisibleItems().eq(d-1);g.focus()}return c.stopPropagation(),!1;case this.keys.down:if(d 0 ? index - 1 : 0; - visibleGroups.eq(prevIndex).focus(); + if (this.isGroupCollapsed(item)) { + focusParent(this); + } else { + this.collapseGroup(item); + } + } else { + focusParent(this); } e.stopPropagation(); @@ -362,10 +391,12 @@ define(['jquery'], function($) { // If this is a group item then expand it and focus the first child item // in accordance with the aria spec. if (this.isGroupItem(item)) { - this.expandGroup(item).done(function() { + if (this.isGroupCollapsed(item)) { + this.expandGroup(item); + } else { // Move to the first item in the child group. item.find(SELECTORS.ITEM).first().focus(); - }); + } } e.stopPropagation();