You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
2.5 KiB

define(["jquery","core/custom_interaction_events","core/log"],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",SECTION:'.list-group-item[href*="#section-"]'},e=a(document).width()<768,f=function(){a(d.TOGGLE_REGION).length||c.debug("Page is missing a drawer region"),a(d.TOGGLE_ACTION).length||c.debug("Page is missing a drawer toggle link"),a(d.TOGGLE_REGION).each(function(b,c){var f=a(c).find(d.TOGGLE_ACTION),g=f.attr("aria-controls"),h=a(document.getElementById(g)),i="false"==f.attr("aria-expanded"),j=f.attr("data-side"),k=a(d.BODY),l=f.attr("data-preference");e&&M.util.set_user_preference(l,"false"),h.on("mousewheel DOMMouseScroll",this.preventPageScroll),i?f.attr("aria-expanded","false"):(k.addClass("drawer-open-"+j),f.attr("aria-expanded","true"))}.bind(this)),this.registerEventListeners(),e&&this.closeAll()};return f.prototype.closeAll=function(){a(d.TOGGLE_REGION).each(function(b,c){var f=a(c).find(d.TOGGLE_ACTION),g=f.attr("data-side"),h=a(d.BODY),i=f.attr("aria-controls"),j=a(document.getElementById(i)),k=f.attr("data-preference");f.attr("aria-expanded","false"),h.removeClass("drawer-open-"+g),j.attr("aria-hidden","true"),j.addClass("closed"),e||M.util.set_user_preference(k,"false")})},f.prototype.toggleDrawer=function(b){var c=a(b.target).closest("[data-action=toggle-drawer]"),f=c.attr("aria-controls"),g=a(document.getElementById(f)),h=a(d.BODY),i=c.attr("data-side"),j=c.attr("data-preference");e&&M.util.set_user_preference(j,"false"),h.addClass("drawer-ease");var k="true"==c.attr("aria-expanded");k?(h.removeClass("drawer-open-"+i),c.attr("aria-expanded","false"),g.attr("aria-hidden","true"),g.addClass("closed"),e||M.util.set_user_preference(j,"false")):(c.attr("aria-expanded","true"),g.attr("aria-hidden","false"),g.focus(),h.addClass("drawer-open-"+i),g.removeClass("closed"),e||M.util.set_user_preference(j,"true"))},f.prototype.preventPageScroll=function(b){var c=b.wheelDelta||b.originalEvent&&b.originalEvent.wheelDelta||-b.originalEvent.detail,d=this.scrollTop+a(this).outerHeight()-this.scrollHeight>=0,e=this.scrollTop<=0;(c<0&&d||c>0&&e)&&b.preventDefault()},f.prototype.registerEventListeners=function(){a(d.TOGGLE_ACTION).each(function(c,d){b.define(a(d),[b.events.activate]),a(d).on(b.events.activate,function(a,b){this.toggleDrawer(b.originalEvent),b.originalEvent.preventDefault()}.bind(this))}.bind(this)),a(d.SECTION).click(function(){e&&this.closeAll()}.bind(this))},{init:function(){return new f}}});