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
7.2 KiB
1 line
7.2 KiB
2 years ago
|
define(["jquery"],function(a){var b=!1,c=!1,d=function(){a(".tool-lp-menu .tool-lp-sub-menu").attr("aria-hidden","true"),c=!1},e=function(a,b){this.menuRoot=a,this.handlers=b,this.rootMenus=this.menuRoot.children("li"),this.subMenus=this.rootMenus.children("ul"),this.subMenuItems=this.subMenus.children("li"),this.allItems=this.rootMenus.add(this.subMenuItems),this.activeItem=null,this.isChildOpen=!1,this.keys={tab:9,enter:13,esc:27,space:32,left:37,up:38,right:39,down:40},this.addAriaAttributes(),this.addEventListeners()};return e.prototype.openSubMenu=function(a){this.setOpenDirection(),d(),a.attr("aria-hidden","false"),c=!0},e.prototype.addEventListeners=function(){var e=this;b===!1&&(a(document).click(function(){c&&d()}),b=!0),this.subMenuItems.mouseenter(function(){return a(this).addClass("menu-hover"),!0}),this.subMenuItems.mouseout(function(){return a(this).removeClass("menu-hover"),!0}),this.allItems.click(function(b){return e.handleClick(a(this),b)}),this.allItems.keydown(function(b){return e.handleKeyDown(a(this),b)}),this.allItems.focus(function(){return e.handleFocus(a(this))}),this.allItems.blur(function(){return e.handleBlur(a(this))})},e.prototype.handleClick=function(b,c){c.stopPropagation();var d=b.parent();if(d.is(".tool-lp-menu"))"true"==b.children("ul").first().attr("aria-hidden")?this.openSubMenu(b.children("ul").first()):b.children("ul").first().attr("aria-hidden","true");else{this.allItems.removeClass("menu-hover menu-focus"),this.activeItem=null,this.menuRoot.find("ul").not(".root-level").attr("aria-hidden","true");var e=b.find("a").first(),f=new a.Event("click");f.target=e;var g=!1;this.handlers&&a.each(this.handlers,function(c,d){if(!g&&b.find(c).length>0){var h=a.proxy(d,e);g=h(f)===!1||f.isDefaultPrevented()}}),g||"#"===e.attr("href")||(window.location.href=e.attr("href"))}return!1},e.prototype.handleFocus=function(a){if(null===this.activeItem)this.activeItem=a;else if(a[0]!=this.activeItem[0])return!0;var b=this.activeItem.parentsUntil("ul.tool-lp-menu").filter("li");if(this.allItems.removeClass("menu-focus"),this.activeItem.addClass("menu-focus"),b.addClass("menu-focus"),this.isChildOpen===!0){var c=a.parent();c.is(".tool-lp-menu")&&"true"==a.attr("aria-haspopup")&&this.openSubMenu(a.children("ul").first())}return!0},e.prototype.handleBlur=function(a){return a.removeClass("menu-focus"),!0},e.prototype.setOpenDirection=function(){var b=this.menuRoot.offset(),c=a(document.body).hasClass("dir-rtl"),d=!0,e=this.rootMenus.outerHeight(),f=this.rootMenus.outerWidth(),g=this.rootMenus.find("ul.tool-lp-sub-menu");g.css("margin-right",""),g.css("margin-left",""),g.css("margin-top",""),g.attr("aria-hidden",!1);var h=g.outerWidth(),i=g.outerHeight(),j=null,k=null,l=null,m=b.top-a(window).scrollTop();m+i>a(window).height()&&(j=i+e,g.css("margin-top","-"+j+"px")),c?b.left-h<0&&(k=h-f,g.css("margin-right","-"+k+"px")):b.left+h>a(window).width()&&(l=h-f,g.css("margin-left","-"+l+"px")),d?this.menuRoot.addClass("tool-lp-menu-open-left"):this.menuRoot.removeClass("tool-lp-menu-open-left")},e.prototype.handleKeyDown=function(a,b){if(b.altKey||b.ctrlKey)return!0;switch(b.keyCode){case this.keys.tab:this.menuRoot.find("ul").attr("aria-hidden","true"),this.allItems.removeClass("menu-focus"),this.activeItem=null,this.isChildOpen=!1;break;case this.keys.esc:var c=a.parent();return c.is(".tool-lp-menu")?a.children("ul").first().attr("aria-hidden","true"):(this.activeItem=c.parent(),this.isChildOpen=!1,this.activeItem.focus(),c.attr("aria-hidden","true")),b.stopPropagation(),!1;case this.keys.enter:case this.keys.space:return this.handleClick(a,b);case this.keys.left:return this.activeItem=this.moveToPrevious(a),this.activeItem.focus(),b.stopPropagation(),!1;case this.keys.right:return this.activeItem=this.moveToNext(a),this.activeItem.focus(),b.stopPropagation(),!1;case this.keys.up:return this.activeItem=this.moveUp(a),this.activeItem.focus(),b.stopPropagation(),!1;case this.keys.down:return this.activeItem=this.moveDown(a),this.activeItem.focus(),b.stopPropagation(),!1}return!0},e.prototype.moveToNext=function(a){
|