Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions web/src/.editorconfig

This file was deleted.

38 changes: 22 additions & 16 deletions web/src/app/browser/src/keymanEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class KeymanEngine extends KeymanEngineBase<BrowserConfiguration, Context
* activationPending (bool): KMW being activated
* activated (bool): KMW active
*
* See https://help.keyman.com/developer/engine/web/16.0/reference/core/getUIState
* See https://help.keyman.com/developer/engine/web/current-version/reference/core/getUIState
*/
public getUIState(): FocusStateAPIObject {
return this.contextManager.focusAssistant.getUIState();
Expand All @@ -266,7 +266,7 @@ export class KeymanEngine extends KeymanEngineBase<BrowserConfiguration, Context
/**
* Set or clear the IsActivatingKeymanWebUI flag (exposed function)
*
* See https://help.keyman.com/developer/engine/web/16.0/reference/core/activatingUI
* See https://help.keyman.com/developer/engine/web/current-version/reference/core/activatingUI
*
* @param {(boolean|number)} state Activate (true,false)
*/
Expand All @@ -275,35 +275,41 @@ export class KeymanEngine extends KeymanEngineBase<BrowserConfiguration, Context
}

/**
* Function setKeyboardForControl
* Scope Public
* @param {Element} Pelem Control element
* @param {string|null=} Pkbd JSKeyboard (Clears the set keyboard if set to null.)
* @param {string|null=} Plc Language Code
* Description Set default keyboard for the control
* Associate control with independent keyboard settings initialized to a specific keyboard.
* The pair of `keyboard` and `languageCode` (if not `null`) must refer to a
* registered keyboard stub.
*
* See https://help.keyman.com/developer/engine/web/current-version/reference/core/setKeyboardForControl
*
* @param {Element} elem The control element to be managed manually
* @param {string|null=} keyboard The id of a keyboard, consisting of the word
* `Keyboard_` followed by the internal keyboard
* name. For a keyboard with the internal name
* `laokeys` this would be `Keyboard_laokeys`.
* If `null` clears the set keyboard.
* @param {string|null=} languageCode A BCP47 language code which was used when
* registering the keyboard stub.
*/
public setKeyboardForControl(Pelem: HTMLElement, Pkbd?: string, Plc?: string): void {
if(Pelem instanceof Pelem.ownerDocument.defaultView.HTMLIFrameElement) {
public setKeyboardForControl(elem: HTMLElement, keyboard?: string, languageCode?: string): void {
if(elem instanceof elem.ownerDocument.defaultView.HTMLIFrameElement) {
console.warn("'keymanweb.setKeyboardForControl' cannot set keyboard on iframes.");
return;
}

if(!this.isAttached(Pelem)) {
console.error("KeymanWeb is not attached to element " + Pelem);
if(!this.isAttached(elem)) {
console.error("KeymanWeb is not attached to element " + elem);
return;
}

let stub = null;
if(Pkbd) {
stub = this.keyboardRequisitioner.cache.getStub(Pkbd, Plc);
if(keyboard) {
stub = this.keyboardRequisitioner.cache.getStub(keyboard, languageCode);
if(!stub) {
throw new Error(`No keyboard has been registered with id ${Pkbd} and language code ${Plc}.`);
throw new Error(`No keyboard has been registered with id ${keyboard} and language code ${languageCode}.`);
}
}

this.contextManager.setKeyboardForTextStore(Pelem._kmwAttachment.textStore, Pkbd, Plc);
this.contextManager.setKeyboardForTextStore(elem._kmwAttachment.textStore, keyboard, languageCode);
}

/**
Expand Down
100 changes: 53 additions & 47 deletions web/src/app/ui/kmwuitoggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ if(!keymanweb) {
}

osk.addEventListener('show', (oskPosition) => {
// Ensure that the ui.controller is visible if help is displayed
this.controller.style.display = 'block';
this.oskButton._setSelected(true);
// Ensure that the ui.controller is visible if help is displayed
this.controller.style.display = 'block';
this.oskButton._setSelected(true);

return oskPosition;
});
return oskPosition;
});

osk.addEventListener('hide', (byUser) => {
if(byUser['HiddenByUser']) {
Expand Down Expand Up @@ -565,24 +565,24 @@ if(!keymanweb) {
/**
* Function selecKbd
* Scope Private
* @param {number} _kbd
* @param {number} kbdIndex
* Description Select a keyboard from the drop down menu
**/
private async selectKbd(_kbd: number): Promise<boolean> {
let _name,_lgCode;
if(_kbd < 0) {
_name = '';
_lgCode='';
private async selectKbd(kbdIndex: number): Promise<boolean> {
let name: string, languageCode: string;
if (kbdIndex < 0) {
name = '';
languageCode = '';
} else {
_name = this.keyboards[_kbd]._InternalName;
_lgCode = this.keyboards[_kbd]._LanguageCode;
name = this.keyboards[kbdIndex]._InternalName;
languageCode = this.keyboards[kbdIndex]._LanguageCode;
}

await keymanweb.setActiveKeyboard(_name,_lgCode);
await keymanweb.setActiveKeyboard(name, languageCode);
keymanweb.focusLastActiveElement();
this.kbdButton._setSelected(_name != '');
if(_kbd >= 0) {
this.lastActiveKeyboard = _kbd;
this.kbdButton._setSelected(name != '');
if (kbdIndex >= 0) {
this.lastActiveKeyboard = kbdIndex;
}

return false;
Expand Down Expand Up @@ -697,6 +697,22 @@ if(!keymanweb) {
`;
}

private createMenuItem(index: number, id: string, name: string, isSelected: boolean): { li: HTMLLIElement, a: HTMLAnchorElement } {
const li = util.createElement('li');
const a = util.createElement('a');
a.innerHTML = name;
a.href = "#";
a.onclick = ((x) => {
return () => this.selectKbd(x);
})(index);
a.id = id;
if (isSelected) {
a.className = 'selected';
}
li.appendChild(a);
return { li, a };
}

/**
* Function createMenu
* Scope Private
Expand All @@ -711,46 +727,36 @@ if(!keymanweb) {
this.keyboardMenu.innerHTML = ''; // I2403 - Allow toggle design to be loaded twice
}

const _li = util.createElement('li');
const _a = util.createElement('a');
_a.innerHTML='(System keyboard)';
_a.href="#";
_a.onclick = () => {
return this.selectKbd(-1);
};
_a.id='KMWSel_$';
_a.className='selected';
_li.appendChild(_a);

this.selectedMenuItem=_a;
this.keyboardMenu.appendChild(_li);
// Add the default (system) keyboard as the first entry in the menu
const { li, a } = this.createMenuItem(-1, 'KMWSel_$', '(System keyboard)', true);
this.selectedMenuItem = a;
this.keyboardMenu.appendChild(li);

const _kbds=keymanweb.getKeyboards(), _added: Record<string, number> = {};
// Add loaded keyboards to the menu
this.keyboards = [];
for(let _kbd = 0; _kbd < _kbds.length; _kbd++) {
const _li1=util.createElement('li');
const _a1=util.createElement('a');
_a1.innerHTML=_kbds[_kbd].LanguageName + ' - ' + _kbds[_kbd].Name;
if(!_added[_kbds[_kbd].InternalName]) _added[_kbds[_kbd].InternalName]=0;
_added[_kbds[_kbd].InternalName]++;

const _n=_added[_kbds[_kbd].InternalName];
this.keyboards.push({_InternalName: _kbds[_kbd].InternalName, _LanguageCode:_kbds[_kbd].LanguageCode, _Index: _n});
const keyboards = keymanweb.getKeyboards();
const added: Record<string, number> = {};
for (let kbdIndex = 0; kbdIndex < keyboards.length; kbdIndex++) {
if (!added[keyboards[kbdIndex].InternalName]) {
added[keyboards[kbdIndex].InternalName] = 0;
}
added[keyboards[kbdIndex].InternalName]++;

_a1.href="#";
_a1.onclick = ((x) => { return () => this.selectKbd(x); })(this.keyboards.length-1);
_a1.id='KMWSel_'+_kbds[_kbd].InternalName+'$'+_n;
const kbdInstanceCount = added[keyboards[kbdIndex].InternalName];
this.keyboards.push({ _InternalName: keyboards[kbdIndex].InternalName, _LanguageCode: keyboards[kbdIndex].LanguageCode, _Index: kbdInstanceCount });

_li1.appendChild(_a1);
this.keyboardMenu.appendChild(_li1);
const { li } = this.createMenuItem(this.keyboards.length - 1,
`KMWSel_${keyboards[kbdIndex].InternalName}\$${kbdInstanceCount}`,
`${keyboards[kbdIndex].LanguageName} - ${keyboards[kbdIndex].Name}`,
false);
this.keyboardMenu.appendChild(li);
}

//if(!ui.initialized) // I2403 - Allow toggle design to be loaded twice
if(this.keyboardMenu.parentNode != this.kbdButton.getElem()) {
this.kbdButton.getElem().appendChild(this.keyboardMenu);
}
};

}


Expand Down Expand Up @@ -805,4 +811,4 @@ if(!keymanweb) {
ui.initialize();

} catch(ex){}
}
}
Loading