From 8cb4e8da1b47c57206f46a7db8f7a20de9da3d34 Mon Sep 17 00:00:00 2001 From: mderrier Date: Tue, 8 Dec 2020 12:30:18 +0100 Subject: [PATCH] fix(chronoquiz --- src/editor-mathfield/keyboard-input.ts | 2 +- src/editor-mathfield/mathfield-private.ts | 35 ++++++--------- src/editor/a11y.ts | 2 +- src/editor/commands.ts | 6 +-- src/editor/options.ts | 52 +---------------------- 5 files changed, 21 insertions(+), 76 deletions(-) diff --git a/src/editor-mathfield/keyboard-input.ts b/src/editor-mathfield/keyboard-input.ts index d38fd6ef9..16103591b 100644 --- a/src/editor-mathfield/keyboard-input.ts +++ b/src/editor-mathfield/keyboard-input.ts @@ -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 diff --git a/src/editor-mathfield/mathfield-private.ts b/src/editor-mathfield/mathfield-private.ts index a3f1c14df..0c3422543 100644 --- a/src/editor-mathfield/mathfield-private.ts +++ b/src/editor-mathfield/mathfield-private.ts @@ -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()} @@ -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; @@ -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) ) { @@ -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 diff --git a/src/editor/a11y.ts b/src/editor/a11y.ts index f27651000..0f96b2494 100644 --- a/src/editor/a11y.ts +++ b/src/editor/a11y.ts @@ -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') { diff --git a/src/editor/commands.ts b/src/editor/commands.ts index 89645a96e..a42b18f13 100644 --- a/src/editor/commands.ts +++ b/src/editor/commands.ts @@ -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' || @@ -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); } diff --git a/src/editor/options.ts b/src/editor/options.ts index 5b7ee28e0..be7d64f84 100644 --- a/src/editor/options.ts +++ b/src/editor/options.ts @@ -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': @@ -329,7 +281,7 @@ export function getDefault(): Required { virtualKeyboardTheme: /android|cros/i.test(navigator?.userAgent) ? 'material' : 'apple', - keypressVibration: true, + keypressVibration: false, keypressSound: null, plonkSound: null, virtualKeyboardToolbar: 'default',