Browse Source

Tooltip interaction

master
Muthu Kumar 7 years ago
parent
commit
1bd74ca491
  1. 6
      js/main.js
  2. 37
      js/modules/tooltip.js

6
js/main.js

@ -0,0 +1,6 @@
'use strict'
// import addToolTip from './modules/tooltip'
const addToolTip = require('./modules/tooltip')
addToolTip('myname')

37
js/modules/tooltip.js

@ -0,0 +1,37 @@
'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
Loading…
Cancel
Save