From 923800b451341ccf226a678db69a415719f55028 Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Thu, 24 Sep 2020 13:09:35 +0200 Subject: [PATCH 1/2] Add non-optional default parameters in constructor --- src/app.js | 24 ++++++++++++++++++++++++ src/components/Util.js | 25 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/components/Util.js diff --git a/src/app.js b/src/app.js index 05ca316..caa0b3f 100644 --- a/src/app.js +++ b/src/app.js @@ -29,6 +29,30 @@ export default class { * @param {object} contentData */ constructor(params, contentId, contentData = {}) { + params = Util.extend({ + l10n: { + recordAnswer: 'Record', + pause: 'Pause', + continue: 'Continue', + download: 'Download', + done: 'Done', + retry: 'Retry', + microphoneNotSupported: 'Microphone not supported. Make sure you are using a browser that allows microphone recording.', + microphoneInaccessible: 'Microphone is not accessible. Make sure that the browser microphone is enabled.', + insecureNotAllowed: 'Access to microphone is not allowed in your browser since this page is not served using HTTPS. Please contact the author, and ask him to make this available using HTTPS', + statusReadyToRecord: 'Press a button below to record your answer.', + statusRecording: 'Recording...', + statusPaused: 'Recording paused. Press a button to continue recording.', + statusFinishedRecording: 'You have successfully recorded your answer! Listen to the recording below.', + downloadRecording: 'Download this recording or retry.', + retryDialogHeaderText: 'Retry recording?', + retryDialogBodyText: 'By pressing "Retry" you will lose your current recording.', + retryDialogConfirmText: 'Retry', + retryDialogCancelText: 'Cancel', + statusCantCreateTheAudioFile: 'Can\'t create the audio file.' + } + }, params); + const rootElement = document.createElement('div'); rootElement.classList.add('h5p-audio-recorder'); diff --git a/src/components/Util.js b/src/components/Util.js new file mode 100644 index 0000000..9104434 --- /dev/null +++ b/src/components/Util.js @@ -0,0 +1,25 @@ +/** Class for utility functions */ +class Util { + /** + * Extend an array just like JQuery's extend. + * @param {object} arguments Objects to be merged. + * @return {object} Merged objects. + */ + static extend() { + for (let i = 1; i < arguments.length; i++) { + for (let key in arguments[i]) { + if (arguments[i].hasOwnProperty(key)) { + if (typeof arguments[0][key] === 'object' && typeof arguments[i][key] === 'object') { + this.extend(arguments[0][key], arguments[i][key]); + } + else { + arguments[0][key] = arguments[i][key]; + } + } + } + } + return arguments[0]; + } +} + +export default Util; From 799639ffc368b0887931607408a285960fbc8341 Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Tue, 31 Aug 2021 11:17:39 +0200 Subject: [PATCH 2/2] Import Util --- src/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app.js b/src/app.js index caa0b3f..ac7464a 100644 --- a/src/app.js +++ b/src/app.js @@ -4,6 +4,7 @@ import VUMeter from './views/VUMeter.vue'; import Timer from './views/Timer.vue'; import Recorder from 'components/Recorder'; import State from 'components/State'; +import Util from 'components/Util'; const AUDIO_SRC_NOT_SPECIFIED = '';