mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-01-19 16:52:59 +08:00
Return button in onKeyReleased method. Tests updated. Fixes #145
This commit is contained in:
parent
8ba6f879d0
commit
d4e9f51182
@ -1,6 +1,6 @@
|
|||||||
/*!
|
/*!
|
||||||
*
|
*
|
||||||
* simple-keyboard v2.24.0
|
* simple-keyboard v2.24.1
|
||||||
* https://github.com/hodgef/simple-keyboard
|
* https://github.com/hodgef/simple-keyboard
|
||||||
*
|
*
|
||||||
* Copyright (c) Francisco Hodge (https://github.com/hodgef)
|
* Copyright (c) Francisco Hodge (https://github.com/hodgef)
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
/*!
|
/*!
|
||||||
*
|
*
|
||||||
* simple-keyboard v2.24.0 (Non-minified build)
|
* simple-keyboard v2.24.1 (Non-minified build)
|
||||||
* https://github.com/hodgef/simple-keyboard
|
* https://github.com/hodgef/simple-keyboard
|
||||||
*
|
*
|
||||||
* Copyright (c) Francisco Hodge (https://github.com/hodgef)
|
* Copyright (c) Francisco Hodge (https://github.com/hodgef)
|
||||||
|
10
build/index.d.ts
vendored
10
build/index.d.ts
vendored
@ -133,6 +133,11 @@ declare module 'simple-keyboard' {
|
|||||||
*/
|
*/
|
||||||
onKeyPress?: (button: string) => any;
|
onKeyPress?: (button: string) => any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the callback function on key release.
|
||||||
|
*/
|
||||||
|
onKeyReleased?: (button: string) => any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the callback function on input change. Returns the current input's string.
|
* Executes the callback function on input change. Returns the current input's string.
|
||||||
*/
|
*/
|
||||||
@ -162,11 +167,6 @@ declare module 'simple-keyboard' {
|
|||||||
* Executes the callback function on input change. Returns the input object with all defined inputs.
|
* Executes the callback function on input change. Returns the input object with all defined inputs.
|
||||||
*/
|
*/
|
||||||
onChangeAll?: (inputs: any) => any;
|
onChangeAll?: (inputs: any) => any;
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the callback function on key release.
|
|
||||||
*/
|
|
||||||
onKeyReleased?: () => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Keyboard {
|
class Keyboard {
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
/*!
|
/*!
|
||||||
*
|
*
|
||||||
* simple-keyboard v2.24.0 (Non-minified build)
|
* simple-keyboard v2.24.1 (Non-minified build)
|
||||||
* https://github.com/hodgef/simple-keyboard
|
* https://github.com/hodgef/simple-keyboard
|
||||||
*
|
*
|
||||||
* Copyright (c) Francisco Hodge (https://github.com/hodgef)
|
* Copyright (c) Francisco Hodge (https://github.com/hodgef)
|
||||||
@ -995,15 +995,15 @@
|
|||||||
* Handles button mouseup
|
* Handles button mouseup
|
||||||
*/ }, {
|
*/ }, {
|
||||||
key: "handleButtonMouseUp",
|
key: "handleButtonMouseUp",
|
||||||
value: function handleButtonMouseUp() {
|
value: function handleButtonMouseUp(button) {
|
||||||
this.isMouseHold = false;
|
this.isMouseHold = false;
|
||||||
if (this.holdInteractionTimeout) {
|
if (this.holdInteractionTimeout) {
|
||||||
clearTimeout(this.holdInteractionTimeout);
|
clearTimeout(this.holdInteractionTimeout);
|
||||||
/**
|
/**
|
||||||
* Calling onKeyReleased
|
* Calling onKeyReleased
|
||||||
*/ }
|
*/ }
|
||||||
if (typeof this.options.onKeyReleased === "function") {
|
if (button && typeof this.options.onKeyReleased === "function") {
|
||||||
this.options.onKeyReleased();
|
this.options.onKeyReleased(button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -1328,7 +1328,7 @@
|
|||||||
this.caretEventHandler(event);
|
this.caretEventHandler(event);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Called by {@link caretEventHandler} when an event that warrants a cursor position update is triggered
|
* Called by {@link setEventListeners} when an event that warrants a cursor position update is triggered
|
||||||
*/ }, {
|
*/ }, {
|
||||||
key: "caretEventHandler",
|
key: "caretEventHandler",
|
||||||
value: function caretEventHandler(event) {
|
value: function caretEventHandler(event) {
|
||||||
@ -1684,11 +1684,11 @@
|
|||||||
_this10.handleButtonClicked(button);
|
_this10.handleButtonClicked(button);
|
||||||
_this10.handleButtonMouseDown(button, e);
|
_this10.handleButtonMouseDown(button, e);
|
||||||
};
|
};
|
||||||
buttonDOM.onpointerup = function(e) {
|
buttonDOM.onpointerup = function() {
|
||||||
_this10.handleButtonMouseUp();
|
return _this10.handleButtonMouseUp(button);
|
||||||
};
|
};
|
||||||
buttonDOM.onpointercancel = function(e) {
|
buttonDOM.onpointercancel = function() {
|
||||||
return _this10.handleButtonMouseUp();
|
return _this10.handleButtonMouseUp(button);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
@ -1700,11 +1700,11 @@
|
|||||||
_this10.handleButtonClicked(button);
|
_this10.handleButtonClicked(button);
|
||||||
_this10.handleButtonMouseDown(button, e);
|
_this10.handleButtonMouseDown(button, e);
|
||||||
};
|
};
|
||||||
buttonDOM.ontouchend = function(e) {
|
buttonDOM.ontouchend = function() {
|
||||||
return _this10.handleButtonMouseUp();
|
return _this10.handleButtonMouseUp(button);
|
||||||
};
|
};
|
||||||
buttonDOM.ontouchcancel = function(e) {
|
buttonDOM.ontouchcancel = function() {
|
||||||
return _this10.handleButtonMouseUp();
|
return _this10.handleButtonMouseUp(button);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
@ -1714,7 +1714,10 @@
|
|||||||
_this10.handleButtonClicked(button);
|
_this10.handleButtonClicked(button);
|
||||||
};
|
};
|
||||||
buttonDOM.onmousedown = function(e) {
|
buttonDOM.onmousedown = function(e) {
|
||||||
_this10.handleButtonMouseDown(button, e);
|
return _this10.handleButtonMouseDown(button, e);
|
||||||
|
};
|
||||||
|
buttonDOM.onmouseup = function() {
|
||||||
|
return _this10.handleButtonMouseUp(button);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1767,10 +1770,10 @@
|
|||||||
} else if (useTouchEvents) {
|
} else if (useTouchEvents) {
|
||||||
/**
|
/**
|
||||||
* Handling ontouchend, ontouchcancel
|
* Handling ontouchend, ontouchcancel
|
||||||
*/ document.ontouchend = function(e) {
|
*/ document.ontouchend = function() {
|
||||||
return _this10.handleButtonMouseUp();
|
return _this10.handleButtonMouseUp();
|
||||||
};
|
};
|
||||||
document.ontouchcancel = function(e) {
|
document.ontouchcancel = function() {
|
||||||
return _this10.handleButtonMouseUp();
|
return _this10.handleButtonMouseUp();
|
||||||
};
|
};
|
||||||
} else if (!useTouchEvents) {
|
} else if (!useTouchEvents) {
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "simple-keyboard",
|
"name": "simple-keyboard",
|
||||||
"version": "2.24.0",
|
"version": "2.24.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "simple-keyboard",
|
"name": "simple-keyboard",
|
||||||
"version": "2.24.0",
|
"version": "2.24.1",
|
||||||
"description": "On-screen Javascript Virtual Keyboard",
|
"description": "On-screen Javascript Virtual Keyboard",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"types": "build/index.d.ts",
|
"types": "build/index.d.ts",
|
||||||
|
10
src/lib/@types/index.d.ts
vendored
10
src/lib/@types/index.d.ts
vendored
@ -133,6 +133,11 @@ declare module 'simple-keyboard' {
|
|||||||
*/
|
*/
|
||||||
onKeyPress?: (button: string) => any;
|
onKeyPress?: (button: string) => any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the callback function on key release.
|
||||||
|
*/
|
||||||
|
onKeyReleased?: (button: string) => any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the callback function on input change. Returns the current input's string.
|
* Executes the callback function on input change. Returns the current input's string.
|
||||||
*/
|
*/
|
||||||
@ -162,11 +167,6 @@ declare module 'simple-keyboard' {
|
|||||||
* Executes the callback function on input change. Returns the input object with all defined inputs.
|
* Executes the callback function on input change. Returns the input object with all defined inputs.
|
||||||
*/
|
*/
|
||||||
onChangeAll?: (inputs: any) => any;
|
onChangeAll?: (inputs: any) => any;
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the callback function on key release.
|
|
||||||
*/
|
|
||||||
onKeyReleased?: () => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Keyboard {
|
class Keyboard {
|
||||||
|
@ -295,15 +295,15 @@ class SimpleKeyboard {
|
|||||||
/**
|
/**
|
||||||
* Handles button mouseup
|
* Handles button mouseup
|
||||||
*/
|
*/
|
||||||
handleButtonMouseUp() {
|
handleButtonMouseUp(button) {
|
||||||
this.isMouseHold = false;
|
this.isMouseHold = false;
|
||||||
if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);
|
if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calling onKeyReleased
|
* Calling onKeyReleased
|
||||||
*/
|
*/
|
||||||
if (typeof this.options.onKeyReleased === "function")
|
if (button && typeof this.options.onKeyReleased === "function")
|
||||||
this.options.onKeyReleased();
|
this.options.onKeyReleased(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -672,7 +672,7 @@ class SimpleKeyboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by {@link caretEventHandler} when an event that warrants a cursor position update is triggered
|
* Called by {@link setEventListeners} when an event that warrants a cursor position update is triggered
|
||||||
*/
|
*/
|
||||||
caretEventHandler(event) {
|
caretEventHandler(event) {
|
||||||
let targetTagName;
|
let targetTagName;
|
||||||
@ -1164,10 +1164,8 @@ class SimpleKeyboard {
|
|||||||
this.handleButtonClicked(button);
|
this.handleButtonClicked(button);
|
||||||
this.handleButtonMouseDown(button, e);
|
this.handleButtonMouseDown(button, e);
|
||||||
};
|
};
|
||||||
buttonDOM.onpointerup = e => {
|
buttonDOM.onpointerup = () => this.handleButtonMouseUp(button);
|
||||||
this.handleButtonMouseUp();
|
buttonDOM.onpointercancel = () => this.handleButtonMouseUp(button);
|
||||||
};
|
|
||||||
buttonDOM.onpointercancel = e => this.handleButtonMouseUp();
|
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
* Fallback for browsers not supporting PointerEvents
|
* Fallback for browsers not supporting PointerEvents
|
||||||
@ -1180,8 +1178,8 @@ class SimpleKeyboard {
|
|||||||
this.handleButtonClicked(button);
|
this.handleButtonClicked(button);
|
||||||
this.handleButtonMouseDown(button, e);
|
this.handleButtonMouseDown(button, e);
|
||||||
};
|
};
|
||||||
buttonDOM.ontouchend = e => this.handleButtonMouseUp();
|
buttonDOM.ontouchend = () => this.handleButtonMouseUp(button);
|
||||||
buttonDOM.ontouchcancel = e => this.handleButtonMouseUp();
|
buttonDOM.ontouchcancel = () => this.handleButtonMouseUp(button);
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
* Handle mouse events
|
* Handle mouse events
|
||||||
@ -1190,9 +1188,8 @@ class SimpleKeyboard {
|
|||||||
this.isMouseHold = false;
|
this.isMouseHold = false;
|
||||||
this.handleButtonClicked(button);
|
this.handleButtonClicked(button);
|
||||||
};
|
};
|
||||||
buttonDOM.onmousedown = e => {
|
buttonDOM.onmousedown = e => this.handleButtonMouseDown(button, e);
|
||||||
this.handleButtonMouseDown(button, e);
|
buttonDOM.onmouseup = () => this.handleButtonMouseUp(button);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1274,8 +1271,8 @@ class SimpleKeyboard {
|
|||||||
/**
|
/**
|
||||||
* Handling ontouchend, ontouchcancel
|
* Handling ontouchend, ontouchcancel
|
||||||
*/
|
*/
|
||||||
document.ontouchend = e => this.handleButtonMouseUp();
|
document.ontouchend = () => this.handleButtonMouseUp();
|
||||||
document.ontouchcancel = e => this.handleButtonMouseUp();
|
document.ontouchcancel = () => this.handleButtonMouseUp();
|
||||||
} else if (!useTouchEvents) {
|
} else if (!useTouchEvents) {
|
||||||
/**
|
/**
|
||||||
* Handling mouseup
|
* Handling mouseup
|
||||||
|
@ -1281,10 +1281,12 @@ it('Keyboard onKeyReleased will work', () => {
|
|||||||
|
|
||||||
let pressed = false;
|
let pressed = false;
|
||||||
let firedTimes = 0;
|
let firedTimes = 0;
|
||||||
|
let buttonPressed;
|
||||||
|
|
||||||
let keyboard = new Keyboard({
|
let keyboard = new Keyboard({
|
||||||
onKeyReleased: () => {
|
onKeyReleased: button => {
|
||||||
pressed = true;
|
pressed = true;
|
||||||
|
buttonPressed = button;
|
||||||
firedTimes++;
|
firedTimes++;
|
||||||
},
|
},
|
||||||
debug: true
|
debug: true
|
||||||
@ -1295,4 +1297,5 @@ it('Keyboard onKeyReleased will work', () => {
|
|||||||
|
|
||||||
expect(pressed).toBeTruthy();
|
expect(pressed).toBeTruthy();
|
||||||
expect(firedTimes).toBe(1);
|
expect(firedTimes).toBe(1);
|
||||||
|
expect(buttonPressed).toBe("q");
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user