MDL-56350 tool_usertours: Apply aria-hidden to other page elements
[moodle.git] / admin / tool / usertours / amd / build / tour.min.js
CommitLineData
741c2d46 1!function(a,b){"function"==typeof define&&define.amd?define(["jquery","./popper"],function(c,d){return a.Tour=b(c,d)}):"object"==typeof exports?module.exports=b(require("jquery"),require("popper.js")):a.Tour=b($,Popper)}(this,function(a,b){"use strict";function c(a){this.init(a)}var d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol?"symbol":typeof a};return c.prototype.tourName,c.prototype.originalConfiguration,c.prototype.listeners,c.prototype.eventHandlers,c.prototype.steps,c.prototype.currentStepNode,c.prototype.currentStepNumber,c.prototype.currentStepPopper,c.prototype.currentStepConfig,c.prototype.templateContent,c.prototype.init=function(a){return this.eventHandlers={},this.reset(),this.originalConfiguration=a||{},this.configure.apply(this,arguments),this},c.prototype.reset=function(){return this.hide(),this.eventHandlers=[],this.resetStepListeners(),this.originalConfiguration={},this.steps=[],this.currentStepNumber=0,this},c.prototype.configure=function(a){var b=this;return"object"===("undefined"==typeof a?"undefined":d(a))&&("undefined"!=typeof a.tourName&&(this.tourName=a.tourName),a.eventHandlers&&!function(){var c=void 0;for(c in a.eventHandlers)a.eventHandlers[c].forEach(function(a){this.addEventHandler(c,a)},b)}(),this.resetStepDefaults(!0),"object"===d(a.steps)&&(this.steps=a.steps),"undefined"!=typeof a.template&&(this.templateContent=a.template)),this.checkMinimumRequirements(),this},c.prototype.checkMinimumRequirements=function(){if(!this.tourName)throw new Error("Tour Name required");if(!this.steps||!this.steps.length)throw new Error("Steps must be specified")},c.prototype.resetStepDefaults=function(a){return"undefined"==typeof a&&(a=!0),this.stepDefaults={},a&&"undefined"!=typeof this.originalConfiguration.stepDefaults?this.setStepDefaults(this.originalConfiguration.stepDefaults):this.setStepDefaults({}),this},c.prototype.setStepDefaults=function(b){return this.stepDefaults||(this.stepDefaults={}),a.extend(this.stepDefaults,{element:"",placement:"top",delay:0,moveOnClick:!1,moveAfterTime:0,orphan:!1,direction:1},b),this},c.prototype.getCurrentStepNumber=function(){return parseInt(this.currentStepNumber,10)},c.prototype.setCurrentStepNumber=function(a){this.currentStepNumber=a},c.prototype.getNextStepNumber=function(a){"undefined"==typeof a&&(a=this.getCurrentStepNumber());for(var b=a+1;b<=this.steps.length;){if(this.isStepPotentiallyVisible(this.getStepConfig(b)))return b;b++}return null},c.prototype.getPreviousStepNumber=function(a){"undefined"==typeof a&&(a=this.getCurrentStepNumber());for(var b=a-1;b>=0;){if(this.isStepPotentiallyVisible(this.getStepConfig(b)))return b;b--}return null},c.prototype.isLastStep=function(a){var b=this.getNextStepNumber(a);return null===b},c.prototype.isFirstStep=function(a){var b=this.getPreviousStepNumber(a);return null===b},c.prototype.isStepPotentiallyVisible=function(a){return!!a&&(!!this.isStepActuallyVisible(a)||(!("undefined"==typeof a.orphan||!a.orphan)||!("undefined"==typeof a.delay||!a.delay)))},c.prototype.isStepActuallyVisible=function(a){if(!a)return!1;var b=this.getStepTarget(a);return!!(b&&b.length&&b.is(":visible"))&&!!b.length},c.prototype.next=function(){return this.gotoStep(this.getNextStepNumber())},c.prototype.previous=function(){return this.gotoStep(this.getPreviousStepNumber(),-1)},c.prototype.gotoStep=function(a,b){if(a<0)return this.endTour();var c=this.getStepConfig(a);return null===c?this.endTour():this._gotoStep(c,b)},c.prototype._gotoStep=function(a,b){if(!a)return this.endTour();if("undefined"!=typeof a.delay&&a.delay&&!a.delayed)return a.delayed=!0,window.setTimeout(this._gotoStep.bind(this),a.delay,a,b),this;if(!a.orphan&&!this.isStepActuallyVisible(a)){var c=b==-1?"getPreviousStepNumber":"getNextStepNumber";return this.gotoStep(this[c](a.stepNumber),b)}return this.hide(),this.fireEventHandlers("beforeRender",a),this.renderStep(a),this.fireEventHandlers("afterRender",a),this},c.prototype.getStepConfig=function(b){if(null===b||b<0||b>=this.steps.length)return null;var c=this.normalizeStepConfig(this.steps[b]);return c=a.extend(c,{stepNumber:b})},c.prototype.normalizeStepConfig=function(b){return"undefined"!=typeof b.reflex&&"undefined"==typeof b.moveAfterClick&&(b.moveAfterClick=b.reflex),"undefined"!=typeof b.element&&"undefined"==typeof b.target&&(b.target=b.element),"undefined"!=typeof b.content&&"undefined"==typeof b.body&&(b.body=b.content),b=a.extend({},this.stepDefaults,b),b=a.extend({},{attachTo:b.target,attachPoint:"after"},b)},c.prototype.getStepTarget=function(b){return b.target?a(b.target):null},c.prototype.fireEventHandlers=function(a,b){return"undefined"==typeof this.eventHandlers[a]?this:(this.eventHandlers[a].forEach(function(a){a.call(this,b)},this),this)},c.prototype.addEventHandler=function(a,b){return"undefined"==typeof this.eventHandlers[a]&&(this.eventHandlers[a]=[]),this.eventHandlers[a].push(b),this},c.prototype.processStepListeners=function(b){if(this.listeners.push({node:this.currentStepNode,args:["click",'[data-role="next"]',a.proxy(this.next,this)]},{node:this.currentStepNode,args:["click",'[data-role="previous"]',a.proxy(this.previous,this)]},{node:this.currentStepNode,args:["click",'[data-role="end"]',a.proxy(this.endTour,this)]},{node:a("body"),args:["keydown",a.proxy(this.handleKeyDown,this)]}),b.moveOnClick){var c=this.getStepTarget(b);this.listeners.push({node:c,args:["click",a.proxy(function(b){0===a(b.target).parents('[data-flexitour="container"]').length&&window.setTimeout(a.proxy(this.next,this),100)},this)]})}return this.listeners.forEach(function(a){a.node.on.apply(a.node,a.args)}),this},c.prototype.resetStepListeners=function(){return this.listeners&&this.listeners.forEach(function(a){a.node.off.apply(a.node,a.args)}),this.listeners=[],this},c.prototype.renderStep=function(b){this.currentStepConfig=b,this.setCurrentStepNumber(b.stepNumber);var c=a(this.getTemplateContent());return c.find('[data-placeholder="title"]').html(b.title),c.find('[data-placeholder="body"]').html(b.body),this.isFirstStep(b.stepNumber)?c.find('[data-role="previous"]').prop("disabled",!0):c.find('[data-role="previous"]').prop("disabled",!1),this.isLastStep(b.stepNumber)?c.find('[data-role="next"]').prop("disabled",!0):c.find('[data-role="next"]').prop("disabled",!1),c.find('[data-role="previous"]').attr("role","button"),c.find('[data-role="next"]').attr("role","button"),c.find('[data-role="end"]').attr("role","button"),b.template=c,this.addStepToPage(b),this.processStepListeners(b),this},c.prototype.getTemplateContent=function(){return a(this.templateContent).clone()},c.prototype.addStepToPage=function(c){var d=(c.template,a('<span data-flexitour="container"></span>').html(c.template).hide()),e=a("body, html").stop(!0,!0);if(this.isStepActuallyVisible(c)){var f=this.getStepTarget(c);f.data("flexitour","target");var g=this.calculateZIndex(f);g&&(c.zIndex=g+1),c.zIndex&&d.css("zIndex",c.zIndex+1),this.positionBackdrop(c),"append"===c.attachPoint?(a(c.attachTo).append(d),this.currentStepNode=d):this.currentStepNode=d.insertAfter(a(c.attachTo)),this.currentStepNode.css({top:0,left:0}),e.animate({scrollTop:this.calculateScrollTop(c)}).promise().then(a.proxy(function(){this.positionStep(c),this.revealStep(c)},this))}else c.orphan&&(c.isOrphan=!0,c.attachTo="body",c.attachPoint="append",this.positionBackdrop(c),d.addClass("orphan"),a(c.attachTo).append(d),this.currentStepNode=d,this.currentStepNode.offset(this.calculateStepPositionInPage()),this.currentStepPopper=new b(a("body"),this.currentStepNode[0],{removeOnDestroy:!0,placement:c.placement+"-start",arrowElement:'[data-role="arrow"]',modifiers:[]}),this.revealStep(c));return this},c.prototype.revealStep=function(b){return this.currentStepNode.fadeIn("",a.proxy(function(){this.announceStep(b),this.currentStepNode.focus(),window.setTimeout(a.proxy(function(){this.currentStepNode&&this.currentStepNode.focus()},this),100)},this)),this},c.prototype.announceStep=function(a){var b="tour-step-"+this.tourName+"-"+a.stepNumber;this.currentStepNode.attr("id",b);var c=this.currentStepNode.find('[data-placeholder="body"]').first();c.attr("id",b+"-body"),c.attr("role","document");var d=this.currentStepNode.find('[data-placeholder="title"]').first();d.attr("id",b+"-title"),d.attr("aria-labelledby",b+"-body"),this.currentStepNode.attr("role","dialog"),this.currentStepNode.attr("tabindex",0),this.currentStepNode.attr("aria-labelledby",b+"-title"),this.currentStepNode.attr("aria-describedby",b+"-body");var e=this.getStepTarget(a);return e&&(e.attr("tabindex")||e.attr("tabindex",0),e.data("original-describedby",e.attr("aria-describedby")).attr("aria-describedby",b+"-body")),this.accessibilityShow(a),this},c.prototype.handleKeyDown=function(b){var c="a[href], link[href], [draggable=true], [contenteditable=true], :input:enabled, [tabindex], button";switch(b.keyCode){case 27:this.endTour();break;case 9:(function(){if(this.currentStepConfig.hasBackdrop){var d=a(document.activeElement),e=this.getStepTarget(this.currentStepConfig),f=a(c),g=void 0;f.filter(function(a,b){if(d.is(b))return g=a,!1});var h=void 0,i=void 0,j=void 0;if(g){var k=1;b.shiftKey&&(k=-1),h=g;do h+=k,i=a(f[h]);while(i.length&&i.is(":disabled")||i.is(":hidden"));i.length?(j=i.closest(e).length,j=j||i.closest(this.currentStepNode).length):j=!1}j?i.focus():b.shiftKey?this.currentStepNode.find(c).last().focus():this.currentStepConfig.isOrphan?this.currentStepNode.focus():e.focus(),b.preventDefault()}}).call(this)}},c.prototype.startTour=function(a){return"undefined"==typeof a&&(a=this.getCurrentStepNumber()),this.fireEventHandlers("beforeStart",a),this.gotoStep(a),this.fireEventHandlers("afterStart",a),this},c.prototype.restartTour=function(){return this.startTour(0)},c.prototype.endTour=function(){if(this.fireEventHandlers("beforeEnd"),this.currentStepConfig){var a=this.getStepTarget(this.currentStepConfig);a&&(a.attr("tabindex")||a.attr("tabindex","-1"),a.focus())}return this.hide(!0),this.fireEventHandlers("afterEnd"),this},c.prototype.hide=function(b){if(this.fireEventHandlers("beforeHide"),this.currentStepNode&&this.currentStepNode.length&&(this.currentStepNode.hide(),this.currentStepPopper&&this.currentStepPopper.destroy()),this.currentStepConfig){var c=this.getStepTarget(this.currentStepConfig);c&&(c.data("original-labelledby")&&c.attr("aria-labelledby",c.data("original-labelledby")),c.data("original-describedby")&&c.attr("aria-describedby",c.data("original-describedby")),c.data("original-tabindex")&&c.attr("tabindex",c.data("tabindex"))),this.currentStepConfig=null}var d=0;return b&&(d=400),a('[data-flexitour="step-background"]').remove(),a('[data-flexitour="step-backdrop"]').removeAttr("data-flexitour"),a('[data-flexitour="backdrop"]').fadeOut(d,function(){a(this).remove()}),this.resetStepListeners(),this.accessibilityHide(),this.fireEventHandlers("afterHide"),this.currentStepNode=null,this.currentStepPopper=null,this},c.prototype.show=function(){var a=this.getCurrentStepNumber();return this.gotoStep(a)},c.prototype.getStepContainer=function(){return a(this.currentStepNode)},c.prototype.calculateScrollTop=function(b){var c=a(window).scrollTop(),d=a(window).height(),e=this.getStepTarget(b);return c="top"===b.placement?e.offset().top-d/2:"bottom"===b.placement?e.offset().top+e.height()-d/2:e.height()<=.8*d?e.offset().top-(d-e.height())/2:e.offset().top-.2*d,c=Math.max(0,c),c=Math.min(a(document).height()-d,c),Math.ceil(c)},c.prototype.calculateStepPositionInPage=function(){var b=a(window).height(),c=this.currentStepNode.height(),d=a(window).scrollTop(),e=a(window).width(),f=this.currentStepNode.width(),g=a(window).scrollLeft();return{top:Math.ceil(d+(b-c)/2),left:Math.ceil(g+(e-f)/2)}},c.prototype.positionStep=function(c){var d=this.currentStepNode;if(!d||!d.length)return this;var e=void 0;switch(c.placement){case"left":e=["left","right","top","bottom"];break;case"right":e=["right","left","top","bottom"];break;case"top":e=["top","bottom","right","left"];break;case"bottom":e=["bottom","top","right","left"];break;default:e="flip"}var f=this.getStepTarget(c),g=a('[data-flexitour="step-background"]');return g.length&&(f=g),this.currentStepPopper=new b(f,d[0],{placement:c.placement+"-start",removeOnDestroy:!0,flipBehavior:e,arrowElement:'[data-role="arrow"]',modifiers:["shift","offset","preventOverflow","keepTogether",this.centerPopper,"arrow","flip","applyStyle"]}),this},c.prototype.positionBackdrop=function(b){if(b.backdrop){this.currentStepConfig.hasBackdrop=!0;var c=a('<div data-flexitour="backdrop"></div>');if(b.zIndex?"append"===b.attachPoint?a(b.attachTo).append(c):c.insertAfter(a(b.attachTo)):a("body").append(c),this.isStepActuallyVisible(b)){var d=a('<div data-flexitour="step-background"></div>'),e=this.getStepTarget(b),f=10,g=e;f&&(g=a("body")),d.css({width:e.outerWidth()+f+f,height:e.outerHeight()+f+f,left:e.offset().left-f,top:e.offset().top-f,backgroundColor:this.calculateInherittedBackgroundColor(g)}),e.offset().left<f&&d.css({width:e.outerWidth()+e.offset().left+f,left:e.offset().left}),e.offset().top<f&&d.css({height:e.outerHeight()+e.offset().top+f,top:e.offset().top});var h=e.css("borderRadius");h&&h!==a("body").css("borderRadius")&&d.css("borderRadius",h);var i=this.calculatePosition(e);"fixed"===i&&d.css("top",0);var j=d.clone();j.css({backgroundColor:c.css("backgroundColor"),opacity:c.css("opacity")}),j.attr("data-flexitour","step-background-fader"),b.zIndex?"append"===b.attachPoint?a(b.attachTo).append(d):(j.insertAfter(a(b.attachTo)),d.insertAfter(a(b.attachTo))):(a("body").append(j),a("body").append(d)),e.attr("data-flexitour","step-backdrop"),b.zIndex&&(c.css("zIndex",b.zIndex),d.css("zIndex",b.zIndex+1),e.css("zIndex",b.zIndex+2)),j.fadeOut("2000",function(){a(this).remove()})}}return this},c.prototype.calculateZIndex=function(b){for(b=a(b);b.length&&b[0]!==document;){var c=b.css("position");if("absolute"===c||"relative"===c||"fixed"===c){var d=parseInt(b.css("zIndex"),10);if(!isNaN(d)&&0!==d)return d}b=b.parent()}return 0},c.prototype.calculateInherittedBackgroundColor=function(b){var c=a("<div>").hide();a("body").append(c);var d=c.css("backgroundColor");for(c.remove(),b=a(b);b.length&&b[0]!==document;){var e=b.css("backgroundColor");if(e!==d)return e;b=b.parent()}return null},c.prototype.calculatePosition=function(b){for(b=a(b);b.length&&b[0]!==document;){var c=b.css("position");if("static"!==c)return c;b=b.parent()}return null},c.prototype.centerPopper=function(a){if(!this.isModifierRequired(c.prototype.centerPopper,this.modifiers.keepTogether))return console.warn("WARNING: keepTogether modifier is required by centerPopper modifier in order to work, be sure to include it before arrow!"),a;var b=a.placement.split("-")[0],d=a.offsets.reference,e=["left","right"].indexOf(b)!==-1,f=e?"height":"width",g=e?"top":"left";return a.offsets.popper[g]+=Math.max(d[f]/2-a.offsets.popper[f]/2,0),a},c.prototype.accessibilityShow=function(b){var c="data-has-hidden",d="aria-hidden",e=function(a){var b=a.data("flexitour");if(b)switch(b){case"container":case"target":return}var e=a.attr(d);e||(a.attr(c,!0),a.attr(d,!0))};this.currentStepNode.siblings().each(function(b,c){e(a(c))}),this.currentStepNode.parentsUntil("body").siblings().each(function(b,c){e(a(c))})},c.prototype.accessibilityHide=function(){var b="data-has-hidden",c="aria-hidden",d=function(a){var d=a.attr(b);"undefined"!=typeof d&&(a.removeAttr(b),a.removeAttr(c))};a("["+b+"]").each(function(b,c){d(a(c))})},"object"===("undefined"==typeof exports?"undefined":d(exports))&&(module.exports=c),c});