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.7 KiB

!function(factory){"function"==typeof define&&define.amd?define(["jquery"],factory):"object"==typeof exports?module.exports=factory(require("jquery")):factory(jQuery)}(function($){var DropdownSubmenu=function(){function DropdownSubmenu(element){this.element=element.parentElement,this.menuElement=this.element.querySelector(".dropdown-menu"),this.init()}var _proto=DropdownSubmenu.prototype;return _proto.init=function(){var _this=this;$(this.element).off("keydown.bs.dropdown.data-api"),this.menuElement.addEventListener("keydown",this.itemKeydown.bind(this));var dropdownItemNodeList=this.menuElement.querySelectorAll(".dropdown-item");Array.from(dropdownItemNodeList).forEach(function(element){element.addEventListener("keydown",_this.handleKeydownDropdownItem.bind(_this))}),$(this.menuElement).on("keydown",".dropdown-submenu > .dropdown-item",this.handleKeydownSubmenuDropdownItem.bind(this)),$(this.menuElement).on("click",".dropdown-submenu > .dropdown-item",this.handleClickSubmenuDropdownItem.bind(this)),$(this.element).on("hidden.bs.dropdown",function(){_this.close(_this.menuElement)})},_proto.handleKeydownDropdownItem=function(event){27===event.keyCode&&(event.target.closest(".dropdown-menu").previousElementSibling.focus(),event.target.closest(".dropdown-menu").classList.remove("show"))},_proto.handleKeydownSubmenuDropdownItem=function(event){32===event.keyCode&&(event.preventDefault(),this.toggle(event.target))},_proto.handleClickSubmenuDropdownItem=function(event){event.stopPropagation(),this.toggle(event.target)},_proto.itemKeydown=function(event){if([38,40].includes(event.keyCode)){event.preventDefault(),event.stopPropagation();var itemNodeList=this.element.querySelectorAll(".show > .dropdown-item:not(:disabled):not(.disabled), .show > .dropdown > .dropdown-item"),index=Array.from(itemNodeList).indexOf(event.target);if(38===event.keyCode&&0!==index)index--;else{if(40!==event.keyCode||index===itemNodeList.length-1)return;index++}itemNodeList[index].focus()}},_proto.toggle=function(element){var dropdownElement=element.closest(".dropdown"),parentMenuElement=dropdownElement.closest(".dropdown-menu"),menuElement=dropdownElement.querySelector(".dropdown-menu"),isOpen=menuElement.classList.contains("show");this.close(parentMenuElement),menuElement.classList.toggle("show",!isOpen)},_proto.close=function(menuElement){var menuNodeList=menuElement.querySelectorAll(".dropdown-menu.show");Array.from(menuNodeList).forEach(function(element){element.classList.remove("show")})},DropdownSubmenu}();return $.fn.submenupicker=function(elements){return(this instanceof $?this:$(elements)).each(function(){var data=$.data(this,"bs.submenu");data||(data=new DropdownSubmenu(this),$.data(this,"bs.submenu",data))})},DropdownSubmenu});