-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
173 lines (162 loc) · 5.37 KB
/
index.html
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MT4Everyone activity explorer</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<style>
body {
margin: 10px 10% 20px 10%;
background-color: white;
}
#h5p-container {
border: 1px solid grey;
}
#current {
margin-top: 10px;
margin-bottom: 10px;
font-size: 80%;
color: gray;
}
#box {
padding: 20px;
border: 1px solid lightgrey;
}
footer {
margin-top: 25px;
text-align: right;
margin-bottom: 15px;
}
footer img {
height: 70px;
margin-left: 30px;
}
header a:link, header a:visited, header a:hover, header a:active {
color: gray;
}
</style>
<script src='./h5p-standalone/dist/main.bundle.js'></script>
</head>
<body>
<header>
<h1>Machine translation for everyone</h1>
<h2>Learning activity explorer</h2>
<p>
<a href="https://github.com/jaspock/mt4everyone">About</a> <img style="height:1em;" src="./assets/logo-github.png" alt="Github logo"></img>
</p>
</header>
<form class="row g-3">
<div class="col-md-6">
<!-- <label for="modules" class="form-label">Select chapter</label> -->
<select id="modules" class="form-select" aria-label="Select chapter to show activities for"></select>
</div>
<div class="col-md-6">
<button type='button' id='previous' class="btn btn-primary">Previous</button>
<button type='button' id='next' class="btn btn-primary">Next</button>
</div>
</form>
<div id='current'></div>
<div id='box'>
<h3 id='title'></h3>
<div id='h5p-container'></div>
</div>
<script>
var activities = null;
var activity = -1;
var module = null;
var data = null;
const options = {
h5pJsonPath: null,
frameJs: './h5p-standalone/dist/frame.bundle.js',
frameCss: './h5p-standalone/dist/styles/h5p.css',
frame: true,
copyright: true,
export: true,
icon: true,
downloadUrl: null,
fullScreen: false,
embed: false,
};
async function changeModule (event) {
module = event.target.value;
activities = data[module].activities;
activity = -1
await showActivity();
}
async function populateModules() {
const list = document.getElementById('modules');
list.innerHTML = '';
const response = await fetch('./activities/config.json');
data = await response.json();
for(const m of data.modules) {
list.innerHTML += `<option value=${m}>${data[m].title}</option>`;
}
if (window.location.search.startsWith("?q=") && window.location.search.length >= 8) {
var query = window.location.search.substr(3);
var mod = parseInt(query[1]);
var act = query;
if (mod >= 1 && mod <= 9) {
module = data.modules[mod-1];
activities = data[module].activities;
activity = activities.indexOf(act) != -1 ? activities.indexOf(act) - 1 : -1; // indexOf returns -1 if activity not found
document.getElementById("modules").selectedIndex = mod-1;
}
else {
module = data.modules[0];
activities = data[module].activities;
activity = -1;
}
}
else {
module = data.modules[0];
activities = data[module].activities;
activity = -1;
}
await showActivity();
}
async function showActivity (event) {
if (event === undefined) {
var event = {currentTarget: {id: 'next'}};
}
if (event.currentTarget.id === 'next') {
activity= (activity+1 === activities.length) ? 0 : activity+1;
}
else {
activity= (activity === 0) ? activities.length-1 : activity-1;
}
console.log(activity);
const h5p = document.getElementById('h5p-container');
const title = document.getElementById('title');
const newurl = window.location.protocol + "//" + window.location.host
+ ("/" + window.location.pathname ? window.location.pathname : "")
+ `?q=${activities[activity]}`;
window.history.replaceState(activities[activity], activities[activity], newurl);
document.title = activities[activity]
h5p.innerHTML= '';
options.h5pJsonPath = `./activities/${module}/${activities[activity]}`;
options.downloadUrl = `./activities/${module}/${activities[activity]}.h5p`;
await new H5PStandalone.H5P(h5p, options);
const response = await fetch(`./activities/${module}/${activities[activity]}/h5p.json`);
const metadata = await response.json();
title.innerHTML = metadata.title;
const current = document.getElementById('current');
current.textContent = `Activity: ${activity+1}/${activities.length}`;
}
async function main() {
const bp = document.getElementById('previous');
bp.addEventListener('click', showActivity);
const bn = document.getElementById('next');
bn.addEventListener('click', showActivity);
const s = document.getElementById('modules');
s.addEventListener('change', changeModule);
await populateModules();
}
main();
</script>
<footer>
<a href="https://multitrainmt.eu"><img src="./assets/logo-multitrainmt.png" alt="MultitraiNMT logo"></a>
<img src="./assets/logo-erasmusplus.png" alt="Erasmus+ logo">
</footer>
</body>
</html>