jclic 2.2.1 → 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 -672
  8. package/TRANSLATIONS.md +0 -11
  9. package/build-locales.mjs +0 -82
  10. package/dist/jclic-node.js +0 -31680
  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 -660
  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,660 +0,0 @@
1
- /**
2
- * File : activities/text/TextActivityDocument.js
3
- * Created : 14/04/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
- /* global structuredClone */
33
-
34
- import $ from 'jquery';
35
- import { log, attrForEach, checkColor, getBoolean, getAttr, setAttr, getVal, getNumber, settings } from '../../Utils.js';
36
- import ActiveBoxContent from '../../boxes/ActiveBoxContent.js';
37
- import MediaContent from '../../media/MediaContent.js';
38
-
39
- /**
40
- * This is the HTML DOM element used in text activities like {@link module:activities/text/FillInBlanks.FillInBlanks FillInBlanks},
41
- * {@link module:activities/text/IdentifyText.IdentifyText IdentifyText}, {@link module:activities/text/OrderText.OrderText OrderText} and {@link module:activities/text/Complete.Complete Complete}. It contains the main document of
42
- * the activity, usually with some elements marked as "targets". In {@link module:activities/text/FillInBlanks.FillInBlanks FillInBlanks}, this
43
- * targets are encapsulated in {@link module:activities/text/TextActivityDocument.TextTarget TextTarget} objects.
44
- */
45
- export class TextActivityDocument {
46
- /**
47
- * TextActivityDocument constructor
48
- */
49
- constructor() {
50
- // Make a deep clone of the default style
51
- this.style = { 'default': structuredClone(TextActivityDocument.DEFAULT_DOC_STYLE) };
52
- this.p = [];
53
- }
54
-
55
- /**
56
- * Loads the document settings from a specific JQuery XML element
57
- * @param {external:jQuery} $xml - The XML element to parse
58
- * @param {module:bags/MediaBag.MediaBag} mediaBag - The media bag used to load images and media content
59
- */
60
- setProperties($xml, mediaBag) {
61
- // Read named styles
62
- // Sort styles according to its "base" dependencies
63
- const styles = $xml.children('style').toArray().sort((a, b) => {
64
- var aName = a.getAttribute('name'), aBase = a.getAttribute('base') || null;
65
- var bName = b.getAttribute('name'), bBase = b.getAttribute('base') || null;
66
- // Put 'default' always first, then each style below their base (if any)
67
- return aName === 'default' ? -1 : bName === 'default' ? 1
68
- : aBase === bName ? 1 : bBase === aName ? -1
69
- : !aBase ? -1 : !bBase ? 1 : 0;
70
- });
71
-
72
- // Process the ordered list of styles
73
- styles.forEach(style => {
74
- const attr = this.readDocAttributes($(style));
75
- // Grant always that basic attributes are defined
76
- this.style[attr.name] = attr.name === 'default' ? $.extend(true, this.style.default, attr) : attr;
77
- });
78
-
79
- // Read paragraphs
80
- $xml.find('section > p').each((_n, par) => {
81
-
82
- const p = { elements: [] };
83
-
84
- // Read paragraph attributes
85
- attrForEach(par.attributes, (name, value) => {
86
- switch (name) {
87
- case 'style':
88
- p[name] = value;
89
- break;
90
- case 'bidiLevel':
91
- case 'Alignment':
92
- p[name] = Number(value);
93
- break;
94
- }
95
- });
96
-
97
- // Read paragraph objects
98
- $(par).children().each((_n, child) => {
99
- let obj;
100
- const $child = $(child);
101
- switch (child.nodeName) {
102
-
103
- case 'cell':
104
- obj = new ActiveBoxContent().setProperties($child, mediaBag);
105
- break;
106
-
107
- case 'text':
108
- obj = { text: child.textContent.replace(/\t/g, '&#9;') };
109
- const attr = this.readDocAttributes($child);
110
- if (!$.isEmptyObject(attr)) {
111
- obj.attr = attr;
112
- }
113
- break;
114
-
115
- case 'target':
116
- obj = new TextTarget(this, child.textContent.replace(/\t/g, '&#9;'));
117
- obj.setProperties($child, mediaBag);
118
- this.numTargets++;
119
- break;
120
-
121
- default:
122
- log('error', `Unknown object in activity document: "${child.nodeName}"`);
123
- }
124
- if (obj) {
125
- obj.objectType = child.nodeName;
126
- p.elements.push(obj);
127
- }
128
- });
129
-
130
- this.p.push(p);
131
- });
132
- return this;
133
- }
134
-
135
- /**
136
- * Reads sets of text attributes, sometimes in form of named styles
137
- * @param {external:jQuery} $xml - The XML element to parse
138
- * @returns {object}
139
- */
140
- readDocAttributes($xml) {
141
- let
142
- attr = {},
143
- css = {};
144
- attrForEach($xml.get(0).attributes, (name, val) => {
145
- switch (name) {
146
- case 'background':
147
- val = checkColor(val, 'white');
148
- attr[name] = val;
149
- css['background-color'] = val;
150
- break;
151
- case 'foreground':
152
- val = checkColor(val, 'black');
153
- attr[name] = val;
154
- css['color'] = val;
155
- break;
156
- case 'family':
157
- css['font-family'] = val;
158
- /* falls through */
159
- case 'name':
160
- case 'style':
161
- // Attributes specific to named styles:
162
- attr[name] = val;
163
- break;
164
- case 'base':
165
- attr[name] = val;
166
- // If base style exists, merge it with current settings
167
- if (this.style[val]) {
168
- //attr = Object.apply({}, this.style[val], attr)
169
- attr = $.extend(true, {}, this.style[val], attr);
170
- if (this.style[val].css)
171
- //css = Object.apply({}, this.style[val].css, css)
172
- css = $.extend({}, this.style[val].css, css);
173
- }
174
- break;
175
- case 'bold':
176
- val = getBoolean(val);
177
- attr[name] = val;
178
- css['font-weight'] = val ? 'bold' : 'normal';
179
- break;
180
- case 'italic':
181
- val = getBoolean(val);
182
- attr[name] = val;
183
- css['font-style'] = val ? 'italic' : 'normal';
184
- break;
185
- case 'target':
186
- attr[name] = getBoolean(val);
187
- break;
188
- case 'size':
189
- attr[name] = Number(val);
190
- css['font-size'] = `${val}px`;
191
- break;
192
- case 'tabWidth':
193
- // `tab-size` CSS attribute is only set when the document has a specific `tabWidth`
194
- // setting. It must be accompanied of `white-space:pre` to successfully work.
195
- this.tabSpc = val;
196
- css['tab-size'] = this.tabSpc;
197
- css['white-space'] = 'pre-wrap';
198
- break;
199
- default:
200
- log('warn', `Unknown text attribute: "${name}" = "${val}"`);
201
- attr[name] = val;
202
- break;
203
- }
204
- });
205
-
206
- if (!$.isEmptyObject(css))
207
- attr['css'] = css;
208
-
209
- return attr;
210
- }
211
-
212
- /**
213
- * Gets a object with the basic attributes needed to rebuild this instance excluding functions,
214
- * parent references, constants and also attributes retaining the default value.
215
- * The resulting object is commonly usued to serialize elements in JSON format.
216
- * @returns {object} - The resulting object, with minimal attrributes
217
- */
218
- getAttributes() {
219
- // TODO: simplify the serialization of styles (now too verbose!)
220
- return getAttr(this, ['style', 'tabSpc', 'targetType', 'p']);
221
- }
222
-
223
- /**
224
- * Reads the properties of this TextActivityDocument from a data object
225
- * @param {object} data - The data object to be parsed, or just the text content
226
- * @returns {module:activities/text/TextActivityDocument.TextActivityDocument}
227
- */
228
- setAttributes(data, mediaBag) {
229
-
230
- setAttr(this, data, ['style', 'tabSpc', 'targetType', 'p']);
231
-
232
- // Build paragraphs:
233
- this.p.forEach(p => {
234
- if (p.elements)
235
- p.elements = p.elements.map(el => {
236
- if (el.objectType === 'cell')
237
- return (new ActiveBoxContent()).setAttributes(el, mediaBag);
238
- else if (el.objectType === 'target')
239
- return (new TextTarget(this)).setAttributes(el, mediaBag);
240
- else
241
- return el;
242
- });
243
- else
244
- p.elements = [];
245
- });
246
- return this;
247
- }
248
-
249
- /**
250
- * Gets the full text of this document in raw format
251
- * @returns {string} - The text of the document.
252
- */
253
- getRawText() {
254
- const $html = $('<div/>');
255
- // Process paragraphs
256
- this.p.forEach(p => {
257
- // Creates a new DOM paragraph
258
- const $p = $('<p/>');
259
- let empty = true;
260
- // Process the paragraph elements
261
- p.elements.forEach(element => {
262
- switch (element.objectType) {
263
- case 'text':
264
- case 'target':
265
- $p.append(element.text);
266
- break;
267
- case 'cell':
268
- // cells are not considered raw text of the document
269
- break;
270
- default:
271
- break;
272
- }
273
- empty = false;
274
- });
275
- if (empty) {
276
- // Don't leave paragraphs empty
277
- $p.html('&nbsp;');
278
- }
279
- // Adds the paragraph to the DOM element
280
- $html.append($p);
281
- });
282
- return $html.text().trim();
283
- }
284
-
285
- /**
286
- * Gets a `style` object filled with default attributes plus attributes present in the
287
- * requested style name.
288
- * @param {string} name - The requested style name
289
- * @returns {object} - The result of combining `default` with the requested style
290
- */
291
- getFullStyle(name) {
292
- const st = $.extend(true, {}, this.style.default);
293
- return $.extend(true, st, this.style[name] ? this.style[name] : {});
294
- //return Object.assign({}, this.style.default, this.style[name] ? this.style[name] : {})
295
- }
296
- }
297
-
298
- /**
299
- * Default style
300
- */
301
- TextActivityDocument.DEFAULT_DOC_STYLE = {
302
- background: '0xFFFFFF',
303
- foreground: '0x000000',
304
- family: 'Arial',
305
- bold: false,
306
- italic: false,
307
- size: 17,
308
- css: {
309
- 'background-color': '#FFFFFF',
310
- 'color': '#000000',
311
- 'font-family': 'Arial',
312
- 'font-weight': 'normal',
313
- 'font-style': 'normal',
314
- 'font-size': '17px',
315
- },
316
- };
317
-
318
- Object.assign(TextActivityDocument.prototype, {
319
- /**
320
- * Number of blank spaces between tabulators.
321
- * @name module:activities/text/TextActivityDocument.TextActivityDocument#tabSpc
322
- * @type {number} */
323
- tabSpc: 12,
324
- /**
325
- * Index of the last {@link module:boxes/ActiveBox.ActiveBox ActiveBox} activated.
326
- * @name module:activities/text/TextActivityDocument.TextActivityDocument#lastBoxId
327
- * @type {number} */
328
- lastBoxId: 0,
329
- /**
330
- * A bag of {@link module:activities/text/TextActivityDocument.TargetMarker TargetMarker} objects
331
- * @name module:activities/text/TextActivityDocument.TextActivityDocument#tmb
332
- * @type {object} */
333
- tmb: null,
334
- /**
335
- * Number of targets
336
- * @name module:activities/text/TextActivityDocument.TextActivityDocument#numTargets
337
- * @type {number} */
338
- numTargets: 0,
339
- /**
340
- * Type of targets used in this activity. Possible values are: `TT_FREE`, `TT_CHAR`, `TT_WORD`
341
- * and `TT_PARAGRAPH`.
342
- * @name module:activities/text/TextActivityDocument.TextActivityDocument#targetType
343
- * @type {string} */
344
- targetType: 'TT_FREE',
345
- /**
346
- * Collection of named styles of the document
347
- * @name module:activities/text/TextActivityDocument.TextActivityDocument#style
348
- * @type {object} */
349
- style: null,
350
- /**
351
- * The main document, represented as a collection of DOM objects
352
- * @name module:activities/text/TextActivityDocument.TextActivityDocument#p
353
- * @type {object} */
354
- p: null,
355
- });
356
-
357
- /**
358
- * This class contains the properties and methods of the document elements that are the real
359
- * targets of user actions in text activities.
360
- */
361
- export class TextTarget {
362
- /**
363
- * TextTarget constructor
364
- * @param {module:activities/text/TextActivityDocument.TextActivityDocument} doc - The document to which this target belongs.
365
- * @param {string} text - Main text of this target.
366
- */
367
- constructor(doc, text = '') {
368
- this.doc = doc;
369
- this.text = text;
370
- this.numIniChars = text.length;
371
- this.answers = [text];
372
- this.maxLenResp = this.numIniChars;
373
- }
374
-
375
- /**
376
- * Resets the TextTarget status
377
- * @param {string} [status] - The `targetStatus` to be established. Default is `NOT_EDITED`
378
- */
379
- reset(status) {
380
- this.targetStatus = status ? status : 'NOT_EDITED';
381
- this.flagModified = false;
382
- }
383
-
384
- /**
385
- * Loads the text target settings from a specific JQuery XML element
386
- * @param {external:jQuery} $xml - The XML element to parse
387
- * @param {module:bags/MediaBag.MediaBag} mediaBag - The media bag used to load images and media content
388
- */
389
- setProperties($xml, mediaBag) {
390
- let firstAnswer = true;
391
- // Read specific nodes
392
- $xml.children().each((_n, child) => {
393
- const $node = $(child);
394
- switch (child.nodeName) {
395
- case 'answer':
396
- if (firstAnswer) {
397
- firstAnswer = false;
398
- this.answers = [];
399
- }
400
- if (this.answers === null)
401
- this.answers = [];
402
- this.answers.push(child.textContent);
403
- break;
404
-
405
- case 'optionList':
406
- $node.children('option').each((_n, opChild) => {
407
- this.isList = true;
408
- if (this.options === null)
409
- this.options = [];
410
- this.options.push(opChild.textContent);
411
- });
412
- break;
413
-
414
- case 'response':
415
- this.iniChar = getVal($node.attr('fill'), this.iniChar).charAt(0);
416
- // Use underscores instead of whitespace chars
417
- if (settings.WHITESPACES.indexOf(this.iniChar) >= 0)
418
- this.iniChar = '_';
419
- this.numIniChars = getNumber($node.attr('length'), this.numIniChars);
420
- this.maxLenResp = getNumber($node.attr('maxLength'), this.maxLenResp);
421
- this.iniText = getVal($node.attr('show'), this.iniText);
422
- break;
423
-
424
- case 'info':
425
- this.infoMode = getVal($node.attr('mode'), 'always');
426
- this.popupDelay = getNumber($node.attr('delay'), this.popupDelay);
427
- this.popupMaxTime = getNumber($node.attr('maxTime'), this.popupMaxTime);
428
- $node.children('media').each((_n, media) => {
429
- this.onlyPlay = true;
430
- this.popupContent = new ActiveBoxContent();
431
- this.popupContent.mediaContent = new MediaContent().setProperties($(media));
432
- });
433
- if (!this.popupContent) {
434
- $node.children('cell').each((_n, cell) => {
435
- this.popupContent = new ActiveBoxContent().setProperties($(cell), mediaBag);
436
- });
437
- }
438
- break;
439
-
440
- case 'text':
441
- this.text = child.textContent.replace(/\t/g, '&#9;');
442
- const attr = this.doc.readDocAttributes($(child));
443
- if (!$.isEmptyObject(attr))
444
- this.attr = attr;
445
- break;
446
-
447
- default:
448
- break;
449
- }
450
- });
451
- }
452
-
453
- /**
454
- * Gets a object with the basic attributes needed to rebuild this instance excluding functions,
455
- * parent references, constants and also attributes retaining the default value.
456
- * The resulting object is commonly usued to serialize elements in JSON format.
457
- * @returns {object} - The resulting object, with minimal attrributes
458
- */
459
- getAttributes() {
460
- return getAttr(this, [
461
- 'objectType', 'text', 'attr', 'isList',
462
- 'answers', 'options', 'iniChar', 'numIniChars', 'maxLenResp', 'iniText',
463
- 'infoMode', 'popupDelay', 'popupKey', 'popupMaxTime', 'onlyPlay',
464
- 'popupContent',
465
- ]);
466
- }
467
-
468
- /**
469
- * Reads the properties of this TextTarget from a data object
470
- * @param {object} data - The data object to be parsed, or just the text content
471
- * @returns {module:activities/text/TextActivityDocument.TextTarget}
472
- */
473
- setAttributes(data, mediaBag) {
474
- return setAttr(this, data, [
475
- 'objectType', 'text', 'attr', 'isList',
476
- 'answers', 'options', 'iniChar', 'numIniChars', 'maxLenResp', 'iniText',
477
- 'infoMode', 'popupDelay', 'popupKey', 'popupMaxTime', 'onlyPlay',
478
- { key: 'popupContent', fn: ActiveBoxContent, params: [mediaBag] },
479
- ]);
480
- }
481
-
482
- /**
483
- * Gets a string with all valid answers of this TextTarget. Useful for reporting users' activity.
484
- * @returns {string}
485
- */
486
- getAnswers() {
487
- return this.answers ? this.answers.join('|') : '';
488
- }
489
-
490
- /**
491
- * Sets specific colors to the target jQuery element, based on its `targetStatus` value. Red
492
- * color usually means error.
493
- */
494
- checkColors() {
495
- const $element = this.$comboList || this.$span;
496
- if ($element) {
497
- const style = this.doc.style[
498
- this.targetStatus === 'WITH_ERROR' ? 'targetError' :
499
- this.targetStatus === 'HIDDEN' ? 'default' : 'target'];
500
- if (style && style.css) {
501
- $element.css(style.css);
502
- }
503
- }
504
- }
505
-
506
- /**
507
- * Fills the `currentText` member with the text currently hosted in $span or selected in $comboList
508
- * @returns {string} - The current text of this target
509
- */
510
- readCurrentText() {
511
- if (this.$span)
512
- this.currentText = this.$span.text();
513
- else if (this.$comboList)
514
- this.currentText = this.$comboList.val();
515
- return this.currentText;
516
- }
517
- }
518
-
519
- Object.assign(TextTarget.prototype, {
520
- /**
521
- * The {@link module:activities/text/TextActivityDocument.TextActivityDocument TextActivityDocument} to which this target belongs
522
- * @name module:activities/text/TextActivityDocument.TextTarget#doc
523
- * @type {module:activities/text/TextActivityDocument.TextActivityDocument} */
524
- doc: null,
525
- /**
526
- * The current text displayed by this TextTarget
527
- * @name module:activities/text/TextActivityDocument.TextTarget#text
528
- * @type {string} */
529
- text: null,
530
- /**
531
- * A set of optional attributes for `text`
532
- * @name module:activities/text/TextActivityDocument.TextTarget#attr
533
- * @type {object} */
534
- attr: null,
535
- /**
536
- * `true` when the target is a drop-down list
537
- * @name module:activities/text/TextActivityDocument.TextTarget#isList
538
- * @type {boolean} */
539
- isList: false,
540
- /**
541
- * Number of characters initially displayed on the text field
542
- * @name module:activities/text/TextActivityDocument.TextTarget#numIniChars
543
- * @type {number} */
544
- numIniChars: 1,
545
- /**
546
- * Character used to fill-in the text field
547
- * @name module:activities/text/TextActivityDocument.TextTarget#iniChar
548
- * @type {string} */
549
- iniChar: '_',
550
- /**
551
- * Maximum length of the answer
552
- * @name module:activities/text/TextActivityDocument.TextTarget#maxLenResp
553
- * @type {number} */
554
- maxLenResp: 0,
555
- /**
556
- * Array of valid answers
557
- * @name module:activities/text/TextActivityDocument.TextTarget#answers
558
- * @type {string[]} */
559
- answers: null,
560
- /**
561
- * Set of specific options
562
- * @name module:activities/text/TextActivityDocument.TextTarget#options
563
- * @type {object} */
564
- options: null,
565
- /**
566
- * Text displayed by the target when the activity begins
567
- * @name module:activities/text/TextActivityDocument.TextTarget#iniText
568
- * @type {string} */
569
- iniText: null,
570
- /**
571
- * Type of additional information offered to the user. Possible values are: `no_info`, `always`,
572
- * `onError` and `onDemand`.
573
- * @name module:activities/text/TextActivityDocument.TextTarget#infoMode
574
- * @type {string} */
575
- infoMode: 'no_info',
576
- /**
577
- * Key that triggers the associated popup when `infoMode` is `onDemand`
578
- * @name module:activities/text/TextActivityDocument.TextTarget#popupKey
579
- * @type {string} */
580
- popupKey: 'F1',
581
- /**
582
- * An optional {@link module:boxes/ActiveBoxContent.ActiveBoxContent ActiveBoxContent} with information about this TextTarget
583
- * @name module:activities/text/TextActivityDocument.TextTarget#popupContent
584
- * @type {module:boxes/ActiveBoxContent.ActiveBoxContent} */
585
- popupContent: null,
586
- /**
587
- * Time (seconds) to wait before showing the additional information
588
- * @name module:activities/text/TextActivityDocument.TextTarget#popupDelay
589
- * @type {number} */
590
- popupDelay: 0,
591
- /**
592
- * Maximum amount of time (seconds) that the additional information will be shown
593
- * @name module:activities/text/TextActivityDocument.TextTarget#popupMaxTime
594
- * @type {number} */
595
- popupMaxTime: 0,
596
- /**
597
- * When this flag is `true` and `popupContent` contains audio, no visual feedback will be
598
- * provided (meaning that audio will be just played)
599
- * @name module:activities/text/TextActivityDocument.TextTarget#onlyPlay
600
- * @type {boolean} */
601
- onlyPlay: false,
602
- //
603
- // TRANSIENT PROPERTIES
604
- //
605
- /**
606
- * The drop-down list associated to this target
607
- * @name module:activities/text/TextActivityDocument.TextTarget#$comboList
608
- * @type {external:jQuery} */
609
- $comboList: null,
610
- /**
611
- * The span element associated to this target
612
- * @name module:activities/text/TextActivityDocument.TextTarget#$span
613
- * @type {external:jQuery} */
614
- $span: null,
615
- /**
616
- * The paragraph element where $span is currently located
617
- * @name module:activities/text/TextActivityDocument.TextTarget#$p
618
- * @type {external:jQuery} */
619
- $p: null,
620
- /**
621
- * The span element containing the popup
622
- * @name module:activities/text/TextActivityDocument.TextTarget#$popup
623
- * @type {external:jQuery} */
624
- $popup: null,
625
- /**
626
- * Current text in the $span element
627
- * @name module:activities/text/TextActivityDocument.TextTarget#currentText
628
- * @type {string} */
629
- currentText: '',
630
- /**
631
- * Ordinal number of this target in the collection of targets
632
- * @name module:activities/text/TextActivityDocument.TextTarget#num
633
- * @type {number} */
634
- num: 0,
635
- /**
636
- * Current ordinal position of this target in the document
637
- * (used in {@link module:activities/text/OrderText.OrderText OrderText} activities)
638
- * @name module:activities/text/TextActivityDocument.TextTarget#pos
639
- * @type {number} */
640
- pos: 0,
641
- /**
642
- * Current status of the target. Valid values are: `NOT_EDITED`, `EDITED`, `SOLVED`, `WITH_ERROR` and `HIDDEN`
643
- * @name module:activities/text/TextActivityDocument.TextTarget#targetStatus
644
- * @type {string} */
645
- targetStatus: 'NOT_EDITED',
646
- /**
647
- * Flag to control if the initial content of this TextTarget has been modified
648
- * @name module:activities/text/TextActivityDocument.TextTarget#flagModified
649
- * @type {boolean} */
650
- flagModified: false,
651
- /**
652
- * Pointer to the activity panel containing this TextTarget
653
- * @name module:activities/text/TextActivityDocument.TextTarget#parentPane
654
- * @type {module:activities/text/TextActivityBase.TextActivityBasePanel} */
655
- parentPane: null,
656
- });
657
-
658
- TextActivityDocument.TextTarget = TextTarget;
659
-
660
- export default TextActivityDocument;