-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
191 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/scripts/components/exercise-screen/timer-display.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import './timer-display.scss'; | ||
|
||
/** Class representing a timer on screen */ | ||
export default class TimerDisplay { | ||
/** | ||
* @class | ||
*/ | ||
constructor() { | ||
this.handleNotifyingEnded = this.handleNotifyingEnded.bind(this); | ||
|
||
this.dom = document.createElement('div'); | ||
this.dom.classList.add('h5p-game-map-exercise-headline-timer'); | ||
|
||
this.hide(); | ||
} | ||
|
||
/** | ||
* Get DOM. | ||
* @returns {HTMLElement} DOM. | ||
*/ | ||
getDOM() { | ||
return this.dom; | ||
} | ||
|
||
/** | ||
* Show. | ||
*/ | ||
show() { | ||
if ((this.dom.innerText || '') === '') { | ||
return; | ||
} | ||
|
||
this.dom.classList.remove('display-none'); | ||
} | ||
|
||
/** | ||
* Hide. | ||
*/ | ||
hide() { | ||
this.dom.classList.add('display-none'); | ||
|
||
this.handleNotifyingEnded(); | ||
} | ||
|
||
/** | ||
* Set time. | ||
* @param {number} timeMs Time in milliseconds. | ||
*/ | ||
setTime(timeMs) { | ||
if (timeMs === null || timeMs === '') { | ||
this.dom.innerText = ''; | ||
this.hide(); | ||
return; | ||
} | ||
|
||
if (typeof timeMs !== 'number') { | ||
return; | ||
} | ||
|
||
const date = new Date(0); | ||
date.setSeconds(Math.round(Math.max(0, timeMs / 1000))); | ||
|
||
this.dom.innerText = date | ||
.toISOString() | ||
.split('T')[1] | ||
.split('.')[0] | ||
.replace(/^[0:]+/, '') || '0'; | ||
|
||
this.show(); | ||
} | ||
|
||
/** | ||
* Set timeout warning. | ||
* @param {boolean} state If true, set warning state. Else hide. | ||
*/ | ||
setTimeoutWarning(state) { | ||
if (!this.isTimeoutwarning && state) { | ||
this.notify(); // Only notify if not yet notified. | ||
} | ||
this.isTimeoutwarning = state; | ||
|
||
this.dom.classList.toggle('timeout-warning', state); | ||
} | ||
|
||
/** | ||
* Notify about timeout warning. | ||
*/ | ||
notify() { | ||
this.dom.addEventListener( | ||
'animationend', this.handleNotifyingEnded | ||
); | ||
|
||
this.dom.classList.add('notify-animation'); | ||
} | ||
|
||
/** | ||
* Handle notification ended. | ||
*/ | ||
handleNotifyingEnded() { | ||
this.dom.removeEventListener( | ||
'animationend', this.handleNotifyingEnded | ||
); | ||
this.dom.classList.remove('notify-animation'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
.h5p-game-map-exercise-headline-timer { | ||
font-size: 1.25rem; | ||
font-weight: bold; | ||
justify-self: flex-end; | ||
|
||
&.timeout-warning { | ||
color: #bb0000; | ||
} | ||
|
||
&::before { | ||
content: "\f017"; | ||
font-family: "H5PFontAwesome4", sans-serif; | ||
margin-right: 0.5rem; | ||
} | ||
|
||
&.display-none { | ||
display: none; | ||
} | ||
|
||
&.notify-animation { | ||
animation: pulse; | ||
animation-duration: 1s; | ||
animation-timing-function: ease-in-out; | ||
} | ||
|
||
@keyframes pulse { | ||
0% { | ||
transform: scale3d(1, 1, 1); | ||
} | ||
|
||
50% { | ||
transform: scale3d(1.25, 1.25, 1.25); | ||
} | ||
|
||
100% { | ||
transform: scale3d(1, 1, 1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters