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