Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mouse-change

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mouse-change - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

138

mouse-listen.js

@@ -8,6 +8,6 @@ 'use strict'

function mouseListen(element, callback) {
if(!callback) {
callback = element
element = window
element = document.body
}

@@ -24,2 +24,3 @@

}
var attached = false

@@ -55,3 +56,3 @@ function updateMods(ev) {

nextX !== x ||
nextY !== y ||
nextY !== y ||
updateMods(ev)) {

@@ -70,4 +71,4 @@ buttonState = nextButtons|0

function handleBlur() {
if(buttonState ||
x ||
if(buttonState ||
x ||
y ||

@@ -92,3 +93,3 @@ mods.shift ||

element.addEventListener('mousemove', function(ev) {
function handleMouseMove(ev) {
if(mouse.buttons(ev) === 0) {

@@ -99,27 +100,114 @@ handleEvent(0, ev)

}
})
}
element.addEventListener('mousedown', function(ev) {
function handleMouseDown(ev) {
handleEvent(buttonState | mouse.buttons(ev), ev)
})
}
element.addEventListener('mouseup', function(ev) {
function handleMouseUp(ev) {
handleEvent(buttonState & ~mouse.buttons(ev), ev)
})
}
element.addEventListener('mouseleave', clearState)
element.addEventListener('mouseenter', clearState)
element.addEventListener('mouseout', clearState)
element.addEventListener('mouseover', clearState)
element.addEventListener('blur', handleBlur)
element.addEventListener('keyup', handleMods)
element.addEventListener('keydown', handleMods)
element.addEventListener('keypress', handleMods)
function attachListeners() {
if(attached) {
return
}
attached = true
if(element !== window) {
window.addEventListener('blur', handleBlur)
window.addEventListener('keyup', handleMods)
window.addEventListener('keydown', handleMods)
window.addEventListener('keypress', handleMods)
element.addEventListener('mousemove', handleMouseMove)
element.addEventListener('mousedown', handleMouseDown)
element.addEventListener('mouseup', handleMouseUp)
element.addEventListener('mouseleave', clearState)
element.addEventListener('mouseenter', clearState)
element.addEventListener('mouseout', clearState)
element.addEventListener('mouseover', clearState)
element.addEventListener('blur', handleBlur)
element.addEventListener('keyup', handleMods)
element.addEventListener('keydown', handleMods)
element.addEventListener('keypress', handleMods)
if(element !== window) {
window.addEventListener('blur', handleBlur)
window.addEventListener('keyup', handleMods)
window.addEventListener('keydown', handleMods)
window.addEventListener('keypress', handleMods)
}
}
}
function detachListeners() {
if(!attached) {
return
}
attached = false
element.removeEventListener('mousemove', handleMouseMove)
element.removeEventListener('mousedown', handleMouseDown)
element.removeEventListener('mouseup', handleMouseUp)
element.removeEventListener('mouseleave', clearState)
element.removeEventListener('mouseenter', clearState)
element.removeEventListener('mouseout', clearState)
element.removeEventListener('mouseover', clearState)
element.removeEventListener('blur', handleBlur)
element.removeEventListener('keyup', handleMods)
element.removeEventListener('keydown', handleMods)
element.removeEventListener('keypress', handleMods)
if(element !== window) {
window.removeEventListener('blur', handleBlur)
window.removeEventListener('keyup', handleMods)
window.removeEventListener('keydown', handleMods)
window.removeEventListener('keypress', handleMods)
}
}
//Attach listeners
attachListeners()
var result = {
element: element
}
Object.defineProperties(result, {
enabled: {
get: function() { return attached },
set: function(f) {
if(f) {
attachListeners()
} else {
detachListeners
}
},
enumerable: true
},
buttons: {
get: function() { return buttonState },
enumerable: true
},
x: {
get: function() { return x },
enumerable: true
},
y: {
get: function() { return y },
enumerable: true
},
mods: {
get: function() { return mods },
enumerable: true
}
})
return result
}

2

package.json
{
"name": "mouse-change",
"version": "1.1.1",
"version": "1.2.0",
"description": "Mouse state change listener",

@@ -5,0 +5,0 @@ "main": "mouse-listen.js",

@@ -9,5 +9,5 @@ mouse-change

require('mouse-change')(function(buttons, x, y) {
document.body.innerHTML =
'<p>Buttons: 0b' + buttons.toString(2) +
', x:' + x +
document.body.innerHTML =
'<p>Buttons: 0b' + buttons.toString(2) +
', x:' + x +
', y:' + y + '</p>'

@@ -27,3 +27,3 @@ })

#### `require('mouse-change')([element,] onchange(buttons,x,y,mods))`
#### `var l = require('mouse-change')([element,] onchange(buttons,x,y,mods))`
Listens for any mouse state changes on the given element.

@@ -42,3 +42,20 @@

**Returns** A new listener object which can be used to configure the listener.
#### `l.enabled`
Toggles whether or not
#### `l.x`
The x coordinate of the mouse
#### `l.y`
The y coordinate of the mouse
#### `l.buttons`
The button state of the mouse
#### `l.mods`
The current state of the keyboard modifiers
# License
(c) 2015 Mikola Lysenko. MIT License
(c) 2015 Mikola Lysenko. MIT License
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc