Added methods beforeRender, beforeFirstRender

This commit is contained in:
Francisco Hodge 2019-03-06 19:33:28 -05:00
parent c007f7406a
commit 18a3aa9dd5

View File

@ -703,6 +703,27 @@ class SimpleKeyboard {
if (typeof this.options.onInit === "function") this.options.onInit();
}
/**
* Executes the callback function before a simple-keyboard render.
*/
beforeFirstRender(){
/**
* Performing actions when touch device detected
*/
if(this.utilities.isTouchDevice()){
this.onTouchDeviceDetected();
}
if (typeof this.options.beforeFirstRender === "function") this.options.beforeFirstRender();
}
/**
* Executes the callback function before a simple-keyboard render.
*/
beforeRender(){
if (typeof this.options.beforeRender === "function") this.options.beforeRender();
}
/**
* Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
*/
@ -780,6 +801,18 @@ class SimpleKeyboard {
*/
this.clear();
/**
* Calling beforeFirstRender
*/
if(!this.initialized){
this.beforeFirstRender();
}
/**
* Calling beforeRender
*/
this.beforeRender();
let layoutClass = `hg-layout-${this.options.layoutName}`;
let layout = this.options.layout || KeyboardLayout.getDefaultLayout();
let useTouchEvents = this.options.useTouchEvents || false;
@ -896,7 +929,7 @@ class SimpleKeyboard {
if (!this.initialized) {
/**
* Ensures that onInit is only called once per instantiation
* Ensures that onInit and beforeFirstRender are only called once per instantiation
*/
this.initialized = true;