Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

fix(chronoquiz #13

Merged
merged 1 commit into from
Dec 8, 2020
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
2 changes: 1 addition & 1 deletion src/editor-mathfield/keyboard-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export function onTypedText(
if (mathfield.options.keypressVibration && navigator?.vibrate) {
navigator.vibrate(HAPTIC_FEEDBACK_DURATION);
}
mathfield.keypressSound?.play().catch(console.warn);
//mathfield.keypressSound?.play().catch(console.warn);
}
//
// 2/ Switch mode if requested
Expand Down
35 changes: 14 additions & 21 deletions src/editor-mathfield/mathfield-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ export class MathfieldPrivate implements Mathfield {

private eventHandlingInProgress = '';

keypressSound: HTMLAudioElement;
spacebarKeypressSound: HTMLAudioElement;
returnKeypressSound: HTMLAudioElement;
deleteKeypressSound: HTMLAudioElement;
plonkSound: HTMLAudioElement;
keypressSound: boolean | HTMLAudioElement;
spacebarKeypressSound: boolean | HTMLAudioElement;
returnKeypressSound: boolean | HTMLAudioElement;
deleteKeypressSound: boolean | HTMLAudioElement;
plonkSound: boolean | HTMLAudioElement;

/**
* To create a mathfield, you would typically use {@linkcode makeMathField | MathLive.makeMathField()}
Expand All @@ -174,20 +174,13 @@ export class MathfieldPrivate implements Mathfield {
...options,
});

this.plonkSound = this.options.plonkSound as HTMLAudioElement;
if (
typeof this.options.keypressSound !== 'string' &&
!(this.options.keypressSound instanceof HTMLAudioElement)
) {
this.keypressSound = this.options.keypressSound
.default as HTMLAudioElement;
this.spacebarKeypressSound = this.options.keypressSound
.spacebar as HTMLAudioElement;
this.returnKeypressSound = this.options.keypressSound
.return as HTMLAudioElement;
this.deleteKeypressSound = this.options.keypressSound
.delete as HTMLAudioElement;
}
this.plonkSound = false

this.keypressSound = false
this.spacebarKeypressSound = false
this.returnKeypressSound = false
this.deleteKeypressSound = false


this.element = element;
element['mathfield'] = this;
Expand Down Expand Up @@ -578,7 +571,7 @@ export class MathfieldPrivate implements Mathfield {
);

this.plonkSound = this.options.plonkSound as HTMLAudioElement;
if (
if ( this.options.keypressSound &&
typeof this.options.keypressSound !== 'string' &&
!(this.options.keypressSound instanceof HTMLAudioElement)
) {
Expand Down Expand Up @@ -1031,7 +1024,7 @@ export class MathfieldPrivate implements Mathfield {
if (this.options.keypressVibration && navigator?.vibrate) {
navigator.vibrate(HAPTIC_FEEDBACK_DURATION);
}
this.keypressSound?.play();
//this.keypressSound?.play();
}
if (s === '\\\\') {
// This string is interpreted as an "insert row after" command
Expand Down
2 changes: 1 addition & 1 deletion src/editor/a11y.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function defaultAnnounceHook(
if (action === 'plonk') {
// Use this sound to indicate minor errors, for
// example when an action has no effect.
mathfield.plonkSound?.play().catch((err) => console.warn(err));
//mathfield.plonkSound?.play().catch((err) => console.warn(err));
// As a side effect, reset the keystroke buffer
mathfield.resetKeystrokeBuffer();
} else if (action === 'delete') {
Expand Down
6 changes: 3 additions & 3 deletions src/editor/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function performWithFeedback(
selector === 'moveToPreviousPlaceholder' ||
selector === 'complete'
) {
mathfield.returnKeypressSound?.play().catch(console.warn);
//mathfield.returnKeypressSound?.play().catch(console.warn);
} else if (
selector === 'deleteBackward' ||
selector === 'deleteForward' ||
Expand All @@ -165,9 +165,9 @@ export function performWithFeedback(
selector === 'deleteToMathFieldStart' ||
selector === 'deleteToMathFieldEnd'
) {
mathfield.deleteKeypressSound?.play().catch(console.warn);
//mathfield.deleteKeypressSound?.play().catch(console.warn);
} else {
mathfield.keypressSound?.play().catch(console.warn);
//mathfield.keypressSound?.play().catch(console.warn);
}
return mathfield.executeCommand(selector);
}
Expand Down
52 changes: 2 additions & 50 deletions src/editor/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,58 +163,10 @@ export function update(
}
break;
case 'plonkSound':
unloadSound(result.plonkSound);
result.plonkSound = loadSound(
soundsDirectory,
updates.plonkSound
);
break;
case 'keypressSound':
unloadSound(result.keypressSound);
if (typeof updates.keypressSound === 'string') {
const sound = loadSound(
soundsDirectory,
updates.keypressSound
);
result.keypressSound = {
delete: sound,
return: sound,
spacebar: sound,
default: sound,
};
} else if (updates.keypressSound instanceof HTMLAudioElement) {
result.keypressSound = {
delete: updates.keypressSound,
return: updates.keypressSound,
spacebar: updates.keypressSound,
default: updates.keypressSound,
};
} else {
if (!updates.keypressSound.default) {
throw Error('Missing keypressSound.default');
}
result.keypressSound = { ...updates.keypressSound };
result.keypressSound.default = loadSound(
soundsDirectory,
result.keypressSound.default
);
result.keypressSound.delete =
loadSound(
soundsDirectory,
result.keypressSound.delete
) ?? updates.keypressSound.default;
result.keypressSound.return =
loadSound(
soundsDirectory,
result.keypressSound.return
) ?? updates.keypressSound.default;
result.keypressSound.spacebar =
loadSound(
soundsDirectory,
result.keypressSound.spacebar
) ?? updates.keypressSound.default;
}
break;

case 'onBlur':
case 'onFocus':
case 'onContentWillChange':
Expand Down Expand Up @@ -329,7 +281,7 @@ export function getDefault(): Required<MathfieldOptionsPrivate> {
virtualKeyboardTheme: /android|cros/i.test(navigator?.userAgent)
? 'material'
: 'apple',
keypressVibration: true,
keypressVibration: false,
keypressSound: null,
plonkSound: null,
virtualKeyboardToolbar: 'default',
Expand Down