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,557 +0,0 @@
1
- /**
2
- * File : activities/text/WrittenAnswer.js
3
- * Created : 04/06/2015
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
- import $ from 'jquery';
33
- import { Activity, ActivityPanel } from '../../Activity.js';
34
- import ActiveBoxGrid from '../../boxes/ActiveBoxGrid.js';
35
- import BoxBag from '../../boxes/BoxBag.js';
36
- import { Rectangle, Point } from '../../AWT.js';
37
- import { compareMultipleOptions } from '../../Utils.js';
38
- import Rectangular from '../../shapers/Rectangular.js';
39
-
40
- /**
41
- * This class of {@link module:Activity.Activity Activity} shows a panel with {@link module:boxes/ActiveBox.ActiveBox ActiveBox} objects acting as cells
42
- * with questions. The answers to these questions must be written in a separate text field.
43
- *
44
- * The ActiveBox objects are filled with data stored in {@link module:boxes/ActiveBagContent.ActiveBagContent ActiveBagContent} repositories.
45
- *
46
- * A second {@link module:boxes/ActiveBagContent.ActiveBagContent ActiveBagContent} can be used as alternative content, revealed as the questions
47
- * are solved.
48
- * @extends module:Activity.Activity
49
- */
50
- export class WrittenAnswer extends Activity {
51
- /**
52
- * WrittenAnswer constructor
53
- * @param {module:project/JClicProject.JClicProject} project - The JClic project to which this activity belongs
54
- */
55
- constructor(project) {
56
- super(project);
57
- }
58
-
59
- /**
60
- * Loads this object settings from an XML element
61
- * @override
62
- * @param {external:jQuery} $xml - The jQuery XML element to parse
63
- */
64
- setProperties($xml) {
65
- super.setProperties($xml);
66
- this.abc['primary'].avoidAllIdsNull(this.abc['answers'].getNumCells());
67
- }
68
-
69
- /**
70
- * Retrieves the minimum number of actions needed to solve this activity
71
- * @override
72
- * @returns {number}
73
- */
74
- getMinNumActions() {
75
- return this.invAss ?
76
- this.abc['answers'].getNumCells() :
77
- this.abc['primary'].getNumCells() - this.nonAssignedCells;
78
- }
79
-
80
- /**
81
- * This activity uses random values to shuffle its internal components
82
- * @override
83
- * @returns {boolean}
84
- */
85
- hasRandom() {
86
- return true;
87
- }
88
-
89
- /**
90
- * This activity makes use of the keyboard
91
- * @override
92
- * @returns {boolean}
93
- */
94
- needsKeyboard() {
95
- return true;
96
- }
97
-
98
- /**
99
- * This activity can permit the user to display the solution
100
- * @override
101
- * @returns {boolean}
102
- */
103
- helpSolutionAllowed() {
104
- return true;
105
- }
106
- }
107
-
108
- Object.assign(WrittenAnswer.prototype, {
109
- /**
110
- * Number of unassigned cells
111
- * @name module:activities/text/WrittenAnswer.WrittenAnswer#nonAssignedCells
112
- * @type {number} */
113
- nonAssignedCells: 0,
114
- /**
115
- * Whether to use or not the cell's `idAss` field to check if pairings match
116
- * @name module:activities/text/WrittenAnswer.WrittenAnswer#useIdAss
117
- * @type {boolean} */
118
- useIdAss: true,
119
- });
120
-
121
- /**
122
- * The {@link module:Activity.ActivityPanel ActivityPanel} where {@link module:activities/text/WrittenAnswer.WrittenAnswer WrittenAnswer} activities are played.
123
- * @extends module:Activity.ActivityPanel
124
- */
125
- export class WrittenAnswerPanel extends ActivityPanel {
126
- /**
127
- * WrittenAnswerPanel constructor
128
- * @param {module:Activity.Activity} act - The {@link module:Activity.Activity Activity} to which this Panel belongs
129
- * @param {module:JClicPlayer.JClicPlayer} ps - Any object implementing the methods defined in the
130
- * [PlayStation](http://projectestac.github.io/jclic/apidoc/edu/xtec/jclic/PlayStation.html) Java interface.
131
- * @param {external:jQuery} [$div] - The jQuery DOM element where this Panel will deploy
132
- */
133
- constructor(act, ps, $div) {
134
- super(act, ps, $div);
135
- }
136
-
137
- /**
138
- * Performs miscellaneous cleaning operations
139
- * @override
140
- */
141
- clear() {
142
- if (this.bgA) {
143
- this.bgA.end();
144
- this.bgA = null;
145
- }
146
- if (this.bgB) {
147
- this.bgB.end();
148
- this.bgB = null;
149
- }
150
- }
151
-
152
- /**
153
- * Prepares the visual components of the activity
154
- * @override
155
- */
156
- buildVisualComponents() {
157
- if (this.firstRun)
158
- super.buildVisualComponents();
159
-
160
- this.clear();
161
-
162
- const
163
- abcA = this.act.abc['primary'],
164
- abcB = this.act.abc['answers'],
165
- solved = this.act.abc['solvedPrimary'];
166
-
167
- if (abcA && abcB) {
168
- if (this.act.invAss)
169
- this.invAssCheck = Array(abcB.getNumCells()).fill(false);
170
-
171
- if (abcA.image) {
172
- abcA.setImgContent(this.act.project.mediaBag, null, false);
173
- if (abcA.animatedGifFile && !abcA.shaper.rectangularShapes && !this.act.shuffleA)
174
- this.$animatedBg = $('<span/>').css({
175
- 'background-image': 'url(' + abcA.animatedGifFile + ')',
176
- 'background-position': 'center',
177
- 'background-repeat': 'no-repeat',
178
- position: 'absolute'
179
- }).appendTo(this.$div);
180
- }
181
-
182
- if (solved && solved.image)
183
- solved.setImgContent(this.act.project.mediaBag, null, false);
184
-
185
- if (this.act.acp !== null) {
186
- const contentKit = [abcA, abcB];
187
- if (solved)
188
- contentKit.push(solved);
189
- this.act.acp.generateContent(abcA.nch, abcA.ncw, contentKit, false);
190
- }
191
-
192
- this.bgA = ActiveBoxGrid.createEmptyGrid(null, this, this.act.margin, this.act.margin, abcA);
193
-
194
- let w = abcB.w;
195
- if (this.act.boxGridPos === 'AUB' || this.act.boxGridPos === 'BUA')
196
- w = abcA.getTotalWidth();
197
- //
198
- // bgB will be used only as a placeholder for `$textField`
199
- this.bgB = new ActiveBoxGrid(null, this, abcB.style, this.act.margin, this.act.margin, w, abcB.h, new Rectangular(1, 1));
200
- this.$form = $('<form/>', { id: 'form1' /*, action: '#' */ });
201
- // Modified 05/Feb/2020: jQuery not catching submit event when on first activity
202
- this.$form[0].addEventListener('submit', event => {
203
- event.preventDefault();
204
- if (this.playing)
205
- this.setCurrentCell(this.currentCell);
206
- return false;
207
- });
208
-
209
- this.$textField = $('<input/>', { type: 'text', size: 200 })
210
- .css(abcB.style.getCSS())
211
- .css({
212
- position: 'absolute', top: 0, left: 0,
213
- border: 0, padding: 0, margin: 0,
214
- 'text-align': 'center'
215
- })
216
- .attr({
217
- autocomplete: 'off',
218
- autocorrect: 'off',
219
- autocapitalize: 'off',
220
- spellcheck: 'false',
221
- });
222
-
223
- this.$div.append(this.$form.append(this.$textField));
224
- this.bgA.setContent(abcA, solved || null);
225
- this.bgA.setDefaultIdAss();
226
- if (this.$animatedBg)
227
- this.bgA.setCellAttr('tmpTrans', true);
228
-
229
- this.act.nonAssignedCells = 0;
230
- for (let i = 0; i < this.bgA.getNumCells(); i++) {
231
- var bx = this.bgA.getActiveBox(i);
232
- if (bx.idAss === -1) {
233
- this.act.nonAssignedCells++;
234
- bx.switchToAlt(this.ps);
235
- }
236
- }
237
- this.bgA.setVisible(true);
238
- this.bgB.setVisible(false);
239
- }
240
- }
241
-
242
- /**
243
- * Basic initialization procedure
244
- * @override
245
- */
246
- initActivity() {
247
- super.initActivity();
248
- if (!this.firstRun)
249
- this.buildVisualComponents();
250
- else
251
- this.firstRun = false;
252
-
253
- if (this.bgA && this.bgB) {
254
- // Scramble cells
255
- if (this.act.shuffleA)
256
- this.shuffle([this.bgA], true, true);
257
-
258
- if (this.useOrder)
259
- this.currentItem = this.bgA.getNextItem(-1);
260
-
261
- this.setAndPlayMsg('initial', 'start');
262
- this.invalidate().update();
263
- this.playing = true;
264
- }
265
- }
266
-
267
- /**
268
- * Called by [JClicPlayer](JClicPlayer.html) when this activity panel is fully visible, just
269
- * after the initialization process.
270
- * @override
271
- */
272
- activityReady() {
273
- super.activityReady();
274
- this.setCurrentCell(0);
275
- }
276
-
277
- /**
278
- * Updates the graphic content of this panel.
279
- * This method will be called from {@link module:AWT.Container#update} when needed.
280
- * @override
281
- * @param {module:AWT.Rectangle} dirtyRegion - Specifies the area to be updated. When `null`,
282
- * it's the whole panel.
283
- */
284
- updateContent(dirtyRegion) {
285
- super.updateContent(dirtyRegion);
286
- if (this.bgA && this.$canvas) {
287
- const
288
- canvas = this.$canvas.get(-1),
289
- ctx = canvas.getContext('2d');
290
- if (!dirtyRegion)
291
- dirtyRegion = new Rectangle(0, 0, canvas.width, canvas.height);
292
- ctx.clearRect(dirtyRegion.pos.x, dirtyRegion.pos.y, dirtyRegion.dim.width, dirtyRegion.dim.height);
293
- this.bgA.update(ctx, dirtyRegion);
294
- }
295
- return this;
296
- }
297
-
298
- /**
299
- * Sets the real dimension of this panel.
300
- * @override
301
- * @param {module:AWT.Dimension} preferredMaxSize - The maximum surface available for the activity panel
302
- * @returns {module:AWT.Dimension}
303
- */
304
- setDimension(preferredMaxSize) {
305
- return (!this.bgA || !this.bgB || this.getBounds().equals(preferredMaxSize)) ?
306
- preferredMaxSize :
307
- BoxBag.layoutDouble(preferredMaxSize, this.bgA, this.bgB, this.act.boxGridPos, this.act.margin);
308
- }
309
-
310
- /**
311
- * Sets the size and position of this activity panel
312
- * @override
313
- * @param {module:AWT.Rectangle} rect
314
- */
315
- setBounds(rect) {
316
- if (this.$canvas)
317
- this.$canvas.remove();
318
-
319
- super.setBounds(rect);
320
- if (this.bgA || this.bgB) {
321
- const r = rect.clone();
322
- if (this.act.boxGridPos === 'AUB')
323
- r.height -= this.bgB.pos.y + this.act.margin / 2;
324
- else if (this.act.boxGridPos === 'AB')
325
- r.width -= this.bgB.pos.x + this.act.margin / 2;
326
-
327
- // Create the main canvas
328
- this.$canvas = $('<canvas width="' + r.dim.width + '" height="' + r.dim.height + '"/>').css({
329
- position: 'absolute',
330
- top: 0,
331
- left: 0
332
- });
333
-
334
- // Resize animated gif background
335
- if (this.bgA && this.$animatedBg) {
336
- var bgRect = this.bgA.getBounds();
337
- this.$animatedBg.css({
338
- left: bgRect.pos.x,
339
- top: bgRect.pos.y,
340
- width: bgRect.dim.width + 'px',
341
- height: bgRect.dim.height + 'px',
342
- 'background-size': bgRect.dim.width + 'px ' + bgRect.dim.height + 'px'
343
- });
344
- this.$canvas.insertAfter(this.$animatedBg);
345
- } else
346
- this.$div.prepend(this.$canvas);
347
-
348
- if (this.$textField) {
349
- this.$textField.css({
350
- top: this.bgB.pos.y,
351
- left: this.bgB.pos.x,
352
- width: this.bgB.dim.width,
353
- height: this.bgB.dim.height,
354
- zIndex: 9
355
- });
356
- }
357
- // Repaint all
358
- this.invalidate().update();
359
- }
360
- }
361
-
362
- /**
363
- * Builds the accessible components needed for this ActivityPanel
364
- * This method is called when all main elements are placed and visible, when the activity is ready
365
- * to start or when resized.
366
- * @override
367
- */
368
- buildAccessibleComponents() {
369
- if (this.$canvas && this.accessibleCanvas) {
370
- super.buildAccessibleComponents();
371
- if (this.bgA)
372
- this.bgA.buildAccessibleElements(this.$canvas, this.$div, 'click');
373
- // bgB has a regular input element, so it's already accessible
374
- }
375
- }
376
-
377
- /**
378
- * Checks if all inverse associations are done
379
- * @returns {boolean}
380
- */
381
- checkInvAss() {
382
- return this.act.invAss && this.invAssCheck && this.invAssCheck.every(chk => chk);
383
- }
384
-
385
- /**
386
- * Updates the currently selected cell, evaluating the answer written by the user on the text field.
387
- * @param {number} i - Index into the {@link module:boxes/ActiveBoxbag.ActiveBoxBag ActiveBoxBag} of the cell to make active
388
- * @param {function[]} delayedActions - If set, store the the action in this array for future execution
389
- */
390
- setCurrentCell(i, delayedActions = null) {
391
- if (!this.playing)
392
- return;
393
-
394
- let
395
- bx = null,
396
- m = false;
397
-
398
- if (this.currentCell !== -1) {
399
- let ok = false;
400
- bx = this.bgA ? this.bgA.getActiveBoxWithIdLoc(this.currentCell) : null;
401
- if (bx) {
402
- bx.setMarked(false);
403
- const
404
- src = bx.getDescription(),
405
- id = bx.idAss,
406
- txCheck = id >= 0 ? this.act.abc['answers'].getActiveBoxContent(id).text : '',
407
- txAnswer = this.$textField.val().trim();
408
- if (compareMultipleOptions(txAnswer, txCheck, false, this.act.numericContent)) {
409
- ok = true;
410
- bx.idAss = -1;
411
- // When in multiple-answer, fill-in textField with the first valid option:
412
- const p = txCheck.indexOf('|');
413
- if (p >= 0)
414
- this.$textField.val(txCheck.substring(0, p));
415
-
416
- if (this.act.abc['solvedPrimary']) {
417
- bx.switchToAlt(this.ps);
418
- m = bx.playMedia(this.ps, delayedActions);
419
- } else
420
- bx.clear();
421
- if (this.act.invAss && id >= 0 && id < this.invAssCheck.length) {
422
- this.invAssCheck[id] = true;
423
- }
424
- if (this.act.useOrder)
425
- this.currentItem = this.bgA.getNextItem(this.currentItem);
426
- }
427
-
428
- const cellsPlaced = this.bgA.countCellsWithIdAss(-1);
429
- if (txAnswer.length > 0) {
430
- this.ps.reportNewAction(this.act, 'WRITE', src, txAnswer, ok, cellsPlaced);
431
- }
432
- if (ok && (this.checkInvAss() || cellsPlaced === this.bgA.getNumCells())) {
433
- this.finishActivity(true);
434
- this.$textField.prop('disabled', true);
435
- this.invalidate().update();
436
- return;
437
- } else if (!m && txAnswer.length > 0)
438
- this.playEvent(ok ? 'actionOk' : 'actionError');
439
- }
440
- }
441
-
442
- bx = this.bgA ?
443
- this.act.useOrder ?
444
- this.bgA.getBox(this.currentItem) :
445
- this.bgA.getActiveBoxWithIdLoc(i) :
446
- null;
447
-
448
- if (this.bgA && (!bx || bx.idAss === -1)) {
449
- for (var j = 0; j < this.bgA.getNumCells(); j++) {
450
- bx = this.bgA.getActiveBoxWithIdLoc(j);
451
- if (bx.idAss !== -1)
452
- break;
453
- }
454
- if (bx && bx.idAss === -1) {
455
- this.finishActivity(false);
456
- this.$textField.prop('disabled', true);
457
- this.invalidate().update();
458
- return;
459
- }
460
- }
461
- // Draw border only if it has more than one cell
462
- if (bx && this.bgA && this.bgA.getNumCells() > 1)
463
- bx.setMarked(true);
464
- if (bx)
465
- this.currentCell = bx.idLoc;
466
- this.$textField.val('');
467
- this.$textField.trigger('focus');
468
- this.invalidate().update();
469
- if (bx)
470
- bx.playMedia(this.ps, delayedActions);
471
- }
472
-
473
- /**
474
- * Main handler used to process mouse, touch, keyboard and edit events
475
- * @override
476
- * @param {external:Event} event - The HTML event to be processed
477
- * @returns {boolean} - When this event handler returns `false`, jQuery will stop its
478
- * propagation through the DOM tree. See: {@link http://api.jquery.com/on}
479
- */
480
- processEvent(event) {
481
- if (this.playing) {
482
- // Array to be filled with actions to be executed at the end of event processing
483
- const delayedActions = [];
484
- switch (event.type) {
485
- case 'click':
486
- event.preventDefault();
487
- this.ps.stopMedia(1);
488
- const p = new Point(
489
- event.pageX - this.$div.offset().left,
490
- event.pageY - this.$div.offset().top);
491
-
492
- // Avoid clicks on the text field
493
- if (this.bgB.contains(p)) {
494
- this.$textField.trigger('focus');
495
- break;
496
- }
497
-
498
- const bx = this.bgA ? this.bgA.findActiveBox(p) : null;
499
- if (bx && !bx.isInactive()) {
500
- if (bx.getContent() && bx.getContent().mediaContent === null)
501
- this.playEvent('CLICK');
502
- this.setCurrentCell(bx.idLoc, delayedActions);
503
- }
504
- break;
505
-
506
- case 'change':
507
- event.preventDefault();
508
- this.setCurrentCell(this.currentCell, delayedActions);
509
- break;
510
- }
511
- delayedActions.forEach(action => action());
512
- return false;
513
- }
514
- }
515
- }
516
-
517
- Object.assign(WrittenAnswerPanel.prototype, {
518
- /**
519
- * The input text field where users write the answers
520
- * @name module:activities/text/WrittenAnswer.WrittenAnswerPanel#$textField
521
- * @type {external:jQuery} */
522
- $textField: null,
523
- /**
524
- * Array for storing checked associations
525
- * @name module:activities/text/WrittenAnswer.WrittenAnswerPanel#invAssCheck
526
- * @type {boolean[]} */
527
- invAssCheck: null,
528
- /**
529
- * The {@link module:boxes/ActiveBoxbag.ActiveBoxBag ActiveBoxBag} object containing the questions
530
- * @name module:activities/text/WrittenAnswer.WrittenAnswerPanel#bgA
531
- * @type {module:boxes/ActiveBoxBag.ActiveBoxBag} */
532
- bgA: null,
533
- /**
534
- * An optional {@link module:boxes/ActiveBoxbag.ActiveBoxBag ActiveBoxBag} with content displayed as cells are solved.
535
- * @name module:activities/text/WrittenAnswer.WrittenAnswerPanel#bgB
536
- * @type {module:boxes/ActiveBoxBag.ActiveBoxBag} */
537
- bgB: null,
538
- /**
539
- * The currently selected cell
540
- * @name module:activities/text/WrittenAnswer.WrittenAnswerPanel#currentCell
541
- * @type {number} */
542
- currentCell: -1,
543
- /**
544
- * Mouse events intercepted by this panel
545
- * @override
546
- * @name module:activities/text/WrittenAnswer.WrittenAnswerPanel#events
547
- * @type {string[]} */
548
- events: ['click', 'change'],
549
- });
550
-
551
- /**
552
- * Panel class associated to this type of activity: {@link module:activities/text/WrittenAnswer.WrittenAnswerPanel WrittenAnswerPanel}
553
- * @type {class} */
554
- WrittenAnswer.Panel = WrittenAnswerPanel;
555
-
556
- // Register activity class
557
- export default Activity.registerClass('@text.WrittenAnswer', WrittenAnswer);