-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bbb69d
commit 9220ae9
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// v-b-hover directive | ||
import { isBrowser } from '../../utils/env' | ||
import { EVENT_OPTIONS_NO_CAPTURE, eventOn, eventOff } from '../../utils/events' | ||
import { isFunction } from '../../utils/inspect' | ||
|
||
// --- Constants --- | ||
|
||
const PROP = '__BV_hover_handler__' | ||
const MOUSEENTER = 'mouseenter' | ||
const MOUSELEAVE = 'mouseleave' | ||
|
||
// --- Directive bind/unbind/update handler --- | ||
|
||
const directive = (el, { value: callback }) { | ||
if (isBrowser && isFunction(el[PROP] && el[PROP] !== callback) { | ||
eventOff(el, MOUSEENTER, el[PROP], EVENT_OPTIONS_NO_CAPTURE) | ||
eventOff(el, MOUSELEAVE, el[PROP], EVENT_OPTIONS_NO_CAPTURE) | ||
} | ||
if (isBrowser && isFunction(callback) && isBrowser) { | ||
el[PROP] = evt => { | ||
callback(evt.type === 'mouseenter') | ||
} | ||
eventOn(el, MOUSEENTER, el[PROP], EVENT_OPTIONS_NO_CAPTURE) | ||
eventOn(el, MOUSELEAVE, el[PROP], EVENT_OPTIONS_NO_CAPTURE) | ||
} | ||
} | ||
|
||
// VBHover directive | ||
|
||
export const VBHover = { | ||
bind: directive, | ||
componentUpdated: directive, | ||
unbind(el) { | ||
directive(el, { value: null } | ||
} | ||
} |