Skip to content

Commit

Permalink
Add non-optional default parameters in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
otacke committed May 27, 2021
1 parent 532a8a6 commit 923800b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
25 changes: 25 additions & 0 deletions src/components/Util.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 923800b

Please sign in to comment.