diff --git a/web/src/app/browser/src/beepHandler.ts b/web/src/app/browser/src/beepHandler.ts index eb6d6583ee..6e23c09464 100644 --- a/web/src/app/browser/src/beepHandler.ts +++ b/web/src/app/browser/src/beepHandler.ts @@ -38,7 +38,7 @@ export class BeepHandler { } // All code after this point is DOM-based, triggered by the beep. - var Pelem: HTMLElement = outputTarget.getElement(); + let Pelem: HTMLElement = outputTarget.getElement(); if(outputTarget instanceof DesignIFrame) { Pelem = outputTarget.docRoot; // I1446 - beep sometimes fails to flash when using OSK and rich control } @@ -51,7 +51,7 @@ export class BeepHandler { return; } - for(var Lbo=0; Lbo { this.keyboardInterface.resetContextCache(); - var Lbo; + let Lbo; this._BeepTimeout = 0; for(Lbo=0;Lbo { - let target = this.currentTarget || this.mostRecentTarget; + const target = this.currentTarget || this.mostRecentTarget; if(this.isTargetKeyboardIndependent(target)) { return target; @@ -378,7 +378,7 @@ export default class ContextManager extends ContextManagerBase): boolean { - let attachmentInfo = target?.getElement()._kmwAttachment; + const attachmentInfo = target?.getElement()._kmwAttachment; // If null or undefined, we're in 'global' mode. return !!(attachmentInfo?.keyboard || attachmentInfo?.keyboard === ''); @@ -386,7 +386,7 @@ export default class ContextManager extends ContextManagerBase) { - let attachment = target?.getElement()._kmwAttachment; + const attachment = target?.getElement()._kmwAttachment; if(!attachment) { // if not set with an "independent keyboard", changes the global. @@ -425,7 +425,7 @@ export default class ContextManager extends ContextManagerBase): boolean { const focusAssistant = this.focusAssistant; - let activeKeyboard = this.activeKeyboard?.keyboard; + const activeKeyboard = this.activeKeyboard?.keyboard; if(!focusAssistant.restoringFocus) { outputTarget?.deadkeys().clear(); activeKeyboard?.notify(0, outputTarget, 1); // I2187 @@ -684,7 +684,7 @@ export default class ContextManager extends ContextManagerBase) { if(target.changed) { - let event = new Event('change', {"bubbles": true, "cancelable": false}); + const event = new Event('change', {"bubbles": true, "cancelable": false}); target.getElement().dispatchEvent(event); } @@ -756,7 +756,7 @@ export default class ContextManager extends ContextManagerBase('KeymanWeb_Keyboard'); - var v = cookie.load(decodeURIComponent); + const v = cookie.load(decodeURIComponent); if(typeof(v.current) != 'string') { return null; @@ -776,7 +776,7 @@ export default class ContextManager extends ContextManagerBase { const contextManager = this.contextManager; diff --git a/web/src/app/browser/src/hardwareEventKeyboard.ts b/web/src/app/browser/src/hardwareEventKeyboard.ts index 5e8b30ce4f..1710834368 100644 --- a/web/src/app/browser/src/hardwareEventKeyboard.ts +++ b/web/src/app/browser/src/hardwareEventKeyboard.ts @@ -59,10 +59,11 @@ export function preprocessKeyboardEvent(e: KeyboardEvent, keyboardState: Keyboar } // Stage 1 - track the true state of the keyboard's modifiers. - var prevModState = keyboardState.modStateFlags, curModState = 0x0000; - var ctrlEvent = false, altEvent = false; + const prevModState = keyboardState.modStateFlags; + let curModState = 0x0000; + let ctrlEvent = false, altEvent = false; - let keyCodes = Codes.keyCodes; + const keyCodes = Codes.keyCodes; switch(Lcode) { case keyCodes['K_CTRL']: // The 3 shorter "K_*CTRL" entries exist in some legacy keyboards. case keyCodes['K_LCTRL']: @@ -129,7 +130,7 @@ export function preprocessKeyboardEvent(e: KeyboardEvent, keyboardState: Keyboar keyboardState.modStateFlags = curModState; // For European keyboards, not all browsers properly send both key-up events for the AltGr combo. - let altGrMask = ModifierKeyConstants.RALTFLAG | ModifierKeyConstants.LCTRLFLAG; + const altGrMask = ModifierKeyConstants.RALTFLAG | ModifierKeyConstants.LCTRLFLAG; if((prevModState & altGrMask) == altGrMask && (curModState & altGrMask) != altGrMask) { // We just released AltGr - make sure it's all released. curModState &= ~ altGrMask; @@ -139,7 +140,7 @@ export function preprocessKeyboardEvent(e: KeyboardEvent, keyboardState: Keyboar curModState &= ~ModifierKeyConstants.LCTRLFLAG; } - let modifierBitmasks = Codes.modifierBitmasks; + const modifierBitmasks = Codes.modifierBitmasks; // Stage 4 - map the modifier set to the appropriate keystroke's modifiers. const activeKeyboard = keyboardState.activeKeyboard; let Lmodifiers: number; @@ -192,12 +193,12 @@ export function preprocessKeyboardEvent(e: KeyboardEvent, keyboardState: Keyboar }); // The 0x6F used to be 0x60 - this adjustment now includes the chiral alt and ctrl modifiers in that check. - let LisVirtualKeyCode = (typeof e.charCode != 'undefined' && e.charCode != null && (e.charCode == 0 || (Lmodifiers & 0x6F) != 0)); + const LisVirtualKeyCode = (typeof e.charCode != 'undefined' && e.charCode != null && (e.charCode == 0 || (Lmodifiers & 0x6F) != 0)); s.LisVirtualKey = LisVirtualKeyCode || e.type != 'keypress'; s = processForMnemonicsAndLegacy(s, activeKeyboard, keyboardState.baseLayout); - let processedEvent = new KeyEvent(s); + const processedEvent = new KeyEvent(s); processedEvent.source = e; return processedEvent; } @@ -304,17 +305,17 @@ export default class HardwareEventKeyboard extends HardKeyboard { */ _KeyUp: (e: KeyboardEvent) => boolean = (e) => { const target = eventOutputTarget(e); - var Levent = preprocessKeyboardEvent(e, this.processor, this.hardDevice); + const Levent = preprocessKeyboardEvent(e, this.processor, this.hardDevice); if(Levent == null || target == null) { return true; } - var inputEle = target.getElement(); + const inputEle = target.getElement(); // Since this part concerns DOM element + browser interaction management, we preprocess it for // browser form commands before passing control to the Processor module. if(Levent.Lcode == 13) { - var ignore = false; + let ignore = false; if(nestedInstanceOf(inputEle, "HTMLTextAreaElement")) { ignore = true; } @@ -349,12 +350,12 @@ export default class HardwareEventKeyboard extends HardKeyboard { this.swallowKeypress = false; // Get event properties - var Levent = preprocessKeyboardEvent(e, this.processor, this.hardDevice); + const Levent = preprocessKeyboardEvent(e, this.processor, this.hardDevice); if(Levent == null) { return true; } - let resultCapture: { LeventMatched: boolean } = { + const resultCapture: { LeventMatched: boolean } = { LeventMatched: false } @@ -385,17 +386,17 @@ export default class HardwareEventKeyboard extends HardKeyboard { // 1) To detect browser form submissions (handled in kmwdomevents.ts) // 2) To detect modifier state changes. private keyUp(e: KeyboardEvent): boolean { - var Levent = preprocessKeyboardEvent(e, this.processor, this.hardDevice); + const Levent = preprocessKeyboardEvent(e, this.processor, this.hardDevice); if(Levent == null) { return true; } - let outputTarget = eventOutputTarget(e); + const outputTarget = eventOutputTarget(e); return this.processor.doModifierPress(Levent, outputTarget, false); } private keyPress(e: KeyboardEvent): boolean { - var Levent = preprocessKeyboardEvent(e, this.processor, this.hardDevice); + const Levent = preprocessKeyboardEvent(e, this.processor, this.hardDevice); if(Levent == null || Levent.LisVirtualKey) { return true; } @@ -417,7 +418,7 @@ export default class HardwareEventKeyboard extends HardKeyboard { // Only reached if it's a mnemonic keyboard. - let resultCapture: { preventDefaultKeystroke?: boolean } = {}; + const resultCapture: { preventDefaultKeystroke?: boolean } = {}; // Should only be run if `preventDefaultKeystroke` is required by the following conditional // block. If it isn't - that is, swallowKeypress == true, we want to swallow that keypress diff --git a/web/src/app/browser/src/hotkeyManager.ts b/web/src/app/browser/src/hotkeyManager.ts index 11da2aea3b..f0dbe8b3bb 100644 --- a/web/src/app/browser/src/hotkeyManager.ts +++ b/web/src/app/browser/src/hotkeyManager.ts @@ -29,7 +29,7 @@ export class HotkeyManager { */ addHotKey(keyCode: number, shiftState: number, handler: () => void) { // Test if existing handler for this code and replace it if so - for(var i=0; i) { - let deviceDetector = new DeviceDetector(); - let device = deviceDetector.detect(); + const deviceDetector = new DeviceDetector(); + const device = deviceDetector.detect(); const totalOptions = {...BrowserInitOptionDefaults, ...options}; @@ -397,7 +397,7 @@ export default class KeymanEngine extends KeymanEngineBase /* [b/c Toolbar UI]*/) { let kbd: Keyboard; if(k0) { - let kbdDetail = k0 as ReturnType; + const kbdDetail = k0 as ReturnType; if(kbdDetail.KeyboardID){ kbd = this.keyboardRequisitioner.cache.getKeyboard(kbdDetail.KeyboardID); } else { @@ -682,7 +682,7 @@ export default class KeymanEngine extends KeymanEngineBase { @@ -55,8 +55,8 @@ export class LanguageMenu { // Display build only if touching menu, space *and* one other point on screen (build 369) if(e.touches.length > 2) { - var sX=e.touches[1].pageX,sY=e.touches[1].pageY; - let spaceBar = osk.vkbd.spaceBar; + const sX=e.touches[1].pageX,sY=e.touches[1].pageY; + const spaceBar = osk.vkbd.spaceBar; if(sX > spaceBar.offsetLeft && sX < spaceBar.offsetLeft+spaceBar.offsetWidth && sY > spaceBar.offsetTop && sY < spaceBar.offsetTop+spaceBar.offsetHeight ) { @@ -73,26 +73,26 @@ export class LanguageMenu { **/ show() { const device = this.keyman.config.hostDevice; - let kbdList=this.keyman.keyboardRequisitioner.cache.getStubList(); - let nKbds=kbdList.length; + const kbdList=this.keyman.keyboardRequisitioner.cache.getStubList(); + const nKbds=kbdList.length; if(nKbds < 1) { return; } // Create the menu list container element - var menu=this.lgList=util._CreateElement('div'); + const menu=this.lgList=util._CreateElement('div'); this.lgList.id='kmw-language-menu'; // Insert a transparent overlay to prevent anything else happening during keyboard selection, // but allow the menu to be closed if anywhere else on screen is touched - let languageMenu = this; + const languageMenu = this; document.body.appendChild(this.shim); // Add two nested DIVs to properly support iOS scrolling with momentum // c.f. https://github.com/joelambert/ScrollFix/issues/2 - var m2=util._CreateElement('div'),s2=m2.style, + const m2=util._CreateElement('div'),s2=m2.style, m3=util._CreateElement('div'); m2.id='kmw-menu-scroll-container'; m3.id='kmw-menu-scroller'; @@ -105,7 +105,8 @@ export class LanguageMenu { menu.appendChild(m2); // Add menu index strip - let x,mx=util._CreateElement('div'); + let x: HTMLParagraphElement; + const mx=util._CreateElement('div'); mx.id='kmw-menu-index'; for(let i=1; i<=26; i++) { x=util._CreateElement('p'); @@ -154,7 +155,7 @@ export class LanguageMenu { // Adjust width for pixel scaling on Android tablets if(device.OS == 'android' && device.formFactor == 'tablet' && 'devicePixelRatio' in window) { - var w=parseInt(util.getStyleValue(menu,'width'),10), + let w=parseInt(util.getStyleValue(menu,'width'),10), ms=menu.style; if(!isNaN(w)) { ms.width=ms.maxWidth=(2*w/window.devicePixelRatio)+'px'; @@ -175,17 +176,17 @@ export class LanguageMenu { this.adjust(0); // Adjust the index font size and line height - var dy=(mx.childNodes[1]).offsetTop-(mx.childNodes[0]).offsetTop, - lineHeight=Math.floor(menu.offsetHeight/26.0), - scale=Math.round(100.0*lineHeight/dy)/100.0, - factor=(scale > 0.6 ? 1 : 2); + const dy=(mx.childNodes[1]).offsetTop-(mx.childNodes[0]).offsetTop; + const lineHeight=Math.floor(menu.offsetHeight/26.0); + let scale=Math.round(100.0*lineHeight/dy)/100.0; + const factor=(scale > 0.6 ? 1 : 2); if(scale > 1.25) { scale=1.25; } for(let i=0;i<26;i++) { - var qs=(mx.childNodes[i]).style; + const qs=(mx.childNodes[i]).style; if(factor == 2 && (i%2) == 1) { qs.display='none'; } else { @@ -195,7 +196,7 @@ export class LanguageMenu { } // Increase width of outer menu DIV by index, else hide index - var menuWidth=m2.offsetWidth; + let menuWidth=m2.offsetWidth; if(m2.scrollHeight > m2.offsetHeight+3) { menuWidth = menuWidth+mx.offsetWidth; } else { @@ -216,15 +217,16 @@ export class LanguageMenu { * @param {number} nKbds number of displayed keyboards to add to number of languages **/ adjust(nKbds: number) { - let osk = this.keyman.osk; - let device = this.keyman.config.hostDevice; + const osk = this.keyman.osk; + const device = this.keyman.config.hostDevice; - var menu=this.lgList, m2=menu.firstChild, m3=m2.firstChild, - barWidth=0,s=menu.style,mx=menu.childNodes[1], - maxHeight=window.innerHeight-osk.vkbd.lgKey.offsetHeight-16, + const menu=this.lgList, m2=menu.firstChild, m3=m2.firstChild; + let barWidth=0; + let maxHeight=window.innerHeight-osk.vkbd.lgKey.offsetHeight-16; + const s=menu.style,mx=menu.childNodes[1], nItems=m3.childNodes.length+nKbds-1, // Number of (visible) keyboard selectors - itemHeight=(m3.firstChild.firstChild).offsetHeight, - menuHeight=nItems*itemHeight; + itemHeight=(m3.firstChild.firstChild).offsetHeight; + let menuHeight=nItems*itemHeight; // Correct maxheight for viewport scaling (iPhone/iPod only) and internal position corrections if(device.OS == 'ios') { @@ -263,17 +265,18 @@ export class LanguageMenu { e.stopPropagation(); e.preventDefault(); - let target = e.touches[0].target; + const target = e.touches[0].target; // Will return 'P', not 'p'. if(target.nodeName != 'P') { return; } - var i,t,initial=target.innerHTML.charCodeAt(0),nn=menu.childNodes; + let i: number; + const initial=target.innerHTML.charCodeAt(0), nn=menu.childNodes; try { for(i=0; inn[i].firstChild).innerHTML.toUpperCase().charCodeAt(0); + const t=(nn[i].firstChild).innerHTML.toUpperCase().charCodeAt(0); if(t >= initial) { break; } @@ -316,11 +319,11 @@ export class LanguageMenu { * @return {number} index of currently active language **/ addLanguages(menu: HTMLDivElement, kbdList: KeyboardStub[]): number { - var nStubs=kbdList.length; - let device = this.keyman.config.hostDevice; + const nStubs=kbdList.length; + const device = this.keyman.config.hostDevice; // Create and sort a list of languages - let langs: string[] = []; + const langs: string[] = []; for(let n=0; nlanguageMenu.lgList.childNodes[0], - yMax=scroller.scrollHeight-scroller.offsetHeight, - y, dy; + const scroller=languageMenu.lgList.childNodes[0]; + const yMax=scroller.scrollHeight-scroller.offsetHeight; + let y: number; // TS does not have a standard definition for TouchEvent.pageY. //@ts-ignore @@ -513,7 +516,7 @@ export class LanguageMenu { return false; } - dy=y-languageMenu.y0; + const dy=y-languageMenu.y0; // Scroll up (show later listed languages) if(dy < 0) { @@ -577,7 +580,7 @@ export class LanguageMenu { * Remove the language menu again **/ hide() { - let osk = this.keyman.osk; + const osk = this.keyman.osk; if(this.lgList) { osk.vkbd.highlightKey(osk.vkbd.lgKey,false); diff --git a/web/src/app/browser/src/release-main.ts b/web/src/app/browser/src/release-main.ts index 01b318c714..2261d185c4 100644 --- a/web/src/app/browser/src/release-main.ts +++ b/web/src/app/browser/src/release-main.ts @@ -8,9 +8,9 @@ import { Worker } from '@keymanapp/lexical-model-layer/web' * This can only be done during load when the active script will be the * last script loaded. Otherwise the script must be identified by name. */ - var scripts = document.getElementsByTagName('script'); - var ss = scripts[scripts.length-1].src; - var sPath = ss.substr(0,ss.lastIndexOf('/')+1); + const scripts = document.getElementsByTagName('script'); + const ss = scripts[scripts.length-1].src; + const sPath = ss.substr(0,ss.lastIndexOf('/')+1); // @ts-ignore window['keyman'] = new KeymanEngine(Worker, sPath); \ No newline at end of file diff --git a/web/src/app/browser/src/utils/rotationProcessor.ts b/web/src/app/browser/src/utils/rotationProcessor.ts index e8141d1ab1..f9d573b765 100644 --- a/web/src/app/browser/src/utils/rotationProcessor.ts +++ b/web/src/app/browser/src/utils/rotationProcessor.ts @@ -40,7 +40,7 @@ export class RotationProcessor { } resolve() { - var osk = this.keyman.osk; + const osk = this.keyman.osk; // `keyman: KeymanEngine` (modularized app/browser) this.keyman.touchLanguageMenu?.hide(); @@ -81,8 +81,8 @@ export class RotationProcessor { */ init() { // Note: we use wrapper functions instead of `.bind(this)` in this method to facilitate stubbing for our rotation test page. - var os = this.keyman.config.hostDevice.OS; - var util = this.keyman.util; + const os = this.keyman.config.hostDevice.OS; + const util = this.keyman.util; if(os == 'ios') { /* iOS is rather inconsistent about these events, with changes to important window state information - @@ -137,7 +137,7 @@ export class RotationProcessor { } iOSEventUpdate() { - var newState = new RotationState(); + const newState = new RotationState(); if(this.rotState.equals(newState)) { if(++this.idlePermutationCounter == RotationProcessor.IDLE_PERMUTATION_CAP) { diff --git a/web/src/app/browser/src/viewsAnchorpoint.ts b/web/src/app/browser/src/viewsAnchorpoint.ts index 3df908c402..8db8781f2c 100644 --- a/web/src/app/browser/src/viewsAnchorpoint.ts +++ b/web/src/app/browser/src/viewsAnchorpoint.ts @@ -18,7 +18,7 @@ function buildBaseOskConfiguration(engine: KeymanEngine) { class PublishedAnchoredOSKView extends AnchoredOSKView { constructor(engine: KeymanEngine, config?: ViewConfiguration) { - let finalConfig = { + const finalConfig = { ...buildBaseOskConfiguration(engine), ...(config || {}) }; @@ -29,7 +29,7 @@ class PublishedAnchoredOSKView extends AnchoredOSKView { class PublishedFloatingOSKView extends FloatingOSKView { constructor(engine: KeymanEngine, config?: FloatingOSKViewConfiguration) { - let finalConfig: FloatingOSKViewConfiguration = { + const finalConfig: FloatingOSKViewConfiguration = { ...buildBaseOskConfiguration(engine), ...(config || {}) }; @@ -40,7 +40,7 @@ class PublishedFloatingOSKView extends FloatingOSKView { class PublishedInlineOSKView extends InlinedOSKView { constructor(engine: KeymanEngine, config?: ViewConfiguration) { - let finalConfig: ViewConfiguration = { + const finalConfig: ViewConfiguration = { ...buildBaseOskConfiguration(engine), ...(config || {}) };