MDL-56350 tool_usertours: Apply aria-hidden to other page elements
authorAndrew Nicols <andrew@nicols.co.uk>
Fri, 21 Oct 2016 04:41:40 +0000 (12:41 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Fri, 21 Oct 2016 04:41:44 +0000 (12:41 +0800)
Note: This patch is in the upstream library.

admin/tool/usertours/amd/build/tour.min.js
admin/tool/usertours/amd/src/tour.js
admin/tool/usertours/thirdpartylibs.xml

index 2a58fee..2f37014 100644 (file)
Binary files a/admin/tool/usertours/amd/build/tour.min.js and b/admin/tool/usertours/amd/build/tour.min.js differ
index 46a0e19..1f7d0c6 100644 (file)
@@ -722,7 +722,11 @@ Tour.prototype.addStepToPage = function (stepConfig) {
     var animationTarget = $('body, html').stop(true, true);
 
     if (this.isStepActuallyVisible(stepConfig)) {
-        var zIndex = this.calculateZIndex(this.getStepTarget(stepConfig));
+        var targetNode = this.getStepTarget(stepConfig);
+
+        targetNode.data('flexitour', 'target');
+
+        var zIndex = this.calculateZIndex(targetNode);
         if (zIndex) {
             stepConfig.zIndex = zIndex + 1;
         }
@@ -774,6 +778,7 @@ Tour.prototype.addStepToPage = function (stepConfig) {
         this.currentStepNode.offset(this.calculateStepPositionInPage());
 
         this.currentStepPopper = new Popper($('body'), this.currentStepNode[0], {
+            removeOnDestroy: true,
             placement: stepConfig.placement + '-start',
             arrowElement: '[data-role="arrow"]',
             // Empty the modifiers. We've already placed the step and don't want it moved.
@@ -847,6 +852,8 @@ Tour.prototype.announceStep = function (stepConfig) {
         target.data('original-describedby', target.attr('aria-describedby')).attr('aria-describedby', stepId + '-body');
     }
 
+    this.accessibilityShow(stepConfig);
+
     return this;
 };
 
@@ -1036,6 +1043,8 @@ Tour.prototype.hide = function (transition) {
     // Reset the listeners.
     this.resetStepListeners();
 
+    this.accessibilityHide();
+
     this.fireEventHandlers('afterHide');
 
     this.currentStepNode = null;
@@ -1372,6 +1381,50 @@ Tour.prototype.centerPopper = function (data) {
     return data;
 };
 
+Tour.prototype.accessibilityShow = function (stepConfig) {
+    var stateHolder = 'data-has-hidden';
+    var attrName = 'aria-hidden';
+    var hideFunction = function hideFunction(child) {
+        var flexitourRole = child.data('flexitour');
+        if (flexitourRole) {
+            switch (flexitourRole) {
+                case 'container':
+                case 'target':
+                    return;
+            }
+        }
+
+        var hidden = child.attr(attrName);
+        if (!hidden) {
+            child.attr(stateHolder, true);
+            child.attr(attrName, true);
+        }
+    };
+
+    this.currentStepNode.siblings().each(function (index, node) {
+        hideFunction($(node));
+    });
+    this.currentStepNode.parentsUntil('body').siblings().each(function (index, node) {
+        hideFunction($(node));
+    });
+};
+
+Tour.prototype.accessibilityHide = function () {
+    var stateHolder = 'data-has-hidden';
+    var attrName = 'aria-hidden';
+    var showFunction = function showFunction(child) {
+        var hidden = child.attr(stateHolder);
+        if (typeof hidden !== 'undefined') {
+            child.removeAttr(stateHolder);
+            child.removeAttr(attrName);
+        }
+    };
+
+    $('[' + stateHolder + ']').each(function (index, node) {
+        showFunction($(node));
+    });
+};
+
 if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') {
     module.exports = Tour;
 }
index 99e6120..45bad95 100644 (file)
@@ -4,7 +4,7 @@
     <location>amd/src/tour.js</location>
     <name>Flexitour</name>
     <license>GPLv3</license>
-    <version>0.9.6</version>
+    <version>0.9.7</version>
     <licenseversion>3</licenseversion>
   </library>
   <library>