Select DOM elements with the mouse.
$ component install timoxley/element-selector
var ElementSelector = require('element-selector');
var elementSelector = ElementSelector();
// Disable default styles so you can
// use custom .selected and .highlighted css.
var elementSelector = ElementSelector({
useDefaultStyles: false
})
Events are fired whenever an element's selected or highlighted status changes. Two arguments are passed to the callback: the element that was highlighted or selected, and the original mouse event that triggered the action (if it exists). The second event argument is supplied if you wish to prevent default actions or otherwise query the triggering event.
Events will be one of the following:
- select
- deselect
- highlight
- dehighlight
ElementSelector's event API is inherited from component/emitter.
elementSelector.on('select', function(el, event) {
event.preventDefault()
console.log('element selected', el)
})
elementSelector.once('dehighlight', function(el) {
console.log('element dehighlighted', el)
})
elementSelector.disable()
elementSelector.enable()
Only tested in Chrome. Pull request welcome if you get it working in IE.