mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-04-30 00:00:04 +08:00
Added destroy method
This commit is contained in:
Vendored
+5
@@ -220,6 +220,11 @@ declare module 'simple-keyboard' {
|
||||
* @param {string} button The button layout name to select
|
||||
*/
|
||||
getButtonElement(button: string): HTMLElement | HTMLElement[];
|
||||
|
||||
/**
|
||||
* Clears keyboard listeners and DOM elements.
|
||||
*/
|
||||
destroy(): void;
|
||||
}
|
||||
|
||||
export default Keyboard;
|
||||
|
||||
@@ -64,6 +64,7 @@ class SimpleKeyboard {
|
||||
* @property {boolean} useTouchEvents Instructs simple-keyboard to use touch events instead of click events.
|
||||
* @property {boolean} autoUseTouchEvents Enable useTouchEvents automatically when touch device is detected.
|
||||
* @property {boolean} useMouseEvents Opt out of PointerEvents handling, falling back to the prior mouse event logic.
|
||||
* @property {function} destroy Clears keyboard listeners and DOM elements.
|
||||
*/
|
||||
this.options = options;
|
||||
this.options.layoutName = this.options.layoutName || "default";
|
||||
@@ -646,6 +647,23 @@ class SimpleKeyboard {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy keyboard listeners and DOM elements
|
||||
*/
|
||||
destroy() {
|
||||
/**
|
||||
* Remove listeners
|
||||
*/
|
||||
document.removeEventListener("keyup", this.caretEventHandler);
|
||||
document.removeEventListener("mouseup", this.caretEventHandler);
|
||||
document.removeEventListener("touchend", this.caretEventHandler);
|
||||
|
||||
/**
|
||||
* Clear DOM
|
||||
*/
|
||||
this.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process buttonTheme option
|
||||
*/
|
||||
|
||||
@@ -1222,4 +1222,14 @@ it('Keyboard inputName change will trigget caretPosition reset', () => {
|
||||
keyboard.getButtonElement("b").onpointerdown();
|
||||
|
||||
expect(keyboard.caretPosition).toBe(null);
|
||||
});
|
||||
|
||||
it('Keyboard destroy will work', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
keyboard.destroy();
|
||||
|
||||
expect(keyboard.keyboardDOM.innerHTML).toBeFalsy();
|
||||
});
|
||||
Reference in New Issue
Block a user