[
{
"__docId__": 1,
"kind": "external",
"name": "Infinity",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Infinity",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 2,
"kind": "external",
"name": "NaN",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~NaN",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 3,
"kind": "external",
"name": "undefined",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~undefined",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 4,
"kind": "external",
"name": "null",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~null",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 5,
"kind": "external",
"name": "Object",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Object",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 6,
"kind": "external",
"name": "object",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~object",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 7,
"kind": "external",
"name": "Function",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Function",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 8,
"kind": "external",
"name": "function",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~function",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 9,
"kind": "external",
"name": "Boolean",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Boolean",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 10,
"kind": "external",
"name": "boolean",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~boolean",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 11,
"kind": "external",
"name": "Symbol",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Symbol",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 12,
"kind": "external",
"name": "Error",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Error",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 13,
"kind": "external",
"name": "EvalError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~EvalError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 14,
"kind": "external",
"name": "InternalError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/InternalError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~InternalError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 15,
"kind": "external",
"name": "RangeError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~RangeError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 16,
"kind": "external",
"name": "ReferenceError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~ReferenceError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 17,
"kind": "external",
"name": "SyntaxError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~SyntaxError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 18,
"kind": "external",
"name": "TypeError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~TypeError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 19,
"kind": "external",
"name": "URIError",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~URIError",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 20,
"kind": "external",
"name": "Number",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Number",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 21,
"kind": "external",
"name": "number",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~number",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 22,
"kind": "external",
"name": "Date",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Date",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 23,
"kind": "external",
"name": "String",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~String",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 24,
"kind": "external",
"name": "string",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~string",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 25,
"kind": "external",
"name": "RegExp",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~RegExp",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 26,
"kind": "external",
"name": "Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 27,
"kind": "external",
"name": "Int8Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Int8Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 28,
"kind": "external",
"name": "Uint8Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Uint8Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 29,
"kind": "external",
"name": "Uint8ClampedArray",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Uint8ClampedArray",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 30,
"kind": "external",
"name": "Int16Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Int16Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 31,
"kind": "external",
"name": "Uint16Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Uint16Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 32,
"kind": "external",
"name": "Int32Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Int32Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 33,
"kind": "external",
"name": "Uint32Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Uint32Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 34,
"kind": "external",
"name": "Float32Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Float32Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 35,
"kind": "external",
"name": "Float64Array",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Float64Array",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 36,
"kind": "external",
"name": "Map",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Map",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 37,
"kind": "external",
"name": "Set",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Set",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 38,
"kind": "external",
"name": "WeakMap",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~WeakMap",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 39,
"kind": "external",
"name": "WeakSet",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~WeakSet",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 40,
"kind": "external",
"name": "ArrayBuffer",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~ArrayBuffer",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 41,
"kind": "external",
"name": "DataView",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~DataView",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 42,
"kind": "external",
"name": "JSON",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~JSON",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 43,
"kind": "external",
"name": "Promise",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Promise",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 44,
"kind": "external",
"name": "Generator",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Generator",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 45,
"kind": "external",
"name": "GeneratorFunction",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/GeneratorFunction",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~GeneratorFunction",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 46,
"kind": "external",
"name": "Reflect",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Reflect",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 47,
"kind": "external",
"name": "Proxy",
"externalLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy",
"memberof": "src/.external-ecmascript.js",
"static": true,
"longname": "src/.external-ecmascript.js~Proxy",
"access": "public",
"description": "",
"builtinExternal": true
},
{
"__docId__": 48,
"kind": "file",
"name": "src/demo/App.js",
"content": "import Keyboard from '../lib';\r\nimport './css/App.css';\r\n\r\n/**\r\n * simple-keyboard demo\r\n */\r\nclass App {\r\n /**\r\n * Instantiates the demo class\r\n */\r\n constructor(){\r\n document.addEventListener('DOMContentLoaded', this.onDOMLoaded);\r\n\r\n /**\r\n * Default input name\r\n * @type {string}\r\n */\r\n this.layoutName = \"default\";\r\n }\r\n\r\n /**\r\n * Executed when the DOM is ready\r\n */\r\n onDOMLoaded = () => {\r\n /**\r\n * Creates a new simple-keyboard instance\r\n */\r\n this.keyboard = new Keyboard({\r\n debug: true,\r\n layoutName: this.layoutName,\r\n onChange: input => this.onChange(input),\r\n onKeyPress: button => this.onKeyPress(button),\r\n newLineOnEnter: true,\r\n physicalKeyboardHighlight: true,\r\n });\r\n \r\n /**\r\n * Adding preview (demo only)\r\n */\r\n document.querySelector('.simple-keyboard').insertAdjacentHTML('beforebegin', `\r\n
\r\n \r\n
\r\n `);\r\n \r\n document.querySelector('.input').addEventListener('input', (event) => {\r\n this.keyboard.setInput(event.target.value);\r\n });\r\n }\r\n\r\n /**\r\n * Handles shift functionality\r\n */\r\n handleShiftButton = () => {\r\n let layoutName = this.layoutName;\r\n let shiftToggle = this.layoutName = layoutName === \"default\" ? \"shift\" : \"default\";\r\n \r\n this.keyboard.setOptions({\r\n layoutName: shiftToggle\r\n });\r\n }\r\n\r\n /**\r\n * Called when simple-keyboard input has changed\r\n */\r\n onChange = input => {\r\n document.querySelector('.input').value = input;\r\n }\r\n\r\n /**\r\n * Called when a simple-keyboard key is pressed\r\n */\r\n onKeyPress = button => {\r\n console.log(\"Button pressed\", button);\r\n \r\n /**\r\n * Shift functionality\r\n */\r\n if(button === \"{lock}\" || button === \"{shift}\")\r\n this.handleShiftButton();\r\n }\r\n\r\n}\r\n\r\nexport default App;",
"static": true,
"longname": "X:/Dev/simple-keyboard/src/demo/App.js",
"access": "public",
"description": null,
"lineNumber": 1
},
{
"__docId__": 49,
"kind": "class",
"name": "App",
"memberof": "src/demo/App.js",
"static": true,
"longname": "src/demo/App.js~App",
"access": "public",
"export": true,
"importPath": "simple-keyboard/src/demo/App.js",
"importStyle": "App",
"description": "simple-keyboard demo",
"lineNumber": 7,
"interface": false
},
{
"__docId__": 50,
"kind": "constructor",
"name": "constructor",
"memberof": "src/demo/App.js~App",
"generator": false,
"async": false,
"static": false,
"longname": "src/demo/App.js~App#constructor",
"access": "public",
"description": "Instantiates the demo class",
"lineNumber": 11
},
{
"__docId__": 51,
"kind": "member",
"name": "layoutName",
"memberof": "src/demo/App.js~App",
"static": false,
"longname": "src/demo/App.js~App#layoutName",
"access": "public",
"description": "Default input name",
"lineNumber": 18,
"type": {
"nullable": null,
"types": [
"string"
],
"spread": false,
"description": null
}
},
{
"__docId__": 52,
"kind": "member",
"name": "onDOMLoaded",
"memberof": "src/demo/App.js~App",
"static": false,
"longname": "src/demo/App.js~App#onDOMLoaded",
"access": "public",
"description": "Executed when the DOM is ready",
"lineNumber": 24,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 53,
"kind": "member",
"name": "keyboard",
"memberof": "src/demo/App.js~App",
"longname": "src/demo/App.js~App#keyboard",
"access": "public",
"description": "Creates a new simple-keyboard instance",
"lineNumber": 28,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 54,
"kind": "member",
"name": "handleShiftButton",
"memberof": "src/demo/App.js~App",
"static": false,
"longname": "src/demo/App.js~App#handleShiftButton",
"access": "public",
"description": "Handles shift functionality",
"lineNumber": 54,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 55,
"kind": "member",
"name": "onChange",
"memberof": "src/demo/App.js~App",
"static": false,
"longname": "src/demo/App.js~App#onChange",
"access": "public",
"description": "Called when simple-keyboard input has changed",
"lineNumber": 66,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 56,
"kind": "member",
"name": "onKeyPress",
"memberof": "src/demo/App.js~App",
"static": false,
"longname": "src/demo/App.js~App#onKeyPress",
"access": "public",
"description": "Called when a simple-keyboard key is pressed",
"lineNumber": 73,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 57,
"kind": "file",
"name": "src/demo/index.js",
"content": "import App from './App';\r\n\r\n/**\r\n * Initializing demo\r\n */\r\nnew App();",
"static": true,
"longname": "X:/Dev/simple-keyboard/src/demo/index.js",
"access": "public",
"description": null,
"lineNumber": 1
},
{
"__docId__": 58,
"kind": "file",
"name": "src/lib/components/Keyboard.js",
"content": "import './Keyboard.css';\r\n\r\n// Services\r\nimport PhysicalKeyboard from '../services/PhysicalKeyboard';\r\nimport KeyboardLayout from '../services/KeyboardLayout';\r\nimport Utilities from '../services/Utilities';\r\n\r\n/**\r\n * Root class for simple-keyboard\r\n * This class:\r\n * - Parses the options\r\n * - Renders the rows and buttons\r\n * - Handles button functionality\r\n */\r\nclass SimpleKeyboard {\r\n /**\r\n * Creates an instance of SimpleKeyboard\r\n * @param {Array} params If first parameter is a string, it is considered the container class. The second parameter is then considered the options object. If first parameter is an object, it is considered the options object.\r\n */\r\n constructor(...params){\r\n let keyboardDOMQuery = typeof params[0] === \"string\" ? params[0] : '.simple-keyboard';\r\n let options = typeof params[0] === \"object\" ? params[0] : params[1];\r\n\r\n if(!options)\r\n options = {};\r\n\r\n /**\r\n * Initializing Utilities\r\n */\r\n this.utilities = new Utilities(this);\r\n\r\n /**\r\n * Processing options\r\n */\r\n this.keyboardDOM = document.querySelector(keyboardDOMQuery);\r\n\r\n /**\r\n * @type {object}\r\n * @property {object} layout Modify the keyboard layout.\r\n * @property {string} layoutName Specifies which layout should be used.\r\n * @property {object} display Replaces variable buttons (such as {bksp}) with a human-friendly name (e.g.: “backspace”).\r\n * @property {boolean} mergeDisplay By default, when you set the display property, you replace the default one. This setting merges them instead.\r\n * @property {string} theme A prop to add your own css classes to the keyboard wrapper. You can add multiple classes separated by a space.\r\n * @property {Array} buttonTheme A prop to add your own css classes to one or several buttons.\r\n * @property {boolean} debug Runs a console.log every time a key is pressed. Displays the buttons pressed and the current input.\r\n * @property {boolean} newLineOnEnter Specifies whether clicking the “ENTER” button will input a newline (\\n) or not.\r\n * @property {boolean} tabCharOnTab Specifies whether clicking the “TAB” button will input a tab character (\\t) or not.\r\n * @property {string} inputName Allows you to use a single simple-keyboard instance for several inputs.\r\n * @property {number} maxLength Restrains all of simple-keyboard inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute.\r\n * @property {object} maxLength Restrains simple-keyboard’s individual inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute.\r\n * @property {boolean} syncInstanceInputs When set to true, this option synchronizes the internal input of every simple-keyboard instance.\r\n * @property {boolean} physicalKeyboardHighlight Enable highlighting of keys pressed on physical keyboard.\r\n * @property {boolean} preventMouseDownDefault Calling preventDefault for the mousedown events keeps the focus on the input.\r\n * @property {string} physicalKeyboardHighlightTextColor Define the text color that the physical keyboard highlighted key should have.\r\n * @property {string} physicalKeyboardHighlightBgColor Define the background color that the physical keyboard highlighted key should have.\r\n * @property {function(button: string):string} onKeyPress Executes the callback function on key press. Returns button layout name (i.e.: “{shift}”).\r\n * @property {function(input: string):string} onChange Executes the callback function on input change. Returns the current input’s string.\r\n * @property {function} onRender Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).\r\n * @property {function} onInit Executes the callback function once simple-keyboard is rendered for the first time (on initialization).\r\n * @property {function(inputs: object):object} onChangeAll Executes the callback function on input change. Returns the input object with all defined inputs.\r\n */\r\n this.options = options;\r\n this.options.layoutName = this.options.layoutName || \"default\";\r\n this.options.theme = this.options.theme || \"hg-theme-default\";\r\n this.options.inputName = this.options.inputName || \"default\";\r\n this.options.preventMouseDownDefault = this.options.preventMouseDownDefault === false ? false : true;\r\n\r\n /**\r\n * @type {object} Classes identifying loaded plugins\r\n */\r\n this.keyboardPluginClasses = '';\r\n\r\n /**\r\n * Bindings\r\n */\r\n this.handleButtonClicked = this.handleButtonClicked.bind(this);\r\n this.syncInstanceInputs = this.syncInstanceInputs.bind(this);\r\n this.clearInput = this.clearInput.bind(this);\r\n this.getInput = this.getInput.bind(this);\r\n this.setInput = this.setInput.bind(this);\r\n this.replaceInput = this.replaceInput.bind(this);\r\n this.clear = this.clear.bind(this);\r\n this.dispatch = this.dispatch.bind(this);\r\n this.addButtonTheme = this.addButtonTheme.bind(this);\r\n this.removeButtonTheme = this.removeButtonTheme.bind(this);\r\n this.getButtonElement = this.getButtonElement.bind(this);\r\n this.handleCaret = this.handleCaret.bind(this);\r\n this.caretEventHandler = this.caretEventHandler.bind(this);\r\n this.onInit = this.onInit.bind(this);\r\n this.onRender = this.onRender.bind(this);\r\n this.render = this.render.bind(this);\r\n this.loadModules = this.loadModules.bind(this);\r\n this.handleButtonMouseUp = this.handleButtonMouseUp.bind(this);\r\n this.handleButtonMouseDown = this.handleButtonMouseDown.bind(this);\r\n this.handleButtonHold = this.handleButtonHold.bind(this);\r\n this.onModulesLoaded = this.onModulesLoaded.bind(this);\r\n\r\n /**\r\n * simple-keyboard uses a non-persistent internal input to keep track of the entered string (the variable `keyboard.input`).\r\n * This removes any dependency to input DOM elements. You can type and directly display the value in a div element, for example.\r\n * @example\r\n * // To get entered input\r\n * let input = keyboard.getInput();\r\n * \r\n * // To clear entered input.\r\n * keyboard.clearInput();\r\n * \r\n * @type {object}\r\n * @property {object} default Default SimpleKeyboard internal input.\r\n * @property {object} myInputName Example input that can be set through `options.inputName:\"myInputName\"`.\r\n */\r\n this.input = {};\r\n this.input[this.options.inputName] = '';\r\n\r\n /**\r\n * @type {string} DOM class of the keyboard wrapper, normally \"simple-keyboard\" by default.\r\n */\r\n this.keyboardDOMClass = keyboardDOMQuery.split('.').join(\"\");\r\n\r\n /**\r\n * @type {object} Contains the DOM elements of every rendered button, the key being the button's layout name (e.g.: \"{enter}\").\r\n */\r\n this.buttonElements = {};\r\n\r\n /**\r\n * Rendering keyboard\r\n */\r\n if(this.keyboardDOM)\r\n this.render();\r\n else {\r\n console.warn(`\"${keyboardDOMQuery}\" was not found in the DOM.`);\r\n throw new Error(\"KEYBOARD_DOM_ERROR\");\r\n }\r\n\r\n /**\r\n * Saving instance\r\n * This enables multiple simple-keyboard support with easier management\r\n */\r\n if(!window['SimpleKeyboardInstances'])\r\n window['SimpleKeyboardInstances'] = {};\r\n \r\n window['SimpleKeyboardInstances'][this.utilities.camelCase(this.keyboardDOMClass)] = this;\r\n\r\n /**\r\n * Physical Keyboard support\r\n */\r\n this.physicalKeyboardInterface = new PhysicalKeyboard(this);\r\n\r\n /**\r\n * Modules\r\n */\r\n this.modules = {};\r\n this.loadModules();\r\n }\r\n\r\n /**\r\n * Handles clicks made to keyboard buttons\r\n * @param {string} button The button's layout name.\r\n */\r\n handleButtonClicked(button){\r\n let debug = this.options.debug;\r\n\r\n /**\r\n * Ignoring placeholder buttons\r\n */\r\n if(button === '{//}')\r\n return false;\r\n\r\n /**\r\n * Calling onKeyPress\r\n */\r\n if(typeof this.options.onKeyPress === \"function\")\r\n this.options.onKeyPress(button);\r\n \r\n if(!this.input[this.options.inputName])\r\n this.input[this.options.inputName] = '';\r\n\r\n let updatedInput = this.utilities.getUpdatedInput(\r\n button, this.input[this.options.inputName], this.options, this.caretPosition\r\n );\r\n\r\n if(this.input[this.options.inputName] !== updatedInput){\r\n\r\n /**\r\n * If maxLength and handleMaxLength yield true, halting\r\n */\r\n if(this.options.maxLength && this.utilities.handleMaxLength(this.input, this.options, updatedInput)){\r\n return false;\r\n }\r\n\r\n this.input[this.options.inputName] = this.utilities.getUpdatedInput(\r\n button, this.input[this.options.inputName], this.options, this.caretPosition, true\r\n );\r\n\r\n if(debug)\r\n console.log('Input changed:', this.input);\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if(this.options.syncInstanceInputs)\r\n this.syncInstanceInputs(this.input);\r\n\r\n /**\r\n * Calling onChange\r\n */\r\n if(typeof this.options.onChange === \"function\")\r\n this.options.onChange(this.input[this.options.inputName]);\r\n }\r\n \r\n if(debug){\r\n console.log(\"Key pressed:\", button);\r\n }\r\n }\r\n\r\n /**\r\n * Handles button mousedown\r\n */\r\n /* istanbul ignore next */\r\n handleButtonMouseDown(button, e){\r\n /**\r\n * @type {boolean} Whether the mouse is being held onKeyPress\r\n */\r\n this.isMouseHold = true;\r\n\r\n if(this.holdInteractionTimeout)\r\n clearTimeout(this.holdInteractionTimeout);\r\n\r\n if(this.holdTimeout)\r\n clearTimeout(this.holdTimeout);\r\n\r\n /**\r\n * @type {object} Time to wait until a key hold is detected\r\n */\r\n this.holdTimeout = setTimeout(() => {\r\n if(\r\n this.isMouseHold &&\r\n (\r\n (!button.includes(\"{\") && !button.includes(\"}\")) ||\r\n button === \"{bksp}\" ||\r\n button === \"{space}\" ||\r\n button === \"{tab}\"\r\n )\r\n ){\r\n if(this.options.debug)\r\n console.log(\"Button held:\", button);\r\n\r\n this.handleButtonHold(button, e);\r\n }\r\n clearTimeout(this.holdTimeout);\r\n }, 500);\r\n }\r\n\r\n /**\r\n * Handles button mouseup\r\n */\r\n handleButtonMouseUp(){\r\n this.isMouseHold = false;\r\n if(this.holdInteractionTimeout)\r\n clearTimeout(this.holdInteractionTimeout);\r\n }\r\n\r\n /**\r\n * Handles button hold\r\n */\r\n /* istanbul ignore next */\r\n handleButtonHold(button){\r\n if(this.holdInteractionTimeout)\r\n clearTimeout(this.holdInteractionTimeout);\r\n\r\n /**\r\n * @type {object} Timeout dictating the speed of key hold iterations\r\n */\r\n this.holdInteractionTimeout = setTimeout(() => {\r\n if(this.isMouseHold){\r\n this.handleButtonClicked(button);\r\n this.handleButtonHold(button);\r\n } else {\r\n clearTimeout(this.holdInteractionTimeout);\r\n }\r\n }, 100);\r\n }\r\n\r\n /**\r\n * Send a command to all simple-keyboard instances (if you have several instances).\r\n */\r\n syncInstanceInputs(){\r\n this.dispatch((instance) => {\r\n instance.replaceInput(this.input);\r\n });\r\n }\r\n \r\n /**\r\n * Clear the keyboard’s input.\r\n * @param {string} [inputName] optional - the internal input to select\r\n */\r\n clearInput(inputName){\r\n inputName = inputName || this.options.inputName;\r\n this.input[inputName] = '';\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if(this.options.syncInstanceInputs)\r\n this.syncInstanceInputs(this.input);\r\n }\r\n\r\n /**\r\n * Get the keyboard’s input (You can also get it from the onChange prop).\r\n * @param {string} [inputName] optional - the internal input to select\r\n */\r\n getInput(inputName){\r\n inputName = inputName || this.options.inputName;\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if(this.options.syncInstanceInputs)\r\n this.syncInstanceInputs(this.input);\r\n\r\n return this.input[this.options.inputName];\r\n }\r\n\r\n /**\r\n * Set the keyboard’s input.\r\n * @param {string} input the input value\r\n * @param {string} inputName optional - the internal input to select\r\n */\r\n setInput(input, inputName){\r\n inputName = inputName || this.options.inputName;\r\n this.input[inputName] = input;\r\n\r\n /**\r\n * Enforce syncInstanceInputs, if set\r\n */\r\n if(this.options.syncInstanceInputs)\r\n this.syncInstanceInputs(this.input);\r\n }\r\n \r\n /**\r\n * Replace the input object (`keyboard.input`)\r\n * @param {object} inputObj The input object\r\n */\r\n replaceInput(inputObj){\r\n this.input = inputObj;\r\n }\r\n\r\n /**\r\n * Set new option or modify existing ones after initialization. \r\n * @param {object} option The option to set\r\n */\r\n setOptions = option => {\r\n option = option || {};\r\n this.options = Object.assign(this.options, option);\r\n this.render();\r\n }\r\n\r\n /**\r\n * Remove all keyboard rows and reset keyboard values.\r\n * Used interally between re-renders.\r\n */\r\n clear(){\r\n this.keyboardDOM.innerHTML = '';\r\n this.keyboardDOM.className = this.keyboardDOMClass;\r\n this.buttonElements = {};\r\n }\r\n\r\n /**\r\n * Send a command to all simple-keyboard instances at once (if you have multiple instances).\r\n * @param {function(instance: object, key: string)} callback Function to run on every instance\r\n */\r\n dispatch(callback){\r\n if(!window['SimpleKeyboardInstances']){\r\n console.warn(`SimpleKeyboardInstances is not defined. Dispatch cannot be called.`);\r\n throw new Error(\"INSTANCES_VAR_ERROR\");\r\n }\r\n \r\n return Object.keys(window['SimpleKeyboardInstances']).forEach((key) => {\r\n callback(window['SimpleKeyboardInstances'][key], key);\r\n })\r\n }\r\n\r\n /**\r\n * Adds/Modifies an entry to the `buttonTheme`. Basically a way to add a class to a button.\r\n * @param {string} buttons List of buttons to select (separated by a space).\r\n * @param {string} className Classes to give to the selected buttons (separated by space).\r\n */\r\n addButtonTheme(buttons, className){\r\n if(!className || !buttons)\r\n return false;\r\n\r\n buttons.split(\" \").forEach(button => {\r\n className.split(\" \").forEach(classNameItem => {\r\n if(!this.options.buttonTheme)\r\n this.options.buttonTheme = [];\r\n\r\n let classNameFound = false;\r\n \r\n /**\r\n * If class is already defined, we add button to class definition\r\n */\r\n this.options.buttonTheme.map(buttonTheme => {\r\n\r\n if(buttonTheme.class.split(\" \").includes(classNameItem)){\r\n classNameFound = true;\r\n \r\n let buttonThemeArray = buttonTheme.buttons.split(\" \");\r\n if(!buttonThemeArray.includes(button)){\r\n classNameFound = true;\r\n buttonThemeArray.push(button);\r\n buttonTheme.buttons = buttonThemeArray.join(\" \");\r\n }\r\n }\r\n return buttonTheme;\r\n });\r\n\r\n /**\r\n * If class is not defined, we create a new entry\r\n */\r\n if(!classNameFound){\r\n this.options.buttonTheme.push({\r\n class: classNameItem,\r\n buttons: buttons\r\n });\r\n }\r\n\r\n });\r\n });\r\n\r\n this.render();\r\n }\r\n\r\n /**\r\n * Removes/Amends an entry to the `buttonTheme`. Basically a way to remove a class previously added to a button through buttonTheme or addButtonTheme.\r\n * @param {string} buttons List of buttons to select (separated by a space).\r\n * @param {string} className Classes to give to the selected buttons (separated by space).\r\n */\r\n removeButtonTheme(buttons, className){\r\n /**\r\n * When called with empty parameters, remove all button themes\r\n */\r\n if(!buttons && !className){\r\n this.options.buttonTheme = [];\r\n this.render();\r\n return false;\r\n }\r\n\r\n /**\r\n * If buttons are passed and buttonTheme has items\r\n */\r\n if(buttons && Array.isArray(this.options.buttonTheme) && this.options.buttonTheme.length){\r\n let buttonArray = buttons.split(\" \");\r\n buttonArray.forEach((button, key) => {\r\n this.options.buttonTheme.map((buttonTheme, index) => {\r\n\r\n /**\r\n * If className is set, we affect the buttons only for that class\r\n * Otherwise, we afect all classes\r\n */\r\n if(\r\n (className && className.includes(buttonTheme.class)) ||\r\n !className\r\n ){\r\n let filteredButtonArray = buttonTheme.buttons.split(\" \").filter(item => item !== button);\r\n\r\n /**\r\n * If buttons left, return them, otherwise, remove button Theme\r\n */\r\n if(filteredButtonArray.length){\r\n buttonTheme.buttons = filteredButtonArray.join(\" \");\r\n } else {\r\n this.options.buttonTheme.splice(index, 1);\r\n buttonTheme = null;\r\n }\r\n \r\n }\r\n\r\n return buttonTheme;\r\n });\r\n });\r\n\r\n this.render();\r\n }\r\n }\r\n\r\n /**\r\n * Get the DOM Element of a button. If there are several buttons with the same name, an array of the DOM Elements is returned.\r\n * @param {string} button The button layout name to select\r\n */\r\n getButtonElement(button){\r\n let output;\r\n\r\n let buttonArr = this.buttonElements[button];\r\n if(buttonArr){\r\n if(buttonArr.length > 1){\r\n output = buttonArr;\r\n } else {\r\n output = buttonArr[0];\r\n }\r\n }\r\n\r\n return output;\r\n }\r\n\r\n /**\r\n * Retrieves the current cursor position within a input or textarea (if any)\r\n */\r\n handleCaret(){\r\n /**\r\n * Only first instance should insall the caret handling events\r\n */\r\n this.caretPosition = null;\r\n let simpleKeyboardInstances = window['SimpleKeyboardInstances'];\r\n\r\n if(\r\n (\r\n simpleKeyboardInstances &&\r\n Object.keys(simpleKeyboardInstances)[0] === this.utilities.camelCase(this.keyboardDOMClass)\r\n ) ||\r\n !simpleKeyboardInstances\r\n ){\r\n if(this.options.debug){\r\n console.log(`Caret handling started (${this.keyboardDOMClass})`)\r\n }\r\n\r\n document.addEventListener(\"keyup\", this.caretEventHandler);\r\n document.addEventListener(\"mouseup\", this.caretEventHandler);\r\n document.addEventListener(\"touchend\", this.caretEventHandler);\r\n }\r\n }\r\n\r\n /**\r\n * Called by {@link handleCaret} when an event that warrants a cursor position update is triggered\r\n */\r\n caretEventHandler(event){\r\n let targetTagName;\r\n if(event.target.tagName){\r\n targetTagName = event.target.tagName.toLowerCase();\r\n }\r\n\r\n this.dispatch(instance => {\r\n if(instance.isMouseHold){\r\n instance.isMouseHold = false;\r\n }\r\n\r\n if(\r\n (targetTagName === \"textarea\" ||\r\n targetTagName === \"input\") &&\r\n !instance.options.disableCaretPositioning\r\n ){\r\n /**\r\n * Tracks current cursor position\r\n * As keys are pressed, text will be added/removed at that position within the input.\r\n */\r\n instance.caretPosition = event.target.selectionStart;\r\n\r\n if(instance.options.debug){\r\n console.log('Caret at: ', event.target.selectionStart, event.target.tagName.toLowerCase(), `(${instance.keyboardDOMClass})`);\r\n } \r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Executes the callback function once simple-keyboard is rendered for the first time (on initialization).\r\n */\r\n onInit(){\r\n if(this.options.debug){\r\n console.log(`${this.keyboardDOMClass} Initialized`)\r\n }\r\n\r\n /**\r\n * Caret handling\r\n */\r\n this.handleCaret();\r\n\r\n if(typeof this.options.onInit === \"function\")\r\n this.options.onInit();\r\n }\r\n\r\n /**\r\n * Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).\r\n */\r\n onRender(){\r\n if(typeof this.options.onRender === \"function\")\r\n this.options.onRender();\r\n }\r\n\r\n /**\r\n * Executes the callback function once all modules have been loaded\r\n */\r\n onModulesLoaded(){\r\n if(typeof this.options.onModulesLoaded === \"function\")\r\n this.options.onModulesLoaded();\r\n }\r\n\r\n /**\r\n * Register module\r\n */\r\n registerModule = (name, initCallback) => {\r\n if(!this.modules[name])\r\n this.modules[name] = {};\r\n\r\n initCallback(this.modules[name]);\r\n }\r\n\r\n /**\r\n * Load modules\r\n */\r\n loadModules(){\r\n if(Array.isArray(this.options.modules)){\r\n this.options.modules.forEach(Module => {\r\n let module = new Module();\r\n\r\n /* istanbul ignore next */\r\n if(module.constructor.name && module.constructor.name !== \"Function\"){\r\n let classStr = `module-${this.utilities.camelCase(module.constructor.name)}`;\r\n this.keyboardPluginClasses = this.keyboardPluginClasses + ` ${classStr}`;\r\n }\r\n\r\n module.init(this);\r\n });\r\n\r\n this.keyboardPluginClasses = this.keyboardPluginClasses + ' modules-loaded';\r\n\r\n this.render();\r\n this.onModulesLoaded();\r\n }\r\n }\r\n\r\n /**\r\n * Get module prop\r\n */\r\n getModuleProp = (name, prop) => {\r\n if(!this.modules[name])\r\n return false;\r\n \r\n return this.modules[name][prop];\r\n }\r\n\r\n /**\r\n * getModulesList\r\n */\r\n getModulesList = () => {\r\n return Object.keys(this.modules);\r\n }\r\n\r\n /**\r\n * Renders rows and buttons as per options\r\n */\r\n render(){\r\n /**\r\n * Clear keyboard\r\n */\r\n this.clear();\r\n\r\n let layoutClass = this.options.layout ? \"hg-layout-custom\" : `hg-layout-${this.options.layoutName}`;\r\n let layout = this.options.layout || KeyboardLayout.getDefaultLayout();\r\n let useTouchEvents = this.options.useTouchEvents || false\r\n\r\n /**\r\n * Account for buttonTheme, if set\r\n */\r\n let buttonThemesParsed = {};\r\n if(Array.isArray(this.options.buttonTheme)){\r\n this.options.buttonTheme.forEach(themeObj => {\r\n if(themeObj.buttons && themeObj.class){\r\n let themeButtons;\r\n\r\n if(typeof themeObj.buttons === \"string\"){\r\n themeButtons = themeObj.buttons.split(' ');\r\n }\r\n\r\n if(themeButtons){\r\n themeButtons.forEach(themeButton => {\r\n let themeParsed = buttonThemesParsed[themeButton];\r\n\r\n // If the button has already been added\r\n if(themeParsed){\r\n // Making sure we don't add duplicate classes, even when buttonTheme has duplicates\r\n if(!this.utilities.countInArray(themeParsed.split(\" \"), themeObj.class)){\r\n buttonThemesParsed[themeButton] = `${themeParsed} ${themeObj.class}`;\r\n }\r\n } else {\r\n buttonThemesParsed[themeButton] = themeObj.class;\r\n }\r\n });\r\n }\r\n } else {\r\n console.warn(`buttonTheme row is missing the \"buttons\" or the \"class\". Please check the documentation.`)\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Adding themeClass, layoutClass to keyboardDOM\r\n */\r\n this.keyboardDOM.className += ` ${this.options.theme} ${layoutClass} ${this.keyboardPluginClasses}`;\r\n\r\n /**\r\n * Iterating through each row\r\n */\r\n layout[this.options.layoutName].forEach((row, rIndex) => {\r\n let rowArray = row.split(' ');\r\n\r\n /**\r\n * Creating empty row\r\n */\r\n var rowDOM = document.createElement('div');\r\n rowDOM.className += \"hg-row\";\r\n\r\n /**\r\n * Iterating through each button in row\r\n */\r\n rowArray.forEach((button, bIndex) => {\r\n let fctBtnClass = this.utilities.getButtonClass(button);\r\n let buttonThemeClass = buttonThemesParsed[button];\r\n let buttonDisplayName = this.utilities.getButtonDisplayName(button, this.options.display, this.options.mergeDisplay);\r\n\r\n /**\r\n * Creating button\r\n */\r\n var buttonDOM = document.createElement('div');\r\n buttonDOM.className += `hg-button ${fctBtnClass}${buttonThemeClass ? \" \"+buttonThemeClass : \"\"}`;\r\n \r\n if (useTouchEvents) {\r\n buttonDOM.ontouchstart = (e) => {\r\n this.handleButtonClicked(button);\r\n this.handleButtonMouseDown(button, e);\r\n }\r\n buttonDOM.ontouchend = e => this.handleButtonMouseUp();\r\n buttonDOM.ontouchcancel = e => this.handleButtonMouseUp();\r\n } else {\r\n buttonDOM.onclick = () => {\r\n this.isMouseHold = false;\r\n this.handleButtonClicked(button);\r\n }\r\n buttonDOM.onmousedown = (e) => {\r\n if (this.options.preventMouseDownDefault) e.preventDefault();\r\n this.handleButtonMouseDown(button, e);\r\n }\r\n }\r\n \r\n /**\r\n * Adding identifier\r\n */\r\n buttonDOM.setAttribute(\"data-skBtn\", button);\r\n\r\n /**\r\n * Adding unique id\r\n * Since there's no limit on spawning same buttons, the unique id ensures you can style every button\r\n */\r\n let buttonUID = `${this.options.layoutName}-r${rIndex}b${bIndex}`;\r\n buttonDOM.setAttribute(\"data-skBtnUID\", buttonUID);\r\n\r\n /**\r\n * Adding display label\r\n */\r\n buttonDOM.setAttribute(\"data-displayLabel\", buttonDisplayName);\r\n\r\n /**\r\n * Adding button label to button\r\n */\r\n var buttonSpanDOM = document.createElement('span');\r\n buttonSpanDOM.innerHTML = buttonDisplayName;\r\n buttonDOM.appendChild(buttonSpanDOM);\r\n\r\n /**\r\n * Adding to buttonElements\r\n */\r\n if(!this.buttonElements[button])\r\n this.buttonElements[button] = [];\r\n\r\n this.buttonElements[button].push(buttonDOM);\r\n\r\n /**\r\n * Appending button to row\r\n */\r\n rowDOM.appendChild(buttonDOM);\r\n\r\n });\r\n\r\n /**\r\n * Appending row to keyboard\r\n */\r\n this.keyboardDOM.appendChild(rowDOM);\r\n });\r\n\r\n /**\r\n * Calling onRender\r\n */\r\n this.onRender();\r\n\r\n if(!this.initialized){\r\n /**\r\n * Ensures that onInit is only called once per instantiation\r\n */\r\n this.initialized = true;\r\n\r\n /**\r\n * Handling mouseup\r\n */\r\n if (!useTouchEvents) {\r\n document.onmouseup = () => this.handleButtonMouseUp();\r\n }\r\n\r\n /**\r\n * Calling onInit\r\n */\r\n this.onInit();\r\n }\r\n }\r\n}\r\n\r\nexport default SimpleKeyboard;\r\n",
"static": true,
"longname": "X:/Dev/simple-keyboard/src/lib/components/Keyboard.js",
"access": "public",
"description": null,
"lineNumber": 1
},
{
"__docId__": 59,
"kind": "class",
"name": "SimpleKeyboard",
"memberof": "src/lib/components/Keyboard.js",
"static": true,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard",
"access": "public",
"export": true,
"importPath": "simple-keyboard/src/lib/components/Keyboard.js",
"importStyle": "SimpleKeyboard",
"description": "Root class for simple-keyboard\nThis class:\n- Parses the options\n- Renders the rows and buttons\n- Handles button functionality",
"lineNumber": 15,
"interface": false
},
{
"__docId__": 60,
"kind": "constructor",
"name": "constructor",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#constructor",
"access": "public",
"description": "Creates an instance of SimpleKeyboard",
"lineNumber": 20,
"params": [
{
"nullable": null,
"types": [
"Array"
],
"spread": false,
"optional": false,
"name": "params",
"description": "If first parameter is a string, it is considered the container class. The second parameter is then considered the options object. If first parameter is an object, it is considered the options object."
}
]
},
{
"__docId__": 61,
"kind": "member",
"name": "utilities",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#utilities",
"access": "public",
"description": "Initializing Utilities",
"lineNumber": 30,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 62,
"kind": "member",
"name": "keyboardDOM",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#keyboardDOM",
"access": "public",
"description": "Processing options",
"lineNumber": 35,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 63,
"kind": "member",
"name": "options",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#options",
"access": "public",
"description": "",
"lineNumber": 62,
"properties": [
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "layout",
"description": "Modify the keyboard layout."
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "layoutName",
"description": "Specifies which layout should be used."
},
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "display",
"description": "Replaces variable buttons (such as {bksp}) with a human-friendly name (e.g.: “backspace”)."
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "mergeDisplay",
"description": "By default, when you set the display property, you replace the default one. This setting merges them instead."
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "theme",
"description": "A prop to add your own css classes to the keyboard wrapper. You can add multiple classes separated by a space."
},
{
"nullable": null,
"types": [
"Array"
],
"spread": false,
"optional": false,
"name": "buttonTheme",
"description": "A prop to add your own css classes to one or several buttons."
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "debug",
"description": "Runs a console.log every time a key is pressed. Displays the buttons pressed and the current input."
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "newLineOnEnter",
"description": "Specifies whether clicking the “ENTER” button will input a newline (\\n) or not."
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "tabCharOnTab",
"description": "Specifies whether clicking the “TAB” button will input a tab character (\\t) or not."
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "inputName",
"description": "Allows you to use a single simple-keyboard instance for several inputs."
},
{
"nullable": null,
"types": [
"number"
],
"spread": false,
"optional": false,
"name": "maxLength",
"description": "Restrains all of simple-keyboard inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute."
},
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "maxLength",
"description": "Restrains simple-keyboard’s individual inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute."
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "syncInstanceInputs",
"description": "When set to true, this option synchronizes the internal input of every simple-keyboard instance."
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "physicalKeyboardHighlight",
"description": "Enable highlighting of keys pressed on physical keyboard."
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "preventMouseDownDefault",
"description": "Calling preventDefault for the mousedown events keeps the focus on the input."
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "physicalKeyboardHighlightTextColor",
"description": "Define the text color that the physical keyboard highlighted key should have."
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "physicalKeyboardHighlightBgColor",
"description": "Define the background color that the physical keyboard highlighted key should have."
},
{
"nullable": null,
"types": [
"function(button: string):string"
],
"spread": false,
"optional": false,
"name": "onKeyPress",
"description": "Executes the callback function on key press. Returns button layout name (i.e.: “{shift}”)."
},
{
"nullable": null,
"types": [
"function(input: string):string"
],
"spread": false,
"optional": false,
"name": "onChange",
"description": "Executes the callback function on input change. Returns the current input’s string."
},
{
"nullable": null,
"types": [
"function"
],
"spread": false,
"optional": false,
"name": "onRender",
"description": "Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts)."
},
{
"nullable": null,
"types": [
"function"
],
"spread": false,
"optional": false,
"name": "onInit",
"description": "Executes the callback function once simple-keyboard is rendered for the first time (on initialization)."
},
{
"nullable": null,
"types": [
"function(inputs: object):object"
],
"spread": false,
"optional": false,
"name": "onChangeAll",
"description": "Executes the callback function on input change. Returns the input object with all defined inputs."
}
],
"type": {
"nullable": null,
"types": [
"object"
],
"spread": false,
"description": null
}
},
{
"__docId__": 64,
"kind": "member",
"name": "keyboardPluginClasses",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#keyboardPluginClasses",
"access": "public",
"description": "",
"lineNumber": 71,
"type": {
"nullable": null,
"types": [
"object"
],
"spread": false,
"description": null
}
},
{
"__docId__": 86,
"kind": "member",
"name": "input",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#input",
"access": "public",
"description": "simple-keyboard uses a non-persistent internal input to keep track of the entered string (the variable `keyboard.input`).\nThis removes any dependency to input DOM elements. You can type and directly display the value in a div element, for example.",
"examples": [
"// To get entered input\nlet input = keyboard.getInput();\n\n// To clear entered input.\nkeyboard.clearInput();"
],
"lineNumber": 112,
"properties": [
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "default",
"description": "Default SimpleKeyboard internal input."
},
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "myInputName",
"description": "Example input that can be set through `options.inputName:\"myInputName\"`."
}
],
"type": {
"nullable": null,
"types": [
"object"
],
"spread": false,
"description": null
}
},
{
"__docId__": 87,
"kind": "member",
"name": "keyboardDOMClass",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#keyboardDOMClass",
"access": "public",
"description": "",
"lineNumber": 118,
"type": {
"nullable": null,
"types": [
"string"
],
"spread": false,
"description": null
}
},
{
"__docId__": 88,
"kind": "member",
"name": "buttonElements",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#buttonElements",
"access": "public",
"description": "",
"lineNumber": 123,
"type": {
"nullable": null,
"types": [
"object"
],
"spread": false,
"description": null
}
},
{
"__docId__": 89,
"kind": "member",
"name": "physicalKeyboardInterface",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#physicalKeyboardInterface",
"access": "public",
"description": "Physical Keyboard support",
"lineNumber": 147,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 90,
"kind": "member",
"name": "modules",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#modules",
"access": "public",
"description": "Modules",
"lineNumber": 152,
"type": {
"types": [
"{}"
]
}
},
{
"__docId__": 91,
"kind": "method",
"name": "handleButtonClicked",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#handleButtonClicked",
"access": "public",
"description": "Handles clicks made to keyboard buttons",
"lineNumber": 160,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "button",
"description": "The button's layout name."
}
],
"return": {
"types": [
"boolean"
]
}
},
{
"__docId__": 92,
"kind": "method",
"name": "handleButtonMouseDown",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#handleButtonMouseDown",
"access": "public",
"description": "Handles button mousedown",
"lineNumber": 220,
"params": [
{
"name": "button",
"types": [
"*"
]
},
{
"name": "e",
"types": [
"*"
]
}
],
"return": null
},
{
"__docId__": 93,
"kind": "member",
"name": "isMouseHold",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#isMouseHold",
"access": "public",
"description": "",
"lineNumber": 224,
"type": {
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"description": null
}
},
{
"__docId__": 94,
"kind": "member",
"name": "holdTimeout",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#holdTimeout",
"access": "public",
"description": "",
"lineNumber": 235,
"type": {
"nullable": null,
"types": [
"object"
],
"spread": false,
"description": null
}
},
{
"__docId__": 95,
"kind": "method",
"name": "handleButtonMouseUp",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#handleButtonMouseUp",
"access": "public",
"description": "Handles button mouseup",
"lineNumber": 257,
"params": [],
"return": null
},
{
"__docId__": 97,
"kind": "method",
"name": "handleButtonHold",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#handleButtonHold",
"access": "public",
"description": "Handles button hold",
"lineNumber": 267,
"params": [
{
"name": "button",
"types": [
"*"
]
}
],
"return": null
},
{
"__docId__": 98,
"kind": "member",
"name": "holdInteractionTimeout",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#holdInteractionTimeout",
"access": "public",
"description": "",
"lineNumber": 274,
"type": {
"nullable": null,
"types": [
"object"
],
"spread": false,
"description": null
}
},
{
"__docId__": 99,
"kind": "method",
"name": "syncInstanceInputs",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#syncInstanceInputs",
"access": "public",
"description": "Send a command to all simple-keyboard instances (if you have several instances).",
"lineNumber": 287,
"params": [],
"return": null
},
{
"__docId__": 100,
"kind": "method",
"name": "clearInput",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#clearInput",
"access": "public",
"description": "Clear the keyboard’s input.",
"lineNumber": 297,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": true,
"name": "inputName",
"description": "optional - the internal input to select"
}
],
"return": null
},
{
"__docId__": 101,
"kind": "method",
"name": "getInput",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#getInput",
"access": "public",
"description": "Get the keyboard’s input (You can also get it from the onChange prop).",
"lineNumber": 312,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": true,
"name": "inputName",
"description": "optional - the internal input to select"
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 102,
"kind": "method",
"name": "setInput",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#setInput",
"access": "public",
"description": "Set the keyboard’s input.",
"lineNumber": 329,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "input",
"description": "the input value"
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "inputName",
"description": "optional - the internal input to select"
}
],
"return": null
},
{
"__docId__": 103,
"kind": "method",
"name": "replaceInput",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#replaceInput",
"access": "public",
"description": "Replace the input object (`keyboard.input`)",
"lineNumber": 344,
"params": [
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "inputObj",
"description": "The input object"
}
],
"return": null
},
{
"__docId__": 105,
"kind": "member",
"name": "setOptions",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#setOptions",
"access": "public",
"description": "Set new option or modify existing ones after initialization. ",
"lineNumber": 352,
"params": [
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "option",
"description": "The option to set"
}
],
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 107,
"kind": "method",
"name": "clear",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#clear",
"access": "public",
"description": "Remove all keyboard rows and reset keyboard values.\nUsed interally between re-renders.",
"lineNumber": 362,
"params": [],
"return": null
},
{
"__docId__": 109,
"kind": "method",
"name": "dispatch",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#dispatch",
"access": "public",
"description": "Send a command to all simple-keyboard instances at once (if you have multiple instances).",
"lineNumber": 372,
"params": [
{
"nullable": null,
"types": [
"function(instance: object, key: string)"
],
"spread": false,
"optional": false,
"name": "callback",
"description": "Function to run on every instance"
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 110,
"kind": "method",
"name": "addButtonTheme",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#addButtonTheme",
"access": "public",
"description": "Adds/Modifies an entry to the `buttonTheme`. Basically a way to add a class to a button.",
"lineNumber": 388,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "buttons",
"description": "List of buttons to select (separated by a space)."
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "className",
"description": "Classes to give to the selected buttons (separated by space)."
}
],
"return": {
"types": [
"boolean"
]
}
},
{
"__docId__": 111,
"kind": "method",
"name": "removeButtonTheme",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#removeButtonTheme",
"access": "public",
"description": "Removes/Amends an entry to the `buttonTheme`. Basically a way to remove a class previously added to a button through buttonTheme or addButtonTheme.",
"lineNumber": 438,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "buttons",
"description": "List of buttons to select (separated by a space)."
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "className",
"description": "Classes to give to the selected buttons (separated by space)."
}
],
"return": {
"types": [
"boolean"
]
}
},
{
"__docId__": 112,
"kind": "method",
"name": "getButtonElement",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#getButtonElement",
"access": "public",
"description": "Get the DOM Element of a button. If there are several buttons with the same name, an array of the DOM Elements is returned.",
"lineNumber": 490,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "button",
"description": "The button layout name to select"
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 113,
"kind": "method",
"name": "handleCaret",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#handleCaret",
"access": "public",
"description": "Retrieves the current cursor position within a input or textarea (if any)",
"lineNumber": 508,
"params": [],
"return": null
},
{
"__docId__": 114,
"kind": "member",
"name": "caretPosition",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#caretPosition",
"access": "public",
"description": "Only first instance should insall the caret handling events",
"lineNumber": 512,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 115,
"kind": "method",
"name": "caretEventHandler",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#caretEventHandler",
"access": "public",
"description": "Called by {@link handleCaret} when an event that warrants a cursor position update is triggered",
"lineNumber": 535,
"params": [
{
"name": "event",
"types": [
"*"
]
}
],
"return": null
},
{
"__docId__": 116,
"kind": "method",
"name": "onInit",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#onInit",
"access": "public",
"description": "Executes the callback function once simple-keyboard is rendered for the first time (on initialization).",
"lineNumber": 567,
"params": [],
"return": null
},
{
"__docId__": 117,
"kind": "method",
"name": "onRender",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#onRender",
"access": "public",
"description": "Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).",
"lineNumber": 584,
"params": [],
"return": null
},
{
"__docId__": 118,
"kind": "method",
"name": "onModulesLoaded",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#onModulesLoaded",
"access": "public",
"description": "Executes the callback function once all modules have been loaded",
"lineNumber": 592,
"params": [],
"return": null
},
{
"__docId__": 119,
"kind": "member",
"name": "registerModule",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#registerModule",
"access": "public",
"description": "Register module",
"lineNumber": 600,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 120,
"kind": "method",
"name": "loadModules",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#loadModules",
"access": "public",
"description": "Load modules",
"lineNumber": 610,
"params": [],
"return": null
},
{
"__docId__": 123,
"kind": "member",
"name": "getModuleProp",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#getModuleProp",
"access": "public",
"description": "Get module prop",
"lineNumber": 634,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 124,
"kind": "member",
"name": "getModulesList",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#getModulesList",
"access": "public",
"description": "getModulesList",
"lineNumber": 644,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 125,
"kind": "method",
"name": "render",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#render",
"access": "public",
"description": "Renders rows and buttons as per options",
"lineNumber": 651,
"params": [],
"return": null
},
{
"__docId__": 127,
"kind": "member",
"name": "initialized",
"memberof": "src/lib/components/Keyboard.js~SimpleKeyboard",
"static": false,
"longname": "src/lib/components/Keyboard.js~SimpleKeyboard#initialized",
"access": "public",
"description": "Ensures that onInit is only called once per instantiation",
"lineNumber": 798,
"type": {
"types": [
"boolean"
]
}
},
{
"__docId__": 128,
"kind": "file",
"name": "src/lib/index.js",
"content": "import SimpleKeyboard from './components/Keyboard';\r\nexport default SimpleKeyboard;\r\n",
"static": true,
"longname": "X:/Dev/simple-keyboard/src/lib/index.js",
"access": "public",
"description": null,
"lineNumber": 1
},
{
"__docId__": 129,
"kind": "file",
"name": "src/lib/services/KeyboardLayout.js",
"content": "/**\r\n * Keyboard Layout Service\r\n */\r\nclass KeyboardLayout {\r\n /**\r\n * Get default simple-keyboard layout\r\n * @return {object} The default layout (US-QWERTY)\r\n */\r\n static getDefaultLayout(){\r\n return {\r\n 'default': [\r\n '` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',\r\n '{tab} q w e r t y u i o p [ ] \\\\',\r\n '{lock} a s d f g h j k l ; \\' {enter}',\r\n '{shift} z x c v b n m , . / {shift}',\r\n '.com @ {space}'\r\n ],\r\n 'shift': [\r\n '~ ! @ # $ % ^ & * ( ) _ + {bksp}',\r\n '{tab} Q W E R T Y U I O P { } |',\r\n '{lock} A S D F G H J K L : \" {enter}',\r\n '{shift} Z X C V B N M < > ? {shift}',\r\n '.com @ {space}'\r\n ]\r\n } \r\n }\r\n}\r\n\r\nexport default KeyboardLayout;",
"static": true,
"longname": "X:/Dev/simple-keyboard/src/lib/services/KeyboardLayout.js",
"access": "public",
"description": null,
"lineNumber": 1
},
{
"__docId__": 130,
"kind": "class",
"name": "KeyboardLayout",
"memberof": "src/lib/services/KeyboardLayout.js",
"static": true,
"longname": "src/lib/services/KeyboardLayout.js~KeyboardLayout",
"access": "public",
"export": true,
"importPath": "simple-keyboard/src/lib/services/KeyboardLayout.js",
"importStyle": "KeyboardLayout",
"description": "Keyboard Layout Service",
"lineNumber": 4,
"interface": false
},
{
"__docId__": 131,
"kind": "method",
"name": "getDefaultLayout",
"memberof": "src/lib/services/KeyboardLayout.js~KeyboardLayout",
"generator": false,
"async": false,
"static": true,
"longname": "src/lib/services/KeyboardLayout.js~KeyboardLayout.getDefaultLayout",
"access": "public",
"description": "Get default simple-keyboard layout",
"lineNumber": 9,
"return": {
"nullable": null,
"types": [
"object"
],
"spread": false,
"description": "The default layout (US-QWERTY)"
},
"params": []
},
{
"__docId__": 132,
"kind": "file",
"name": "src/lib/services/PhysicalKeyboard.js",
"content": "/**\r\n * Physical Keyboard Service\r\n */\r\nclass PhysicalKeyboard {\r\n /**\r\n * Creates an instance of the PhysicalKeyboard service\r\n */\r\n constructor(simpleKeyboardInstance){\r\n /**\r\n * @type {object} A simple-keyboard instance\r\n */\r\n this.simpleKeyboardInstance = simpleKeyboardInstance;\r\n\r\n /**\r\n * Bindings\r\n */\r\n this.initKeyboardListener = this.initKeyboardListener.bind(this);\r\n this.getSimpleKeyboardLayoutKey = this.getSimpleKeyboardLayoutKey.bind(this);\r\n\r\n /**\r\n * Initialize key listeners\r\n */\r\n this.initKeyboardListener();\r\n }\r\n\r\n /**\r\n * Initializes key event listeners\r\n */\r\n initKeyboardListener(){\r\n // Adding button style on keydown\r\n document.addEventListener(\"keydown\", (event) => {\r\n if(this.simpleKeyboardInstance.options.physicalKeyboardHighlight){\r\n let buttonPressed = this.getSimpleKeyboardLayoutKey(event);\r\n\r\n this.simpleKeyboardInstance.dispatch(instance => {\r\n let buttonDOM = instance.getButtonElement(buttonPressed) || instance.getButtonElement(`{${buttonPressed}}`);\r\n\r\n if(buttonDOM){\r\n buttonDOM.style.backgroundColor = this.simpleKeyboardInstance.options.physicalKeyboardHighlightBgColor || \"#9ab4d0\";\r\n buttonDOM.style.color = this.simpleKeyboardInstance.options.physicalKeyboardHighlightTextColor || \"white\";\r\n }\r\n });\r\n }\r\n });\r\n\r\n // Removing button style on keyup\r\n document.addEventListener(\"keyup\", (event) => {\r\n if(this.simpleKeyboardInstance.options.physicalKeyboardHighlight){\r\n let buttonPressed = this.getSimpleKeyboardLayoutKey(event);\r\n\r\n this.simpleKeyboardInstance.dispatch(instance => {\r\n let buttonDOM = instance.getButtonElement(buttonPressed) || instance.getButtonElement(`{${buttonPressed}}`);\r\n\r\n if(buttonDOM && buttonDOM.removeAttribute){\r\n buttonDOM.removeAttribute(\"style\");\r\n }\r\n });\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Transforms a KeyboardEvent's \"key.code\" string into a simple-keyboard layout format\r\n * @param {object} event The KeyboardEvent\r\n */\r\n getSimpleKeyboardLayoutKey(event){\r\n let output;\r\n\r\n if(\r\n event.code.includes(\"Numpad\") ||\r\n event.code.includes(\"Shift\") ||\r\n event.code.includes(\"Space\") ||\r\n event.code.includes(\"Backspace\") ||\r\n event.code.includes(\"Control\") ||\r\n event.code.includes(\"Alt\") ||\r\n event.code.includes(\"Meta\")\r\n ){\r\n output = event.code;\r\n } else {\r\n output = event.key;\r\n }\r\n\r\n /**\r\n * If button is not uppercase, casting to lowercase\r\n */\r\n if (\r\n output !== output.toUpperCase() ||\r\n (event.code[0] === \"F\" && Number.isInteger(Number(event.code[1])) && event.code.length <= 3)\r\n ) {\r\n output = output.toLowerCase();\r\n }\r\n\r\n return output;\r\n }\r\n}\r\n\r\nexport default PhysicalKeyboard;",
"static": true,
"longname": "X:/Dev/simple-keyboard/src/lib/services/PhysicalKeyboard.js",
"access": "public",
"description": null,
"lineNumber": 1
},
{
"__docId__": 133,
"kind": "class",
"name": "PhysicalKeyboard",
"memberof": "src/lib/services/PhysicalKeyboard.js",
"static": true,
"longname": "src/lib/services/PhysicalKeyboard.js~PhysicalKeyboard",
"access": "public",
"export": true,
"importPath": "simple-keyboard/src/lib/services/PhysicalKeyboard.js",
"importStyle": "PhysicalKeyboard",
"description": "Physical Keyboard Service",
"lineNumber": 4,
"interface": false
},
{
"__docId__": 134,
"kind": "constructor",
"name": "constructor",
"memberof": "src/lib/services/PhysicalKeyboard.js~PhysicalKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/PhysicalKeyboard.js~PhysicalKeyboard#constructor",
"access": "public",
"description": "Creates an instance of the PhysicalKeyboard service",
"lineNumber": 8
},
{
"__docId__": 135,
"kind": "member",
"name": "simpleKeyboardInstance",
"memberof": "src/lib/services/PhysicalKeyboard.js~PhysicalKeyboard",
"static": false,
"longname": "src/lib/services/PhysicalKeyboard.js~PhysicalKeyboard#simpleKeyboardInstance",
"access": "public",
"description": "",
"lineNumber": 12,
"type": {
"nullable": null,
"types": [
"object"
],
"spread": false,
"description": null
}
},
{
"__docId__": 138,
"kind": "method",
"name": "initKeyboardListener",
"memberof": "src/lib/services/PhysicalKeyboard.js~PhysicalKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/PhysicalKeyboard.js~PhysicalKeyboard#initKeyboardListener",
"access": "public",
"description": "Initializes key event listeners",
"lineNumber": 29,
"params": [],
"return": null
},
{
"__docId__": 139,
"kind": "method",
"name": "getSimpleKeyboardLayoutKey",
"memberof": "src/lib/services/PhysicalKeyboard.js~PhysicalKeyboard",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/PhysicalKeyboard.js~PhysicalKeyboard#getSimpleKeyboardLayoutKey",
"access": "public",
"description": "Transforms a KeyboardEvent's \"key.code\" string into a simple-keyboard layout format",
"lineNumber": 66,
"params": [
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "event",
"description": "The KeyboardEvent"
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 140,
"kind": "file",
"name": "src/lib/services/Utilities.js",
"content": "/**\r\n * Utility Service\r\n */\r\nclass Utilities {\r\n /**\r\n * Creates an instance of the Utility service\r\n */\r\n constructor(simpleKeyboardInstance){\r\n /**\r\n * @type {object} A simple-keyboard instance\r\n */\r\n this.simpleKeyboardInstance = simpleKeyboardInstance;\r\n\r\n /**\r\n * Bindings\r\n */\r\n this.getButtonClass = this.getButtonClass.bind(this);\r\n this.getButtonDisplayName = this.getButtonDisplayName.bind(this);\r\n this.getUpdatedInput = this.getUpdatedInput.bind(this);\r\n this.updateCaretPos = this.updateCaretPos.bind(this);\r\n this.updateCaretPosAction = this.updateCaretPosAction.bind(this);\r\n this.isMaxLengthReached = this.isMaxLengthReached.bind(this);\r\n this.camelCase = this.camelCase.bind(this);\r\n this.countInArray = this.countInArray.bind(this);\r\n }\r\n\r\n /**\r\n * Adds default classes to a given button\r\n * \r\n * @param {string} button The button's layout name\r\n * @return {string} The classes to be added to the button\r\n */\r\n getButtonClass(button){\r\n let buttonTypeClass = (button.includes(\"{\") && button.includes(\"}\") && button !== '{//}') ? \"functionBtn\" : \"standardBtn\";\r\n let buttonWithoutBraces = button.replace(\"{\", \"\").replace(\"}\", \"\");\r\n let buttonNormalized = '';\r\n\r\n if(buttonTypeClass !== \"standardBtn\")\r\n buttonNormalized = ` hg-button-${buttonWithoutBraces}`;\r\n\r\n return `hg-${buttonTypeClass}${buttonNormalized}`;\r\n }\r\n\r\n /**\r\n * Default button display labels\r\n */\r\n getDefaultDiplay(){\r\n return {\r\n '{bksp}': 'backspace',\r\n '{backspace}': 'backspace',\r\n '{enter}': '< enter',\r\n '{shift}': 'shift',\r\n '{shiftleft}': 'shift',\r\n '{shiftright}': 'shift',\r\n '{alt}': 'alt',\r\n '{s}': 'shift',\r\n '{tab}': 'tab',\r\n '{lock}': 'caps',\r\n '{capslock}': 'caps',\r\n '{accept}': 'Submit',\r\n '{space}': ' ',\r\n '{//}': ' ',\r\n \"{esc}\": \"esc\",\r\n \"{escape}\": \"esc\",\r\n \"{f1}\": \"f1\",\r\n \"{f2}\": \"f2\",\r\n \"{f3}\": \"f3\",\r\n \"{f4}\": \"f4\",\r\n \"{f5}\": \"f5\",\r\n \"{f6}\": \"f6\",\r\n \"{f7}\": \"f7\",\r\n \"{f8}\": \"f8\",\r\n \"{f9}\": \"f9\",\r\n \"{f10}\": \"f10\",\r\n \"{f11}\": \"f11\",\r\n \"{f12}\": \"f12\",\r\n '{numpaddivide}': '/',\r\n '{numlock}': 'lock',\r\n \"{arrowup}\": \"↑\",\r\n \"{arrowleft}\": \"←\",\r\n \"{arrowdown}\": \"↓\",\r\n \"{arrowright}\": \"→\",\r\n \"{prtscr}\": \"print\",\r\n \"{scrolllock}\": \"scroll\",\r\n \"{pause}\": \"pause\",\r\n \"{insert}\": \"ins\",\r\n \"{home}\": \"home\",\r\n \"{pageup}\": \"up\",\r\n \"{delete}\": \"del\",\r\n \"{end}\": \"end\",\r\n \"{pagedown}\": \"down\",\r\n \"{numpadmultiply}\": \"*\",\r\n \"{numpadsubtract}\": \"-\",\r\n \"{numpadadd}\": \"+\",\r\n \"{numpadenter}\": \"enter\",\r\n \"{period}\": \".\",\r\n \"{numpaddecimal}\": \".\",\r\n \"{numpad0}\": \"0\",\r\n \"{numpad1}\": \"1\",\r\n \"{numpad2}\": \"2\",\r\n \"{numpad3}\": \"3\",\r\n \"{numpad4}\": \"4\",\r\n \"{numpad5}\": \"5\",\r\n \"{numpad6}\": \"6\",\r\n \"{numpad7}\": \"7\",\r\n \"{numpad8}\": \"8\",\r\n \"{numpad9}\": \"9\",\r\n };\r\n }\r\n /**\r\n * Returns the display (label) name for a given button\r\n * \r\n * @param {string} button The button's layout name\r\n * @param {object} display The provided display option\r\n * @param {boolean} mergeDisplay Whether the provided param value should be merged with the default one.\r\n */\r\n getButtonDisplayName(button, display, mergeDisplay){\r\n if(mergeDisplay){\r\n display = Object.assign({}, this.getDefaultDiplay(), display);\r\n } else {\r\n display = display || this.getDefaultDiplay();\r\n }\r\n\r\n return display[button] || button;\r\n }\r\n\r\n \r\n /**\r\n * Returns the updated input resulting from clicking a given button\r\n * \r\n * @param {string} button The button's layout name\r\n * @param {string} input The input string\r\n * @param {object} options The simple-keyboard options object\r\n * @param {number} caretPos The cursor's current position\r\n * @param {boolean} moveCaret Whether to update simple-keyboard's cursor\r\n */\r\n getUpdatedInput(button, input, options, caretPos, moveCaret){\r\n \r\n let output = input;\r\n\r\n if((button === \"{bksp}\" || button === \"{backspace}\") && output.length > 0){\r\n output = this.removeAt(output, caretPos, moveCaret);\r\n\r\n } else if(button === \"{space}\")\r\n output = this.addStringAt(output, \" \", caretPos, moveCaret);\r\n\r\n else if(button === \"{tab}\" && !(typeof options.tabCharOnTab === \"boolean\" && options.tabCharOnTab === false)){\r\n output = this.addStringAt(output, \"\\t\", caretPos, moveCaret);\r\n\r\n } else if((button === \"{enter}\" || button === \"{numpadenter}\") && options.newLineOnEnter)\r\n output = this.addStringAt(output, \"\\n\", caretPos, moveCaret);\r\n\r\n else if(button.includes(\"numpad\") && Number.isInteger(Number(button[button.length - 2]))){\r\n output = this.addStringAt(output, button[button.length - 2], caretPos);\r\n }\r\n else if(button === \"{numpaddivide}\")\r\n output = this.addStringAt(output, '/', caretPos, moveCaret);\r\n\r\n else if(button === \"{numpadmultiply}\")\r\n output = this.addStringAt(output, '*', caretPos, moveCaret);\r\n\r\n else if(button === \"{numpadsubtract}\")\r\n output = this.addStringAt(output, '-', caretPos, moveCaret);\r\n\r\n else if(button === \"{numpadadd}\")\r\n output = this.addStringAt(output, '+', caretPos, moveCaret);\r\n\r\n else if(button === \"{numpaddecimal}\")\r\n output = this.addStringAt(output, '.', caretPos, moveCaret);\r\n\r\n else if(button === \"{\" || button === \"}\")\r\n output = this.addStringAt(output, button, caretPos, moveCaret);\r\n\r\n else if(!button.includes(\"{\") && !button.includes(\"}\"))\r\n output = this.addStringAt(output, button, caretPos, moveCaret);\r\n\r\n return output;\r\n }\r\n\r\n /**\r\n * Moves the cursor position by a given amount\r\n * \r\n * @param {number} length Represents by how many characters the input should be moved\r\n * @param {boolean} minus Whether the cursor should be moved to the left or not.\r\n */\r\n updateCaretPos(length, minus){\r\n if(this.simpleKeyboardInstance.options.syncInstanceInputs){\r\n this.simpleKeyboardInstance.dispatch(instance => {\r\n this.updateCaretPosAction(instance, length, minus);\r\n });\r\n } else {\r\n this.updateCaretPosAction(this.simpleKeyboardInstance, length, minus);\r\n }\r\n }\r\n\r\n /**\r\n * Action method of updateCaretPos\r\n * \r\n * @param {object} instance The instance whose position should be updated\r\n * @param {number} length Represents by how many characters the input should be moved\r\n * @param {boolean} minus Whether the cursor should be moved to the left or not.\r\n */\r\n updateCaretPosAction(instance, length, minus){\r\n if(minus){\r\n if(instance.caretPosition > 0)\r\n instance.caretPosition = instance.caretPosition - length;\r\n } else {\r\n instance.caretPosition = instance.caretPosition + length;\r\n }\r\n\r\n if(this.simpleKeyboardInstance.options.debug){\r\n console.log(\"Caret at:\", instance.caretPosition, `(${instance.keyboardDOMClass})`);\r\n }\r\n }\r\n\r\n /**\r\n * Adds a string to the input at a given position\r\n * \r\n * @param {string} source The source input\r\n * @param {string} string The string to add\r\n * @param {number} position The (cursor) position where the string should be added\r\n * @param {boolean} moveCaret Whether to update simple-keyboard's cursor\r\n */\r\n addStringAt(source, string, position, moveCaret){\r\n let output;\r\n\r\n if(!position && position !== 0){\r\n output = source + string;\r\n } else {\r\n output = [source.slice(0, position), string, source.slice(position)].join('');\r\n\r\n /**\r\n * Avoid caret position change when maxLength is set\r\n */\r\n if(!this.isMaxLengthReached()){\r\n if(moveCaret) this.updateCaretPos(string.length);\r\n }\r\n\r\n }\r\n\r\n return output;\r\n }\r\n\r\n /**\r\n * Removes an amount of characters at a given position\r\n * \r\n * @param {string} source The source input\r\n * @param {number} position The (cursor) position from where the characters should be removed\r\n * @param {boolean} moveCaret Whether to update simple-keyboard's cursor\r\n */\r\n removeAt(source, position, moveCaret){\r\n if(this.simpleKeyboardInstance.caretPosition === 0){\r\n return source;\r\n }\r\n\r\n let output;\r\n let prevTwoChars;\r\n let emojiMatched;\r\n let emojiMatchedReg = /([\\uD800-\\uDBFF][\\uDC00-\\uDFFF])/g;\r\n\r\n /**\r\n * Emojis are made out of two characters, so we must take a custom approach to trim them.\r\n * For more info: https://mathiasbynens.be/notes/javascript-unicode\r\n */\r\n if(position && position >= 0){\r\n prevTwoChars = source.substring(position - 2, position)\r\n emojiMatched = prevTwoChars.match(emojiMatchedReg);\r\n\r\n if(emojiMatched){\r\n output = source.substr(0, (position - 2)) + source.substr(position);\r\n if(moveCaret) this.updateCaretPos(2, true);\r\n } else {\r\n output = source.substr(0, (position - 1)) + source.substr(position);\r\n if(moveCaret) this.updateCaretPos(1, true);\r\n }\r\n } else {\r\n prevTwoChars = source.slice(-2);\r\n emojiMatched = prevTwoChars.match(emojiMatchedReg);\r\n\r\n if(emojiMatched){\r\n output = source.slice(0, -2);\r\n if(moveCaret) this.updateCaretPos(2, true);\r\n } else {\r\n output = source.slice(0, -1);\r\n if(moveCaret) this.updateCaretPos(1, true);\r\n }\r\n }\r\n\r\n return output;\r\n }\r\n /**\r\n * Determines whether the maxLength has been reached. This function is called when the maxLength option it set.\r\n * \r\n * @param {object} inputObj\r\n * @param {object} options\r\n * @param {string} updatedInput\r\n */\r\n handleMaxLength(inputObj, options, updatedInput){\r\n let maxLength = options.maxLength;\r\n let currentInput = inputObj[options.inputName];\r\n let condition = currentInput.length === maxLength;\r\n\r\n if(\r\n /**\r\n * If pressing this button won't add more characters\r\n * We exit out of this limiter function\r\n */\r\n updatedInput.length <= currentInput.length\r\n ){\r\n return false;\r\n }\r\n\r\n if(Number.isInteger(maxLength)){\r\n if(options.debug){\r\n console.log(\"maxLength (num) reached:\", condition);\r\n }\r\n\r\n if(condition){\r\n /**\r\n * @type {boolean} Boolean value that shows whether maxLength has been reached\r\n */\r\n this.maxLengthReached = true;\r\n return true;\r\n } else {\r\n this.maxLengthReached = false;\r\n return false;\r\n }\r\n }\r\n\r\n if(typeof maxLength === \"object\"){\r\n let condition = currentInput.length === maxLength[options.inputName];\r\n\r\n if(options.debug){\r\n console.log(\"maxLength (obj) reached:\", condition);\r\n }\r\n\r\n if(condition){\r\n this.maxLengthReached = true;\r\n return true;\r\n } else {\r\n this.maxLengthReached = false;\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current value of maxLengthReached\r\n */\r\n isMaxLengthReached(){\r\n return Boolean(this.maxLengthReached);\r\n }\r\n\r\n /**\r\n * Transforms an arbitrary string to camelCase\r\n * \r\n * @param {string} string The string to transform.\r\n */\r\n camelCase(string){\r\n return string.toLowerCase().trim().split(/[.\\-_\\s]/g).reduce((string, word) => string + word[0].toUpperCase() + word.slice(1));\r\n };\r\n\r\n /**\r\n * Counts the number of duplicates in a given array\r\n * \r\n * @param {Array} array The haystack to search in\r\n * @param {string} value The needle to search for\r\n */\r\n countInArray(array, value){\r\n return array.reduce((n, x) => n + (x === value), 0);\r\n }\r\n}\r\n\r\nexport default Utilities;",
"static": true,
"longname": "X:/Dev/simple-keyboard/src/lib/services/Utilities.js",
"access": "public",
"description": null,
"lineNumber": 1
},
{
"__docId__": 141,
"kind": "class",
"name": "Utilities",
"memberof": "src/lib/services/Utilities.js",
"static": true,
"longname": "src/lib/services/Utilities.js~Utilities",
"access": "public",
"export": true,
"importPath": "simple-keyboard/src/lib/services/Utilities.js",
"importStyle": "Utilities",
"description": "Utility Service",
"lineNumber": 4,
"interface": false
},
{
"__docId__": 142,
"kind": "constructor",
"name": "constructor",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#constructor",
"access": "public",
"description": "Creates an instance of the Utility service",
"lineNumber": 8
},
{
"__docId__": 143,
"kind": "member",
"name": "simpleKeyboardInstance",
"memberof": "src/lib/services/Utilities.js~Utilities",
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#simpleKeyboardInstance",
"access": "public",
"description": "",
"lineNumber": 12,
"type": {
"nullable": null,
"types": [
"object"
],
"spread": false,
"description": null
}
},
{
"__docId__": 152,
"kind": "method",
"name": "getButtonClass",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#getButtonClass",
"access": "public",
"description": "Adds default classes to a given button",
"lineNumber": 33,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "button",
"description": "The button's layout name"
}
],
"return": {
"nullable": null,
"types": [
"string"
],
"spread": false,
"description": "The classes to be added to the button"
}
},
{
"__docId__": 153,
"kind": "method",
"name": "getDefaultDiplay",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#getDefaultDiplay",
"access": "public",
"description": "Default button display labels",
"lineNumber": 47,
"params": [],
"return": {
"types": [
"{\"{bksp}\": string, \"{backspace}\": string, \"{enter}\": string, \"{shift}\": string, \"{shiftleft}\": string, \"{shiftright}\": string, \"{alt}\": string, \"{s}\": string, \"{tab}\": string, \"{lock}\": string, \"{capslock}\": string, \"{accept}\": string, \"{space}\": string, \"{//}\": string, \"{esc}\": string, \"{escape}\": string, \"{f1}\": string, \"{f2}\": string, \"{f3}\": string, \"{f4}\": string, \"{f5}\": string, \"{f6}\": string, \"{f7}\": string, \"{f8}\": string, \"{f9}\": string, \"{f10}\": string, \"{f11}\": string, \"{f12}\": string, \"{numpaddivide}\": string, \"{numlock}\": string, \"{arrowup}\": string, \"{arrowleft}\": string, \"{arrowdown}\": string, \"{arrowright}\": string, \"{prtscr}\": string, \"{scrolllock}\": string, \"{pause}\": string, \"{insert}\": string, \"{home}\": string, \"{pageup}\": string, \"{delete}\": string, \"{end}\": string, \"{pagedown}\": string, \"{numpadmultiply}\": string, \"{numpadsubtract}\": string, \"{numpadadd}\": string, \"{numpadenter}\": string, \"{period}\": string, \"{numpaddecimal}\": string, \"{numpad0}\": string, \"{numpad1}\": string, \"{numpad2}\": string, \"{numpad3}\": string, \"{numpad4}\": string, \"{numpad5}\": string, \"{numpad6}\": string, \"{numpad7}\": string, \"{numpad8}\": string, \"{numpad9}\": string}"
]
}
},
{
"__docId__": 154,
"kind": "method",
"name": "getButtonDisplayName",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#getButtonDisplayName",
"access": "public",
"description": "Returns the display (label) name for a given button",
"lineNumber": 117,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "button",
"description": "The button's layout name"
},
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "display",
"description": "The provided display option"
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "mergeDisplay",
"description": "Whether the provided param value should be merged with the default one."
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 155,
"kind": "method",
"name": "getUpdatedInput",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#getUpdatedInput",
"access": "public",
"description": "Returns the updated input resulting from clicking a given button",
"lineNumber": 137,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "button",
"description": "The button's layout name"
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "input",
"description": "The input string"
},
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "options",
"description": "The simple-keyboard options object"
},
{
"nullable": null,
"types": [
"number"
],
"spread": false,
"optional": false,
"name": "caretPos",
"description": "The cursor's current position"
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "moveCaret",
"description": "Whether to update simple-keyboard's cursor"
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 156,
"kind": "method",
"name": "updateCaretPos",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#updateCaretPos",
"access": "public",
"description": "Moves the cursor position by a given amount",
"lineNumber": 186,
"params": [
{
"nullable": null,
"types": [
"number"
],
"spread": false,
"optional": false,
"name": "length",
"description": "Represents by how many characters the input should be moved"
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "minus",
"description": "Whether the cursor should be moved to the left or not."
}
],
"return": null
},
{
"__docId__": 157,
"kind": "method",
"name": "updateCaretPosAction",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#updateCaretPosAction",
"access": "public",
"description": "Action method of updateCaretPos",
"lineNumber": 203,
"params": [
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "instance",
"description": "The instance whose position should be updated"
},
{
"nullable": null,
"types": [
"number"
],
"spread": false,
"optional": false,
"name": "length",
"description": "Represents by how many characters the input should be moved"
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "minus",
"description": "Whether the cursor should be moved to the left or not."
}
],
"return": null
},
{
"__docId__": 158,
"kind": "method",
"name": "addStringAt",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#addStringAt",
"access": "public",
"description": "Adds a string to the input at a given position",
"lineNumber": 224,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "source",
"description": "The source input"
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "string",
"description": "The string to add"
},
{
"nullable": null,
"types": [
"number"
],
"spread": false,
"optional": false,
"name": "position",
"description": "The (cursor) position where the string should be added"
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "moveCaret",
"description": "Whether to update simple-keyboard's cursor"
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 159,
"kind": "method",
"name": "removeAt",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#removeAt",
"access": "public",
"description": "Removes an amount of characters at a given position",
"lineNumber": 251,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "source",
"description": "The source input"
},
{
"nullable": null,
"types": [
"number"
],
"spread": false,
"optional": false,
"name": "position",
"description": "The (cursor) position from where the characters should be removed"
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "moveCaret",
"description": "Whether to update simple-keyboard's cursor"
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 160,
"kind": "method",
"name": "handleMaxLength",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#handleMaxLength",
"access": "public",
"description": "Determines whether the maxLength has been reached. This function is called when the maxLength option it set.",
"lineNumber": 298,
"params": [
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "inputObj",
"description": ""
},
{
"nullable": null,
"types": [
"object"
],
"spread": false,
"optional": false,
"name": "options",
"description": ""
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "updatedInput",
"description": ""
}
],
"return": {
"types": [
"boolean"
]
}
},
{
"__docId__": 161,
"kind": "member",
"name": "maxLengthReached",
"memberof": "src/lib/services/Utilities.js~Utilities",
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#maxLengthReached",
"access": "public",
"description": "",
"lineNumber": 322,
"type": {
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"description": null
}
},
{
"__docId__": 165,
"kind": "method",
"name": "isMaxLengthReached",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#isMaxLengthReached",
"access": "public",
"description": "Gets the current value of maxLengthReached",
"lineNumber": 350,
"params": [],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 166,
"kind": "method",
"name": "camelCase",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#camelCase",
"access": "public",
"description": "Transforms an arbitrary string to camelCase",
"lineNumber": 359,
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "string",
"description": "The string to transform."
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 167,
"kind": "method",
"name": "countInArray",
"memberof": "src/lib/services/Utilities.js~Utilities",
"generator": false,
"async": false,
"static": false,
"longname": "src/lib/services/Utilities.js~Utilities#countInArray",
"access": "public",
"description": "Counts the number of duplicates in a given array",
"lineNumber": 369,
"params": [
{
"nullable": null,
"types": [
"Array"
],
"spread": false,
"optional": false,
"name": "array",
"description": "The haystack to search in"
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "value",
"description": "The needle to search for"
}
],
"return": {
"types": [
"*"
]
}
},
{
"__docId__": 168,
"kind": "file",
"name": "src/lib/tests/TestUtility.js",
"content": "/**\r\n * Test Utility Functions\r\n */\r\nexport default class TestUtility {\r\n /**\r\n * Set's a basic DOM structure to test in\r\n */\r\n setDOM = (divClass) => {\r\n this.clear();\r\n const div = document.createElement('div');\r\n div.className += divClass || \"simple-keyboard\";\r\n document.body.appendChild(div);\r\n }\r\n\r\n /**\r\n * Clears DOM structure\r\n */\r\n clear = () => {\r\n document.body.innerHTML = \"\";\r\n }\r\n\r\n /**\r\n * Test if standard buttons respect maxLength and do input a value\r\n */\r\n testLayoutStdButtons = (keyboard) => {\r\n let stdBtnCount = 0;\r\n let fullInput = '';\r\n\r\n this.iterateButtons((button) => {\r\n let label = button.getAttribute(\"data-skbtn\");\r\n\r\n if(label.includes(\"{\"))\r\n return false;\r\n\r\n // Click all standard buttons, respects maxLength\r\n button.onclick();\r\n\r\n // Recording fullInput, bypasses maxLength\r\n fullInput = keyboard.utilities.getUpdatedInput(label, fullInput, keyboard.options, null);\r\n\r\n stdBtnCount += label.length;\r\n });\r\n\r\n /**\r\n * Check if maxLength is respected\r\n */\r\n if(\r\n (\r\n typeof keyboard.options.maxLength === \"object\" &&\r\n keyboard.getInput().length !== keyboard.options.maxLength[keyboard.options.layoutName]\r\n ) ||\r\n (\r\n typeof keyboard.options.maxLength !== \"object\" &&\r\n keyboard.getInput().length !== keyboard.options.maxLength\r\n )\r\n )\r\n throw new Error(\"MAX_LENGTH_ISSUE\");\r\n else\r\n console.log(\"MAX_LENGTH PASSED:\", keyboard.options.layoutName, keyboard.getInput().length, keyboard.options.maxLength);\r\n\r\n /**\r\n * Check if all standard buttons are inputting something\r\n * (Regardless of maxLength)\r\n */\r\n if(stdBtnCount !== fullInput.length)\r\n throw new Error(\"STANDARD_BUTTONS_ISSUE\");\r\n else\r\n console.log(\"STANDARD_BUTTONS PASSED:\", keyboard.options.layoutName, stdBtnCount, fullInput.length);\r\n }\r\n\r\n /**\r\n * Test if function buttons are interactive (have an onclick)\r\n */\r\n testLayoutFctButtons = (callback) => {\r\n let fctBtnCount = 0;\r\n let fctBtnHasOnclickCount = 0;\r\n\r\n this.iterateButtons((button) => {\r\n let label = button.getAttribute(\"data-skbtn\");\r\n\r\n if(!label.includes(\"{\") && !label.includes(\"}\"))\r\n return false;\r\n\r\n fctBtnCount++;\r\n\r\n if(button.onclick){\r\n button.onclick();\r\n fctBtnHasOnclickCount++;\r\n }\r\n\r\n callback(fctBtnCount, fctBtnHasOnclickCount);\r\n });\r\n }\r\n\r\n /**\r\n * Iterates on the keyboard buttons\r\n */\r\n iterateButtons = (callback, selector) => {\r\n let rows = document.body.querySelector(selector || '.simple-keyboard').children;\r\n\r\n Array.from(rows).forEach(row => {\r\n Array.from(row.children).forEach((button) => {\r\n callback(button);\r\n });\r\n });\r\n }\r\n}",
"static": true,
"longname": "X:/Dev/simple-keyboard/src/lib/tests/TestUtility.js",
"access": "public",
"description": null,
"lineNumber": 1
},
{
"__docId__": 169,
"kind": "class",
"name": "TestUtility",
"memberof": "src/lib/tests/TestUtility.js",
"static": true,
"longname": "src/lib/tests/TestUtility.js~TestUtility",
"access": "public",
"export": true,
"importPath": "simple-keyboard/src/lib/tests/TestUtility.js",
"importStyle": "TestUtility",
"description": "Test Utility Functions",
"lineNumber": 4,
"interface": false
},
{
"__docId__": 170,
"kind": "member",
"name": "setDOM",
"memberof": "src/lib/tests/TestUtility.js~TestUtility",
"static": false,
"longname": "src/lib/tests/TestUtility.js~TestUtility#setDOM",
"access": "public",
"description": "Set's a basic DOM structure to test in",
"lineNumber": 8,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 171,
"kind": "member",
"name": "clear",
"memberof": "src/lib/tests/TestUtility.js~TestUtility",
"static": false,
"longname": "src/lib/tests/TestUtility.js~TestUtility#clear",
"access": "public",
"description": "Clears DOM structure",
"lineNumber": 18,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 172,
"kind": "member",
"name": "testLayoutStdButtons",
"memberof": "src/lib/tests/TestUtility.js~TestUtility",
"static": false,
"longname": "src/lib/tests/TestUtility.js~TestUtility#testLayoutStdButtons",
"access": "public",
"description": "Test if standard buttons respect maxLength and do input a value",
"lineNumber": 25,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 173,
"kind": "member",
"name": "testLayoutFctButtons",
"memberof": "src/lib/tests/TestUtility.js~TestUtility",
"static": false,
"longname": "src/lib/tests/TestUtility.js~TestUtility#testLayoutFctButtons",
"access": "public",
"description": "Test if function buttons are interactive (have an onclick)",
"lineNumber": 74,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 174,
"kind": "member",
"name": "iterateButtons",
"memberof": "src/lib/tests/TestUtility.js~TestUtility",
"static": false,
"longname": "src/lib/tests/TestUtility.js~TestUtility#iterateButtons",
"access": "public",
"description": "Iterates on the keyboard buttons",
"lineNumber": 98,
"type": {
"types": [
"*"
]
}
},
{
"kind": "index",
"content": "\r\n
\r\n
\r\n
The easily customisable and responsive on-screen virtual keyboard for Javascript projects.
\r\n
\r\n \r\n \r\n \r\n \r\n
\r\n
\r\n\r\n## 📦 Installation & Usage\r\nYou can use simple-keyboard as a `