Skip to content

Commit 8a453be

Browse files
committed
Make eslint happy
1 parent b08ff0c commit 8a453be

6 files changed

+54
-30
lines changed

src/scripts/components/h5p-ar-scavenger-content-camera.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
import './h5p-ar-scavenger-content-camera.scss';
33
import Util from '@scripts/h5p-ar-scavenger-util.js';
44

5+
/** @constant {number} WAIT_FOR_VIDEO_MAX_MS Maximum time to wait for video. */
6+
const WAIT_FOR_VIDEO_MAX_MS = 10000;
7+
8+
/** @constant {number} WAIT_FOR_VIDEO_TIMEOUT_MS Timeout for waiting for video. */
9+
const WAIT_FOR_VIDEO_TIMEOUT_MS = 100;
10+
511
/** Class representing the subject */
612
export default class ARScavengerContentCamera {
713
/**
@@ -73,7 +79,8 @@ export default class ARScavengerContentCamera {
7379
}
7480
else {
7581
this.container.style.maxWidth = `${document.body.offsetWidth - contentMarginHorizontal}px`;
76-
this.iframe.style.height = `${(this.container.offsetWidth - contentMarginHorizontal) / this.videoRatio || this.params.fallbackHeight}px`;
82+
this.iframe.style.height =
83+
`${(this.container.offsetWidth - contentMarginHorizontal) / this.videoRatio || this.params.fallbackHeight}px`;
7784
}
7885

7986
this.callbacks.onResize();
@@ -235,12 +242,18 @@ export default class ARScavengerContentCamera {
235242
asset.appendChild(assetItem);
236243
scene.appendChild(asset);
237244

238-
const scale = `${marker.model.geometry.scale.scale / 100} ${marker.model.geometry.scale.scale / 100} ${marker.model.geometry.scale.scale / 100}`;
239-
const rotation = `${marker.model.geometry.rotation.x} ${marker.model.geometry.rotation.y} ${marker.model.geometry.rotation.z}`;
240-
const position = `${marker.model.geometry.position.x} ${marker.model.geometry.position.y} ${marker.model.geometry.position.z}`;
245+
// eslint-disable-next-line no-magic-numbers
246+
const scalePercentage = marker.model.geometry.scale.scale / 100;
247+
const scale = `${scalePercentage} ${scalePercentage} ${scalePercentage}`;
248+
249+
const rotationX = marker.model.geometry.rotation.x;
250+
const rotationY = marker.model.geometry.rotation.y;
251+
const rotationZ = marker.model.geometry.rotation.z;
252+
const rotation = `${rotationX} ${rotationY} ${rotationZ}`;
253+
const position = `${rotationX} ${rotationY} ${rotationZ}`;
241254

242255
const entity = document.createElement('a-entity');
243-
entity.setAttribute('gltf-model', '#' + id);
256+
entity.setAttribute('gltf-model', `#${ id}`);
244257
entity.setAttribute('scale', scale);
245258
entity.setAttribute('rotation', rotation);
246259
entity.setAttribute('position', position);
@@ -293,7 +306,7 @@ export default class ARScavengerContentCamera {
293306
* @param {function} callback Callback when video found.
294307
* @param {number} [timeout] Maximum timeout.
295308
*/
296-
waitForVideo(callback, timeout = 10000) {
309+
waitForVideo(callback, timeout = WAIT_FOR_VIDEO_MAX_MS) {
297310
if (!callback) {
298311
return;
299312
}
@@ -308,8 +321,8 @@ export default class ARScavengerContentCamera {
308321
}
309322
else {
310323
setTimeout(() => {
311-
this.waitForVideo(callback, timeout - 100);
312-
}, 100);
324+
this.waitForVideo(callback, timeout - WAIT_FOR_VIDEO_TIMEOUT_MS);
325+
}, WAIT_FOR_VIDEO_TIMEOUT_MS);
313326
}
314327
}
315328

