Docs update

This commit is contained in:
Francisco Hodge
2018-10-30 23:33:29 -04:00
parent 288fcf3507
commit e7284b0e38
16 changed files with 136331 additions and 113895 deletions
+67 -16
View File
@@ -105,6 +105,31 @@ class SimpleKeyboard {
this.options.theme = this.options.theme || "hg-theme-default";
this.options.inputName = this.options.inputName || "default";
/**
* Module namespace
*/
this.modules = {};
/**
* Bindings
*/
this.handleButtonClicked = this.handleButtonClicked.bind(this);
this.syncInstanceInputs = this.syncInstanceInputs.bind(this);
this.clearInput = this.clearInput.bind(this);
this.getInput = this.getInput.bind(this);
this.setInput = this.setInput.bind(this);
this.replaceInput = this.replaceInput.bind(this);
this.clear = this.clear.bind(this);
this.dispatch = this.dispatch.bind(this);
this.addButtonTheme = this.addButtonTheme.bind(this);
this.removeButtonTheme = this.removeButtonTheme.bind(this);
this.getButtonElement = this.getButtonElement.bind(this);
this.handleCaret = this.handleCaret.bind(this);
this.caretEventHandler = this.caretEventHandler.bind(this);
this.onInit = this.onInit.bind(this);
this.onRender = this.onRender.bind(this);
this.render = this.render.bind(this);
/**
* simple-keyboard uses a non-persistent internal input to keep track of the entered string (the variable `keyboard.input`).
* This removes any dependency to input DOM elements. You can type and directly display the value in a div element, for example.
@@ -160,7 +185,7 @@ class SimpleKeyboard {
* Handles clicks made to keyboard buttons
* @param {string} button The button's layout name.
*/
handleButtonClicked = (button) => {
handleButtonClicked(button){
let debug = this.options.debug;
/**
@@ -215,7 +240,7 @@ class SimpleKeyboard {
/**
* Send a command to all simple-keyboard instances (if you have several instances).
*/
syncInstanceInputs = () => {
syncInstanceInputs(){
this.dispatch((instance) => {
instance.replaceInput(this.input);
});
@@ -225,7 +250,7 @@ class SimpleKeyboard {
* Clear the keyboard’s input.
* @param {string} [inputName] optional - the internal input to select
*/
clearInput = (inputName) => {
clearInput(inputName){
inputName = inputName || this.options.inputName;
this.input[this.options.inputName] = '';
@@ -240,7 +265,7 @@ class SimpleKeyboard {
* Get the keyboard’s input (You can also get it from the onChange prop).
* @param {string} [inputName] optional - the internal input to select
*/
getInput = (inputName) => {
getInput(inputName){
inputName = inputName || this.options.inputName;
/**
@@ -257,7 +282,7 @@ class SimpleKeyboard {
* @param {string} input the input value
* @param {string} inputName optional - the internal input to select
*/
setInput = (input, inputName) => {
setInput(input, inputName){
inputName = inputName || this.options.inputName;
this.input[inputName] = input;
@@ -272,7 +297,7 @@ class SimpleKeyboard {
* Replace the input object (`keyboard.input`)
* @param {object} inputObj The input object
*/
replaceInput = (inputObj) => {
replaceInput(inputObj){
this.input = inputObj;
}
@@ -290,7 +315,7 @@ class SimpleKeyboard {
* Remove all keyboard rows and reset keyboard values.
* Used interally between re-renders.
*/
clear = () => {
clear(){
this.keyboardDOM.innerHTML = '';
this.keyboardDOM.className = this.keyboardDOMClass;
this.buttonElements = {};
@@ -300,7 +325,7 @@ class SimpleKeyboard {
* Send a command to all simple-keyboard instances at once (if you have multiple instances).
* @param {function(instance: object, key: string)} callback Function to run on every instance
*/
dispatch = (callback) => {
dispatch(callback){
if(!window['SimpleKeyboardInstances']){
console.warn(`SimpleKeyboardInstances is not defined. Dispatch cannot be called.`);
throw new Error("INSTANCES_VAR_ERROR");
@@ -316,7 +341,7 @@ class SimpleKeyboard {
* @param {string} buttons List of buttons to select (separated by a space).
* @param {string} className Classes to give to the selected buttons (separated by space).
*/
addButtonTheme = (buttons, className) => {
addButtonTheme(buttons, className){
if(!className || !buttons)
return false;
@@ -366,7 +391,7 @@ class SimpleKeyboard {
* @param {string} buttons List of buttons to select (separated by a space).
* @param {string} className Classes to give to the selected buttons (separated by space).
*/
removeButtonTheme = (buttons, className) => {
removeButtonTheme(buttons, className){
/**
* When called with empty parameters, remove all button themes
*/
@@ -418,7 +443,7 @@ class SimpleKeyboard {
* Get the DOM Element of a button. If there are several buttons with the same name, an array of the DOM Elements is returned.
* @param {string} button The button layout name to select
*/
getButtonElement = (button) => {
getButtonElement(button){
let output;
let buttonArr = this.buttonElements[button];
@@ -436,7 +461,7 @@ class SimpleKeyboard {
/**
* Retrieves the current cursor position within a input or textarea (if any)
*/
handleCaret = () => {
handleCaret(){
if(this.options.debug){
console.log("Caret handling started");
}
@@ -449,7 +474,7 @@ class SimpleKeyboard {
/**
* Called by {@link handleCaret} when an event that warrants a cursor position update is triggered
*/
caretEventHandler = (event) => {
caretEventHandler(event){
let targetTagName = event.target.tagName.toLowerCase();
if(
@@ -471,7 +496,7 @@ class SimpleKeyboard {
/**
* Executes the callback function once simple-keyboard is rendered for the first time (on initialization).
*/
onInit = () => {
onInit(){
if(this.options.debug){
console.log("Initialized");
}
@@ -488,15 +513,41 @@ class SimpleKeyboard {
/**
* Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
*/
onRender = () => {
onRender(){
if(typeof this.options.onRender === "function")
this.options.onRender();
}
/**
* Register module
*/
registerModule = (name, initCallback) => {
this.modules[name] = {};
initCallback(this.modules[name]);
}
/**
* Get module prop
*/
getModuleProp = (name, prop) => {
if(!this.modules[name])
return false;
return this.modules[name][prop];
}
/**
* getModulesList
*/
getModulesList = () => {
return Object.keys(this.modules);
}
/**
* Renders rows and buttons as per options
*/
render = () => {
render(){
/**
* Clear keyboard
*/
@@ -44,12 +44,11 @@
* Keyboard Layout Service
*/
class KeyboardLayout {
/**
* Get default simple-keyboard layout
* @return {object} The default layout (US-QWERTY)
*/
static getDefaultLayout = () => {
static getDefaultLayout(){
return {
'default': [
'` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
@@ -53,13 +53,22 @@ class PhysicalKeyboard {
*/
this.simpleKeyboardInstance = simpleKeyboardInstance;
/**
* Bindings
*/
this.initKeyboardListener = this.initKeyboardListener.bind(this);
this.getSimpleKeyboardLayoutKey = this.getSimpleKeyboardLayoutKey.bind(this);
/**
* Initialize key listeners
*/
this.initKeyboardListener();
}
/**
* Initializes key event listeners
*/
initKeyboardListener = () => {
initKeyboardListener(){
// Adding button style on keydown
document.addEventListener("keydown", (event) => {
if(this.simpleKeyboardInstance.options.physicalKeyboardHighlight){
@@ -96,7 +105,7 @@ class PhysicalKeyboard {
* Transforms a KeyboardEvent's "key.code" string into a simple-keyboard layout format
* @param {object} event The KeyboardEvent
*/
getSimpleKeyboardLayoutKey = (event) => {
getSimpleKeyboardLayoutKey(event){
let output;
if(
+18 -7
View File
@@ -52,6 +52,17 @@ class Utilities {
* @type {object} A simple-keyboard instance
*/
this.simpleKeyboardInstance = simpleKeyboardInstance;
/**
* Bindings
*/
this.getButtonClass = this.getButtonClass.bind(this);
this.getButtonDisplayName = this.getButtonDisplayName.bind(this);
this.getUpdatedInput = this.getUpdatedInput.bind(this);
this.updateCaretPos = this.updateCaretPos.bind(this);
this.isMaxLengthReached = this.isMaxLengthReached.bind(this);
this.camelCase = this.camelCase.bind(this);
this.countInArray = this.countInArray.bind(this);
}
/**
@@ -60,7 +71,7 @@ class Utilities {
* @param {string} button The button's layout name
* @return {string} The classes to be added to the button
*/
getButtonClass = button => {
getButtonClass(button){
let buttonTypeClass = (button.includes("{") && button.includes("}") && button !== '{//}') ? "functionBtn" : "standardBtn";
let buttonWithoutBraces = button.replace("{", "").replace("}", "");
let buttonNormalized = '';
@@ -144,7 +155,7 @@ class Utilities {
* @param {object} display The provided display option
* @param {boolean} mergeDisplay Whether the provided param value should be merged with the default one.
*/
getButtonDisplayName = (button, display, mergeDisplay) => {
getButtonDisplayName(button, display, mergeDisplay){
if(mergeDisplay){
display = Object.assign({}, this.getDefaultDiplay(), display);
} else {
@@ -163,7 +174,7 @@ class Utilities {
* @param {object} options The simple-keyboard options object
* @param {number} caretPos The cursor's current position
*/
getUpdatedInput = (button, input, options, caretPos) => {
getUpdatedInput(button, input, options, caretPos){
let output = input;
@@ -210,7 +221,7 @@ class Utilities {
* @param {number} length Represents by how many characters the input should be moved
* @param {boolean} minus Whether the cursor should be moved to the left or not.
*/
updateCaretPos = (length, minus) => {
updateCaretPos(length, minus){
if(minus){
if(this.simpleKeyboardInstance.caretPosition > 0)
this.simpleKeyboardInstance.caretPosition = this.simpleKeyboardInstance.caretPosition - length
@@ -356,7 +367,7 @@ class Utilities {
/**
* Gets the current value of maxLengthReached
*/
isMaxLengthReached = () => {
isMaxLengthReached(){
return Boolean(this.maxLengthReached);
}
@@ -365,7 +376,7 @@ class Utilities {
*
* @param {string} string The string to transform.
*/
camelCase = (string) => {
camelCase(string){
return string.toLowerCase().trim().split(/[.\-_\s]/g).reduce((string, word) => string + word[0].toUpperCase() + word.slice(1));
};
@@ -375,7 +386,7 @@ class Utilities {
* @param {Array} array The haystack to search in
* @param {string} value The needle to search for
*/
countInArray = (array, value) => {
countInArray(array, value){
return array.reduce((n, x) => n + (x === value), 0);
}