trabajo-afectivo/app/assets/javascripts/knowledge_base_public/dropdown.js

29 lines
797 B
JavaScript
Raw Permalink Normal View History

2019-06-04 03:40:48 +00:00
(function() {
document.addEventListener('DOMContentLoaded', function(event) {
document
.querySelector('[data-toggle="dropdown"]')
.addEventListener('click', toggleDropdown)
document
.querySelector('.dropdown-menu')
.addEventListener('click', function(event) { event.stopPropagation() })
})
function toggleDropdown(event){
event.stopPropagation()
event.preventDefault()
var elem = document.querySelector('.dropdown-menu')
var open = elem.classList.toggle('is-open')
if(elem.setAttribute) // not supported by IE11
elem.setAttribute('aria-expanded', open ? 'true' : 'false')
if(open) {
window.addEventListener('click', toggleDropdown)
} else {
window.removeEventListener('click', toggleDropdown)
}
}
}())