Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'MDL-62144-35' of git://github.com/damyon/moodle into MO…
…ODLE_35_STABLE
  • Loading branch information
David Monllao committed Oct 22, 2018
2 parents f9f8edc + 40a9015 commit 5cccfd2
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 14 deletions.
1 change: 1 addition & 0 deletions lang/en/moodle.php
Expand Up @@ -26,6 +26,7 @@
$string['action'] = 'Action';
$string['actionchoice'] = 'What do you want to do with the file \'{$a}\'?';
$string['actions'] = 'Actions';
$string['actionsmenu'] = 'Actions menu';
$string['active'] = 'Active';
$string['activeusers'] = 'Active users';
$string['activities'] = 'Activities';
Expand Down
36 changes: 33 additions & 3 deletions lib/outputcomponents.php
Expand Up @@ -4127,6 +4127,12 @@ class action_menu implements renderable, templatable {
*/
public $actiontext = null;

/**
* The string to use for the accessible label for the menu.
* @var array
*/
public $actionlabel = null;

/**
* An icon to use for the toggling the secondary menu (dropdown).
* @var actionicon
Expand Down Expand Up @@ -4184,6 +4190,16 @@ public function __construct(array $actions = array()) {
}
}

/**
* Sets the label for the menu trigger.
*
* @param string $label The text
* @return null
*/
public function set_action_label($label) {
$this->actionlabel = $label;
}

/**
* Sets the menu trigger text.
*
Expand Down Expand Up @@ -4287,7 +4303,7 @@ public function get_primary_actions(core_renderer $output = null) {
$pixicon = '<b class="caret"></b>';
$linkclasses[] = 'textmenu';
} else {
$title = new lang_string('actions', 'moodle');
$title = new lang_string('actionsmenu', 'moodle');
$this->actionicon = new pix_icon(
't/edit_menu',
'',
Expand All @@ -4306,10 +4322,17 @@ public function get_primary_actions(core_renderer $output = null) {
if ($this->actiontext) {
$string = $this->actiontext;
}
$label = '';
if ($this->actionlabel) {
$label = $this->actionlabel;
} else {
$label = $title;
}
$actions = $this->primaryactions;
$attributes = array(
'class' => implode(' ', $linkclasses),
'title' => $title,
'aria-label' => $label,
'id' => 'action-menu-toggle-'.$this->instance,
'role' => 'menuitem'
);
Expand Down Expand Up @@ -4475,9 +4498,16 @@ public function export_for_template(renderer_base $output) {
if (!empty($this->menutrigger)) {
$primary->menutrigger = $this->menutrigger;
$primary->triggerextraclasses = $this->triggerextraclasses;
if ($this->actionlabel) {
$primary->title = $this->actionlabel;
} else if ($this->actiontext) {
$primary->title = $this->actiontext;
} else {
$primary->title = strip_tags($this->menutrigger);
}
} else {
$primary->title = get_string('actions');
$actionicon = new pix_icon('t/edit_menu', '', 'moodle', ['class' => 'iconsmall actionmenu', 'title' => '']);
$primary->title = get_string('actionsmenu');
$actionicon = new pix_icon('t/edit_menu', '', 'moodle', ['class' => 'iconsmall actionmenu', 'title' => $primary->title]);
}

if ($actionicon instanceof pix_icon) {
Expand Down
1 change: 1 addition & 0 deletions lib/outputrenderers.php
Expand Up @@ -3418,6 +3418,7 @@ public function user_menu($user = null, $withlinks = null) {
$am->set_menu_trigger(
$returnstr
);
$am->set_action_label(get_string('usermenu'));
$am->set_alignment(action_menu::TR, action_menu::BR);
$am->set_nowrap_on_items();
if ($withlinks) {
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/action_menu_trigger.mustache
Expand Up @@ -27,4 +27,4 @@
"triggerextraclasses": ""
}
}}
<a href="#" class="{{triggerextraclasses}} toggle-display {{#menutrigger}}textmenu{{/menutrigger}}" id="action-menu-toggle-{{instance}}" title="{{title}}" role="menuitem">{{{actiontext}}}{{{menutrigger}}}{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{#rawicon}}{{{.}}}{{/rawicon}}{{#menutrigger}}<b class="caret"></b>{{/menutrigger}}</a>
<a tabindex="0" class="{{triggerextraclasses}} toggle-display {{#menutrigger}}textmenu{{/menutrigger}}" id="action-menu-toggle-{{instance}}" aria-label="{{title}}" role="menuitem" aria-controls="action-menu-{{instance}}-menu">{{{actiontext}}}{{{menutrigger}}}{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{#rawicon}}{{{.}}}{{/rawicon}}{{#menutrigger}}<b class="caret"></b>{{/menutrigger}}</a>
5 changes: 4 additions & 1 deletion lib/tests/user_menu_test.php
Expand Up @@ -86,6 +86,8 @@ public function test_custom_user_menu($data, $entrycount, $dividercount) {
$this->setAdminUser();
$PAGE->set_url('/');
$CFG->theme = 'clean';
$PAGE->reset_theme_and_output();
$PAGE->initialise_theme_and_output();

// Set the configuration.
set_config('customusermenuitems', $data);
Expand All @@ -94,7 +96,8 @@ public function test_custom_user_menu($data, $entrycount, $dividercount) {
$dividercount += 2;

// The basic entry count will additionally include the wrapper menu, Dashboard, Profile, Logout and switch roles link.
$entrycount += 4;
// On clean theme only, the trigger is also a menuitem.
$entrycount += 5;

$output = $OUTPUT->user_menu($USER);
preg_match_all('/<a [^>]+role="menuitem"[^>]+>/', $output, $results);
Expand Down
1 change: 1 addition & 0 deletions theme/boost/amd/build/aria.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion theme/boost/amd/build/loader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

183 changes: 183 additions & 0 deletions theme/boost/amd/src/aria.js
@@ -0,0 +1,183 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Enhancements to Bootstrap components for accessibility.
*
* @module theme_boost/aria
* @copyright 2018 Damyon Wiese <damyon@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery'], function($) {
return {
init: function() {
// Drop downs from bootstrap don't support keyboard accessibility by default.
var focusEnd = false,
setFocusEnd = function() {
focusEnd = true;
},
getFocusEnd = function() {
var result = focusEnd;
focusEnd = false;
return result;
};

// Special handling for "up" keyboard control.
$('[data-toggle="dropdown"]').keydown(function (e) {
var trigger = e.which || e.keyCode,
expanded;

// Up key opens the menu at the end.
if (trigger == 38) {
// Focus the end of the menu, not the beginning.
setFocusEnd();
}

// Escape key only closes the menu, it doesn't open it.
if (trigger == 27) {
expanded = $(e.target).attr('aria-expanded');
e.preventDefault();
if (expanded == "false") {
$(e.target).click();
}
}

// Space key or Enter key opens the menu.
if (trigger == 32 || trigger == 13) {
// Cancel random scroll.
e.preventDefault();
// Open the menu instead.
$(e.target).click();
}
});

// Special handling for navigation keys when menu is open.
var shiftFocus = function(element) {
var delayedFocus = function() {
$(this).focus();
}.bind(element);
setTimeout(delayedFocus, 50);
};

$('.dropdown').on('shown.bs.dropdown', function(e) {
// We need to focus on the first menuitem.
var menu = $(e.target).find('[role="menu"]'),
menuItems = false,
foundMenuItem = false;

if (menu) {
menuItems = $(menu).find('[role="menuitem"]');
}
if (menuItems && menuItems.length > 0) {
if (getFocusEnd()) {
foundMenuItem = menuItems[menuItems.length - 1];
} else {
// The first menu entry, pretty reasonable.
foundMenuItem = menuItems[0];
}
}
if (foundMenuItem) {
shiftFocus(foundMenuItem);
}
});
// Search for menu items.
$('.dropdown [role="menu"] [role="menuitem"]').keypress(function (e) {
var trigger = String.fromCharCode(e.which || e.keyCode),
menu = $(e.target).closest('[role="menu"]'),
i = 0,
menuItems = false,
item;

if (!menu) {
return;
}
menuItems = $(menu).find('[role="menuitem"]');
if (!menuItems) {
return;
}

trigger = trigger.toLowerCase();
for (i = 0; i < menuItems.length; i++) {
item = $(menuItems[i]);
if ((item.text().trim().indexOf(trigger) == 0) ||
(item.text().trim().indexOf(trigger.toUpperCase()) == 0)) {
shiftFocus(item);
break;
}
}
});

// Keyboard navigation for arrow keys, home and end keys.
$('.dropdown [role="menu"] [role="menuitem"]').keydown(function (e) {
var trigger = e.which || e.keyCode,
next = false,
menu = $(e.target).closest('[role="menu"]'),
i = 0,
menuItems = false;
if (!menu) {
return;
}
menuItems = $(menu).find('[role="menuitem"]');
if (!menuItems) {
return;
}
// Down.
if (trigger == 40) {
for (i = 0; i < menuItems.length - 1; i++) {
if (menuItems[i] == e.target) {
next = menuItems[i + 1];
}
}
if (!next) {
// Wrap to first item.
trigger = 36;
}
}
// Up.
if (trigger == 38) {
for (i = 1; i < menuItems.length; i++) {
if (menuItems[i] == e.target) {
next = menuItems[i - 1];
}
}
if (!next) {
// Wrap to last item.
trigger = 35;
}
}
// Home.
if (trigger == 36) {
next = menuItems[0];
}
// End.
if (trigger == 35) {
next = menuItems[menuItems.length - 1];
}
if (next) {
e.preventDefault();
shiftFocus(next);
}
return;
});
$('.dropdown').on('hidden.bs.dropdown', function(e) {
// We need to focus on the menu trigger.
var trigger = $(e.target).find('[data-toggle="dropdown"]');
if (trigger) {
shiftFocus(trigger);
}
});
}
};
});
8 changes: 6 additions & 2 deletions theme/boost/amd/src/loader.js
Expand Up @@ -28,7 +28,8 @@ define(['jquery', './tether', 'core/event'], function(jQuery, Tether, Event) {
window.jQuery = jQuery;
window.Tether = Tether;

require(['theme_boost/util',
require(['theme_boost/aria',
'theme_boost/util',
'theme_boost/alert',
'theme_boost/button',
'theme_boost/carousel',
Expand All @@ -39,7 +40,7 @@ define(['jquery', './tether', 'core/event'], function(jQuery, Tether, Event) {
'theme_boost/tab',
'theme_boost/tooltip',
'theme_boost/popover'],
function() {
function(Aria) {

// We do twice because: https://github.com/twbs/bootstrap/issues/10547
jQuery('body').popover({
Expand All @@ -63,8 +64,11 @@ define(['jquery', './tether', 'core/event'], function(jQuery, Tether, Event) {
selector: '[data-toggle="popover"]',
trigger: 'focus'
});

});
});

Aria.init();
});


Expand Down
2 changes: 1 addition & 1 deletion theme/boost/templates/core/action_menu.mustache
Expand Up @@ -52,4 +52,4 @@
</div>

{{/primary}}
</div>
</div>
6 changes: 3 additions & 3 deletions theme/boost/templates/core/action_menu_trigger.mustache
Expand Up @@ -78,7 +78,7 @@
}
}}
<div class="dropdown">
<a href="#" class="{{triggerextraclasses}} dropdown-toggle" id="dropdown-{{instance}}" title="{{title}}" role="menuitem" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<a tabindex="0" class="btn {{triggerextraclasses}} dropdown-toggle" id="dropdown-{{instance}}" aria-label="{{title}}" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" aria-controls="action-menu-{{instance}}-menu">
{{{actiontext}}}
{{{menutrigger}}}
{{#icon}}
Expand All @@ -92,7 +92,7 @@
{{/menutrigger}}
</a>
{{#secondary}}
<div class="dropdown-menu dropdown-menu-right {{classes}}"{{#attributes}} {{name}}="{{value}}"{{/attributes}}>
<div class="dropdown-menu dropdown-menu-right {{classes}}"{{#attributes}} {{name}}="{{value}}"{{/attributes}} id="dropdown-menu-{{instance}}">
{{#items}}
{{#actionmenulink}}
<a href="{{url}}" class="dropdown-item {{classes}}" {{#attributes}}{{name}}={{#quote}}{{value}}{{/quote}} {{/attributes}}{{#showtext}}aria-labelledby="actionmenuaction-{{instance}}"{{/showtext}}>
Expand All @@ -107,7 +107,7 @@
</a>
{{/actionmenulink}}
{{#actionmenufiller}}
<div class="dropdown-divider"></div>
<div class="dropdown-divider" role="presentation"><span class="filler">&nbsp;</span></div>
{{/actionmenufiller}}
{{^actionmenulink}}
{{^actionmenufiller}}
Expand Down
2 changes: 1 addition & 1 deletion theme/boost/templates/core/custom_menu_item.mustache
Expand Up @@ -10,7 +10,7 @@
<a class="dropdown-item" href="{{{url}}}" {{#title}}title="{{{title}}}"{{/title}}>{{{text}}}</a>
{{/divider}}
{{#divider}}
<div class="dropdown-divider"></div>
<div class="dropdown-divider" role="presentation"></div>
{{/divider}}
{{/children}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2018051702.08; // 20180517 = branching date YYYYMMDD - do not modify!
$version = 2018051702.09; // 20180517 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.

Expand Down

0 comments on commit 5cccfd2

Please sign in to comment.