Skip to content

Commit

Permalink
Merge branch 'MDL-60079-34' of https://github.com/nashtechdev01/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_34_STABLE
  • Loading branch information
David Monllao committed Jan 9, 2018
2 parents 99d570f + 3fef39f commit 068f22a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 25 deletions.
2 changes: 1 addition & 1 deletion admin/tool/usertours/amd/build/tour.min.js

Large diffs are not rendered by default.

82 changes: 59 additions & 23 deletions admin/tool/usertours/amd/src/tour.js
Expand Up @@ -619,26 +619,43 @@ Tour.prototype.addEventHandler = function (eventName, handler) {
*/ */
Tour.prototype.processStepListeners = function (stepConfig) { Tour.prototype.processStepListeners = function (stepConfig) {
this.listeners.push( this.listeners.push(
// Next/Previous buttons. // Next/Previous buttons.
{ {
node: this.currentStepNode, node: this.currentStepNode,
args: ['click', '[data-role="next"]', $.proxy(this.next, this)] args: ['click', '[data-role="next"]', $.proxy(this.next, this)]
}, { }, {
node: this.currentStepNode, node: this.currentStepNode,
args: ['click', '[data-role="previous"]', $.proxy(this.previous, this)] args: ['click', '[data-role="previous"]', $.proxy(this.previous, this)]
}, },


// Close and end tour buttons. // Close and end tour buttons.
{ {
node: this.currentStepNode, node: this.currentStepNode,
args: ['click', '[data-role="end"]', $.proxy(this.endTour, this)] args: ['click', '[data-role="end"]', $.proxy(this.endTour, this)]
}, },


// Keypresses. // Click backdrop and hide tour.
{ {
node: $('body'), node: $('[data-flexitour="backdrop"]'),
args: ['keydown', $.proxy(this.handleKeyDown, this)] args: ['click', $.proxy(this.hide, this)]
}); },

// Click out and hide tour without backdrop.
{
node: $('body'),
args: ['click', $.proxy(function (e) {
// Handle click in or click out tour content,
// if click out, hide tour.
if (!this.currentStepNode.is(e.target) && $(e.target).closest('[data-role="flexitour-step"]').length === 0) {
this.hide();
}}, this)]
},

// Keypresses.
{
node: $('body'),
args: ['keydown', $.proxy(this.handleKeyDown, this)]
});


if (stepConfig.moveOnClick) { if (stepConfig.moveOnClick) {
var targetNode = this.getStepTarget(stepConfig); var targetNode = this.getStepTarget(stepConfig);
Expand Down Expand Up @@ -904,7 +921,7 @@ Tour.prototype.announceStep = function (stepConfig) {
* @param {EventFacade} e * @param {EventFacade} e
*/ */
Tour.prototype.handleKeyDown = function (e) { Tour.prototype.handleKeyDown = function (e) {
var tabbableSelector = 'a[href], link[href], [draggable=true], [contenteditable=true], :input:enabled, [tabindex], button'; var tabbableSelector = 'a[href], link[href], [draggable=true], [contenteditable=true], :input:enabled, [tabindex], button:enabled';
switch (e.keyCode) { switch (e.keyCode) {
case 27: case 27:
this.endTour(); this.endTour();
Expand All @@ -923,8 +940,17 @@ Tour.prototype.handleKeyDown = function (e) {
var activeElement = $(document.activeElement); var activeElement = $(document.activeElement);
var stepTarget = this.getStepTarget(this.currentStepConfig); var stepTarget = this.getStepTarget(this.currentStepConfig);
var tabbableNodes = $(tabbableSelector); var tabbableNodes = $(tabbableSelector);
var dialogContainer = $('span[data-flexitour="container"]');
var currentIndex = void 0; var currentIndex = void 0;
tabbableNodes.filter(function (index, element) { // Filter out element which is not belong to target section or dialogue.
if (stepTarget) {
tabbableNodes = tabbableNodes.filter(function (index, element) {
return stepTarget != null && (stepTarget.has(element).length || dialogContainer.has(element).length || stepTarget.is(element) || dialogContainer.is(element));
});
}

// Find index of focusing element.
tabbableNodes.each(function (index, element) {
if (activeElement.is(element)) { if (activeElement.is(element)) {
currentIndex = index; currentIndex = index;
return false; return false;
Expand All @@ -934,7 +960,7 @@ Tour.prototype.handleKeyDown = function (e) {
var nextIndex = void 0; var nextIndex = void 0;
var nextNode = void 0; var nextNode = void 0;
var focusRelevant = void 0; var focusRelevant = void 0;
if (currentIndex) { if (currentIndex != void 0) {
var direction = 1; var direction = 1;
if (e.shiftKey) { if (e.shiftKey) {
direction = -1; direction = -1;
Expand Down Expand Up @@ -1090,6 +1116,16 @@ Tour.prototype.hide = function (transition) {
$(this).remove(); $(this).remove();
}); });


// Remove aria-describedby and tabindex attributes.
if (this.currentStepNode && this.currentStepNode.length) {
var stepId = this.currentStepNode.attr('id');
if (stepId) {
var currentStepElement = '[aria-describedby="' + stepId + '-body"]';
$(currentStepElement).removeAttr('tabindex');
$(currentStepElement).removeAttr('aria-describedby');
}
}

// Reset the listeners. // Reset the listeners.
this.resetStepListeners(); this.resetStepListeners();


Expand Down
20 changes: 20 additions & 0 deletions admin/tool/usertours/tests/behat/tour_filter.feature
Expand Up @@ -157,3 +157,23 @@ Feature: Apply tour filters to a tour
When I am on "Course 2" course homepage When I am on "Course 2" course homepage
And I wait until the page is ready And I wait until the page is ready
Then I should not see "Welcome to your course tour." Then I should not see "Welcome to your course tour."

@javascript
Scenario: Aria tags should not exist
Given I log in as "admin"
And I open the User tour settings page
# Turn on default tour for boost theme.
And I click on "Enable" "link" in the "Boost - administrator" "table_row"
And I am on site homepage
When I click on "Next" "button"
Then "button[aria-describedby^='tour-step-tool_usertours']" "css_element" should exist
And "button[tabindex]" "css_element" should exist
When I click on "Next" "button"
Then "button[aria-describedby^='tour-step-tool_usertours']" "css_element" should not exist
And "button[tabindex]" "css_element" should not exist
When I click on "Previous" "button"
Then "button[aria-describedby^='tour-step-tool_usertours']" "css_element" should exist
And "button[tabindex]" "css_element" should exist
When I click on "End tour" "button"
Then "button[aria-describedby^='tour-step-tool_usertours']" "css_element" should not exist
And "button[tabindex]" "css_element" should not exist
2 changes: 1 addition & 1 deletion admin/tool/usertours/thirdpartylibs.xml
Expand Up @@ -4,7 +4,7 @@
<location>amd/src/tour.js</location> <location>amd/src/tour.js</location>
<name>Flexitour</name> <name>Flexitour</name>
<license>GPLv3</license> <license>GPLv3</license>
<version>0.10.0</version> <version>0.12.0</version>
<licenseversion>3</licenseversion> <licenseversion>3</licenseversion>
</library> </library>
<library> <library>
Expand Down

0 comments on commit 068f22a

Please sign in to comment.