chore(web): address code review comments
Some checks failed
Keyman Build Summary / Summarize build status checks (push) Has been cancelled

Also change a few places that I missed.
This commit is contained in:
Eberhard Beilharz 2026-06-08 19:27:12 +02:00
parent 15d020298e
commit c1113ac21d
No known key found for this signature in database
GPG key ID: E9140597606020D3
25 changed files with 110 additions and 105 deletions

View file

@ -36,22 +36,20 @@
<!-- Initialization: set paths to keyboards, resources and fonts as required -->
<script>
(function(kmw) {
kmw.init({
attachType:'auto'
}).then(function() {
kmw.addKeyboards({
id:'test_8568_deadkeys',
name:'Testcase for deadkeys bug (#8568)',
languages:{
id:'en',
name:'English'
},
filename:'./test_8568_deadkeys.js'
});
keyman.init({
attachType:'auto'
}).then(async function() {
await keyman.addKeyboards({
id:'test_8568_deadkeys',
name:'Testcase for deadkeys bug (#8568)',
languages:{
id:'en',
name:'English'
},
filename:'./test_8568_deadkeys.js'
});
})(keyman);
</script>
});
</script>
</head>

View file

@ -110,7 +110,7 @@ hamburger menu in the Keyman app.
**Web**: copy khmer_angkor.js to your website, then [load it with KeymanWeb][load-keymanweb-keyboard]:
```js
keyman.addKeyboards({
await keyman.addKeyboards({
id:'khmer_angkor', // The keyboard's unique identification code.
name:'Khmer Angkor', // The keyboard's user-readable name.
language:{

View file

@ -109,7 +109,7 @@ hamburger menu in the Keyman app.
**Web**: copy khmer_angkor.js to your website, then [load it with KeymanWeb][load-keymanweb-keyboard]:
```js
keyman.addKeyboards({
await keyman.addKeyboards({
id:'khmer_angkor', // The keyboard's unique identification code.
name:'Khmer Angkor', // The keyboard's user-readable name.
language:{

View file

@ -8,8 +8,8 @@ There are multiple ways to add and install keyboards into your KeymanWeb install
The most efficient way to utilize a keyboard is to obtain a local copy of it and place this copy in a static location on your website. Once this is done, it can be directly linked into KeymanWeb as follows.
```c
keyman.addKeyboards({
```typescript
await keyman.addKeyboards({
id:'us', // The keyboard's unique identification code.
name:'English', // The keyboard's user-readable name.
language:{
@ -22,7 +22,7 @@ keyman.addKeyboards({
Custom fonts may also be utilized via the `language.font` property. For example:
```c
```typescript
font:{
family:'LaoWeb',
source:['../font/saysettha_web.ttf','../font/saysettha_web.woff','../font/saysettha_web.eot']
@ -33,16 +33,16 @@ font:{
To obtain the default Keyman keyboard for a given language, call the following function.
```c
keyman.addKeyboardsForLanguage('Dzongkha');
```typescript
await keyman.addKeyboardsForLanguage('Dzongkha');
```
This example would find the default keyboard for the Dzongkha language. This method will fail if the name doesn't perfectly match any language found in the CDN's repository.
Alternatively, languages may be looked up via their BCP 47 language code as follows:
```c
keyman.addKeyboards('@he')
```typescript
await keyman.addKeyboards('@he')
```
The `@` prefix indicates the use of the BCP 47 language code, which in this case corresponds with Hebrew.
@ -51,8 +51,8 @@ The `@` prefix indicates the use of the BCP 47 language code, which in this case
To obtain a specific keyboard by name or by keyboard name and language code as a pair, see the following:
```c
keyman.addKeyboards('french','sil_euro_latin@sv','sil_euro_latin@no')
```typescript
await keyman.addKeyboards('french','sil_euro_latin@sv','sil_euro_latin@no')
```
This will install three keyboards - one for French (named, quite simply, "French") and two copies of the EuroLatin keyboard - one for Swedish and one for Norwegian.

View file

@ -3,8 +3,8 @@
<head>
<script src='https://s.keyman.com/kmw/engine/17.0.331/keymanweb.js'></script>
<script>
keyman.init().then(function() {
keyman.addKeyboards({
keyman.init().then(async function() {
await keyman.addKeyboards({
id:'laokeys',
name:'Lao (Phonetic)',
languages:{

View file

@ -3,7 +3,6 @@
<head>
<script src='https://s.keyman.com/kmw/engine/17.0.331/keymanweb.js'></script>
<script>var kmw = keyman;</script>
<script src='https://s.keyman.com/kmw/engine/17.0.331/kmwuitoggle.js'></script>
<script type='text/javascript' src='js/unified_loader.js'></script>
@ -20,8 +19,8 @@
// Disable KeymanWeb interaction on the 'Email to' TEXT control
keyman.disableControl(document.f.address);
// Set the default keyboard for the 'Subject' TEXT control to 'off' (i.e. default
// browser keyboard)
// Set the default keyboard for the 'Subject' TEXT control to the first language
// added to KeymanWeb after initialization.
keyman.setKeyboardForControl(document.f.subject, '', '');
// Set the default keyboard for the 'Message body' TEXTAREA to the LaoKeys keyboard
keyman.setKeyboardForControl(document.f.text, 'Keyboard_laokeys', 'lo');
@ -42,4 +41,4 @@
<a href="control-by-control">Back to Document</a>
</body>
</html>
</html>

View file

@ -10,9 +10,9 @@
<script>
keyman.init({
attachType:'auto'
}).then(function() {
keyman.addKeyboards('@en'); // Loads default English keyboard from Keyman Cloud (CDN)
keyman.addKeyboards('@th'); // Loads default Thai keyboard from Keyman Cloud (CDN)
}).then(async function() {
await keyman.addKeyboards('@en'); // Loads default English keyboard from Keyman Cloud (CDN)
await keyman.addKeyboards('@th'); // Loads default Thai keyboard from Keyman Cloud (CDN)
});
</script>
</head>

View file

@ -13,8 +13,8 @@ In this example, we use only the LaoKey keyboard. Please click [this link](./__a
<!-- Start of Code -->
<script src="js/keymanweb.js" type="text/javascript"></script>
<script>
keyman.init().then(function() {
keyman.addKeyboards({
keyman.init().then(async function() {
await keyman.addKeyboards({
id:'laokeys',
name:'Lao (Phonetic)',
languages:{

View file

@ -22,12 +22,10 @@ The source code for the page may be seen below.
<script src='https://s.keyman.com/kmw/engine/18.0.245/keymanweb.js'></script>
<script src='https://s.keyman.com/kmw/engine/18.0.245/kmwuitoggle.js'></script>
<script>
(function() {
keyman.init({attachType:'auto'}).then(function() {
keyman.addKeyboards('@en'); // Loads default English keyboard from Keyman Cloud (CDN)
keyman.addKeyboards('@th'); // Loads default Thai keyboard from Keyman Cloud (CDN)
});
})(keyman);
keyman.init({attachType:'auto'}).then(async function() {
await keyman.addKeyboards('@en'); // Loads default English keyboard from Keyman Cloud (CDN)
await keyman.addKeyboards('@th'); // Loads default Thai keyboard from Keyman Cloud (CDN)
});
</script>
</head>
<body>

View file

@ -9,7 +9,7 @@ Adds keyboards to KeymanWeb.
## Syntax
```js
keyman.addKeyboards(spec[, spec...])
await keyman.addKeyboards([spec...])
```
### Parameters
@ -179,3 +179,13 @@ The `spec.languages.font` object contains the following members:
: `string` <span class="optional">optional</span>
Font size (in CSS dimensions). If not specified, then `1em` is used.
### Not passing any parameter
Not passing any parameter will obtain the Keyman keyboards for English
from the CDN, i.e. these two functions calls are identical:
```js
await keyman.addKeyboards();
await keyman.addKeyboards('@en');
```

View file

@ -9,7 +9,7 @@ Add default or all keyboards for a given language to KeymanWeb.
## Syntax
```js
keyman.addKeyboardsForLanguage(spec[, spec...])
await keyman.addKeyboardsForLanguage(spec[, spec...])
```
### Parameters

View file

@ -8,7 +8,7 @@ Get keyboard meta data for the selected keyboard and language.
## Syntax
```c
```js
keyman.getKeyboard(keyboardName, languageCode)
```
@ -75,5 +75,5 @@ The `keyboard` object contains the following members:
: `string` *optional*
: The font packaged with the keyboard to properly display specialized OSK characters.
## See also
## See also
- [keyman.addKeyboards()](addKeyboards) and its documentation about keyboard specification objects.

View file

@ -8,7 +8,7 @@ Get details of currently installed keyboards.
## Syntax
```c
```js
keyman.getKeyboards()
```
@ -25,5 +25,5 @@ None.
See [keyman.getKeyboard()](getKeyboard) for detail on the returned keyboard specification objects.
## See also
## See also
- [keyman.addKeyboards()](addKeyboards)

View file

@ -8,13 +8,13 @@ Registers the keyboard stub or returns true if already registered.
## Syntax
```c
```js
keyman.interface.registerStub(Pstub);
```
or
```c
```js
KeymanWeb.KRS(Pstub); // Shorthand
```

View file

@ -1150,8 +1150,8 @@ if(!keymanweb) {
internalName: string,
languageCode: string
}) => { // Uses a different format than .getKeyboards(), b/c why not?
// https://help.keyman.com/developer/engine/web/16.0/reference/core/getKeyboards vs
// https://help.keyman.com/developer/engine/web/16.0/reference/events/kmw.keyboardchange
// https://help.keyman.com/developer/engine/web/current-version/reference/core/getKeyboards vs
// https://help.keyman.com/developer/engine/web/current-version/reference/events/kmw.keyboardchange
this.lastSelectedKeyboard = null;
const kbName=p.internalName,
lgName=keymanweb.util.getLanguageCodes(p.languageCode)[0];

View file

@ -44,9 +44,9 @@
// KMW will look for them here - two folders up from root, which is the base sample directory.
keyboards: '/../../',
attachType:'auto'
}).then(function() {
}).then(async function() {
// Loads keyboards from the base sample folder
keyman.addKeyboards({
await keyman.addKeyboards({
id:'us',
name:'English',
languages: {
@ -57,7 +57,7 @@
filename: 'us-1.0.js'
});
// For contrast:
keyman.addKeyboards({
await keyman.addKeyboards({
id:'lao_2008_basic',
name:'Lao Basic',
languages: {
@ -73,12 +73,12 @@
// 1. keyboard name ('french'),
// 2. keyboard name and language code ('sil_euro_latin@no,sv'),
// 3. or just the BCP-47 language code ('@he').
keyman.addKeyboards('french', 'sil_euro_latin@no,sv', '@he');
await keyman.addKeyboards('french', 'sil_euro_latin@no,sv', '@he');
// Add a keyboard by language name. Note that the name must be spelled
// correctly, or the keyboard will not be found. (Using BCP-47 codes is
// usually easier.)
doAddKeyboardsForLanguage('Dzongkha');
await doAddKeyboardsForLanguage('Dzongkha');
});
</script>

View file

@ -43,9 +43,9 @@
function errToString(err) {
// Painful? Kinda. But needed on un-updated Android API 21!
if(Array.isArray(err)) {
var result = '';
for(var i = 0; i < err.length; i++) {
var e = err[i];
let result = '';
for(let i = 0; i < err.length; i++) {
const e = err[i];
if(e.error instanceof Error) {
result += e.error.message + '\n';
} else {
@ -73,13 +73,13 @@
}
async function loadKeyboards(nestLevel) {
var base_prefix = '../';
var prefix = './'; // The default - when prefix == 0.
const base_prefix = '../';
let prefix = './'; // The default - when prefix == 0.
if(nestLevel !== undefined && nestLevel > 0) {
prefix = '';
for(var i=0; i < nestLevel; i++) {
prefix = prefix + base_prefix;
for(let i=0; i < nestLevel; i++) {
prefix += base_prefix;
}
}
@ -116,29 +116,31 @@
}
// Script to allow a user to add any keyboard to the keyboard menu
function addKeyboard(n) {
var sKbd;
async function addKeyboard(n) {
let sKbd;
switch(n) {
case 1:
sKbd=document.getElementById('kbd_id1').value;
doAddKeyboards(sKbd);
await doAddKeyboards(sKbd);
break;
case 2:
sKbd=document.getElementById('kbd_id2').value.toLowerCase();
doAddKeyboards('@'+sKbd);
await doAddKeyboards('@'+sKbd);
break;
case 3:
// Add keyboard for comma-separated language name(s)
sKbd=document.getElementById('kbd_id3').value;
doAddKeyboardsForLanguage(sKbd);
await doAddKeyboardsForLanguage(sKbd);
break;
}
}
// Add keyboard on Enter (as well as pressing button)
function clickOnEnter(e,id)
async function clickOnEnter(e,id)
{
e = e || window.event;
if(e.keyCode == 13) addKeyboard(id);
if (e.keyCode == 13) {
await addKeyboard(id);
}
}

View file

@ -30,8 +30,8 @@
<script>
keyman.init({
attachType:'auto'
}).then(function() {
loadKeyboards();
}).then(async function() {
await loadKeyboards();
});
</script>
<!--
@ -43,10 +43,9 @@
Keyboard paths may be absolute (with respect to the server root) or relative to the keyboards option path.
-->
<script>
function loadKeyboards() {
keyman.addKeyboards().then(function() {
keyman.setActiveKeyboard('basic_kbdus','en');
});
async function loadKeyboards() {
await keyman.addKeyboards();
await keyman.setActiveKeyboard('basic_kbdus','en');
}
</script>

View file

@ -75,8 +75,8 @@
const container = document.createElement('div');
await kmw.addKeyboards(`${kbdid}@${langid}`);
await kmw.setActiveKeyboard(kbdid, langid);
await keyman.addKeyboards(`${kbdid}@${langid}`);
await keyman.setActiveKeyboard(kbdid, langid);
docBase = keyman.BuildVisualKeyboard(kbdid, 1, formFactor, layer);
label.textContent = `${keyman.getKeyboard(kbdid).Name} - ${formFactor} - ${layer} layer`;
@ -94,6 +94,7 @@
}
keyman.init().then(async function() {
await loadKeyboards(1);
await documentKeyboard("gff_amharic", "am", "phone", "default");
await documentKeyboard("sil_euro_latin", "no", "phone", "shift");
await documentKeyboard("lao_2008_basic", "lo", "tablet", "default");

View file

@ -32,9 +32,7 @@
<script>
keyman.init({
attachType: 'auto'
}).then(function () {
loadKeyboards();
});
}).then(loadKeyboards);
</script>
<!-- Add keyboard management script for local selection of keyboards to use -->

View file

@ -32,9 +32,7 @@
<script>
keyman.init({
attachType: 'auto'
}).then(function () {
loadKeyboards();
});
}).then(loadKeyboards);
</script>
<!-- Add keyboard management script for local selection of keyboards to use -->

View file

@ -38,8 +38,8 @@
<script>
keyman.init({
attachType:'auto'
}).then(function() {
keyman.addKeyboards({id:'default_subkey',name:'English',languages:{id:'en',name:'English'}, filename:'./default_subkey.js'});
}).then(async function() {
await keyman.addKeyboards({id:'default_subkey',name:'English',languages:{id:'en',name:'English'}, filename:'./default_subkey.js'});
var pageRef = (window.location.protocol == 'file:')
? window.location.href.substr(0, window.location.href.lastIndexOf('/')+1)

View file

@ -38,8 +38,8 @@
<script>
keyman.init({
attachType:'auto'
}).then(function () {
keyman.addKeyboards();
}).then(async function () {
await keyman.addKeyboards();
});
</script>
</head>

View file

@ -38,8 +38,8 @@
<script>
keyman.init({
attachType:'auto'
}).then(function () {
loadKeyboards();
}).then(async function () {
await loadKeyboards();
});
</script>

View file

@ -1,25 +1,25 @@
// Modified version of commonHeader - contains repeated requests for the same language.
function loadKeyboards() {
async function loadKeyboards() {
// The first keyboard added will be the default keyboard for touch devices.
// For faster loading, it may be best for the default keyboard to be
// locally sourced.
keyman.addKeyboards({id:'us',name:'English',languages:{id:'en',name:'English'},
await keyman.addKeyboards({id:'us',name:'English',languages:{id:'en',name:'English'},
filename:'../us-1.0.js'});
// Add more keyboards to the language menu, by keyboard name,
// keyboard name and language code, or just the BCP-47 language code.
keyman.addKeyboards('french','european2@sv','european2@sv','european2@sv','european2@sv','european2@sv','european2@sv','european2@no','@he');
keyman.addKeyboards('@he');
keyman.addKeyboards('@he');
await keyman.addKeyboards('french','european2@sv','european2@sv','european2@sv','european2@sv','european2@sv','european2@sv','european2@no','@he');
await keyman.addKeyboards('@he');
await keyman.addKeyboards('@he');
// Add a keyboard by language name. Note that the name must be spelled
// correctly, or the keyboard will not be found. (Using BCP-47 codes is
// usually easier.)
keyman.addKeyboardsForLanguage('Dzongkha');
await keyman.addKeyboardsForLanguage('Dzongkha');
// Add a fully-specified, locally-sourced, keyboard with custom font
keyman.addKeyboards({id:'lao_2008_basic',name:'Lao Basic',
await keyman.addKeyboards({id:'lao_2008_basic',name:'Lao Basic',
languages:{
id:'lo',name:'Lao',region:'Asia'
},
@ -38,29 +38,31 @@
}
// Script to allow a user to add any keyboard to the keyboard menu
function addKeyboard(n)
async function addKeyboard(n)
{
let sKbd;
switch(n)
{
case 1:
sKbd=document.getElementById('kbd_id1').value;
keyman.addKeyboards(sKbd);
await keyman.addKeyboards(sKbd);
break;
case 2:
sKbd=document.getElementById('kbd_id2').value.toLowerCase();
keyman.addKeyboards('@'+sKbd);
await keyman.addKeyboards('@'+sKbd);
break;
case 3:
sKbd=document.getElementById('kbd_id3').value;
keyman.addKeyboardsForLanguage(sKbd);
await keyman.addKeyboardsForLanguage(sKbd);
break;
}
}
// Add keyboard on Enter (as well as pressing button)
function clickOnEnter(e,id) {
async function clickOnEnter(e,id) {
e = e || window.event;
if(e.keyCode == 13) addKeyboard(id);
if (e.keyCode == 13) {
await addKeyboard(id);
}
}