mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-04-30 00:00:04 +08:00
Vendored
+5
@@ -162,6 +162,11 @@ declare module 'simple-keyboard' {
|
||||
* Executes the callback function on input change. Returns the input object with all defined inputs.
|
||||
*/
|
||||
onChangeAll?: (inputs: any) => any;
|
||||
|
||||
/**
|
||||
* Executes the callback function on key release.
|
||||
*/
|
||||
onKeyReleased?: () => void;
|
||||
}
|
||||
|
||||
class Keyboard {
|
||||
|
||||
+100
-36
@@ -27,7 +27,16 @@ class SimpleKeyboard {
|
||||
/**
|
||||
* Initializing Utilities
|
||||
*/
|
||||
this.utilities = new Utilities(this);
|
||||
this.utilities = new Utilities({
|
||||
getOptions: this.getOptions,
|
||||
getCaretPosition: this.getCaretPosition,
|
||||
dispatch: this.dispatch
|
||||
});
|
||||
|
||||
/**
|
||||
* Caret position
|
||||
*/
|
||||
this.caretPosition = null;
|
||||
|
||||
/**
|
||||
* Processing options
|
||||
@@ -66,6 +75,7 @@ class SimpleKeyboard {
|
||||
* @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.
|
||||
* @property {boolean} disableButtonHold Disable button hold action.
|
||||
* @property {function} onKeyReleased Executes the callback function on key release.
|
||||
*/
|
||||
this.options = options;
|
||||
this.options.layoutName = this.options.layoutName || "default";
|
||||
@@ -112,16 +122,7 @@ class SimpleKeyboard {
|
||||
this.buttonElements = {};
|
||||
|
||||
/**
|
||||
* Rendering keyboard
|
||||
*/
|
||||
if (this.keyboardDOM) this.render();
|
||||
else {
|
||||
console.warn(`"${keyboardDOMQuery}" was not found in the DOM.`);
|
||||
throw new Error("KEYBOARD_DOM_ERROR");
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving instance
|
||||
* Simple-keyboard Instances
|
||||
* This enables multiple simple-keyboard support with easier management
|
||||
*/
|
||||
if (!window["SimpleKeyboardInstances"])
|
||||
@@ -131,10 +132,31 @@ class SimpleKeyboard {
|
||||
this.utilities.camelCase(this.keyboardDOMClass)
|
||||
] = this;
|
||||
|
||||
/**
|
||||
* Instance vars
|
||||
*/
|
||||
this.allKeyboardInstances = window["SimpleKeyboardInstances"];
|
||||
this.currentInstanceName = this.utilities.camelCase(this.keyboardDOMClass);
|
||||
this.keyboardInstanceNames = Object.keys(window["SimpleKeyboardInstances"]);
|
||||
this.isFirstKeyboardInstance =
|
||||
this.keyboardInstanceNames[0] === this.currentInstanceName;
|
||||
|
||||
/**
|
||||
* Physical Keyboard support
|
||||
*/
|
||||
this.physicalKeyboardInterface = new PhysicalKeyboard(this);
|
||||
this.physicalKeyboard = new PhysicalKeyboard({
|
||||
dispatch: this.dispatch,
|
||||
getOptions: this.getOptions
|
||||
});
|
||||
|
||||
/**
|
||||
* Rendering keyboard
|
||||
*/
|
||||
if (this.keyboardDOM) this.render();
|
||||
else {
|
||||
console.warn(`"${keyboardDOMQuery}" was not found in the DOM.`);
|
||||
throw new Error("KEYBOARD_DOM_ERROR");
|
||||
}
|
||||
|
||||
/**
|
||||
* Modules
|
||||
@@ -143,6 +165,12 @@ class SimpleKeyboard {
|
||||
this.loadModules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getters
|
||||
*/
|
||||
getOptions = () => this.options;
|
||||
getCaretPosition = () => this.caretPosition;
|
||||
|
||||
/**
|
||||
* Handles clicks made to keyboard buttons
|
||||
* @param {string} button The button's layout name.
|
||||
@@ -167,7 +195,6 @@ class SimpleKeyboard {
|
||||
let updatedInput = this.utilities.getUpdatedInput(
|
||||
button,
|
||||
this.input[this.options.inputName],
|
||||
this.options,
|
||||
this.caretPosition
|
||||
);
|
||||
|
||||
@@ -185,7 +212,7 @@ class SimpleKeyboard {
|
||||
*/
|
||||
if (
|
||||
this.options.maxLength &&
|
||||
this.utilities.handleMaxLength(this.input, this.options, updatedInput)
|
||||
this.utilities.handleMaxLength(this.input, updatedInput)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@@ -193,7 +220,6 @@ class SimpleKeyboard {
|
||||
this.input[this.options.inputName] = this.utilities.getUpdatedInput(
|
||||
button,
|
||||
this.input[this.options.inputName],
|
||||
this.options,
|
||||
this.caretPosition,
|
||||
true
|
||||
);
|
||||
@@ -272,6 +298,12 @@ class SimpleKeyboard {
|
||||
handleButtonMouseUp() {
|
||||
this.isMouseHold = false;
|
||||
if (this.holdInteractionTimeout) clearTimeout(this.holdInteractionTimeout);
|
||||
|
||||
/**
|
||||
* Calling onKeyReleased
|
||||
*/
|
||||
if (typeof this.options.onKeyReleased === "function")
|
||||
this.options.onKeyReleased();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -584,33 +616,63 @@ class SimpleKeyboard {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current cursor position within a input or textarea (if any)
|
||||
* Handles simple-keyboard event listeners
|
||||
*/
|
||||
handleCaret() {
|
||||
setEventListeners() {
|
||||
/**
|
||||
* Only first instance should insall the caret handling events
|
||||
* Only first instance should set the event listeners
|
||||
*/
|
||||
this.caretPosition = null;
|
||||
let simpleKeyboardInstances = window["SimpleKeyboardInstances"];
|
||||
|
||||
if (
|
||||
(simpleKeyboardInstances &&
|
||||
Object.keys(simpleKeyboardInstances)[0] ===
|
||||
this.utilities.camelCase(this.keyboardDOMClass)) ||
|
||||
!simpleKeyboardInstances
|
||||
) {
|
||||
if (this.isFirstKeyboardInstance || !this.allKeyboardInstances) {
|
||||
if (this.options.debug) {
|
||||
console.log(`Caret handling started (${this.keyboardDOMClass})`);
|
||||
}
|
||||
|
||||
document.addEventListener("keyup", this.caretEventHandler);
|
||||
document.addEventListener("mouseup", this.caretEventHandler);
|
||||
document.addEventListener("touchend", this.caretEventHandler);
|
||||
/**
|
||||
* Event Listeners
|
||||
*/
|
||||
document.addEventListener("keyup", this.handleKeyUp);
|
||||
document.addEventListener("keydown", this.handleKeyDown);
|
||||
document.addEventListener("mouseup", this.handleMouseUp);
|
||||
document.addEventListener("touchend", this.handleTouchEnd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by {@link handleCaret} when an event that warrants a cursor position update is triggered
|
||||
* Event Handler: KeyUp
|
||||
*/
|
||||
handleKeyUp(event) {
|
||||
this.caretEventHandler(event);
|
||||
|
||||
if (this.options.physicalKeyboardHighlight) {
|
||||
this.physicalKeyboard.handleHighlightKeyUp(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event Handler: KeyDown
|
||||
*/
|
||||
handleKeyDown(event) {
|
||||
if (this.options.physicalKeyboardHighlight) {
|
||||
this.physicalKeyboard.handleHighlightKeyDown(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event Handler: MouseUp
|
||||
*/
|
||||
handleMouseUp(event) {
|
||||
this.caretEventHandler(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event Handler: TouchEnd
|
||||
*/
|
||||
handleTouchEnd(event) {
|
||||
this.caretEventHandler(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by {@link caretEventHandler} when an event that warrants a cursor position update is triggered
|
||||
*/
|
||||
caretEventHandler(event) {
|
||||
let targetTagName;
|
||||
@@ -657,9 +719,10 @@ class SimpleKeyboard {
|
||||
/**
|
||||
* Remove listeners
|
||||
*/
|
||||
document.removeEventListener("keyup", this.caretEventHandler);
|
||||
document.removeEventListener("mouseup", this.caretEventHandler);
|
||||
document.removeEventListener("touchend", this.caretEventHandler);
|
||||
document.removeEventListener("keyup", this.handleKeyUp);
|
||||
document.removeEventListener("keydown", this.handleKeyDown);
|
||||
document.removeEventListener("mouseup", this.handleMouseUp);
|
||||
document.removeEventListener("touchend", this.handleTouchEnd);
|
||||
|
||||
/**
|
||||
* Clear DOM
|
||||
@@ -763,9 +826,9 @@ class SimpleKeyboard {
|
||||
}
|
||||
|
||||
/**
|
||||
* Caret handling
|
||||
* setEventListeners
|
||||
*/
|
||||
this.handleCaret();
|
||||
this.setEventListeners();
|
||||
|
||||
if (typeof this.options.onInit === "function") this.options.onInit();
|
||||
}
|
||||
@@ -788,6 +851,7 @@ class SimpleKeyboard {
|
||||
* Notify about PointerEvents usage
|
||||
*/
|
||||
if (
|
||||
this.isFirstKeyboardInstance &&
|
||||
this.utilities.pointerEventsSupported() &&
|
||||
!this.options.useTouchEvents &&
|
||||
!this.options.useMouseEvents
|
||||
|
||||
@@ -1242,4 +1242,57 @@ it('Keyboard disableButtonHold will work', () => {
|
||||
});
|
||||
|
||||
expect(keyboard.options.disableButtonHold).toBe(true);
|
||||
});
|
||||
|
||||
it('Keyboard caretEventHandler will be triggered on mouseup and ontouchend', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
let keyboard = new Keyboard({
|
||||
disableCaretPositioning: true
|
||||
});
|
||||
|
||||
keyboard.caretPosition = 6;
|
||||
|
||||
document.dispatchEvent(new MouseEvent('mouseup', {
|
||||
target: {
|
||||
tagName: "input"
|
||||
}
|
||||
}));
|
||||
|
||||
expect(keyboard.caretPosition).toBe(null);
|
||||
|
||||
keyboard.setOptions({
|
||||
disableCaretPositioning: false
|
||||
})
|
||||
|
||||
keyboard.caretPosition = 10;
|
||||
|
||||
document.dispatchEvent(new TouchEvent('touchend', {
|
||||
target: {
|
||||
tagName: "input"
|
||||
}
|
||||
}));
|
||||
|
||||
expect(keyboard.caretPosition).toBe(10);
|
||||
});
|
||||
|
||||
it('Keyboard onKeyReleased will work', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
let pressed = false;
|
||||
let firedTimes = 0;
|
||||
|
||||
let keyboard = new Keyboard({
|
||||
onKeyReleased: () => {
|
||||
pressed = true;
|
||||
firedTimes++;
|
||||
},
|
||||
debug: true
|
||||
});
|
||||
|
||||
keyboard.getButtonElement("q").onpointerdown();
|
||||
keyboard.getButtonElement("q").onpointerup();
|
||||
|
||||
expect(pressed).toBeTruthy();
|
||||
expect(firedTimes).toBe(1);
|
||||
});
|
||||
@@ -1,3 +1,5 @@
|
||||
import Utilities from "../services/Utilities";
|
||||
|
||||
/**
|
||||
* Physical Keyboard Service
|
||||
*/
|
||||
@@ -5,66 +7,47 @@ class PhysicalKeyboard {
|
||||
/**
|
||||
* Creates an instance of the PhysicalKeyboard service
|
||||
*/
|
||||
constructor(simpleKeyboardInstance) {
|
||||
constructor({ dispatch, getOptions }) {
|
||||
/**
|
||||
* @type {object} A simple-keyboard instance
|
||||
*/
|
||||
this.simpleKeyboardInstance = simpleKeyboardInstance;
|
||||
this.dispatch = dispatch;
|
||||
this.getOptions = getOptions;
|
||||
|
||||
/**
|
||||
* Bindings
|
||||
*/
|
||||
this.initKeyboardListener = this.initKeyboardListener.bind(this);
|
||||
this.getSimpleKeyboardLayoutKey = this.getSimpleKeyboardLayoutKey.bind(
|
||||
this
|
||||
);
|
||||
|
||||
/**
|
||||
* Initialize key listeners
|
||||
*/
|
||||
this.initKeyboardListener();
|
||||
Utilities.bindMethods(PhysicalKeyboard, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes key event listeners
|
||||
*/
|
||||
initKeyboardListener() {
|
||||
// Adding button style on keydown
|
||||
document.addEventListener("keydown", event => {
|
||||
if (this.simpleKeyboardInstance.options.physicalKeyboardHighlight) {
|
||||
let buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
||||
handleHighlightKeyDown(event) {
|
||||
let options = this.getOptions();
|
||||
let buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
||||
|
||||
this.simpleKeyboardInstance.dispatch(instance => {
|
||||
let buttonDOM =
|
||||
instance.getButtonElement(buttonPressed) ||
|
||||
instance.getButtonElement(`{${buttonPressed}}`);
|
||||
this.dispatch(instance => {
|
||||
let buttonDOM =
|
||||
instance.getButtonElement(buttonPressed) ||
|
||||
instance.getButtonElement(`{${buttonPressed}}`);
|
||||
|
||||
if (buttonDOM) {
|
||||
buttonDOM.style.backgroundColor =
|
||||
this.simpleKeyboardInstance.options
|
||||
.physicalKeyboardHighlightBgColor || "#9ab4d0";
|
||||
buttonDOM.style.color =
|
||||
this.simpleKeyboardInstance.options
|
||||
.physicalKeyboardHighlightTextColor || "white";
|
||||
}
|
||||
});
|
||||
if (buttonDOM) {
|
||||
buttonDOM.style.backgroundColor =
|
||||
options.physicalKeyboardHighlightBgColor || "#9ab4d0";
|
||||
buttonDOM.style.color =
|
||||
options.physicalKeyboardHighlightTextColor || "white";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Removing button style on keyup
|
||||
document.addEventListener("keyup", event => {
|
||||
if (this.simpleKeyboardInstance.options.physicalKeyboardHighlight) {
|
||||
let buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
||||
handleHighlightKeyUp(event) {
|
||||
let buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
||||
|
||||
this.simpleKeyboardInstance.dispatch(instance => {
|
||||
let buttonDOM =
|
||||
instance.getButtonElement(buttonPressed) ||
|
||||
instance.getButtonElement(`{${buttonPressed}}`);
|
||||
this.dispatch(instance => {
|
||||
let buttonDOM =
|
||||
instance.getButtonElement(buttonPressed) ||
|
||||
instance.getButtonElement(`{${buttonPressed}}`);
|
||||
|
||||
if (buttonDOM && buttonDOM.removeAttribute) {
|
||||
buttonDOM.removeAttribute("style");
|
||||
}
|
||||
});
|
||||
if (buttonDOM && buttonDOM.removeAttribute) {
|
||||
buttonDOM.removeAttribute("style");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,11 +5,10 @@ class Utilities {
|
||||
/**
|
||||
* Creates an instance of the Utility service
|
||||
*/
|
||||
constructor(simpleKeyboardInstance) {
|
||||
/**
|
||||
* @type {object} A simple-keyboard instance
|
||||
*/
|
||||
this.simpleKeyboardInstance = simpleKeyboardInstance;
|
||||
constructor({ getOptions, getCaretPosition, dispatch }) {
|
||||
this.getOptions = getOptions;
|
||||
this.getCaretPosition = getCaretPosition;
|
||||
this.dispatch = dispatch;
|
||||
|
||||
/**
|
||||
* Bindings
|
||||
@@ -125,11 +124,11 @@ class Utilities {
|
||||
*
|
||||
* @param {string} button The button's layout name
|
||||
* @param {string} input The input string
|
||||
* @param {object} options The simple-keyboard options object
|
||||
* @param {number} caretPos The cursor's current position
|
||||
* @param {boolean} moveCaret Whether to update simple-keyboard's cursor
|
||||
*/
|
||||
getUpdatedInput(button, input, options, caretPos, moveCaret) {
|
||||
getUpdatedInput(button, input, caretPos, moveCaret) {
|
||||
let options = this.getOptions();
|
||||
let output = input;
|
||||
|
||||
if (
|
||||
@@ -187,43 +186,34 @@ class Utilities {
|
||||
* @param {boolean} minus Whether the cursor should be moved to the left or not.
|
||||
*/
|
||||
updateCaretPos(length, minus) {
|
||||
let newCaretPos = this.updateCaretPosAction(
|
||||
this.simpleKeyboardInstance,
|
||||
length,
|
||||
minus
|
||||
);
|
||||
let newCaretPos = this.updateCaretPosAction(length, minus);
|
||||
|
||||
if (this.simpleKeyboardInstance.options.syncInstanceInputs) {
|
||||
this.simpleKeyboardInstance.dispatch(instance => {
|
||||
instance.caretPosition = newCaretPos;
|
||||
});
|
||||
}
|
||||
this.dispatch(instance => {
|
||||
instance.caretPosition = newCaretPos;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Action method of updateCaretPos
|
||||
*
|
||||
* @param {object} instance The instance whose position should be updated
|
||||
* @param {number} length Represents by how many characters the input should be moved
|
||||
* @param {boolean} minus Whether the cursor should be moved to the left or not.
|
||||
*/
|
||||
updateCaretPosAction(instance, length, minus) {
|
||||
updateCaretPosAction(length, minus) {
|
||||
let options = this.getOptions();
|
||||
let caretPosition = this.getCaretPosition();
|
||||
|
||||
if (minus) {
|
||||
if (instance.caretPosition > 0)
|
||||
instance.caretPosition = instance.caretPosition - length;
|
||||
if (caretPosition > 0) caretPosition = caretPosition - length;
|
||||
} else {
|
||||
instance.caretPosition = instance.caretPosition + length;
|
||||
caretPosition = caretPosition + length;
|
||||
}
|
||||
|
||||
if (this.simpleKeyboardInstance.options.debug) {
|
||||
console.log(
|
||||
"Caret at:",
|
||||
instance.caretPosition,
|
||||
`(${instance.keyboardDOMClass})`
|
||||
);
|
||||
if (options.debug) {
|
||||
console.log("Caret at:", caretPosition, `(${this.keyboardDOMClass})`);
|
||||
}
|
||||
|
||||
return instance.caretPosition;
|
||||
return caretPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,7 +253,9 @@ class Utilities {
|
||||
* @param {boolean} moveCaret Whether to update simple-keyboard's cursor
|
||||
*/
|
||||
removeAt(source, position, moveCaret) {
|
||||
if (this.simpleKeyboardInstance.caretPosition === 0) {
|
||||
let caretPosition = this.getCaretPosition();
|
||||
|
||||
if (caretPosition === 0) {
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -306,10 +298,10 @@ class Utilities {
|
||||
* Determines whether the maxLength has been reached. This function is called when the maxLength option it set.
|
||||
*
|
||||
* @param {object} inputObj
|
||||
* @param {object} options
|
||||
* @param {string} updatedInput
|
||||
*/
|
||||
handleMaxLength(inputObj, options, updatedInput) {
|
||||
handleMaxLength(inputObj, updatedInput) {
|
||||
let options = this.getOptions();
|
||||
let maxLength = options.maxLength;
|
||||
let currentInput = inputObj[options.inputName];
|
||||
let condition = currentInput.length === maxLength;
|
||||
@@ -399,6 +391,8 @@ class Utilities {
|
||||
* @param {string} string The string to transform.
|
||||
*/
|
||||
camelCase(string) {
|
||||
if (!string) return false;
|
||||
|
||||
return string
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
|
||||
@@ -31,7 +31,7 @@ it('Keyboard {bksp} button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{bksp}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{bksp}", "test");
|
||||
|
||||
expect(output).toBe("tes");
|
||||
});
|
||||
@@ -41,7 +41,7 @@ it('Keyboard {space} button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{space}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{space}", "test");
|
||||
|
||||
expect(output).toBe("test ");
|
||||
});
|
||||
@@ -51,7 +51,7 @@ it('Keyboard {tab} button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{tab}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{tab}", "test");
|
||||
|
||||
expect(output).toBe("test\t");
|
||||
});
|
||||
@@ -63,7 +63,7 @@ it('Keyboard {tab} button will work with tabCharOnTab:false', () => {
|
||||
tabCharOnTab: false
|
||||
});
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{tab}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{tab}", "test");
|
||||
|
||||
expect(output).toBe("test");
|
||||
});
|
||||
@@ -73,7 +73,7 @@ it('Keyboard {enter} button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{enter}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{enter}", "test");
|
||||
|
||||
expect(output).toBe("test");
|
||||
});
|
||||
@@ -85,7 +85,7 @@ it('Keyboard {enter} button will work with newLineOnEnter:true', () => {
|
||||
newLineOnEnter: true
|
||||
});
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{enter}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{enter}", "test");
|
||||
|
||||
expect(output).toBe("test\n");
|
||||
});
|
||||
@@ -96,7 +96,7 @@ it('Keyboard {numpadX} buttons will work', () => {
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
for(let i = 0;i<=9;i++){
|
||||
let output = keyboard.utilities.getUpdatedInput(`{numpad${i}}`, "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput(`{numpad${i}}`, "test");
|
||||
expect(output).toBe(`test${i}`);
|
||||
}
|
||||
});
|
||||
@@ -106,7 +106,7 @@ it('Keyboard {numpaddivide} button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpaddivide}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpaddivide}", "test");
|
||||
|
||||
expect(output).toBe("test/");
|
||||
});
|
||||
@@ -116,7 +116,7 @@ it('Keyboard {numpadmultiply} button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpadmultiply}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpadmultiply}", "test");
|
||||
|
||||
expect(output).toBe("test*");
|
||||
});
|
||||
@@ -126,7 +126,7 @@ it('Keyboard {numpadsubtract} button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpadsubtract}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpadsubtract}", "test");
|
||||
|
||||
expect(output).toBe("test-");
|
||||
});
|
||||
@@ -136,7 +136,7 @@ it('Keyboard {numpadadd} button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpadadd}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpadadd}", "test");
|
||||
|
||||
expect(output).toBe("test+");
|
||||
});
|
||||
@@ -146,7 +146,7 @@ it('Keyboard {numpadadd} button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpadadd}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpadadd}", "test");
|
||||
|
||||
expect(output).toBe("test+");
|
||||
});
|
||||
@@ -156,7 +156,7 @@ it('Keyboard {numpaddecimal} button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpaddecimal}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{numpaddecimal}", "test");
|
||||
|
||||
expect(output).toBe("test.");
|
||||
});
|
||||
@@ -172,7 +172,7 @@ it('Keyboard custom function buttons will work', () => {
|
||||
}
|
||||
});
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{randombuttontest}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{randombuttontest}", "test");
|
||||
|
||||
expect(output).toBe("test");
|
||||
expect(keyboard.getButtonElement("{randombuttontest}").onclick).toBeTruthy();
|
||||
@@ -183,7 +183,7 @@ it('Keyboard "{" button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("{", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("{", "test");
|
||||
|
||||
expect(output).toBe("test{");
|
||||
});
|
||||
@@ -193,7 +193,7 @@ it('Keyboard "}" button will work', () => {
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
|
||||
let output = keyboard.utilities.getUpdatedInput("}", "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput("}", "test");
|
||||
|
||||
expect(output).toBe("test}");
|
||||
});
|
||||
@@ -205,7 +205,7 @@ it('Keyboard standard button will affect input', () => {
|
||||
|
||||
for (let i = 65; i <= 90; i++) {
|
||||
let char = String.fromCharCode(i);
|
||||
let output = keyboard.utilities.getUpdatedInput(char, "test", keyboard.options);
|
||||
let output = keyboard.utilities.getUpdatedInput(char, "test");
|
||||
expect(output).toBe(`test${char}`);
|
||||
}
|
||||
});
|
||||
@@ -213,8 +213,9 @@ it('Keyboard standard button will affect input', () => {
|
||||
it('Keyboard updateCaretPos will work with minus', () => {
|
||||
testUtil.setDOM();
|
||||
|
||||
let keyboard = new Keyboard();
|
||||
keyboard.options.syncInstanceInputs = true;
|
||||
let keyboard = new Keyboard({
|
||||
syncInstanceInputs: true
|
||||
});
|
||||
|
||||
keyboard.caretPosition = 5;
|
||||
keyboard.utilities.updateCaretPos(2, true);
|
||||
@@ -282,7 +283,7 @@ it('Keyboard addStringAt will respect maxLength', () => {
|
||||
keyboard.setInput("test");
|
||||
keyboard.caretPosition = 4;
|
||||
|
||||
keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq")
|
||||
keyboard.utilities.handleMaxLength(keyboard.input, "testq")
|
||||
keyboard.utilities.addStringAt("test", "q", 4);
|
||||
|
||||
expect(keyboard.caretPosition).toBe(4);
|
||||
@@ -297,7 +298,7 @@ it('Keyboard handleMaxLength will exit out on same updatedInput', () => {
|
||||
|
||||
keyboard.setInput("test");
|
||||
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "test")
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, "test")
|
||||
|
||||
expect(output).toBeFalsy();
|
||||
});
|
||||
@@ -313,7 +314,7 @@ it('Keyboard handleMaxLength will work with object maxLength', () => {
|
||||
|
||||
keyboard.setInput("test");
|
||||
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq");
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||
|
||||
expect(output).toBeTruthy();
|
||||
});
|
||||
@@ -330,7 +331,7 @@ it('Keyboard handleMaxLength will work with object maxLength and debug', () => {
|
||||
|
||||
keyboard.setInput("test");
|
||||
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq");
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||
|
||||
expect(output).toBeTruthy();
|
||||
});
|
||||
@@ -346,7 +347,7 @@ it('Keyboard handleMaxLength will return false if obj maxLength not reached', ()
|
||||
|
||||
keyboard.setInput("test");
|
||||
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq");
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||
|
||||
expect(output).toBeFalsy();
|
||||
});
|
||||
@@ -361,7 +362,7 @@ it('Keyboard handleMaxLength will work without debug', () => {
|
||||
|
||||
keyboard.setInput("test");
|
||||
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq");
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||
|
||||
expect(output).toBeTruthy();
|
||||
});
|
||||
@@ -376,7 +377,7 @@ it('Keyboard handleMaxLength will work with numeric maxLength', () => {
|
||||
|
||||
keyboard.setInput("test");
|
||||
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq");
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||
|
||||
expect(output).toBeFalsy();
|
||||
});
|
||||
@@ -390,7 +391,7 @@ it('Keyboard handleMaxLength wont work with non numeric or object maxLength', ()
|
||||
|
||||
keyboard.setInput("test");
|
||||
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq");
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||
|
||||
expect(output).toBeFalsy();
|
||||
});
|
||||
@@ -405,7 +406,7 @@ it('Keyboard handleMaxLength wont work with non numeric or object maxLength (wit
|
||||
|
||||
keyboard.setInput("test");
|
||||
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, keyboard.options, "testq");
|
||||
let output = keyboard.utilities.handleMaxLength(keyboard.input, "testq");
|
||||
|
||||
expect(output).toBeFalsy();
|
||||
});
|
||||
@@ -483,4 +484,10 @@ it('Keyboard will work with custom (and weird) class', () => {
|
||||
testUtil.setDOM("my--weird--class");
|
||||
let keyboard = new Keyboard(".my--weird--class");
|
||||
expect(keyboard.keyboardDOMClass).toBe("my--weird--class");
|
||||
});
|
||||
|
||||
it('Keyboard camelCase will work with empty strings', () => {
|
||||
testUtil.setDOM();
|
||||
let keyboard = new Keyboard();
|
||||
expect(keyboard.utilities.camelCase()).toBeFalsy();
|
||||
});
|
||||
Reference in New Issue
Block a user