snappymail/vendors/bootstrap/js/bootstrap.native.min.js
2020-09-22 10:13:32 +02:00

7 lines
2.3 KiB
JavaScript

/*!
* Native JavaScript for Bootstrap v3.0.10 (https://thednp.github.io/bootstrap.native/)
* Copyright 2015-2020 © dnp_theme
* Licensed under MIT (https://github.com/thednp/bootstrap.native/blob/master/LICENSE)
*/
window.BSN=(()=>{"use strict";const e=document,t=e=>e.focus?e.focus():e.setActive();return{Dropdown:function(s){let o,n=[];const r=this,i=s.parentNode,a=e=>{const t=e.target,s=t.href||t.parentNode&&t.parentNode.href;s&&"#"===s.slice(-1)&&e.preventDefault()},c=()=>{let t=s.open?"addEventListener":"removeEventListener";e[t]("click",d,!1),e[t]("keydown",h,!1),e[t]("keyup",p,!1),e[t]("focus",d,!1)},d=e=>{let t=e.target,n=o.contains(t),i=t&&(t.getAttribute("data-toggle")||t.parentNode&&t.parentNode.getAttribute("data-toggle"));"focus"===e.type&&(t===s||n)||i&&n||(r.hide(),a(e))},l=e=>{r.show(),a(e)},h=e=>("ArrowUp"===e.code||"ArrowDown"===e.code)&&e.preventDefault(),p=i=>{let a=e.activeElement,c=a===s,d=o.contains(a),l=a.parentNode===o||a.parentNode.parentNode===o,h=n.indexOf(a);l&&(h=c?0:"ArrowUp"===i.code?h>1?h-1:0:"ArrowDown"===i.code&&h<n.length-1?h+1:h,n[h]&&t(n[h])),(n.length&&l||!n.length&&(d||c)||!d)&&s.open&&"Escape"===i.code&&r.toggle()};r.show=(()=>{o=i.querySelector(".dropdown-menu"),n=[],[...o.children].forEach(e=>{e.children.length&&"A"===e.children[0].tagName&&n.push(e.children[0]),"A"===e.tagName&&n.push(e)}),!("tabindex"in o)&&o.setAttribute("tabindex","0"),o.classList.add("show"),i.classList.add("show"),s.setAttribute("aria-expanded",!0),s.open=!0,s.removeEventListener("click",l,!1),setTimeout(()=>{t(o.getElementsByTagName("INPUT")[0]||s),c()},1)}),r.hide=(()=>{o.classList.remove("show"),i.classList.remove("show"),s.setAttribute("aria-expanded",!1),s.open=!1,c(),t(s),setTimeout(()=>s.Dropdown&&s.addEventListener("click",l,!1),1)}),r.toggle=(()=>i.classList.contains("show")&&s.open?r.hide():r.show()),s.addEventListener("click",l,!1),s.open=!1,s.Dropdown=r},Tab:class{constructor(e){this.element=e,e.Tab=this,e.addEventListener("click",e=>{e.preventDefault(),this.show()})}show(){const t=this.element,s=t.closest("li");if(!s.classList.contains("active")){const o=t.closest("ul").querySelector(".active a");o.closest("li").classList.remove("active"),e.querySelector(o.getAttribute("href")).classList.remove("active"),s.classList.add("active"),e.querySelector(t.getAttribute("href")).classList.add("active")}}}}})();