-
Notifications
You must be signed in to change notification settings - Fork 0
/
js.js
37 lines (34 loc) · 985 Bytes
/
js.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Check some things on load.
*/
jQuery(document).ready(function($) {
$('.audio-play-once-true > audio').each(function () {
// get md5 of the audio-filename
let fileMd5 = $.md5($(this).attr('src'));
// check if audio has already played on load
playOnceCheckState( $(this), fileMd5 );
// check if audio has already played on play
// and mark it als played
$(this).on('play', function () {
playOnceCheckState( $(this), fileMd5 );
// set marker that audio-file has been played
sessionStorage.setItem('audioPlayed' + fileMd5, '1');
});
});
});
/**
* Check if audio has been played.
*
* If yes:
* - empty the src-attribute
* - add disabled-class
*
* @param obj
* @param fileMd5
*/
function playOnceCheckState( obj, fileMd5 ) {
if( sessionStorage.getItem('audioPlayed' + fileMd5) != null ) {
obj.attr('src', '');
obj.addClass('disabled');
}
}