1 line
1.5 KiB
JavaScript
1 line
1.5 KiB
JavaScript
!function(r){"use strict";var o="[data-toggle=dropdown]",a=function(o){var t=r(o).on("click.dropdown.data-api",this.toggle);r("html").on("click.dropdown.data-api",function(){t.parent().removeClass("open")})};function d(){r(o).each(function(){i(r(this)).removeClass("open")})}function i(o){var t,n=o.attr("data-target");return n||(n=(n=o.attr("href"))&&/#/.test(n)&&n.replace(/.*(?=#[^\s]*$)/,"")),(t=r(n)).length||(t=o.parent()),t}a.prototype={constructor:a,toggle:function(o){var t,n,a=r(this);if(!a.is(".disabled, :disabled"))return n=(t=i(a)).hasClass("open"),d(),n||(t.toggleClass("open"),a.focus()),!1},keydown:function(o){var t,n,a,d,e;if(/(38|40|27)/.test(o.keyCode)&&(t=r(this),o.preventDefault(),o.stopPropagation(),!t.is(".disabled, :disabled"))){if(!(d=(a=i(t)).hasClass("open"))||d&&27==o.keyCode)return t.click();(n=r("[role=menu] li:not(.divider) a",a)).length&&(e=n.index(n.filter(":focus")),38==o.keyCode&&0<e&&e--,40==o.keyCode&&e<n.length-1&&e++,~e||(e=0),n.eq(e).focus())}}},r.fn.dropdown=function(n){return this.each(function(){var o=r(this),t=o.data("dropdown");t||o.data("dropdown",t=new a(this)),"string"==typeof n&&t[n].call(o)})},r.fn.dropdown.Constructor=a,r(document).on("click.dropdown.data-api touchstart.dropdown.data-api",d).on("click.dropdown touchstart.dropdown.data-api",".dropdown form",function(o){o.stopPropagation()}).on("click.dropdown.data-api touchstart.dropdown.data-api",o,a.prototype.toggle).on("keydown.dropdown.data-api touchstart.dropdown.data-api",o+", [role=menu]",a.prototype.keydown)}(window.jQuery); |