diff --git a/src/lib/components/Keyboard.js b/src/lib/components/Keyboard.js index eb648420..a34916a6 100644 --- a/src/lib/components/Keyboard.js +++ b/src/lib/components/Keyboard.js @@ -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;