-
Notifications
You must be signed in to change notification settings - Fork 1
/
snap-puzzle-options.ts
249 lines (249 loc) · 7.45 KB
/
snap-puzzle-options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/**
* @module jqSnapPuzzle
*//** */
/**
* Options for the plugin
*
* All the options could be updated using the jquery ui widget method
*
* **Please note**, when some options are updated, the markup of the widget is re-created and the progress of the puzzle will be lost.
*
* @example For example
* ```typescript
* $("someSelector").snapPuzzle("option","rows",4);
* ```
*
* **For multiple options**
* Because set options could reconstruct the component, if more that one option will be provided, pass an object instead of key-value
* @example Multiple options
* * ```typescript
* $("someSelector").snapPuzzle("option",{
* columns:4,
* rows:2,
* backgroundInSlots:false
* });
* ```
*
*/
export interface SnapPuzzleOptions{
/**
* Num of rows for the puzzle.
* Update this option will reconstruct the markup and the progress will be lost
*/
rows:number;
/**
* Num of columns for the puzzle.
* Update this option will reconstruct the markup and the progress will be lost
*/
columns:number;
/**
* Initial width of the image.
* If it's provided, will be used for the initialization instead of wait for the image to be loaded
*/
width?:number;
/**
* Initial height of the image.
* If it's provided, will be used for the initialization instead of wait for the image to be loaded
*/
height?:number;
/**
* Namespace for events.
* Update this option will reconstruct the markup and the progress will be lost
* @default jq-crossword
*/
namespace?: string;
/**
* Disable the widget
* @default false
*/
disabled?:boolean;
/**
* Number of pieces to resolve from the beginning
* @default 0
*/
hints?:number;
/**
* Css classes to use.
*
* Update this option will reconstruct the markup and the progress will be lost.
*/
classes?: {
/**
* Root element
* @default `c-snap-puzzle__image`
*/
root?: string;
/**
* Class for the wrapper and the root element for when the puzzle is completed
* @default `c-snap-puzzle--completed`
*/
completed?:string;
/**
* Class for the disabled state
* @default `c-snap-puzzle--disabled`
*/
disabled?: string;
/**
* Class for the wrapper
* @default `c-snap-puzzle`
*/
wrapper?:string;
/**
* Class for the pieces container
* @default `c-snap-puzzle__pieces-container`
*/
piecesContainer?:string;
/**
* Class for the slots container
* @default `c-snap-puzzle__slots-container`
*/
slotsContainer;
/**
* Class for the pieces
* @default `c-snap-puzzle__piece`
*/
piece?:string;
/**
* Class for the piece when has been dropped or is hover an incorrect slot
* @default `c-snap-puzzle__piece--incorrect`
*/
pieceIncorrect?:string;
/**
* Class for the piece when has been dropped or is hover a correct slot
* @default `c-snap-puzzle__piece--correct`
*/
pieceCorrect?:string;
/**
* Class for the disabled pieces
* @default `c-snap-puzzle__piece--disabled`
*/
pieceDisabled?:string;
/**
* Class for the slots
* @default `c-snap-puzzle__slot`
*/
slot?:string;
/**
* Class for the slots when have a piece placed
* @default `c-snap-puzzle__slot--has-piece`
*/
slotHasPiece?:string;
/**
* Class for the slot when the incorrect piece is hover or has been dropped
* @default `c-snap-puzzle__slot--incorrect`
*/
slotIncorrect?:string;
/**
* Class for the slot when the correct piece is hover or has been dropped
* @default `c-snap-puzzle__slot--correct`
*/
slotCorrect?:string;
/**
* Class for the disabled slots
* @default `c-snap-puzzle__slot--disabled`
*/
slotDisabled?:string;
/**
* Class for the wrapper when the feedbackOnHover option is true
* @default `c-snap-puzzle--feedback-on-hover`
*/
feedbackOnHover?:string;
/**
* Class for the wrapper when the backgroundInSlots option is true
* @default `c-snap-puzzle--slots-background`
*/
backgroundInSlots?:string;
};
/**
* If true, the pieces only could be dropped in the correct slots.
* If the piece is dropped in an incorrect slot, will be reverted to the previous position
* @default false
*/
onlyDropOnValid?:boolean;
/**
* Add the feedback class to the piece when is above the correct or incorrect slot
* @see [[classes.pieceIncorrect]]
* @see [[classes.pieceCorrect]]
* @default false
*/
feedbackOnHover?:boolean;
/**
* Add the background to the slots
* @default true
*/
backgroundInSlots?:boolean;
/**
* Randomize the starting position of the pieces
* @default false
*/
randomPieceStartPosition?:boolean;
/**
* Override the default creation of the pieces container
* @returns {JQuery}
* @example ```typescript
* $(".puzzle").snapPuzzle({
* createPiecesContainer:()=>{
* return $(`<div class="my-custom-element"></div>`);
* }
* })```
* @see [[SnapPuzzleWrapper._createPiecesContainer]]
*/
createPiecesContainer?(): JQuery;
/**
* Override the default creation of the slots container
* The slots container will be appended to the wrapper
* @returns {JQuery}
* @example ```typescript
* $(".puzzle").snapPuzzle({
* createSlotsContainer:()=>{
* return $(`<div class="my-custom-element"></div>`);
* }
* })```
* @see [[SnapPuzzleWrapper._createSlotsContainer]]
*/
createSlotsContainer?(): JQuery;
/**
* Override the default creation of each piece.
* The piece is the draggable item of the puzzle
* @returns {JQuery}
* @example ```typescript
* $(".puzzle").snapPuzzle({
* createPiece:()=>{
* return $(`<div class="my-custom-element"></div>`);
* }
* })```
* @see [[SnapPuzzleWrapper._createPiece]]
*/
createPiece?(): JQuery;
/**
* Override the default creation of each slot.
* The slot is where the piece of the puzzle could be dropped
* @returns {JQuery}
* @example ```typescript
* $(".puzzle").snapPuzzle({
* createSlot:()=>{
* return $(`<div class="my-custom-element"></div>`);
* }
* })```
* @see [[SnapPuzzleWrapper._createSlot]]
*/
createSlot?(): JQuery;
/**
* Override the default creation of the wrapper
* @returns {JQuery}
* @example ```typescript
* $(".puzzle").snapPuzzle({
* createWrapper:()=>{
* return $(`<div class="my-custom-element"></div>`);
* }
* })```
* @see [[SnapPuzzleWrapper._createWrapper]]
*/
createWrapper?(): JQuery;
/**
* Where to append the puzzle pieces
* By default the list will be appended to the pieces container
* If this option is provided, [[createPiecesContainer]] will **not** be invoked
*/
appendPiecesTo?: Element | JQuery | string;
}