Socket
Socket
Sign inDemoInstall

mouse-change

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.0 to 1.4.0

89

mouse-listen.js

@@ -7,4 +7,4 @@ 'use strict'

function mouseListen(element, callback) {
if(!callback) {
function mouseListen (element, callback) {
if (!callback) {
callback = element

@@ -18,24 +18,24 @@ element = window

var mods = {
shift: false,
alt: false,
shift: false,
alt: false,
control: false,
meta: false
meta: false
}
var attached = false
function updateMods(ev) {
function updateMods (ev) {
var changed = false
if('altKey' in ev) {
if ('altKey' in ev) {
changed = changed || ev.altKey !== mods.alt
mods.alt = !!ev.altKey
}
if('shiftKey' in ev) {
if ('shiftKey' in ev) {
changed = changed || ev.shiftKey !== mods.shift
mods.shift = !!ev.shiftKey
}
if('ctrlKey' in ev) {
if ('ctrlKey' in ev) {
changed = changed || ev.ctrlKey !== mods.control
mods.control = !!ev.ctrlKey
}
if('metaKey' in ev) {
if ('metaKey' in ev) {
changed = changed || ev.metaKey !== mods.meta

@@ -47,15 +47,15 @@ mods.meta = !!ev.metaKey

function handleEvent(nextButtons, ev) {
function handleEvent (nextButtons, ev) {
var nextX = mouse.x(ev)
var nextY = mouse.y(ev)
if('buttons' in ev) {
nextButtons = ev.buttons|0
if ('buttons' in ev) {
nextButtons = ev.buttons | 0
}
if(nextButtons !== buttonState ||
nextX !== x ||
nextY !== y ||
updateMods(ev)) {
buttonState = nextButtons|0
x = nextX||0
y = nextY||0
if (nextButtons !== buttonState ||
nextX !== x ||
nextY !== y ||
updateMods(ev)) {
buttonState = nextButtons | 0
x = nextX || 0
y = nextY || 0
callback && callback(buttonState, x, y, mods)

@@ -65,8 +65,8 @@ }

function clearState(ev) {
function clearState (ev) {
handleEvent(0, ev)
}
function handleBlur() {
if(buttonState ||
function handleBlur () {
if (buttonState ||
x ||

@@ -78,3 +78,2 @@ y ||

mods.control) {
x = y = 0

@@ -87,4 +86,4 @@ buttonState = 0

function handleMods(ev) {
if(updateMods(ev)) {
function handleMods (ev) {
if (updateMods(ev)) {
callback && callback(buttonState, x, y, mods)

@@ -94,4 +93,4 @@ }

function handleMouseMove(ev) {
if(mouse.buttons(ev) === 0) {
function handleMouseMove (ev) {
if (mouse.buttons(ev) === 0) {
handleEvent(0, ev)

@@ -103,12 +102,12 @@ } else {

function handleMouseDown(ev) {
function handleMouseDown (ev) {
handleEvent(buttonState | mouse.buttons(ev), ev)
}
function handleMouseUp(ev) {
function handleMouseUp (ev) {
handleEvent(buttonState & ~mouse.buttons(ev), ev)
}
function attachListeners() {
if(attached) {
function attachListeners () {
if (attached) {
return

@@ -135,3 +134,3 @@ }

if(element !== window) {
if (element !== window) {
window.addEventListener('blur', handleBlur)

@@ -145,4 +144,4 @@

function detachListeners() {
if(!attached) {
function detachListeners () {
if (!attached) {
return

@@ -169,3 +168,3 @@ }

if(element !== window) {
if (element !== window) {
window.removeEventListener('blur', handleBlur)

@@ -179,3 +178,3 @@

//Attach listeners
// Attach listeners
attachListeners()

@@ -189,8 +188,8 @@

enabled: {
get: function() { return attached },
set: function(f) {
if(f) {
get: function () { return attached },
set: function (f) {
if (f) {
attachListeners()
} else {
detachListeners
detachListeners()
}

@@ -201,15 +200,15 @@ },

buttons: {
get: function() { return buttonState },
get: function () { return buttonState },
enumerable: true
},
x: {
get: function() { return x },
get: function () { return x },
enumerable: true
},
y: {
get: function() { return y },
get: function () { return y },
enumerable: true
},
mods: {
get: function() { return mods },
get: function () { return mods },
enumerable: true

@@ -216,0 +215,0 @@ }

{
"name": "mouse-change",
"version": "1.3.0",
"version": "1.4.0",
"description": "Mouse state change listener",

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc