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.
- package/README.md +5 -7
- package/dist-node/jclic-node.js +14157 -0
- package/dist-node/jclic-node.umd.cjs +530 -0
- package/package.json +38 -26
- package/.vscode/launch.json +0 -33
- package/.vscode/settings.json +0 -13
- package/CHANGELOG.md +0 -672
- package/TRANSLATIONS.md +0 -11
- package/build-locales.mjs +0 -82
- package/dist/jclic-node.js +0 -31680
- package/dist/jclic-node.js.map +0 -1
- package/dist/jclic.components.LICENSE +0 -2254
- package/dist/jclic.min.js +0 -27
- package/dist/jclic.min.js.map +0 -1
- package/eslint.config.mjs +0 -31
- package/jsdoc.config.js +0 -71
- package/locales/ar.po +0 -244
- package/locales/ast.po +0 -246
- package/locales/bs.po +0 -247
- package/locales/ca.po +0 -248
- package/locales/ca_ES@valencia.po +0 -248
- package/locales/cs.po +0 -244
- package/locales/da.po +0 -244
- package/locales/de.po +0 -246
- package/locales/el.po +0 -244
- package/locales/es.po +0 -248
- package/locales/eu.po +0 -244
- package/locales/fr.po +0 -244
- package/locales/gl.po +0 -244
- package/locales/he.po +0 -244
- package/locales/hr.po +0 -245
- package/locales/it.po +0 -246
- package/locales/ja.po +0 -242
- package/locales/jclic.js.pot +0 -241
- package/locales/nb_NO.po +0 -244
- package/locales/nl.po +0 -244
- package/locales/pl.po +0 -244
- package/locales/pt.po +0 -244
- package/locales/pt_BR.po +0 -248
- package/locales/ro.po +0 -248
- package/locales/ru.po +0 -245
- package/locales/ta.po +0 -244
- package/locales/tr.po +0 -246
- package/locales/uk.po +0 -247
- package/locales/vec.po +0 -244
- package/locales/zh_TW.po +0 -246
- package/patches/po2json+1.0.0-beta-3.patch +0 -12
- package/src/AWT.js +0 -2067
- package/src/Activity.js +0 -1311
- package/src/Deps.js +0 -232
- package/src/GlobalData.js +0 -5
- package/src/JClic.js +0 -196
- package/src/JClicPlayer.js +0 -1308
- package/src/PlayerHistory.js +0 -305
- package/src/Utils.js +0 -1355
- package/src/activities/associations/ComplexAssociation.js +0 -321
- package/src/activities/associations/SimpleAssociation.js +0 -519
- package/src/activities/memory/MemoryGame.js +0 -423
- package/src/activities/panels/Explore.js +0 -349
- package/src/activities/panels/Identify.js +0 -356
- package/src/activities/panels/InformationScreen.js +0 -262
- package/src/activities/panels/Menu.js +0 -209
- package/src/activities/panels/icons/ico00.png +0 -0
- package/src/activities/panels/icons/ico01.png +0 -0
- package/src/activities/panels/icons/ico02.png +0 -0
- package/src/activities/panels/icons/ico03.png +0 -0
- package/src/activities/panels/icons/icofolder.png +0 -0
- package/src/activities/puzzles/DoublePuzzle.js +0 -424
- package/src/activities/puzzles/ExchangePuzzle.js +0 -374
- package/src/activities/puzzles/HolePuzzle.js +0 -360
- package/src/activities/text/Complete.js +0 -127
- package/src/activities/text/Evaluator.js +0 -534
- package/src/activities/text/FillInBlanks.js +0 -426
- package/src/activities/text/IdentifyText.js +0 -253
- package/src/activities/text/OrderText.js +0 -421
- package/src/activities/text/TextActivityBase.js +0 -557
- package/src/activities/text/TextActivityDocument.js +0 -660
- package/src/activities/text/WrittenAnswer.js +0 -557
- package/src/activities/textGrid/CrossWord.js +0 -565
- package/src/activities/textGrid/WordSearch.js +0 -458
- package/src/activities/textGrid/icons/hIcon.svg +0 -3
- package/src/activities/textGrid/icons/vIcon.svg +0 -3
- package/src/automation/AutoContentProvider.js +0 -182
- package/src/automation/arith/Arith.js +0 -864
- package/src/bags/ActivitySequence.js +0 -318
- package/src/bags/ActivitySequenceElement.js +0 -161
- package/src/bags/ActivitySequenceJump.js +0 -140
- package/src/bags/ConditionalJumpInfo.js +0 -113
- package/src/bags/JumpInfo.js +0 -136
- package/src/bags/MediaBag.js +0 -215
- package/src/bags/MediaBagElement.js +0 -516
- package/src/boxes/AbstractBox.js +0 -699
- package/src/boxes/ActiveBagContent.js +0 -494
- package/src/boxes/ActiveBox.js +0 -810
- package/src/boxes/ActiveBoxBag.js +0 -357
- package/src/boxes/ActiveBoxContent.js +0 -484
- package/src/boxes/ActiveBoxGrid.js +0 -179
- package/src/boxes/BoxBag.js +0 -500
- package/src/boxes/BoxBase.js +0 -398
- package/src/boxes/BoxConnector.js +0 -325
- package/src/boxes/TextGrid.js +0 -887
- package/src/boxes/TextGridContent.js +0 -215
- package/src/init-jsdom.js +0 -65
- package/src/jclic-node.js +0 -219
- package/src/media/ActiveMediaBag.js +0 -145
- package/src/media/ActiveMediaPlayer.js +0 -297
- package/src/media/AudioBuffer.js +0 -219
- package/src/media/EventSounds.js +0 -169
- package/src/media/EventSoundsElement.js +0 -155
- package/src/media/MediaContent.js +0 -328
- package/src/media/MidiAudioPlayer.js +0 -254
- package/src/media/icons/audio.svg +0 -3
- package/src/media/icons/generic.svg +0 -3
- package/src/media/icons/mic.svg +0 -3
- package/src/media/icons/movie.svg +0 -3
- package/src/media/icons/music.svg +0 -3
- package/src/media/icons/url.svg +0 -3
- package/src/media/sounds/actionError.mp3 +0 -0
- package/src/media/sounds/actionOk.mp3 +0 -0
- package/src/media/sounds/click.mp3 +0 -0
- package/src/media/sounds/finishedError.mp3 +0 -0
- package/src/media/sounds/finishedOk.mp3 +0 -0
- package/src/media/sounds/start.mp3 +0 -0
- package/src/project/JClicProject.js +0 -282
- package/src/project/ProjectSettings.js +0 -273
- package/src/report/ActionReg.js +0 -123
- package/src/report/ActivityReg.js +0 -271
- package/src/report/EncryptMin.js +0 -210
- package/src/report/Reporter.js +0 -727
- package/src/report/SCORM.js +0 -272
- package/src/report/SequenceReg.js +0 -275
- package/src/report/SessionReg.js +0 -340
- package/src/report/SessionStorageReporter.js +0 -131
- package/src/report/TCPReporter.js +0 -628
- package/src/shapers/ClassicJigSaw.js +0 -138
- package/src/shapers/Holes.js +0 -77
- package/src/shapers/JigSaw.js +0 -161
- package/src/shapers/Rectangular.js +0 -78
- package/src/shapers/Shaper.js +0 -386
- package/src/shapers/TriangularJigSaw.js +0 -121
- package/src/skins/BlueSkin.js +0 -80
- package/src/skins/Counter.js +0 -152
- package/src/skins/CustomSkin.js +0 -412
- package/src/skins/DefaultSkin.js +0 -376
- package/src/skins/EmptySkin.js +0 -82
- package/src/skins/GreenSkin.js +0 -94
- package/src/skins/MiniSkin.js +0 -130
- package/src/skins/OrangeSkin.js +0 -78
- package/src/skins/SimpleSkin.js +0 -92
- package/src/skins/Skin.js +0 -1021
- package/src/skins/assets/actionsIcon.svg +0 -3
- package/src/skins/assets/appLogo.svg +0 -8
- package/src/skins/assets/basic.css +0 -41
- package/src/skins/assets/closeDialogIcon.svg +0 -3
- package/src/skins/assets/closeIcon.svg +0 -3
- package/src/skins/assets/copyIcon.svg +0 -3
- package/src/skins/assets/fullScreenExitIcon.svg +0 -3
- package/src/skins/assets/fullScreenIcon.svg +0 -3
- package/src/skins/assets/infoIcon.svg +0 -3
- package/src/skins/assets/main.css +0 -43
- package/src/skins/assets/mainHalf.css +0 -23
- package/src/skins/assets/mainTwoThirds.css +0 -23
- package/src/skins/assets/mini.css +0 -15
- package/src/skins/assets/nextIcon.svg +0 -3
- package/src/skins/assets/okDialogIcon.svg +0 -3
- package/src/skins/assets/prevIcon.svg +0 -3
- package/src/skins/assets/reports.css +0 -156
- package/src/skins/assets/reportsIcon.svg +0 -3
- package/src/skins/assets/scoreIcon.svg +0 -3
- package/src/skins/assets/simple.css +0 -16
- package/src/skins/assets/simpleHalf.css +0 -11
- package/src/skins/assets/simpleTwoThirds.css +0 -11
- package/src/skins/assets/timeIcon.svg +0 -4
- package/src/skins/assets/waitAnim.css +0 -54
- package/src/skins/assets/waitImgBig.svg +0 -3
- package/src/skins/assets/waitImgSmall.svg +0 -3
- package/webpack.config.mjs +0 -169
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File : boxes/ActiveBoxBag.js
|
|
3
|
-
* Created : 21/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 BoxBag from './BoxBag.js';
|
|
34
|
-
import { Point } from '../AWT.js';
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* This class is a special case of {@link module:boxes/BoxBag.BoxBag BoxBag} containing only objects of type {@link module:boxes/ActiveBox.ActiveBox ActiveBox}.
|
|
38
|
-
* In addition to the members and methods of `BoxBag`, it implements specific methods to deal with
|
|
39
|
-
* {@link module:boxes/ActiveBagContent.ActiveBagContent ActiveBagContent} objects and with the other specific members of `ActiveBox` like its "ids"
|
|
40
|
-
* (`idOrder`, `idLoc` and `idAss`).
|
|
41
|
-
* @extends module:boxes/BoxBag.BoxBag
|
|
42
|
-
*/
|
|
43
|
-
export class ActiveBoxBag extends BoxBag {
|
|
44
|
-
/**
|
|
45
|
-
* ActiveBoxBag constructor
|
|
46
|
-
* @param {module:boxes/AbstractBox.AbstractBox} [parent] - The AbstractBox to which this box bag belongs
|
|
47
|
-
* @param {module:AWT.Container} [container] - The container where this box bag is placed.
|
|
48
|
-
* @param {module:boxes/BoxBase.BoxBase} [boxBase] - The object where colors, fonts, border and other graphic properties
|
|
49
|
-
* of this box bag are defined.
|
|
50
|
-
*/
|
|
51
|
-
constructor(parent, container, boxBase) {
|
|
52
|
-
// ActiveBoxBag extends BoxBag
|
|
53
|
-
super(parent, container, boxBase);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Adds an {@link module:boxes/ActiveBox.ActiveBox ActiveBox} to this bag
|
|
58
|
-
* @param {module:boxes/ActiveBox.ActiveBox} bx - The ActiveBox to be added to this bag
|
|
59
|
-
*/
|
|
60
|
-
addActiveBox(bx) {
|
|
61
|
-
bx.idLoc = this.cells.length;
|
|
62
|
-
bx.idOrder = bx.idLoc;
|
|
63
|
-
return this.addBox(bx);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Finds an ActiveBox by its relative location (`idLoc` field)
|
|
68
|
-
* @param {number} idLoc
|
|
69
|
-
* @returns {module:boxes/ActiveBox.ActiveBox}
|
|
70
|
-
*/
|
|
71
|
-
getActiveBox(idLoc) {
|
|
72
|
-
return this.getBox(idLoc);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Gets the background box
|
|
77
|
-
* @returns {module:boxes/ActiveBox.ActiveBox}
|
|
78
|
-
*/
|
|
79
|
-
getBackgroundActiveBox() {
|
|
80
|
-
return this.getBackgroundBox();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Sets the content of members of this ActiveBoxBag, based on one or more {@link module:boxes/ActiveBagContent.ActiveBagContent ActiveBagContent}
|
|
85
|
-
* objects.
|
|
86
|
-
* @param {module:boxes/ActiveBagContent.ActiveBagContent} abc - The main bag of content
|
|
87
|
-
* @param {module:boxes/ActiveBagContent.ActiveBagContent} [altAbc] - The alternative bag of content
|
|
88
|
-
* @param {number} [fromIndex] - Starts taking the cell content located at this position on the bag
|
|
89
|
-
* @param {number} [toCell] - Starts filling the box located at this position on the ActiveBoxBag
|
|
90
|
-
* @param {number} [numCells] - Acts only with a limited number of elements.
|
|
91
|
-
*/
|
|
92
|
-
setContent(abc, altAbc, fromIndex, toCell, numCells) {
|
|
93
|
-
if (!fromIndex)
|
|
94
|
-
fromIndex = 0;
|
|
95
|
-
if (!toCell)
|
|
96
|
-
toCell = 0;
|
|
97
|
-
if (!numCells)
|
|
98
|
-
numCells = this.cells.length;
|
|
99
|
-
|
|
100
|
-
for (let i = 0; i < numCells; i++) {
|
|
101
|
-
const bx = this.getActiveBox(toCell + i);
|
|
102
|
-
bx.setContent(abc, fromIndex + i);
|
|
103
|
-
bx.setAlternative(false);
|
|
104
|
-
if (altAbc)
|
|
105
|
-
bx.setAltContent(altAbc, fromIndex + i);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (abc.backgroundContent !== null && this.getBackgroundActiveBox() !== null) {
|
|
109
|
-
const bx = this.getBackgroundActiveBox();
|
|
110
|
-
bx.setContent(abc.backgroundContent);
|
|
111
|
-
if (abc.style !== bx.boxBase)
|
|
112
|
-
bx.setBoxBase(abc.style);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Finds an ActiveBox by location
|
|
118
|
-
* @param {module:AWT.Point} point - The location to search for
|
|
119
|
-
* @returns {module:boxes/ActiveBox.ActiveBox}
|
|
120
|
-
*/
|
|
121
|
-
findActiveBox(point) {
|
|
122
|
-
return this.findBox(point);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Clears the content of all boxes
|
|
127
|
-
*/
|
|
128
|
-
clearAllBoxes() {
|
|
129
|
-
this.cells.forEach(bx => bx.clear());
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Clears the content of all boxes and background box
|
|
134
|
-
*/
|
|
135
|
-
clearAll() {
|
|
136
|
-
this.clearAllBoxes();
|
|
137
|
-
if (this.backgroundBox !== null)
|
|
138
|
-
this.getBackgroundActiveBox().clear();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Count the number of cells that are at its original place
|
|
143
|
-
* @returns {number}
|
|
144
|
-
*/
|
|
145
|
-
countCellsAtPlace() {
|
|
146
|
-
return this.cells.reduce((n, bx) => bx.isAtPlace() ? ++n : n, 0);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Finds the {@link module:boxes/ActiveBox.ActiveBox ActiveBox} that has the specified `idLoc` attribute
|
|
151
|
-
* @param {number} idLoc - The idLoc to search for
|
|
152
|
-
* @returns {module:boxes/ActiveBox.ActiveBox}
|
|
153
|
-
*/
|
|
154
|
-
getActiveBoxWithIdLoc(idLoc) {
|
|
155
|
-
return this.cells.find(bx => bx.idLoc === idLoc) || null;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Checks if the place occupied by a cell corresponds to a cell with equivalent content.
|
|
160
|
-
* @param {module:boxes/ActiveBox.ActiveBox} bx - The box to check
|
|
161
|
-
* @param {boolean} checkCase - If `true`, check case when comparing texts
|
|
162
|
-
* @returns {boolean}
|
|
163
|
-
*/
|
|
164
|
-
cellIsAtEquivalentPlace(bx, checkCase) {
|
|
165
|
-
return bx.isAtPlace() ||
|
|
166
|
-
bx.isEquivalent(this.getActiveBoxWithIdLoc(bx.idOrder), checkCase);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Count the number of cells that are at its original place or equivalent
|
|
171
|
-
* @param {boolean} checkCase - - If `true`, check case when comparing texts
|
|
172
|
-
* @returns {number}
|
|
173
|
-
*/
|
|
174
|
-
countCellsAtEquivalentPlace(checkCase) {
|
|
175
|
-
return this.cells.reduce((n, bx) => this.cellIsAtEquivalentPlace(bx, checkCase) ? ++n : n, 0);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Counts the number of cells that have the provided `idAss` attribute
|
|
180
|
-
* @param {number} idAss - The `idAss` attribute to search
|
|
181
|
-
* @returns {number}
|
|
182
|
-
*/
|
|
183
|
-
countCellsWithIdAss(idAss) {
|
|
184
|
-
return this.cells.reduce((n, bx) => bx.idAss === idAss ? ++n : n, 0);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Resets the default `idAss` attribute on all cells
|
|
189
|
-
*/
|
|
190
|
-
setDefaultIdAss() {
|
|
191
|
-
this.cells.map(bx => bx.setDefaultIdAss());
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Shuffles the cells
|
|
196
|
-
* @param {number} times - Number of times to shuffle
|
|
197
|
-
* @param {boolean} fitInArea - Ensure that all cells are inside the bag rectangle
|
|
198
|
-
*/
|
|
199
|
-
shuffleCells(times, fitInArea) {
|
|
200
|
-
let nc = this.cells.length;
|
|
201
|
-
if (nc >= 2) {
|
|
202
|
-
// Array of AWT.Point objects
|
|
203
|
-
const
|
|
204
|
-
pos = [],
|
|
205
|
-
idLoc = [],
|
|
206
|
-
p = new Point();
|
|
207
|
-
|
|
208
|
-
for (let i = 0; i < nc; i++) {
|
|
209
|
-
const bx = this.getActiveBox(i);
|
|
210
|
-
pos[i] = new Point(bx.pos);
|
|
211
|
-
idLoc[i] = bx.idLoc;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
for (let i = 0; i < times; i++) {
|
|
215
|
-
const
|
|
216
|
-
r1 = Math.floor(Math.random() * nc),
|
|
217
|
-
r2 = Math.floor(Math.random() * nc);
|
|
218
|
-
if (r1 !== r2) {
|
|
219
|
-
p.moveTo(pos[r1]);
|
|
220
|
-
pos[r1].moveTo(pos[r2]);
|
|
221
|
-
pos[r2].moveTo(p);
|
|
222
|
-
const j = idLoc[r1];
|
|
223
|
-
idLoc[r1] = idLoc[r2];
|
|
224
|
-
idLoc[r2] = j;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
for (let i = 0; i < nc; i++) {
|
|
229
|
-
const
|
|
230
|
-
bx = this.getActiveBox(i),
|
|
231
|
-
px = pos[i].x,
|
|
232
|
-
py = pos[i].y;
|
|
233
|
-
bx.moveTo(new Point(px, py));
|
|
234
|
-
if (fitInArea)
|
|
235
|
-
this.fitCellsInArea([bx]);
|
|
236
|
-
bx.idLoc = idLoc[i];
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Fits cells inside the ActiveBoxBag area. Useful when non-rectangular cells exchange its positions.
|
|
243
|
-
* @param {module:boxes/ActiveBox.ActiveBox[]} boxes - The boxes to be checked
|
|
244
|
-
*/
|
|
245
|
-
fitCellsInArea(boxes) {
|
|
246
|
-
const
|
|
247
|
-
maxX = this.pos.x + this.dim.width,
|
|
248
|
-
maxY = this.pos.y + this.dim.height;
|
|
249
|
-
|
|
250
|
-
boxes.forEach(bx => {
|
|
251
|
-
// Save original position
|
|
252
|
-
if (!bx.pos0)
|
|
253
|
-
bx.pos0 = new Point(bx.pos);
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
px = Math.min(Math.max(bx.pos.x, this.pos.x), maxX - bx.dim.width),
|
|
257
|
-
py = Math.min(Math.max(bx.pos.y, this.pos.y), maxY - bx.dim.height);
|
|
258
|
-
if (px !== bx.pos.x || py !== bx.pos.y)
|
|
259
|
-
bx.moveTo(new Point(px, py));
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Exchange the positions of two cells inside the ActiveBoxBag area.
|
|
265
|
-
* @param {module:boxes/ActiveBox.ActiveBox} bxa - The first box
|
|
266
|
-
* @param {module:boxes/ActiveBox.ActiveBox} bxb - The second box
|
|
267
|
-
* @param {boolean} fitInArea - Ensure that all cells are inside the bag rectangle
|
|
268
|
-
*/
|
|
269
|
-
swapCellPositions(bxa, bxb, fitInArea) {
|
|
270
|
-
// Save backup of bxb significant properties
|
|
271
|
-
const
|
|
272
|
-
posB = new Point(bxb.pos),
|
|
273
|
-
posB0 = bxb.pos0,
|
|
274
|
-
idLocB = bxb.idLoc;
|
|
275
|
-
|
|
276
|
-
bxb.moveTo(bxa.pos0 || bxa.pos);
|
|
277
|
-
bxb.pos0 = bxa.pos0;
|
|
278
|
-
bxb.idLoc = bxa.idLoc;
|
|
279
|
-
|
|
280
|
-
bxa.moveTo(posB0 || posB);
|
|
281
|
-
bxa.pos0 = posB0;
|
|
282
|
-
bxa.idLoc = idLocB;
|
|
283
|
-
|
|
284
|
-
if (fitInArea)
|
|
285
|
-
this.fitCellsInArea([bxa, bxb]);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Resets the IDs of all cells
|
|
290
|
-
*/
|
|
291
|
-
resetIds() {
|
|
292
|
-
this.cells.forEach((bx, i) => {
|
|
293
|
-
if (bx) {
|
|
294
|
-
bx.idOrder = i;
|
|
295
|
-
bx.idAss = i;
|
|
296
|
-
bx.idLoc = i;
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Gets the index of box located in the `cells` array after the provided index, having the
|
|
303
|
-
* provided `idAssValid` value as `idAss` attribute.
|
|
304
|
-
* When `idAssValid` is `null` or `undefined`, search for the next cell with `idAss>0`
|
|
305
|
-
* @param {number} currentItem - The index after to which start scanning
|
|
306
|
-
* @param {string} [idAssValid] - The `idAss` attribute value to search
|
|
307
|
-
* @returns {number}
|
|
308
|
-
*/
|
|
309
|
-
getNextItem(currentItem, idAssValid) {
|
|
310
|
-
const IDASSNOTUSED = -12345;
|
|
311
|
-
if (!idAssValid)
|
|
312
|
-
idAssValid = IDASSNOTUSED;
|
|
313
|
-
let i = currentItem + 1;
|
|
314
|
-
for (; i < this.cells.length; i++) {
|
|
315
|
-
const bx = this.cells[i];
|
|
316
|
-
if (!bx)
|
|
317
|
-
break;
|
|
318
|
-
if (idAssValid !== IDASSNOTUSED) {
|
|
319
|
-
if (idAssValid === bx.idAss)
|
|
320
|
-
break;
|
|
321
|
-
} else if (bx.idAss >= 0)
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
return i;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Builds a group of hidden `buton` elements that will act as a accessible objects associated
|
|
329
|
-
* to the canvas area of this ActiveBoxBag.
|
|
330
|
-
* The buttons will only be created when `CanvasRenderingContext2D` has a method named `addHitRegion`.
|
|
331
|
-
* See https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Hit_regions_and_accessibility
|
|
332
|
-
* for more information and supported browsers.
|
|
333
|
-
* @param {external:jQuery} $canvas - The `canvas` where this `ActiveBoxBag` will deploy, wrapped up in a jQuery object
|
|
334
|
-
* @param {external:jQuery} $clickReceiver - The DOM element that will be notified when a button is clicked.
|
|
335
|
-
* @param {string} [eventType] - Type of event sent to $clickReceiver. Default is `click`.
|
|
336
|
-
* @returns {external:jQuery} - The $accessibleDiv member, containing the accessible elements associated to this ActiveBoxBag.
|
|
337
|
-
*/
|
|
338
|
-
buildAccessibleElements($canvas, $clickReceiver, eventType) {
|
|
339
|
-
this.$accessibleDiv = this.accessibleText !== '' ? $('<div/>', { 'aria-label': this.accessibleText, tabindex: 0 }) : null;
|
|
340
|
-
$canvas.append(this.$accessibleDiv);
|
|
341
|
-
this.cells
|
|
342
|
-
.map(a => a)
|
|
343
|
-
.sort((a, b) => a.idLoc > b.idLoc ? 1 : -1)
|
|
344
|
-
.forEach(bx => bx.buildAccessibleElement($canvas, $clickReceiver, this.$accessibleDiv, eventType));
|
|
345
|
-
return this.$accessibleDiv;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
Object.assign(ActiveBoxBag.prototype, {
|
|
350
|
-
/**
|
|
351
|
-
* `div` containing the accessible elements associated to this ActiveBoxBag
|
|
352
|
-
* @name module:boxes/ActiveBoxBag.ActiveBoxBag#$accessibleDiv
|
|
353
|
-
* @type {external:jQuery} */
|
|
354
|
-
$accessibleDiv: null,
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
export default ActiveBoxBag;
|