fix(web): publish restorePosition() function

This makes the `osk.restorePosition()` function public and makes it work
even if the OSK is not presently visible. Also DRY out the repeated
implementation.
This commit is contained in:
Marc Durdin 2021-04-22 06:57:02 +10:00
parent ec9a68cd24
commit ffdf71f6ed

View file

@ -354,6 +354,7 @@ namespace com.keyman.osk {
* Create a control bar with title and buttons for the desktop OSK
*/
controlBar(): HTMLDivElement {
// TODO: merge with _TitleBarInterior?
let keymanweb = com.keyman.singleton;
let util = keymanweb.util;
@ -413,20 +414,7 @@ namespace com.keyman.osk {
Limg.id='kmw-pin-image';
Limg.className='kmw-title-bar-image';
Limg.title='Pin the On Screen Keyboard to its default location on the active text box';
Limg.onclick=function(this: OSKManager) {
this.loadCookie();
this.userPositioned=false;
this.saveCookie();
this._Show();
this.doResizeMove(); //allow the UI to respond to OSK movements
if(this.pinImg) {
this.pinImg.style.display='none';
}
if(window.event) {
window.event.returnValue=false;
}
return false;
}.bind(this);
Limg.onclick=this.restorePosition;
Limg.onmousedown=util._CancelMouse;
bar.appendChild(Limg);
@ -482,17 +470,25 @@ namespace com.keyman.osk {
}
/**
* Move OSK back to default position
* Function restorePosition
* Scope Public
* Description Move OSK back to default position, floating under active input element
*/
restorePosition: () => void = function(this: OSKManager) {
if(this._Visible) {
let isVisible = this._Visible;
if(isVisible) {
com.keyman.singleton.domManager.focusLastActiveElement(); // I2036 - OSK does not unpin to correct location
this.loadCookie();
this.userPositioned=false;
this.saveCookie();
this._Show();
this.doResizeMove(); //allow the UI to respond to OSK movements
}
this.loadCookie();
this.userPositioned=false;
this.saveCookie();
if(isVisible) {
this._Show();
}
this.doResizeMove(); //allow the UI to respond to OSK movements
if(this.pinImg) {
this.pinImg.style.display='none';
}