MDL-55074 theme_boost: Navigation and blocks
[moodle.git] / theme / boost / amd / build / drawer.min.js
1 define(["jquery","core/custom_interaction_events","core/notification"],function(a,b,c){var d={TOGGLE_REGION:'[data-region="drawer-toggle"]',TOGGLE_ACTION:'[data-action="toggle-drawer"]',TOGGLE_TARGET:"aria-controls",TOGGLE_SIDE:"left",BODY:"body"},e=function(){a(d.TOGGLE_REGION).length||c.exception({message:"Page is missing a drawer toggle region"}),a(d.TOGGLE_ACTION).length||c.exception({message:"Page is missing a drawer toggle link"}),a(d.TOGGLE_REGION).each(function(b,c){var e=a(c).find(d.TOGGLE_ACTION),f="false"==e.attr("aria-expanded"),g=e.attr("data-side"),h=a(d.BODY);f?e.attr("aria-expanded","false"):(h.addClass("drawer-open-"+g),e.attr("aria-expanded","true"))}.bind(this)),this.registerEventListeners()};return e.prototype.closeAll=function(){a(d.TOGGLE_REGION).each(function(b,c){var e=a(c).find(d.TOGGLE_ACTION),f=e.attr("data-side"),g=a(d.BODY),h=e.attr("aria-controls"),i=a(document.getElementById(h)),j=e.attr("data-preference");e.attr("aria-expanded","false"),g.removeClass("drawer-open-"+f),i.attr("aria-hidden","true"),i.addClass("closed"),M.util.set_user_preference(j,"false")}.bind(this))},e.prototype.toggleDrawer=function(b){var c=a(b.target).closest("[data-action=toggle-drawer]"),e=c.attr("aria-controls"),f=a(document.getElementById(e)),g=a(d.BODY),h=c.attr("data-side"),i=c.attr("data-preference");g.addClass("drawer-ease");var j="true"==c.attr("aria-expanded");if(j)g.removeClass("drawer-open-"+h),c.attr("aria-expanded","false"),f.attr("aria-hidden","true"),f.addClass("closed"),M.util.set_user_preference(i,"false");else{var k=a(document).width()<512;k&&this.closeAll(),c.attr("aria-expanded","true"),f.attr("aria-hidden","false"),g.addClass("drawer-open-"+h),f.removeClass("closed"),M.util.set_user_preference(i,"true")}},e.prototype.registerEventListeners=function(){var c=a(d.BODY);b.define(c,[b.events.activate]),c.on(b.events.activate,d.TOGGLE_ACTION,function(a,b){this.toggleDrawer(b.originalEvent),b.originalEvent.preventDefault()}.bind(this))},{init:function(){return new e}}});