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 lines
2.8 KiB

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