src/scripts/components/h5p-ar-scavenger-content-titlebar.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class ARScavengerContentTitlebar {
3737
this.buttons = {};
3838

3939
// Button for switching views
40-
this.buttons['switchView'] = new ARScavengerButton(
40+
this.buttons.switchView = new ARScavengerButton(
4141
{
4242
a11y: {
4343
inactive: this.params.a11y.buttonSwitchViewAction,
@@ -55,7 +55,7 @@ export default class ARScavengerContentTitlebar {
5555
onClick: this.callbacks.onClickButtonSwitchView
5656
}
5757
);
58-
this.titleBar.appendChild(this.buttons['switchView'].getDOM());
58+
this.titleBar.appendChild(this.buttons.switchView.getDOM());
5959

6060
// Title
6161
const titleDOM = document.createElement('div');
@@ -65,7 +65,7 @@ export default class ARScavengerContentTitlebar {
6565
this.titleBar.appendChild(titleDOM);
6666

6767
// Button for quitting
68-
this.buttons['quit'] = new ARScavengerButton(
68+
this.buttons.quit = new ARScavengerButton(
6969
{
7070
a11y: {
7171
active: this.params.a11y.buttonQuit,
@@ -82,11 +82,11 @@ export default class ARScavengerContentTitlebar {
8282
onClick: this.callbacks.onClickButtonQuit
8383
}
8484
);
85-
this.buttons['quit'].hide();
86-
this.titleBar.appendChild(this.buttons['quit'].getDOM());
85+
this.buttons.quit.hide();
86+
this.titleBar.appendChild(this.buttons.quit.getDOM());
8787

8888
if (this.params.canHasFullScreen) {
89-
this.buttons['fullscreen'] = new ARScavengerButton(
89+
this.buttons.fullscreen = new ARScavengerButton(
9090
{
9191
a11y: {
9292
active: this.params.a11y.buttonFullScreenExit,
@@ -103,7 +103,7 @@ export default class ARScavengerContentTitlebar {
103103
onClick: callbacks.onClickButtonFullScreen
104104
}
105105
);
106-
this.titleBar.appendChild(this.buttons['fullscreen'].getDOM());
106+
this.titleBar.appendChild(this.buttons.fullscreen.getDOM());
107107
}
108108
}
109109

src/scripts/h5p-ar-scavenger-content-setup.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import ARScavengerScreenEnd from '@components/h5p-ar-scavenger-screen-end.js';
55
import ARScavengerScreenStart from '@components/h5p-ar-scavenger-screen-start.js';
66
import Util from './h5p-ar-scavenger-util.js';
77

8+
/** @constant {number} RESIZE_TIMEOUT_MS Resize timeout in ms. */
9+
const RESIZE_TIMEOUT_MS = 100;
10+
811
export default class ContentSetup {
912
/**
1013
* Create titlebar.
@@ -109,7 +112,7 @@ export default class ContentSetup {
109112
this.instances[this.currentInstanceId].trigger('resize');
110113
}
111114
this.resize();
112-
}, 100);
115+
}, RESIZE_TIMEOUT_MS);
113116
});
114117

115118
return camera;

src/scripts/h5p-ar-scavenger-content.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import Util from './h5p-ar-scavenger-util.js';
44
import ContentSetup from './h5p-ar-scavenger-content-setup.js';
55
import ContentHandlers from './h5p-ar-scavenger-content-handlers.js';
66

7+
/** @constant {number} RESIZE_TIMEOUT_MS Resize timeout in ms. */
8+
const RESIZE_TIMEOUT_MS = 100;
9+
710
/** Class representing the content */
811
export default class ARScavengerContent {
912
/**
@@ -243,14 +246,14 @@ export default class ARScavengerContent {
243246
const maxHeight = window.innerHeight - this.titlebar.getDOM().offsetHeight;
244247
this.camera.resizeIframeHeight(maxHeight);
245248
this.action.resizeIframeHeight(maxHeight);
246-
}, 100);
249+
}, RESIZE_TIMEOUT_MS);
247250
}
248251
else {
249252
// Give browser some time to exit from fullscreen mode
250253
setTimeout(() => {
251254
this.camera.resizeIframeHeight(null);
252255
this.action.resizeIframeHeight(null);
253-
}, 100);
256+
}, RESIZE_TIMEOUT_MS);
254257

255258
// FullScreen button cannot know about exiting full screen with escape key
256259
this.titlebar.toggleButtonActive('fullscreen', false);
@@ -281,7 +284,7 @@ export default class ARScavengerContent {
281284
* @returns {boolean} True, if answer was given.
282285
*/
283286
getAnswerGiven() {
284-
return this.instances.some(((instance) => (instance && typeof instance.getAnswerGiven === 'function' && instance.getAnswerGiven())));
287+
return this.instances.some(((instance) => instance?.getAnswerGiven?.()));
285288
}
286289

287290
/**

src/scripts/h5p-ar-scavenger-util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class Util {
9797
}
9898

9999
if (Object.getOwnPropertyNames(masterPrototype).includes(property)) {
100+
// eslint-disable-next-line max-len
100101
throw (`Class ${masterPrototype.constructor.name} already contains ${property}. Cannot add ${mixinPrototype.constructor.name}`);
101102
}
102103

src/scripts/h5p-ar-scavenger.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import './h5p-ar-scavenger.scss';
33
import ARScavengerContent from './h5p-ar-scavenger-content.js';
44
import Util from './h5p-ar-scavenger-util.js';
55

6+
/** @constant {number} FULLSCREEN_TIMEOUT Timout before resizing after entering fullscreen. */
7+
const FULLSCREEN_TIMEOUT = 250;
8+
9+
/** @constant {string} DEFAULT_DESCRIPTION Default content type description. */
10+
const DEFAULT_DESCRIPTION = 'ARScavenger';
11+
12+
/** @constant {number} MIN_WIDTH_FOR_DUALVIEW Breakpoint for dual view. */
13+
const MIN_WIDTH_FOR_DUALVIEW = 1024;
14+
615
/** Class representing ARScavenger */
716
export default class ARScavenger extends H5P.Question {
817
/**
@@ -44,6 +53,7 @@ export default class ARScavenger extends H5P.Question {
4453
errorNoCameraAccess: 'Could not access camera.',
4554
errorNoCameraSupport: 'Your browser does not seem to support a camera.',
4655
errorNoMarkers: 'Did someone forget to add markers?',
56+
// eslint-disable-next-line max-len
4757
warningBrave: 'You seem to be using the Brave browser. Nice! But its strict privacy settings may prevent the camera from working.',
4858
initializingContent: 'Initializing content. Please don\'t forget to allow camera access.'
4959
},
@@ -58,7 +68,7 @@ export default class ARScavenger extends H5P.Question {
5868
actionOpened: 'The view has switched to an exercise.',
5969
actionClosed: 'The view has switched to the camera.',
6070
},
61-
minWidthForDualView: ARScavenger.MIN_WIDTH_FOR_DUALVIEW
71+
minWidthForDualView: MIN_WIDTH_FOR_DUALVIEW
6272
}, params);
6373

6474
// Filter out incomplete markers
@@ -85,7 +95,7 @@ export default class ARScavenger extends H5P.Question {
8595
setTimeout(() => {
8696
this.content.setFullScreen(true);
8797
this.isInFullScreen = true;
88-
}, 250); // Needs time to get into fullscreen for window.innerHeight
98+
}, FULLSCREEN_TIMEOUT); // Needs time to get into fullscreen for window.innerHeight
8999
});
90100

91101
this.on('exitFullScreen', () => {
@@ -113,7 +123,7 @@ export default class ARScavenger extends H5P.Question {
113123
registerDomElements() {
114124
// On desktop, action might be wanted to be open on startup
115125
this.params.behaviour.showActionOnStartup = this.params.behaviour.showActionOnStartup &&
116-
document.querySelector('.h5p-container').offsetWidth >= ARScavenger.MIN_WIDTH_FOR_DUALVIEW;
126+
document.querySelector('.h5p-container').offsetWidth >= MIN_WIDTH_FOR_DUALVIEW;
117127

118128
this.content = new ARScavengerContent(this.params, this.contentId, this.extras, {
119129
onFullScreen: () => {
@@ -318,7 +328,7 @@ export default class ARScavenger extends H5P.Question {
318328
if (this.extras.metadata) {
319329
raw = this.extras.metadata.title;
320330
}
321-
raw = raw || ARScavenger.DEFAULT_DESCRIPTION;
331+
raw = raw || DEFAULT_DESCRIPTION;
322332

323333
return H5P.createTitle(raw);
324334
}
@@ -328,7 +338,7 @@ export default class ARScavenger extends H5P.Question {
328338
* @returns {string} Description.
329339
*/
330340
getDescription() {
331-
return this.params.taskDescription || ARScavenger.DEFAULT_DESCRIPTION;
341+
return this.params.taskDescription || DEFAULT_DESCRIPTION;
332342
}
333343

334344
/**
@@ -344,9 +354,3 @@ export default class ARScavenger extends H5P.Question {
344354
return this.content.getCurrentState();
345355
}
346356
}
347-
348-
/** @constant {string} */
349-
ARScavenger.DEFAULT_DESCRIPTION = 'ARScavenger';
350-
351-
/** @constant {number} */
352-
ARScavenger.MIN_WIDTH_FOR_DUALVIEW = 1024;

0 commit comments

Comments
 (0)