chore(web): clean up some test headers

This commit is contained in:
Eberhard Beilharz 2026-06-09 17:39:41 +02:00
parent cea706c562
commit a354ba1f4a
No known key found for this signature in database
GPG key ID: E9140597606020D3
4 changed files with 165 additions and 284 deletions

View file

@ -1,120 +1,63 @@
// JavaScript Document samplehdr.js: Keyboard management for KeymanWeb demonstration pages
/*
The keyboard name and/or BCP-47 language code must be specified for each keyboard that is to be available.
If the same keyboard is used for several languages, it must be listed for each
language, but the keyboard itself will only be loaded once.
If two (or more) keyboards are to be available for a given language, both must be listed.
Any number of keyboards may be specified in one or more calls.
Keyboard paths may be absolute (with respect to the server root) or relative to the keyboards option path.
The actual keyboard object will be downloaded asynchronously when first selected for use.
* Keyman is copyright (C) SIL Global. MIT License.
*/
async function loadKeyboards()
{
await keyman.addKeyboards({id:'us',name:'English',languages:{id:'en',name:'English'},
filename:'../us-1.0.js'});
await keyman.addKeyboards('french','european2@sv','european2@no','@he');
await keyman.addKeyboardsForLanguage('Dzongkha');
await keyman.addKeyboards({id:'lao_2008_basic',name:'Lao Basic',
languages:{
id:'lo',name:'Lao',region:'Asia',
font:{family:'LaoWeb',source:['../font/saysettha_web.ttf','../font/saysettha_web.woff','../font/saysettha_web.eot']}
},
filename:'../lao_2008_basic-1.2.js'
});
}
Each argument to addKeyboards() is a string, for example:
european2 loads the current version of the Eurolatin 2 keyboard (for its default language)
european2@fr loads the current version of the Eurolatin 2 keyboard for French
european2@fr@1.2 loads version 1.2 of the Eurolatin 2 keyboard for French
Argument syntax also supports the following extensions:
@fr load the current version of the default keyboard for French
@fr$ load all available keyboards (current version) for French
Each call to addKeyboards() requires a single call to the remote server,
(unless all keyboards listed are local and fully specified) so it is better
to use multiple arguments rather than separate function calls.
Calling addKeyboards() with no arguments returns a list of *all* available keyboards.
The Toolbar (desktop browser) UI is best suited for allowing users to select
the appropriate language and keyboard in this case.
Keyboards may also be specified by language name using addKeyboardsForLanguage()
for example:
keymanweb.addKeyboardsForLanguage('Burmese');
Appending $ to the language name will again cause all available keyboards for that
language to be loaded rather than the default keyboard.
The first call to addKeyboardsForLanguage() makes an additional call to the
keyman API to load the current list of keyboard/language associations.
In this example, the following function loads the indicated keyboards,
and is called when the page loads.
*/
async function loadKeyboards()
// Script to allow a user to add any keyboard to the keyboard menu
async function addKeyboard(n)
{
let sKbd;
switch(n)
{
// 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.
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.
await keyman.addKeyboards('french','european2@sv','european2@no','@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.)
await keyman.addKeyboardsForLanguage('Dzongkha');
// Add a fully-specified, locally-sourced, keyboard with custom font
await keyman.addKeyboards({id:'lao_2008_basic',name:'Lao Basic',
languages:{
id:'lo',name:'Lao',region:'Asia',
font:{family:'LaoWeb',source:['../font/saysettha_web.ttf','../font/saysettha_web.woff','../font/saysettha_web.eot']}
},
filename:'../lao_2008_basic-1.2.js'
});
// The following two optional calls should be delayed until language menus are fully loaded:
// (a) a specific mapped input element input is focused, to ensure that the OSK appears
// (b) a specific keyboard is loaded, rather than the keyboard last used.
//window.setTimeout(function(){keyman.setActiveElement('ta1',true);},2500);
//window.setTimeout(function(){keyman.setActiveKeyboard('Keyboard_french','fr');},3000);
// Note that locally specified keyboards will be listed before keyboards
// requested from the remote server by user interfaces that do not order
// keyboards alphabetically by language.
case 1:
sKbd=document.getElementById('kbd_id1').value;
await keyman.addKeyboards(sKbd);
break;
case 2:
sKbd=document.getElementById('kbd_id2').value.toLowerCase();
await keyman.addKeyboards('@'+sKbd);
break;
case 3:
sKbd=document.getElementById('kbd_id3').value;
await keyman.addKeyboardsForLanguage(sKbd);
break;
}
}
// Script to allow a user to add any keyboard to the keyboard menu
async function addKeyboard(n)
{
var sKbd;
switch(n)
{
case 1:
sKbd=document.getElementById('kbd_id1').value;
await keyman.addKeyboards(sKbd);
break;
case 2:
sKbd=document.getElementById('kbd_id2').value.toLowerCase();
await keyman.addKeyboards('@'+sKbd);
break;
case 3:
sKbd=document.getElementById('kbd_id3').value;
await keyman.addKeyboardsForLanguage(sKbd);
break;
}
// Add keyboard on Enter (as well as pressing button)
async function clickOnEnter(e,id)
{
e = e || window.event;
if (e.keyCode == 13) {
await addKeyboard(id);
}
}
// Add keyboard on Enter (as well as pressing button)
async function clickOnEnter(e,id)
{
e = e || window.event;
if(e.keyCode == 13) await addKeyboard(id);
}
async function removeKeyboard() {
var sKbd = document.getElementById('kbd_id4').value;
var result = await keyman.removeKeyboards(sKbd);
console.log("Keyboard '" + sKbd + "' removal success: " + result);
}
// Removes keyboard on Enter (as well as pressing button)
async function removeOnEnter(e)
{
e = e || window.event;
if(e.keyCode == 13) await removeKeyboard();
async function removeKeyboard() {
let sKbd = document.getElementById('kbd_id4').value;
let result = await keyman.removeKeyboards(sKbd);
console.log("Keyboard '" + sKbd + "' removal success: " + result);
}
// Removes keyboard on Enter (as well as pressing button)
async function removeOnEnter(e)
{
e = e || window.event;
if(e.keyCode == 13) {
await removeKeyboard();
}
}

View file

@ -1,169 +1,107 @@
// JavaScript Document samplehdr.js: Keyboard management for KeymanWeb demonstration pages
/*
The keyboard name and/or BCP-47 language code must be specified for each keyboard that is to be available.
If the same keyboard is used for several languages, it must be listed for each
language, but the keyboard itself will only be loaded once.
If two (or more) keyboards are to be available for a given language, both must be listed.
Any number of keyboards may be specified in one or more calls.
Keyboard paths may be absolute (with respect to the server root) or relative to the keyboards option path.
The actual keyboard object will be downloaded asynchronously when first selected for use.
* Keyman is copyright (C) SIL Global. MIT License.
*/
Each argument to addKeyboards() is a string, for example:
european2 loads the current version of the Eurolatin 2 keyboard (for its default language)
european2@fr loads the current version of the Eurolatin 2 keyboard for French
european2@fr@1.2 loads version 1.2 of the Eurolatin 2 keyboard for French
Argument syntax also supports the following extensions:
@fr load the current version of the default keyboard for French
@fr$ load all available keyboards (current version) for French
Each call to addKeyboards() requires a single call to the remote server,
(unless all keyboards listed are local and fully specified) so it is better
to use multiple arguments rather than separate function calls.
Calling addKeyboards() with no arguments returns a list of *all* available keyboards.
The Toolbar (desktop browser) UI is best suited for allowing users to select
the appropriate language and keyboard in this case.
Keyboards may also be specified by language name using addKeyboardsForLanguage()
for example:
keymanweb.addKeyboardsForLanguage('Burmese');
Appending $ to the language name will again cause all available keyboards for that
language to be loaded rather than the default keyboard.
The first call to addKeyboardsForLanguage() makes an additional call to the
keyman API to load the current list of keyboard/language associations.
In this example, the following function loads the indicated keyboards,
and is called when the page loads.
*/
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];
if(e.error instanceof Error) {
result += e.error.message + '\n';
} else {
result += JSON.stringify(e) + '\n';
}
}
return result;
}
if(err instanceof Error) {
return err.message;
}
return JSON.stringify(err);
}
function doAddKeyboards(data) {
return keyman.addKeyboards(data).catch(function(err) {
console.error('keyman.addKeyboards failed with '+errToString(err)+' for '+JSON.stringify(data));
});
}
function doAddKeyboardsForLanguage(data) {
return keyman.addKeyboardsForLanguage(data).catch(function(err) {
console.error('keyman.addKeyboardsForLanguage failed with '+errToString(err)+' for '+JSON.stringify(data));
});
}
function loadKeyboards(nestLevel)
{
var base_prefix = '../';
var prefix = './'; // The default - when prefix == 0.
if(nestLevel !== undefined && nestLevel > 0) {
prefix = '';
for(var i=0; i < nestLevel; i++) {
prefix = prefix + base_prefix;
function errToString(err) {
// Painful? Kinda. But needed on un-updated Android API 21!
if(Array.isArray(err)) {
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 {
result += JSON.stringify(e) + '\n';
}
}
// 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.
// doAddKeyboards({id:'us',name:'English',languages:{id:'en',name:'English'},
// filename:(prefix + 'us-1.0.js')});
// Do NOT link the us-1.0 keyboard here!
doAddKeyboards({id:'test_chirality',name:'test_chirality',languages:{id:'en',name:'English'},
filename:(prefix + 'test_chirality.js')});
doAddKeyboards({id:'obolo_chwerty_6351',name:'obolo_chwerty_6351',languages:{id:'en',name:'English'},
filename:(prefix + 'obolo_chwerty_6351.js')});
doAddKeyboards({id:'gesture_prototyping',name:'Gesture Prototyping',languages:{id:'en',name:'English'},
filename:(prefix + 'keyboards/gesture_prototyping/build/gesture_prototyping.js')});
doAddKeyboards({id:'diacritic_rota',name:'Diacritic 10-key Rota',languages:{id:'en',name:'English'},
filename:(prefix + 'keyboards/diacritic_rota/build/diacritic_rota.js')});
doAddKeyboards({id:'ye_old_ten_key',name:'Classic 10-key',languages:{id:'en',name:'English'},
filename:(prefix + 'keyboards/ye_old_ten_key/build/ye_old_ten_key.js')});
// Add more keyboards to the language menu, by keyboard name,
// keyboard name and language code, or just the BCP-47 language code.
// We use a different loading pattern here than in the samples version to provide a slightly different set of test cases.
doAddKeyboards('french','@he');
doAddKeyboards('khmer_angkor','@km');
doAddKeyboards({id:'sil_euro_latin', name:'SIL EuroLatin', languages: [{id:'no'}, {id:'sv'}]}); // Loads from partial stub instead of the compact string.
// 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');
// Add a fully-specified, locally-sourced, keyboard with custom font
doAddKeyboards({id:'lao_2008_basic',name:'Lao Basic',
languages: {
id:'lo',name:'Lao',region:'Asia',
},
filename:(prefix + 'lao_2008_basic-1.2.js')
});
// The following two optional calls should be delayed until language menus are fully loaded:
// (a) a specific mapped input element input is focused, to ensure that the OSK appears
// (b) a specific keyboard is loaded, rather than the keyboard last used.
//window.setTimeout(function(){keyman.setActiveElement('ta1',true);},2500);
//window.setTimeout(function(){keyman.setActiveKeyboard('Keyboard_french','fr');},3000);
// Note that locally specified keyboards will be listed before keyboards
// requested from the remote server by user interfaces that do not order
// keyboards alphabetically by language.
return result;
}
if(err instanceof Error) {
return err.message;
}
return JSON.stringify(err);
}
// Script to allow a user to add any keyboard to the keyboard menu
function addKeyboard(n)
{
var sKbd;
switch(n)
{
case 1:
sKbd=document.getElementById('kbd_id1').value;
doAddKeyboards(sKbd);
break;
case 2:
sKbd=document.getElementById('kbd_id2').value.toLowerCase();
doAddKeyboards('@'+sKbd);
break;
case 3:
// Add keyboard for comma-separated language name(s)
sKbd=document.getElementById('kbd_id3').value;
doAddKeyboardsForLanguage(sKbd);
break;
async function doAddKeyboards(data) {
return keyman.addKeyboards(data).catch(function(err) {
console.error('keyman.addKeyboards failed with '+errToString(err)+' for '+JSON.stringify(data));
});
}
async function doAddKeyboardsForLanguage(data) {
return keyman.addKeyboardsForLanguage(data).catch(function(err) {
console.error('keyman.addKeyboardsForLanguage failed with '+errToString(err)+' for '+JSON.stringify(data));
});
}
async function loadKeyboards(nestLevel) {
const base_prefix = '../';
let prefix = './'; // The default - when prefix == 0.
if(nestLevel !== undefined && nestLevel > 0) {
prefix = '';
for(let i=0; i < nestLevel; i++) {
prefix += base_prefix;
}
}
// Add keyboard on Enter (as well as pressing button)
function clickOnEnter(e,id)
{
e = e || window.event;
if(e.keyCode == 13) addKeyboard(id);
}
// Do NOT link the us-1.0 keyboard here!
await doAddKeyboards({id:'test_chirality',name:'test_chirality',languages:{id:'en',name:'English'},
filename:(prefix + 'test_chirality.js')});
await doAddKeyboards({id:'obolo_chwerty_6351',name:'obolo_chwerty_6351',languages:{id:'en',name:'English'},
filename:(prefix + 'obolo_chwerty_6351.js')});
await doAddKeyboards({id:'gesture_prototyping',name:'Gesture Prototyping',languages:{id:'en',name:'English'},
filename:(prefix + 'keyboards/gesture_prototyping/build/gesture_prototyping.js')});
await doAddKeyboards({id:'diacritic_rota',name:'Diacritic 10-key Rota',languages:{id:'en',name:'English'},
filename:(prefix + 'keyboards/diacritic_rota/build/diacritic_rota.js')});
await doAddKeyboards({id:'ye_old_ten_key',name:'Classic 10-key',languages:{id:'en',name:'English'},
filename:(prefix + 'keyboards/ye_old_ten_key/build/ye_old_ten_key.js')});
await doAddKeyboards('french', '@he');
await doAddKeyboards('khmer_angkor','@km');
await doAddKeyboards({id:'sil_euro_latin', name:'SIL EuroLatin', languages: [{id:'no'}, {id:'sv'}]}); // Loads from partial stub instead of the compact string.
await doAddKeyboardsForLanguage('Dzongkha');
await doAddKeyboards({
id: 'lao_2008_basic', name: 'Lao Basic',
languages: {
id:'lo',name:'Lao',region:'Asia',
},
filename:(prefix + 'lao_2008_basic-1.2.js')
});
}
// Script to allow a user to add any keyboard to the keyboard menu
async function addKeyboard(n) {
let sKbd;
switch(n)
{
case 1:
sKbd=document.getElementById('kbd_id1').value;
await doAddKeyboards(sKbd);
break;
case 2:
sKbd=document.getElementById('kbd_id2').value.toLowerCase();
await doAddKeyboards('@'+sKbd);
break;
case 3:
// Add keyboard for comma-separated language name(s)
sKbd=document.getElementById('kbd_id3').value;
await doAddKeyboardsForLanguage(sKbd);
break;
}
}
// Add keyboard on Enter (as well as pressing button)
async function clickOnEnter(e,id) {
e = e || window.event;
if (e.keyCode == 13) {
await addKeyboard(id);
}
}

View file

@ -1,16 +1,16 @@
// JavaScript Document samplehdr.js: Keyboard management for KeymanWeb demonstration pages
/*
This script is designed to test KeymanWeb error message handling.
* Keyman is copyright (C) SIL Global. MIT License.
*
* This script is designed to test KeymanWeb error message handling.
*/
function loadKeyboards() {
async function loadKeyboards() {
// We start by adding a keyboard correctly. It's best to include a 'control' in our experiment.
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'});
// Insert a keyboard that cannot be found.
keyman.addKeyboards({id:'lao_2008_basic',name:'wrong-filename',
await keyman.addKeyboards({id:'lao_2008_basic',name:'wrong-filename',
languages:{
id:'lo',name:'debugging',region:'Asia',
font:{family:'LaoWeb',source:['../font/saysettha_web.ttf','../font/saysettha_web.woff','../font/saysettha_web.eot']}
@ -19,7 +19,7 @@ function loadKeyboards() {
});
// Insert a keyboard that is unparsable
keyman.addKeyboards({id:'unparsable',name:'non-parsable',
await keyman.addKeyboards({id:'unparsable',name:'non-parsable',
languages:{
id:'lo',name:'debugging',region:'Asia',
font:{family:'LaoWeb',source:['../font/saysettha_web.ttf','../font/saysettha_web.woff','../font/saysettha_web.eot']}
@ -29,7 +29,7 @@ function loadKeyboards() {
});
// Insert a keyboard that will generate a timing error.
keyman.addKeyboards({id:'timeout',name:'timeout',
await keyman.addKeyboards({id:'timeout',name:'timeout',
languages:{
id:'lo',name:'debugging',region:'Asia',
font:{family:'LaoWeb',source:['../font/saysettha_web.ttf','../font/saysettha_web.woff','../font/saysettha_web.eot']}
@ -38,13 +38,13 @@ function loadKeyboards() {
});
}
function badStubRequest(entry) {
async function badStubRequest(entry) {
switch(entry) {
case 1:
keyman.addKeyboards('1nval1d5tub@reque5t');
await keyman.addKeyboards('1nval1d5tub@reque5t');
break;
case 2:
keyman.addKeyboardsForLanguage(['PigLatn','1337sp34k']);
await keyman.addKeyboardsForLanguage(['PigLatn','1337sp34k']);
break;
}
}

View file

@ -42,8 +42,8 @@
<script>
keyman.init({
attachType:'auto'
}).then(function () {
loadKeyboards(1);
}).then(async function () {
await loadKeyboards();
});
var sentryManager = new KeymanSentryManager();