Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
mouse-presence
Advanced tools
Centralizes handling of mouse appearance/disappearance events in the browser
Centralizes handling of mouse appearance/disappearance events in the browser.
npm: npm install --save mouse-presence
Yarn: yarn add mouse-presence
MousePresence.onDisappear(cb)
cb
: A callback function that takes no arguments and returns nothing.
returns: A deregisterer for cb
.
Registers a callback to be called whenever a mouse cursor disappearance is dispatched.
MousePresence.onAppear(cb)
cb
: A callback function that takes no arguments and returns nothing.
returns: A deregisterer for cb
.
Registers a callback to be called whenever the mouse is moved after a disappearance was dispatched. (Moving the mouse after the cursor disappeared will cause it to reappear.)
MousePresence.unregisterCallback(cb)
cb
: The callback reference to be unregistered.
returns: Nothing.
Unregisters a previously-registered callback from either onDisappear or onAppear (or both). If no such callback is found, nothing happens.
MousePresence.dispatchDisappear()
returns: Nothing.
Dispatches a mouse disappearance event, which will call all registered onDisappear callbacks (will only do this once - subsequent calls will have no effect until the next onAppear event occurs). It will also register a one-time mousemove listener on the document, which when triggered, will call all registered onAppear callbacks.
MousePresence.isPresent()
returns: Boolean indicating whether the mouse cursor is present.
Determine if the mouse cursor is present or not (according to the last reported appearance/disappearance event).
MousePresence.dispatchDisappearOnKeydown(el)
el
: The HTMLElement for which the keydown listener should be added to.
returns: A deregisterer for the keydown listener that will be added.
Adds a keydown listener to the provided HTMLElement, which will trigger a dispatchDisappear call when triggered (since typing will cause the mouse cursor to disappear). This is a convenience function for any text-based input elements, to be used instead of explicitly attaching a listener and calling dispatchDisappear yourself.
Component A:
import MousePresence from 'mouse-presence';
// Gets called on every onDisappear event
MousePresence.onDisappear(() => {
// Take actions...
});
// Gets called on every onAppear event
MousePresence.onAppear(() => {
// Take actions...
});
Component B:
import MousePresence from 'mouse-presence';
// Only gets called for one onDisappear event, then unregisters itself
let disappearCb = MousePresence.onDisappear(() => {
MousePresence.unregisterCallback(disappearCb);
});
Component C:
import MousePresence from 'mouse-presence';
// Mouse cursor disappears when typing
this.element.addEventListener('keydown', () => {
MousePresence.dispatchDisappear();
// Will immediately dispatch onDisappear
// Will automatically attach a mousemove listener, upon which onAppear will be dispatched
// Will not redispatch onDisappear until the onAppear event occurs
});
FAQs
Centralizes handling of mouse appearance/disappearance events in the browser
We found that mouse-presence demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.