Personal Website - https://mkr.pw
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.

37 lines
791 B

'use strict'
// Toggle tooltips
const __ = document.querySelector.bind(document)
function toggle(obj) {
const e = __(obj)
e.style.display =
(e.style.display === 'inline-block')
? 'none' : 'inline-block'
}
function toggleOff(obj) {
__(obj).style.display = 'none'
}
const addListener = (element, events, handler) =>
(Array.isArray(events)
? events
: [events]).forEach(event =>
element.addEventListener(event, handler))
const addToolTip = selector => {
addListener(
__('#' + selector + '-click'),
['click', 'mouseover', 'mouseout'],
() => toggle('#' + selector + '-tip'))
addListener(
__('body'),
'click',
(e) => { if (e.target !== __('#' + selector + '-tip')) toggleOff('#' + selector + '-tip') }
)}
//export default addToolTip
module.exports = addToolTip