mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-25 07:17:41 +00:00
Merge pull request #16591 from keymanapp/refactor/web/cleanup
refactor(web): update function comments and cleanup - modernize function comments - modernize function signatures - rename variables and arguments
This commit is contained in:
commit
5ea3326d4b
4 changed files with 53 additions and 52 deletions
|
|
@ -423,7 +423,7 @@ export class ContextManager extends ContextManagerBase<BrowserConfiguration> {
|
|||
*/
|
||||
public setKeyboardForTextStore(textStore: AbstractElementTextStore<any>, kbdId?: string | null, langId?: string | null): void {
|
||||
if(textStore instanceof DesignIFrameElementTextStore) {
|
||||
console.warn("'keymanweb.setKeyboardForControl' cannot set keyboard on iframes.");
|
||||
console.warn("ContextManager.setKeyboardForTextStore cannot set keyboard on iframes.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,28 +77,28 @@ export class KeymanEngine extends KeymanEngineBase<BrowserConfiguration, Context
|
|||
|
||||
// Scrolls the document-body to ensure that a focused element remains visible after the OSK appears.
|
||||
this.contextManager.on('textstorechange', (textStore) => {
|
||||
const e = (textStore as AbstractElementTextStore<any>)?.getElement();
|
||||
const elem = (textStore as AbstractElementTextStore<any>)?.getElement();
|
||||
if(this.osk) {
|
||||
(this.osk.activationModel as TwoStateActivator<HTMLElement>).activationTrigger = e;
|
||||
(this.osk.activationModel as TwoStateActivator<HTMLElement>).activationTrigger = elem;
|
||||
}
|
||||
|
||||
if(this.config.hostDevice.touchable && textStore) {
|
||||
this.ensureElementVisibility(e);
|
||||
this.ensureElementVisibility(elem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ensureElementVisibility(e: HTMLElement): void {
|
||||
if(!e || !this.osk) {
|
||||
public ensureElementVisibility(elem: HTMLElement): void {
|
||||
if(!elem || !this.osk) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the absolute position of the caret
|
||||
const y = getAbsoluteY(e);
|
||||
const y = getAbsoluteY(elem);
|
||||
const t = window.pageYOffset;
|
||||
let dy = y-t;
|
||||
if(y >= t) {
|
||||
dy -= (window.innerHeight - this.osk._Box.offsetHeight - e.offsetHeight - 2);
|
||||
dy -= (window.innerHeight - this.osk._Box.offsetHeight - elem.offsetHeight - 2);
|
||||
if(dy < 0) {
|
||||
dy=0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,42 @@
|
|||
/**
|
||||
* Checks the type of an input DOM-related object while ensuring that it is checked against the correct prototype,
|
||||
* as class prototypes are (by specification) scoped upon the owning Window.
|
||||
* Checks the type of an input DOM-related object while ensuring that it
|
||||
* is checked against the correct prototype, as class prototypes are (by
|
||||
* specification) scoped upon the owning Window.
|
||||
*
|
||||
* See https://stackoverflow.com/questions/43587286/why-does-instanceof-return-false-on-chrome-safari-and-edge-and-true-on-firefox
|
||||
* See
|
||||
* https://stackoverflow.com/questions/43587286/why-does-instanceof-return-false-on-chrome-safari-and-edge-and-true-on-firefox
|
||||
* for more details.
|
||||
*
|
||||
* @param {EventTarget} Pelem An element of the web page or one of its IFrame-based subdocuments.
|
||||
* @param {string} className The plain-text name of the expected Element type.
|
||||
* @param {EventTarget} elem An element of the web page or one of
|
||||
* its IFrame-based subdocuments.
|
||||
* @param {string} className The plain-text name of the expected
|
||||
* Element type.
|
||||
* @return {boolean}
|
||||
*/
|
||||
export function nestedInstanceOf(Pelem: EventTarget, className: string): boolean {
|
||||
export function nestedInstanceOf(elem: EventTarget, className: string): boolean {
|
||||
let scopedClass;
|
||||
|
||||
if(!Pelem) {
|
||||
if(!elem) {
|
||||
// If we're bothering to check something's type, null references don't match
|
||||
// what we're looking for.
|
||||
return false;
|
||||
}
|
||||
// @ts-ignore
|
||||
if (Pelem['Window']) { // Window objects contain the class definitions for types held within them. So, we can check for those.
|
||||
if (elem['Window']) { // Window objects contain the class definitions for types held within them. So, we can check for those.
|
||||
return className == 'Window';
|
||||
// @ts-ignore
|
||||
} else if (Pelem['defaultView']) { // Covers Document.
|
||||
} else if (elem['defaultView']) { // Covers Document.
|
||||
// @ts-ignore
|
||||
scopedClass = (Pelem as Document)['defaultView'][className];
|
||||
scopedClass = (elem as Document)['defaultView'][className];
|
||||
// @ts-ignore
|
||||
} else if(Pelem['ownerDocument']) {
|
||||
} else if(elem['ownerDocument']) {
|
||||
// @ts-ignore
|
||||
scopedClass = (Pelem as Node).ownerDocument.defaultView[className];
|
||||
scopedClass = (elem as Node).ownerDocument.defaultView[className];
|
||||
}
|
||||
|
||||
if(scopedClass) {
|
||||
return Pelem instanceof scopedClass;
|
||||
return elem instanceof scopedClass;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,23 +183,22 @@ export class FloatingOSKView extends OSKView {
|
|||
}.bind(this);
|
||||
|
||||
/**
|
||||
* Function enabled
|
||||
* Scope Public
|
||||
* @return {boolean|number} True if KMW OSK enabled
|
||||
* Description Test if KMW OSK is enabled
|
||||
* Test if KMW OSK is enabled
|
||||
*
|
||||
* @return {boolean} True if KMW OSK enabled
|
||||
*/
|
||||
['isEnabled'](): boolean {
|
||||
public isEnabled(): boolean {
|
||||
return this.displayIfActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function isVisible
|
||||
* Scope Public
|
||||
* @return {boolean|number} True if KMW OSK visible
|
||||
* Description Test if KMW OSK is actually visible
|
||||
* Note that this will usually return false after any UI event that results in (temporary) loss of input focus
|
||||
* Test if KMW OSK is actually visible
|
||||
* Note that this will usually return false after any UI event that results in
|
||||
* (temporary) loss of input focus.
|
||||
*
|
||||
* @return {boolean} True if KMW OSK visible
|
||||
*/
|
||||
['isVisible'](): boolean {
|
||||
public isVisible(): boolean {
|
||||
return this._Visible;
|
||||
}
|
||||
|
||||
|
|
@ -504,30 +503,30 @@ export class FloatingOSKView extends OSKView {
|
|||
}
|
||||
|
||||
public setDisplayPositioning() {
|
||||
const Ls = this._Box.style;
|
||||
const {style} = this._Box;
|
||||
|
||||
Ls.position='absolute';
|
||||
style.position='absolute';
|
||||
// Keep it hidden if not currently displayed.
|
||||
if(this.activationModel.activate) {
|
||||
Ls.display='block'; //Ls.visibility='visible';
|
||||
style.display='block'; //Ls.visibility='visible';
|
||||
}
|
||||
Ls.left='0px';
|
||||
style.left='0px';
|
||||
if(this.specifiedPosition || this.userPositioned) {
|
||||
Ls.left = this.x+'px';
|
||||
Ls.top = this.y+'px';
|
||||
style.left = this.x+'px';
|
||||
style.top = this.y+'px';
|
||||
} else {
|
||||
const el: HTMLElement = this.typedActivationModel.activationTrigger || null;
|
||||
|
||||
if(this.dfltX) {
|
||||
Ls.left=this.dfltX;
|
||||
style.left=this.dfltX;
|
||||
} else if(typeof el != 'undefined' && el != null) {
|
||||
Ls.left=getAbsoluteX(el) + 'px';
|
||||
style.left=getAbsoluteX(el) + 'px';
|
||||
}
|
||||
|
||||
if(this.dfltY) {
|
||||
Ls.top=this.dfltY;
|
||||
style.top=this.dfltY;
|
||||
} else if(typeof el != 'undefined' && el != null) {
|
||||
Ls.top=(getAbsoluteY(el) + el.offsetHeight)+'px';
|
||||
style.top=(getAbsoluteY(el) + el.offsetHeight)+'px';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -584,24 +583,22 @@ export class FloatingOSKView extends OSKView {
|
|||
}
|
||||
}
|
||||
|
||||
['show'](bShow?: boolean) {
|
||||
public show(bShow?: boolean) {
|
||||
if(bShow !== undefined) {
|
||||
super['show'](bShow);
|
||||
super.show(bShow);
|
||||
} else {
|
||||
super['show']();
|
||||
super.show();
|
||||
}
|
||||
this.savePersistedLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function userPositioned
|
||||
* Scope Public
|
||||
* @return {(boolean|number)} true if user located
|
||||
* Description Test if OSK window has been repositioned by user
|
||||
*
|
||||
* Test if OSK window has been repositioned by user
|
||||
* See https://help.keyman.com/developer/engine/web/current-version/reference/osk/userLocated
|
||||
*
|
||||
* @return {boolean} true if user located
|
||||
*/
|
||||
public userLocated() {
|
||||
public userLocated(): boolean {
|
||||
return this.userPositioned;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue