jclic 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/README.md +5 -7
  2. package/dist-node/jclic-node.js +14157 -0
  3. package/dist-node/jclic-node.umd.cjs +530 -0
  4. package/package.json +38 -26
  5. package/.vscode/launch.json +0 -33
  6. package/.vscode/settings.json +0 -13
  7. package/CHANGELOG.md +0 -664
  8. package/TRANSLATIONS.md +0 -11
  9. package/build-locales.mjs +0 -82
  10. package/dist/jclic-node.js +0 -31678
  11. package/dist/jclic-node.js.map +0 -1
  12. package/dist/jclic.components.LICENSE +0 -2254
  13. package/dist/jclic.min.js +0 -27
  14. package/dist/jclic.min.js.map +0 -1
  15. package/eslint.config.mjs +0 -31
  16. package/jsdoc.config.js +0 -71
  17. package/locales/ar.po +0 -244
  18. package/locales/ast.po +0 -246
  19. package/locales/bs.po +0 -247
  20. package/locales/ca.po +0 -248
  21. package/locales/ca_ES@valencia.po +0 -248
  22. package/locales/cs.po +0 -244
  23. package/locales/da.po +0 -244
  24. package/locales/de.po +0 -246
  25. package/locales/el.po +0 -244
  26. package/locales/es.po +0 -248
  27. package/locales/eu.po +0 -244
  28. package/locales/fr.po +0 -244
  29. package/locales/gl.po +0 -244
  30. package/locales/he.po +0 -244
  31. package/locales/hr.po +0 -245
  32. package/locales/it.po +0 -246
  33. package/locales/ja.po +0 -242
  34. package/locales/jclic.js.pot +0 -241
  35. package/locales/nb_NO.po +0 -244
  36. package/locales/nl.po +0 -244
  37. package/locales/pl.po +0 -244
  38. package/locales/pt.po +0 -244
  39. package/locales/pt_BR.po +0 -248
  40. package/locales/ro.po +0 -248
  41. package/locales/ru.po +0 -245
  42. package/locales/ta.po +0 -244
  43. package/locales/tr.po +0 -246
  44. package/locales/uk.po +0 -247
  45. package/locales/vec.po +0 -244
  46. package/locales/zh_TW.po +0 -246
  47. package/patches/po2json+1.0.0-beta-3.patch +0 -12
  48. package/src/AWT.js +0 -2067
  49. package/src/Activity.js +0 -1311
  50. package/src/Deps.js +0 -232
  51. package/src/GlobalData.js +0 -5
  52. package/src/JClic.js +0 -196
  53. package/src/JClicPlayer.js +0 -1308
  54. package/src/PlayerHistory.js +0 -305
  55. package/src/Utils.js +0 -1355
  56. package/src/activities/associations/ComplexAssociation.js +0 -321
  57. package/src/activities/associations/SimpleAssociation.js +0 -519
  58. package/src/activities/memory/MemoryGame.js +0 -423
  59. package/src/activities/panels/Explore.js +0 -349
  60. package/src/activities/panels/Identify.js +0 -356
  61. package/src/activities/panels/InformationScreen.js +0 -262
  62. package/src/activities/panels/Menu.js +0 -209
  63. package/src/activities/panels/icons/ico00.png +0 -0
  64. package/src/activities/panels/icons/ico01.png +0 -0
  65. package/src/activities/panels/icons/ico02.png +0 -0
  66. package/src/activities/panels/icons/ico03.png +0 -0
  67. package/src/activities/panels/icons/icofolder.png +0 -0
  68. package/src/activities/puzzles/DoublePuzzle.js +0 -424
  69. package/src/activities/puzzles/ExchangePuzzle.js +0 -374
  70. package/src/activities/puzzles/HolePuzzle.js +0 -360
  71. package/src/activities/text/Complete.js +0 -127
  72. package/src/activities/text/Evaluator.js +0 -534
  73. package/src/activities/text/FillInBlanks.js +0 -426
  74. package/src/activities/text/IdentifyText.js +0 -253
  75. package/src/activities/text/OrderText.js +0 -421
  76. package/src/activities/text/TextActivityBase.js +0 -557
  77. package/src/activities/text/TextActivityDocument.js +0 -658
  78. package/src/activities/text/WrittenAnswer.js +0 -557
  79. package/src/activities/textGrid/CrossWord.js +0 -565
  80. package/src/activities/textGrid/WordSearch.js +0 -458
  81. package/src/activities/textGrid/icons/hIcon.svg +0 -3
  82. package/src/activities/textGrid/icons/vIcon.svg +0 -3
  83. package/src/automation/AutoContentProvider.js +0 -182
  84. package/src/automation/arith/Arith.js +0 -864
  85. package/src/bags/ActivitySequence.js +0 -318
  86. package/src/bags/ActivitySequenceElement.js +0 -161
  87. package/src/bags/ActivitySequenceJump.js +0 -140
  88. package/src/bags/ConditionalJumpInfo.js +0 -113
  89. package/src/bags/JumpInfo.js +0 -136
  90. package/src/bags/MediaBag.js +0 -215
  91. package/src/bags/MediaBagElement.js +0 -516
  92. package/src/boxes/AbstractBox.js +0 -699
  93. package/src/boxes/ActiveBagContent.js +0 -494
  94. package/src/boxes/ActiveBox.js +0 -810
  95. package/src/boxes/ActiveBoxBag.js +0 -357
  96. package/src/boxes/ActiveBoxContent.js +0 -484
  97. package/src/boxes/ActiveBoxGrid.js +0 -179
  98. package/src/boxes/BoxBag.js +0 -500
  99. package/src/boxes/BoxBase.js +0 -398
  100. package/src/boxes/BoxConnector.js +0 -325
  101. package/src/boxes/TextGrid.js +0 -887
  102. package/src/boxes/TextGridContent.js +0 -215
  103. package/src/init-jsdom.js +0 -65
  104. package/src/jclic-node.js +0 -219
  105. package/src/media/ActiveMediaBag.js +0 -145
  106. package/src/media/ActiveMediaPlayer.js +0 -297
  107. package/src/media/AudioBuffer.js +0 -219
  108. package/src/media/EventSounds.js +0 -169
  109. package/src/media/EventSoundsElement.js +0 -155
  110. package/src/media/MediaContent.js +0 -328
  111. package/src/media/MidiAudioPlayer.js +0 -254
  112. package/src/media/icons/audio.svg +0 -3
  113. package/src/media/icons/generic.svg +0 -3
  114. package/src/media/icons/mic.svg +0 -3
  115. package/src/media/icons/movie.svg +0 -3
  116. package/src/media/icons/music.svg +0 -3
  117. package/src/media/icons/url.svg +0 -3
  118. package/src/media/sounds/actionError.mp3 +0 -0
  119. package/src/media/sounds/actionOk.mp3 +0 -0
  120. package/src/media/sounds/click.mp3 +0 -0
  121. package/src/media/sounds/finishedError.mp3 +0 -0
  122. package/src/media/sounds/finishedOk.mp3 +0 -0
  123. package/src/media/sounds/start.mp3 +0 -0
  124. package/src/project/JClicProject.js +0 -282
  125. package/src/project/ProjectSettings.js +0 -273
  126. package/src/report/ActionReg.js +0 -123
  127. package/src/report/ActivityReg.js +0 -271
  128. package/src/report/EncryptMin.js +0 -210
  129. package/src/report/Reporter.js +0 -727
  130. package/src/report/SCORM.js +0 -272
  131. package/src/report/SequenceReg.js +0 -275
  132. package/src/report/SessionReg.js +0 -340
  133. package/src/report/SessionStorageReporter.js +0 -131
  134. package/src/report/TCPReporter.js +0 -628
  135. package/src/shapers/ClassicJigSaw.js +0 -138
  136. package/src/shapers/Holes.js +0 -77
  137. package/src/shapers/JigSaw.js +0 -161
  138. package/src/shapers/Rectangular.js +0 -78
  139. package/src/shapers/Shaper.js +0 -386
  140. package/src/shapers/TriangularJigSaw.js +0 -121
  141. package/src/skins/BlueSkin.js +0 -80
  142. package/src/skins/Counter.js +0 -152
  143. package/src/skins/CustomSkin.js +0 -412
  144. package/src/skins/DefaultSkin.js +0 -376
  145. package/src/skins/EmptySkin.js +0 -82
  146. package/src/skins/GreenSkin.js +0 -94
  147. package/src/skins/MiniSkin.js +0 -130
  148. package/src/skins/OrangeSkin.js +0 -78
  149. package/src/skins/SimpleSkin.js +0 -92
  150. package/src/skins/Skin.js +0 -1021
  151. package/src/skins/assets/actionsIcon.svg +0 -3
  152. package/src/skins/assets/appLogo.svg +0 -8
  153. package/src/skins/assets/basic.css +0 -41
  154. package/src/skins/assets/closeDialogIcon.svg +0 -3
  155. package/src/skins/assets/closeIcon.svg +0 -3
  156. package/src/skins/assets/copyIcon.svg +0 -3
  157. package/src/skins/assets/fullScreenExitIcon.svg +0 -3
  158. package/src/skins/assets/fullScreenIcon.svg +0 -3
  159. package/src/skins/assets/infoIcon.svg +0 -3
  160. package/src/skins/assets/main.css +0 -43
  161. package/src/skins/assets/mainHalf.css +0 -23
  162. package/src/skins/assets/mainTwoThirds.css +0 -23
  163. package/src/skins/assets/mini.css +0 -15
  164. package/src/skins/assets/nextIcon.svg +0 -3
  165. package/src/skins/assets/okDialogIcon.svg +0 -3
  166. package/src/skins/assets/prevIcon.svg +0 -3
  167. package/src/skins/assets/reports.css +0 -156
  168. package/src/skins/assets/reportsIcon.svg +0 -3
  169. package/src/skins/assets/scoreIcon.svg +0 -3
  170. package/src/skins/assets/simple.css +0 -16
  171. package/src/skins/assets/simpleHalf.css +0 -11
  172. package/src/skins/assets/simpleTwoThirds.css +0 -11
  173. package/src/skins/assets/timeIcon.svg +0 -4
  174. package/src/skins/assets/waitAnim.css +0 -54
  175. package/src/skins/assets/waitImgBig.svg +0 -3
  176. package/src/skins/assets/waitImgSmall.svg +0 -3
  177. package/webpack.config.mjs +0 -169
@@ -1,340 +0,0 @@
1
- /**
2
- * File : report/SessionReg.js
3
- * Created : 17/05/2016
4
- * By : Francesc Busquets <francesc@gmail.com>
5
- *
6
- * JClic.js
7
- * An HTML5 player of JClic activities
8
- * https://projectestac.github.io/jclic.js
9
- *
10
- * @source https://github.com/projectestac/jclic.js
11
- *
12
- * @license EUPL-1.2
13
- * @licstart
14
- * (c) 2000-2020 Catalan Educational Telematic Network (XTEC)
15
- *
16
- * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by
17
- * the European Commission- subsequent versions of the EUPL (the "Licence");
18
- * You may not use this work except in compliance with the Licence.
19
- *
20
- * You may obtain a copy of the Licence at:
21
- * https://joinup.ec.europa.eu/software/page/eupl
22
- *
23
- * Unless required by applicable law or agreed to in writing, software
24
- * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
25
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
26
- * Licence for the specific language governing permissions and limitations
27
- * under the Licence.
28
- * @licend
29
- * @module
30
- */
31
-
32
- import SequenceReg from './SequenceReg.js';
33
-
34
- /**
35
- * This class encapsulates data of a user's working session, usually associated to a single {@link module:project/JClicProject.JClicProject JClicProject}
36
- * It's main component is `sequences`, an array of {@link module:report/SequenceReg.SequenceReg SequenceReg} objects.
37
- */
38
- export class SessionReg {
39
- /**
40
- * SessionReg constructor
41
- * @param {module:project/JClicProject.JClicProject} project - The JClicProject referenced by this session.
42
- * @param {string} [code] - Optional code to be used by this SessionReg
43
- */
44
- constructor(project, code) {
45
- this.projectName = project.name;
46
- this.code = code || project.code;
47
- this.sequences = [];
48
- this.actNames = [];
49
- this.started = new Date();
50
- this.info = new SessionRegInfo(this);
51
- this.reportableActs = project.reportableActs;
52
- }
53
-
54
- /**
55
- * Builds a complex object with the results of all activities done during this working session
56
- * @param {boolean} recalcInfo - When `true`, global variables (number of sequences, score, total time...)
57
- * will be recalculated from the data stored in the {@link module:report/SequenceReg.SequenceReg SequenceReg} objects.
58
- * @param {boolean} includeEmpty - When `true`, sequences without reported activities will be also included in the results
59
- * @returns {object} - An object containing the full session data
60
- */
61
- getData(recalcInfo, includeEmpty) {
62
- if (recalcInfo)
63
- this.info.recalc();
64
-
65
- const result = {
66
- projectName: this.projectName,
67
- played: this.info.nActivities,
68
- ratioPlayed: Math.round(this.info.ratioPlayed * 100),
69
- solved: this.info.nActSolved,
70
- ratioSolved: Math.round(this.info.ratioSolved * 100),
71
- actions: this.info.nActions,
72
- score: this.info.tScore,
73
- time: Math.round(this.info.tTime / 10) / 100,
74
- sequences: []
75
- };
76
-
77
- this.sequences.forEach(s => {
78
- const seq = s.getData();
79
- if (includeEmpty || seq.activities.length > 0)
80
- result.sequences.push(seq);
81
- });
82
- return result;
83
- }
84
-
85
- /**
86
- * Returns the `info` element associated to this SessionReg.
87
- * @returns {module:report/SessionReg.SessionRegInfo}
88
- */
89
- getInfo() {
90
- return this.info.recalc();
91
- }
92
-
93
- /**
94
- * Closes this session
95
- */
96
- end() {
97
- this.endSequence();
98
- }
99
-
100
- /**
101
- * This method should be called when the current working session finishes.
102
- */
103
- endSequence() {
104
- if (this.currentSequence && this.currentSequence.totalTime === 0)
105
- this.currentSequence.endSequence();
106
- this.currentSequence = null;
107
- this.info.valid = false;
108
- }
109
-
110
- /**
111
- * This method should be invoked when a new sequence starts
112
- * @param {module:bags/ActivitySequenceElement.ActivitySequenceElement} ase - The {@link module:bags/ActivitySequenceElement.ActivitySequenceElement ActivitySequenceElement} referenced by this sequence.
113
- */
114
- newSequence(ase) {
115
- this.endSequence();
116
- this.currentSequence = new SequenceReg(ase);
117
- this.sequences.push(this.currentSequence);
118
- this.info.valid = false;
119
- }
120
-
121
- /**
122
- * This method should be invoked when the user starts a new activity
123
- * @param {module:Activity.Activity} act - The {@link module:Activity.Activity Activity} that has just started
124
- */
125
- newActivity(act) {
126
- if (this.currentSequence) {
127
- // Save activity name if not yet registered
128
- if (this.actNames.indexOf(act.name) === -1)
129
- this.actNames.push(act.name);
130
- this.currentSequence.newActivity(act);
131
- this.info.valid = false;
132
- }
133
- }
134
-
135
- /**
136
- * This method should be called when the current activity finishes. Data about user's final results
137
- * on the activity will then be saved.
138
- * @param {number} score - The final score, usually in a 0-100 scale.
139
- * @param {number} numActions - The total number of actions done by the user to solve the activity
140
- * @param {boolean} solved - `true` if the activity was finally solved, `false` otherwise.
141
- */
142
- endActivity(score, numActions, solved) {
143
- if (this.currentSequence) {
144
- this.currentSequence.endActivity(score, numActions, solved);
145
- this.info.valid = false;
146
- }
147
- }
148
-
149
- /**
150
- * Reports a new action done by the user while playing the current activity
151
- * @param {string} type - Type of action (`click`, `write`, `move`, `select`...)
152
- * @param {string}+ source - Description of the object on which the action is done.
153
- * @param {string}+ dest - Description of the object that acts as a target of the action (used in pairings)
154
- * @param {boolean} ok - `true` if the action was OK, `false`, `null` or `undefined` otherwise
155
- */
156
- newAction(type, source, dest, ok) {
157
- if (this.currentSequence) {
158
- this.currentSequence.newAction(type, source, dest, ok);
159
- this.info.valid = false;
160
- }
161
- }
162
-
163
- /**
164
- * Gets the name of the current sequence
165
- * @returns {string}
166
- */
167
- getCurrentSequenceTag() {
168
- return this.currentSequence ? this.currentSequence.name : null;
169
- }
170
-
171
- /**
172
- * Gets information about the current sequence
173
- * @returns {module:report/SequenceReg.SequenceRegInfo}
174
- */
175
- getCurrentSequenceInfo() {
176
- return this.currentSequence ? this.currentSequence.getInfo() : null;
177
- }
178
- }
179
-
180
- Object.assign(SessionReg.prototype, {
181
- /**
182
- * Number of activities suitable to be reported in this session
183
- * @name module:report/SessionReg.SessionReg#reportableActs
184
- * @type {number} */
185
- reportableActs: 0,
186
- /**
187
- * Array with unique names of the activities being reported in this session
188
- * @name module:report/SessionReg.SessionReg#actNames
189
- * @type {string[]} */
190
- actNames: null,
191
- /**
192
- * List of sequences done in this session
193
- * @name module:report/SessionReg.SessionReg#sequences
194
- * @type {module:report/SequenceReg.SequenceReg[]} */
195
- sequences: null,
196
- /**
197
- * The sequence currently active
198
- * @name module:report/SessionReg.SessionReg#currentSequence
199
- * @type {module:report/SequenceReg.SequenceReg} */
200
- currentSequence: null,
201
- /**
202
- * Starting date and time of this session
203
- * @name module:report/SessionReg.SessionReg#started
204
- * @type {external:Date} */
205
- started: null,
206
- /**
207
- * Name of the {@link module:project/JClicProject.JClicProject JClicProject} associated to this session
208
- * @name module:report/SessionReg.SessionReg#projectName
209
- * @type {string} */
210
- projectName: '',
211
- /**
212
- * Current session info
213
- * @name module:report/SessionReg.SessionReg#info
214
- * @type {module:report/SessionReg.SessionRegInfo} */
215
- info: null,
216
- /**
217
- * Optional code to be used with this session
218
- * @name module:report/SessionReg.SessionReg#code
219
- * @type {string} */
220
- code: null,
221
- });
222
-
223
- /**
224
- * This object stores the global results of a {@link module:report/SessionReg.SessionReg SessionReg}
225
- */
226
- export class SessionRegInfo {
227
- /**
228
- * SessionRegInfo constructor
229
- * @param {module:report/SessionReg.SessionReg} sReg - The {@link module:report/SessionReg.SessionReg SessionReg} associated tho this `Info` object.
230
- */
231
- constructor(sReg) {
232
- this.sReg = sReg;
233
- }
234
-
235
- /**
236
- * Clears all data associated with this working session
237
- */
238
- clear() {
239
- this.numSequences = this.nActivities = this.nActSolved = this.nActScore = 0;
240
- this.ratioSolved = this.ratioPlayed = this.nActions = this.tScore = this.tTime = 0;
241
- this.valid = false;
242
- }
243
-
244
- /**
245
- * Computes the value of all global variables based on the data stored in `sequences`
246
- * @returns {module:report/SessionReg.SessionRegInfo} - This "info" object
247
- */
248
- recalc() {
249
- if (!this.valid) {
250
- this.clear();
251
- this.sReg.sequences.forEach(sr => {
252
- const sri = sr.getInfo();
253
- if (sri.nActivities > 0) {
254
- this.numSequences++;
255
- if (sri.nActClosed > 0) {
256
- this.nActivities += sri.nActClosed;
257
- this.nActions += sri.nActions;
258
- if (sri.nActScore > 0) {
259
- this.nActScore += sri.nActScore;
260
- this.tScore += sri.tScore * sri.nActScore;
261
- }
262
- this.tTime += sri.tTime;
263
- this.nActSolved += sri.nActSolved;
264
- }
265
- }
266
- });
267
- if (this.nActScore > 0)
268
- this.tScore = Math.round(this.tScore / this.nActScore);
269
- if (this.nActivities > 0) {
270
- this.ratioSolved = this.nActSolved / this.nActivities;
271
- if (this.sReg.reportableActs > 0)
272
- this.ratioPlayed = this.sReg.actNames.length / this.sReg.reportableActs;
273
- }
274
- this.valid = true;
275
- }
276
- return this;
277
- }
278
- }
279
-
280
- Object.assign(SessionRegInfo.prototype, {
281
- /**
282
- * The SessionReg linked to this Info object
283
- * @name module:report/SessionReg.SessionRegInfo#sReg
284
- * @type {module:report/SessionReg.SessionReg} */
285
- sReg: null,
286
- /**
287
- * When `false`, this session info needs to be recalculated
288
- * @name module:report/SessionReg.SessionRegInfo#valid
289
- * @type {boolean} */
290
- valid: false,
291
- /**
292
- * Number of sequences played
293
- * @name module:report/SessionReg.SessionRegInfo#numSequences
294
- * @type {number} */
295
- numSequences: 0,
296
- /**
297
- * Number of activities played
298
- * @name module:report/SessionReg.SessionRegInfo#nActivities
299
- * @type {number} */
300
- nActivities: 0,
301
- /**
302
- * Number of activities solved
303
- * @name module:report/SessionReg.SessionRegInfo#nActSolved
304
- * @type {number} */
305
- nActSolved: 0,
306
- /**
307
- * Number of activities with score > 0
308
- * @name module:report/SessionReg.SessionRegInfo#nActScore
309
- * @type {number} */
310
- nActScore: 0,
311
- /**
312
- * Percentage of solved activities
313
- * @name module:report/SessionReg.SessionRegInfo#ratioSolved
314
- * @type {number} */
315
- ratioSolved: 0,
316
- /**
317
- * Percentage of reportable activities played
318
- * @name module:report/SessionReg.SessionRegInfo#ratioPlayed
319
- * @type {number} */
320
- ratioPlayed: 0,
321
- /**
322
- * Number of actions done by the user while in this working session
323
- * @name module:report/SessionReg.SessionRegInfo#nActions
324
- * @type {number} */
325
- nActions: 0,
326
- /**
327
- * Sum of the scores of all the activities played
328
- * @name module:report/SessionReg.SessionRegInfo#tScore
329
- * @type {number} */
330
- tScore: 0,
331
- /**
332
- * Sum of the playing time reported by each activity (not always equals to the session's total time)
333
- * @name module:report/SessionReg.SessionRegInfo#tTime
334
- * @type {number} */
335
- tTime: 0,
336
- });
337
-
338
- SessionReg.Info = SessionRegInfo;
339
-
340
- export default SessionReg;
@@ -1,131 +0,0 @@
1
- /**
2
- * File : report/SessionStorageReporter.js
3
- * Created : 06/09/2017
4
- * By : Francesc Busquets <francesc@gmail.com>
5
- *
6
- * JClic.js
7
- * An HTML5 player of JClic activities
8
- * https://projectestac.github.io/jclic.js
9
- *
10
- * @source https://github.com/projectestac/jclic.js
11
- *
12
- * @license EUPL-1.2
13
- * @licstart
14
- * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)
15
- *
16
- * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by
17
- * the European Commission- subsequent versions of the EUPL (the "Licence");
18
- * You may not use this work except in compliance with the Licence.
19
- *
20
- * You may obtain a copy of the Licence at:
21
- * https://joinup.ec.europa.eu/software/page/eupl
22
- *
23
- * Unless required by applicable law or agreed to in writing, software
24
- * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
25
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
26
- * Licence for the specific language governing permissions and limitations
27
- * under the Licence.
28
- * @licend
29
- * @module
30
- */
31
-
32
- /* global window */
33
-
34
- import Reporter from './Reporter.js';
35
-
36
- /**
37
- * This JClic {@link module:Reporter.Reporter Reporter} writes persistent data to the browser local session storage. It uses some of
38
- * the {@link https://github.com/projectestac/jclic/wiki/JClic-Reports-developers-guide JClic Reports API}.
39
- * Connection parameters (`key`, `context`...) are passed through the `options` element of {@link module:JClicPlayer.JClicPlayer JClicPlayer} (acting as {@link module:JClicPlayer.JClicPlayer JClicPlayer}).
40
- * Set `storage=local` in `options` to store reports in [`window.localStorage`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage}
41
- * instead of [`window.sessionStorage`]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage} (default).
42
- * @extends module:reports/Reporter.Reporter
43
- */
44
- export class SessionStorageReporter extends Reporter {
45
- /**
46
- * SessionStorageReporter constructor
47
- * @param {module:JClicPlayer.JClicPlayer} ps - The {@link module:JClicPlayer.JClicPlayer JClicPlayer} used to retrieve settings and localized messages
48
- */
49
- constructor(ps) {
50
- super(ps);
51
- this.key = `jclic_${(new Date()).toISOString()}#${Math.ceil(Math.random() * 1000)}`;
52
- }
53
-
54
- /**
55
- * Initializes this report system with an optional set of parameters.
56
- * Returns a Promise, fulfilled when the reporter is fully initialized.
57
- * @override
58
- * @param {object} [options] - Initial settings passed to the reporting system
59
- * @returns {external:Promise}
60
- */
61
- init(options) {
62
- if (typeof options === 'undefined' || options === null)
63
- options = this.ps.options;
64
- if (options.storage === 'local') {
65
- this.storage = window.localStorage;
66
- this.descriptionKey = 'Reporting to local storage';
67
- }
68
- return Reporter.prototype.init.call(this, options);
69
- }
70
-
71
- /**
72
- *
73
- * Saves the current report data to sessionStorage
74
- */
75
- saveCurrentReport() {
76
- // Update results out of current thread
77
- window.setTimeout(() => {
78
- this.storage.setItem(this.key, JSON.stringify(this.getData()));
79
- }, 0);
80
- }
81
-
82
- /**
83
- * Finalizes the current sequence
84
- * @override
85
- */
86
- endSequence() {
87
- super.endSequence();
88
- this.saveCurrentReport();
89
- }
90
-
91
- /**
92
- * This method should be called when the current activity finishes. Data about user's final results
93
- * on the activity will then be saved.
94
- * @override
95
- * @param {number} score - The final score, usually in a 0-100 scale.
96
- * @param {number} numActions - The total number of actions done by the user to solve the activity
97
- * @param {boolean} solved - `true` if the activity was finally solved, `false` otherwise.
98
- */
99
- endActivity(score, numActions, solved) {
100
- super.endActivity(score, numActions, solved);
101
- this.saveCurrentReport();
102
- }
103
- }
104
-
105
- Object.assign(SessionStorageReporter.prototype, {
106
- /**
107
- * Type of storage to be used. Defaults to `window.sessionStorage`
108
- * @name module:report/SessionStorageReporter.SessionStorageReporter#storage
109
- * @type {external:Storage} */
110
- storage: window.sessionStorage,
111
- /**
112
- * Description of this reporting system
113
- * @name module:report/SessionStorageReporter.SessionStorageReporter#descriptionKey
114
- * @override
115
- * @type {string} */
116
- descriptionKey: 'Reporting to session storage',
117
- /**
118
- * Additional info to display after the reporter's `description`
119
- * @name module:report/SessionStorageReporter.SessionStorageReporter#descriptionDetail
120
- * @override
121
- * @type {string} */
122
- descriptionDetail: '(browser session)',
123
- /**
124
- * Key used to save the report into sessionStorage
125
- * @name module:report/SessionStorageReporter.SessionStorageReporter#key
126
- * @type {string} */
127
- key: null,
128
- });
129
-
130
- // Register class in Reporter.CLASSES
131
- export default Reporter.registerClass('SessionStorageReporter', SessionStorageReporter);