theshtify 1.0.4 → 2.0.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/.claude/settings.local.json +8 -0
- package/LICENSE +21 -21
- package/css/theshtify.css +50 -40
- package/dist/assets/index-CGwBVT47.css +1 -0
- package/dist/index.html +65 -0
- package/dist/theshtify.cdn.js +674 -0
- package/dist/theshtify.min.js +2 -0
- package/index.html +65 -54
- package/lib/documentation.js +31 -31
- package/lib/theshtify.js +937 -730
- package/lib/theshtifyCDN.js +3 -730
- package/package.json +33 -27
- package/readme.md +221 -331
- package/tests/theshtify.test.js +228 -0
- package/vitest.config.js +7 -0
- package/lib/notif.js +0 -347
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
// lib/theshtify.js
|
|
3
|
+
var theshtify_infos = {
|
|
4
|
+
title: "",
|
|
5
|
+
message: "",
|
|
6
|
+
type: "",
|
|
7
|
+
lang: "en",
|
|
8
|
+
config: {
|
|
9
|
+
main_box_classes: "",
|
|
10
|
+
x_pos: "right",
|
|
11
|
+
y_pos: "top",
|
|
12
|
+
font: {
|
|
13
|
+
family: "arial",
|
|
14
|
+
size: 14,
|
|
15
|
+
weight: ""
|
|
16
|
+
},
|
|
17
|
+
min_duration: 1e3,
|
|
18
|
+
max_duration: 5e3,
|
|
19
|
+
duration: 5e3,
|
|
20
|
+
borderWidth: 2,
|
|
21
|
+
bordered: false,
|
|
22
|
+
progress: false,
|
|
23
|
+
progressHeight: 2,
|
|
24
|
+
closer: false,
|
|
25
|
+
trans: false,
|
|
26
|
+
display: {
|
|
27
|
+
width: 300,
|
|
28
|
+
colors: {
|
|
29
|
+
custom: {
|
|
30
|
+
color: "white",
|
|
31
|
+
bg: "#000",
|
|
32
|
+
border: {
|
|
33
|
+
type: "solid",
|
|
34
|
+
color: "transparent"
|
|
35
|
+
},
|
|
36
|
+
progress: {
|
|
37
|
+
bg: "#fff"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
success: {
|
|
41
|
+
color: "white",
|
|
42
|
+
bg: "rgba(1, 191, 102, 0.822)",
|
|
43
|
+
border: {
|
|
44
|
+
type: "solid",
|
|
45
|
+
color: "transparent"
|
|
46
|
+
},
|
|
47
|
+
progress: {
|
|
48
|
+
bg: "#fff"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
danger: {
|
|
52
|
+
bg: "red",
|
|
53
|
+
color: "white",
|
|
54
|
+
border: {
|
|
55
|
+
type: "solid",
|
|
56
|
+
color: "transparent"
|
|
57
|
+
},
|
|
58
|
+
progress: {
|
|
59
|
+
bg: "#fff"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
info: {
|
|
63
|
+
bg: "rgba(7, 133, 250, 0.822)",
|
|
64
|
+
color: "white",
|
|
65
|
+
border: {
|
|
66
|
+
type: "solid",
|
|
67
|
+
color: "transparent"
|
|
68
|
+
},
|
|
69
|
+
progress: {
|
|
70
|
+
bg: "#fff"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
warning: {
|
|
74
|
+
bg: "#f89406",
|
|
75
|
+
color: "black",
|
|
76
|
+
border: {
|
|
77
|
+
type: "solid",
|
|
78
|
+
color: "transparent"
|
|
79
|
+
},
|
|
80
|
+
progress: {
|
|
81
|
+
bg: "#fff"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
padding: {
|
|
86
|
+
left: 10,
|
|
87
|
+
right: 10,
|
|
88
|
+
top: 10,
|
|
89
|
+
bottom: 10
|
|
90
|
+
},
|
|
91
|
+
margin: {
|
|
92
|
+
left: 20,
|
|
93
|
+
right: 20,
|
|
94
|
+
top: 20,
|
|
95
|
+
bottom: 20
|
|
96
|
+
},
|
|
97
|
+
radius: 5
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
callback: () => {
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var types = ["success", "info", "danger", "warning", "custom"];
|
|
104
|
+
var positions = {
|
|
105
|
+
x: ["middle", "left", "right"],
|
|
106
|
+
y: ["middle", "top", "bottom"]
|
|
107
|
+
};
|
|
108
|
+
var messages = {
|
|
109
|
+
en: {
|
|
110
|
+
errors: {
|
|
111
|
+
type_error: "the {name} have to be {type} ",
|
|
112
|
+
padding_error: "the padding must be a number or an object that include keys left, right, top, bottom with number values",
|
|
113
|
+
type: "{name} is {type}",
|
|
114
|
+
duration: "the {type} duration is {ms}MS ({sec}s)",
|
|
115
|
+
position: "the {axis}_pos property have to be one the listed values {values}"
|
|
116
|
+
},
|
|
117
|
+
labels: {
|
|
118
|
+
empty: "empty",
|
|
119
|
+
undefined: "undefined",
|
|
120
|
+
min: "min",
|
|
121
|
+
max: "max"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
function theshtify(infos) {
|
|
126
|
+
let notif = buildBox(infos);
|
|
127
|
+
if (notif != false) {
|
|
128
|
+
addAndPositionNotif(notif);
|
|
129
|
+
animProgress(notif);
|
|
130
|
+
moveDisplayedNotifications(notif);
|
|
131
|
+
fadeShow(notif);
|
|
132
|
+
fadeHide(notif);
|
|
133
|
+
addCallback(notif);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function configure(datas) {
|
|
137
|
+
let config = datas.config ?? {};
|
|
138
|
+
try {
|
|
139
|
+
datas.message ? message(datas.message) : "";
|
|
140
|
+
datas.title ? theshtify_infos.title = datas.title : "";
|
|
141
|
+
config.main_box_classes && config.main_box_classes != "" ? theshtify_infos.config.main_box_classes = config.main_box_classes : "";
|
|
142
|
+
config.duration ? duration(config.duration) : "";
|
|
143
|
+
config.custom_colors ? setCustomColors(config.custom_colors) : "";
|
|
144
|
+
datas.type ? type(datas.type) : "";
|
|
145
|
+
config.bordered ? bordered(config.bordered) : "";
|
|
146
|
+
config.bordered && config.border_width ? borderWidth(config.border_width) : "";
|
|
147
|
+
config.radius ? radius(config.radius) : "";
|
|
148
|
+
config.colors ? customColors(config.colors) : "";
|
|
149
|
+
config.x_align ? setBoxPosition("x", config.x_align) : "";
|
|
150
|
+
config.y_align ? setBoxPosition("y", config.y_align) : "";
|
|
151
|
+
config.font ? font(config.font) : "";
|
|
152
|
+
config.closer ? withCloser(config.closer) : "";
|
|
153
|
+
config.progress ? haveProgress(config.progress) : "";
|
|
154
|
+
config.padding ? setPadding(config.padding) : "";
|
|
155
|
+
datas.callback ? setCallback(datas.callback) : "";
|
|
156
|
+
config.progress && config.progress_height ? progressHeight(config.progress_height) : "";
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error(`theshtify error
|
|
159
|
+
${error}`);
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
function setPadding(padding) {
|
|
165
|
+
if (checkType(padding, "number")) {
|
|
166
|
+
theshtify_infos.config.display.padding.left = padding;
|
|
167
|
+
theshtify_infos.config.display.padding.right = padding;
|
|
168
|
+
theshtify_infos.config.display.padding.top = padding;
|
|
169
|
+
theshtify_infos.config.display.padding.bottom = padding;
|
|
170
|
+
return;
|
|
171
|
+
} else {
|
|
172
|
+
if (checkType(padding, "object")) {
|
|
173
|
+
if (Object.keys(padding).includes("left") && checkType(padding.left, "number") && Object.keys(padding).includes("right") && checkType(padding.right, "number") && Object.keys(padding).includes("top") && checkType(padding.top, "number") && Object.keys(padding).includes("bottom") && checkType(padding.bottom, "number")) {
|
|
174
|
+
theshtify_infos.config.display.padding = padding;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
throw getMessage(cMessages().errors.padding_error);
|
|
180
|
+
}
|
|
181
|
+
function setCallback(callback) {
|
|
182
|
+
if (checkType(callback, "function")) {
|
|
183
|
+
theshtify_infos.callback = callback;
|
|
184
|
+
} else {
|
|
185
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
186
|
+
name: "callback",
|
|
187
|
+
type: "function"
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function setCustomColors(customColors2) {
|
|
192
|
+
for (const key in customColors2) {
|
|
193
|
+
if (Object.prototype.hasOwnProperty.call(customColors2, key)) {
|
|
194
|
+
if (getColor(key)) {
|
|
195
|
+
theshtify_infos.type = key;
|
|
196
|
+
configureColor(customColors2[key]);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function addAndPositionNotif(notif) {
|
|
202
|
+
document.querySelector("body").before(notif);
|
|
203
|
+
let pos = getPosition({
|
|
204
|
+
width: notif.offsetWidth,
|
|
205
|
+
height: notif.offsetHeight
|
|
206
|
+
});
|
|
207
|
+
notif.style.left = `${pos.x}px`;
|
|
208
|
+
notif.style.top = `${pos.y}px`;
|
|
209
|
+
}
|
|
210
|
+
function message(message2 = null) {
|
|
211
|
+
if (message2 != null) {
|
|
212
|
+
switch (true) {
|
|
213
|
+
case message2 == "":
|
|
214
|
+
throw cMessages().errors.type, { name: "message", type: cMessages().labels.empty };
|
|
215
|
+
case checkType(message2, "undefined"):
|
|
216
|
+
throw cMessages().errors.type, { name: "message", type: cMessages().labels.undefined };
|
|
217
|
+
case !checkType(message2, "string"):
|
|
218
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
219
|
+
name: "message",
|
|
220
|
+
type: "string"
|
|
221
|
+
});
|
|
222
|
+
default:
|
|
223
|
+
theshtify_infos.message = message2;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
return message2;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function setBoxPosition(axis, value) {
|
|
231
|
+
if (checkType(value, "string")) {
|
|
232
|
+
if (positions[axis].includes(value)) {
|
|
233
|
+
theshtify_infos.config[`${axis}_pos`] = value;
|
|
234
|
+
} else {
|
|
235
|
+
throw getMessage(cMessages().errors.position, {
|
|
236
|
+
axis,
|
|
237
|
+
values: positions[axis].join(",")
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
242
|
+
name: "colors.color",
|
|
243
|
+
type: "string"
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function customColors(colors) {
|
|
248
|
+
if (checkType(colors, "object")) {
|
|
249
|
+
if (theshtify_infos.type == "custom") {
|
|
250
|
+
configureColor(colors);
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
254
|
+
name: "colors",
|
|
255
|
+
type: "object"
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function configureColor(colors) {
|
|
260
|
+
colors.bg ? background(colors.bg) : "";
|
|
261
|
+
colors.color ? textColor(colors.color) : "";
|
|
262
|
+
colors.border.type ? borderType(colors.border.type) : "";
|
|
263
|
+
colors.border.color ? borderColor(colors.border.color) : "";
|
|
264
|
+
colors.progress.bg ? progressColor(colors.progress.bg) : "";
|
|
265
|
+
}
|
|
266
|
+
function getColor(name) {
|
|
267
|
+
return theshtify_infos.config.display.colors[name] ?? false;
|
|
268
|
+
}
|
|
269
|
+
function background(bg) {
|
|
270
|
+
if (checkType(bg, "string")) {
|
|
271
|
+
currentColor().bg = bg;
|
|
272
|
+
} else {
|
|
273
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
274
|
+
name: "colors.bg",
|
|
275
|
+
type: "string"
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function textColor(color) {
|
|
280
|
+
if (checkType(color, "string")) {
|
|
281
|
+
currentColor().color = color;
|
|
282
|
+
} else {
|
|
283
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
284
|
+
name: "colors.color",
|
|
285
|
+
type: "string"
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function borderColor(color) {
|
|
290
|
+
if (checkType(color, "string")) {
|
|
291
|
+
currentColor().border.color = color;
|
|
292
|
+
} else {
|
|
293
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
294
|
+
name: "colors.border.color",
|
|
295
|
+
type: "string"
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function borderType(type2) {
|
|
300
|
+
if (checkType(type2, "string")) {
|
|
301
|
+
currentColor().border.type = type2;
|
|
302
|
+
} else {
|
|
303
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
304
|
+
name: "colors.border.type",
|
|
305
|
+
type: "string"
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function borderWidth(width) {
|
|
310
|
+
if (checkType(width, "number")) {
|
|
311
|
+
theshtify_infos.config.borderWidth = width;
|
|
312
|
+
} else {
|
|
313
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
314
|
+
name: "borderWidth",
|
|
315
|
+
type: "number"
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function radius(radius2) {
|
|
320
|
+
if (checkType(radius2, "number")) {
|
|
321
|
+
theshtify_infos.config.display.radius = radius2;
|
|
322
|
+
} else {
|
|
323
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
324
|
+
name: "radius",
|
|
325
|
+
type: "number"
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function bordered(bordered2 = false) {
|
|
330
|
+
if (checkType(bordered2, "boolean")) {
|
|
331
|
+
theshtify_infos.config.bordered = bordered2;
|
|
332
|
+
} else {
|
|
333
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
334
|
+
name: "bordered",
|
|
335
|
+
type: "boolean"
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function haveProgress(progress2 = false) {
|
|
340
|
+
if (checkType(progress2, "boolean")) {
|
|
341
|
+
theshtify_infos.config.progress = progress2;
|
|
342
|
+
} else {
|
|
343
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
344
|
+
name: "progress",
|
|
345
|
+
type: "boolean"
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function withCloser(closer = false) {
|
|
350
|
+
if (checkType(closer, "boolean")) {
|
|
351
|
+
theshtify_infos.config.closer = closer;
|
|
352
|
+
} else {
|
|
353
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
354
|
+
name: "closer",
|
|
355
|
+
type: "boolean"
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function progressHeight(height) {
|
|
360
|
+
if (checkType(height, "number")) {
|
|
361
|
+
theshtify_infos.config.progressHeight = height;
|
|
362
|
+
} else {
|
|
363
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
364
|
+
name: "progressHeight",
|
|
365
|
+
type: "number"
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function progressColor(color) {
|
|
370
|
+
if (checkType(color, "string")) {
|
|
371
|
+
currentColor().progress.bg = color;
|
|
372
|
+
} else {
|
|
373
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
374
|
+
name: "progress.bg",
|
|
375
|
+
type: "string"
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function duration(duration2) {
|
|
380
|
+
if (checkType(duration2, "number")) {
|
|
381
|
+
if (duration2 <= theshtify_infos.config.max_duration) {
|
|
382
|
+
theshtify_infos.config.duration = duration2;
|
|
383
|
+
} else {
|
|
384
|
+
throw getMessage(cMessages().errors.duration, {
|
|
385
|
+
type: cMessages().labels.max,
|
|
386
|
+
ms: `${theshtify_infos.config.max_duration}`,
|
|
387
|
+
sec: `${theshtify_infos.config.max_duration / 1e3}`
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
if (duration2 >= theshtify_infos.config.min_duration) {
|
|
391
|
+
theshtify_infos.config.duration = duration2;
|
|
392
|
+
} else {
|
|
393
|
+
throw getMessage(cMessages().errors.duration, {
|
|
394
|
+
type: cMessages().labels.min,
|
|
395
|
+
ms: `${theshtify_infos.config.min_duration}`,
|
|
396
|
+
sec: `${theshtify_infos.config.min_duration / 1e3}`
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
} else {
|
|
400
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
401
|
+
name: "duration",
|
|
402
|
+
type: "number"
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function type(type2) {
|
|
407
|
+
if (type2 != null) {
|
|
408
|
+
if (types.includes(type2)) {
|
|
409
|
+
theshtify_infos.type = type2;
|
|
410
|
+
} else {
|
|
411
|
+
throw "the given type is not supported";
|
|
412
|
+
}
|
|
413
|
+
} else {
|
|
414
|
+
return type2;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function font(font2) {
|
|
418
|
+
if (font2) {
|
|
419
|
+
if (font2.size) {
|
|
420
|
+
if (checkType(font2.size, "number")) {
|
|
421
|
+
theshtify_infos.config.font.size = font2.size;
|
|
422
|
+
} else {
|
|
423
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
424
|
+
name: "font.size",
|
|
425
|
+
type: "number"
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (font2.weight) {
|
|
430
|
+
if (checkType(font2.weight, "number")) {
|
|
431
|
+
theshtify_infos.config.font.weight = font2.weight;
|
|
432
|
+
} else {
|
|
433
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
434
|
+
name: "font.weight",
|
|
435
|
+
type: "number"
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
if (font2.family) {
|
|
440
|
+
if (checkType(font2.family, "string")) {
|
|
441
|
+
theshtify_infos.config.font.family = font2.family;
|
|
442
|
+
} else {
|
|
443
|
+
throw getMessage(cMessages().errors.type_error, {
|
|
444
|
+
name: "font.family",
|
|
445
|
+
type: "string"
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
} else {
|
|
450
|
+
return theshtify_infos.config.font;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function cMessages() {
|
|
454
|
+
return messages[theshtify_infos.lang];
|
|
455
|
+
}
|
|
456
|
+
function getMessage(message2 = "", params = {}) {
|
|
457
|
+
let mes = message2;
|
|
458
|
+
for (const key in params) {
|
|
459
|
+
if (Object.prototype.hasOwnProperty.call(params, key)) {
|
|
460
|
+
mes = mes.replace(`{${key}}`, params[key]);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return mes;
|
|
464
|
+
}
|
|
465
|
+
function currentColor() {
|
|
466
|
+
return theshtify_infos.config.display.colors[theshtify_infos.type];
|
|
467
|
+
}
|
|
468
|
+
function getPosition(boxSize) {
|
|
469
|
+
let retPos = {
|
|
470
|
+
x: 0,
|
|
471
|
+
y: 0
|
|
472
|
+
};
|
|
473
|
+
theshtify_infos.config.x_pos == "left" ? retPos.x = theshtify_infos.config.display.margin.left : 0;
|
|
474
|
+
theshtify_infos.config.x_pos == "right" ? retPos.x = window.innerWidth - (boxSize.width + theshtify_infos.config.display.margin.right) : 0;
|
|
475
|
+
theshtify_infos.config.x_pos == "middle" ? retPos.x = (window.innerWidth - boxSize.width) / 2 : 0;
|
|
476
|
+
theshtify_infos.config.y_pos == "top" ? retPos.y = 0 + theshtify_infos.config.display.margin.top : 0;
|
|
477
|
+
theshtify_infos.config.y_pos == "bottom" ? retPos.y = window.innerHeight - (boxSize.height + theshtify_infos.config.display.margin.bottom) : 0;
|
|
478
|
+
theshtify_infos.config.y_pos == "middle" ? retPos.y = (window.innerHeight - boxSize.height) / 2 : 0;
|
|
479
|
+
return retPos;
|
|
480
|
+
}
|
|
481
|
+
function checkType(value, neededType) {
|
|
482
|
+
return typeof value === neededType;
|
|
483
|
+
}
|
|
484
|
+
function buildBox(config) {
|
|
485
|
+
if (configure(config)) {
|
|
486
|
+
let box = mainContainer();
|
|
487
|
+
theshtify_infos.config.closer ? box.append(dismiss()) : "";
|
|
488
|
+
box.append(body());
|
|
489
|
+
theshtify_infos.config.progress ? box.append(progress()) : "";
|
|
490
|
+
return box;
|
|
491
|
+
} else {
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function mainContainer() {
|
|
496
|
+
var notif = document.createElement("div");
|
|
497
|
+
notif.setAttribute("class", "Thesharsol-notifyer");
|
|
498
|
+
theshtify_infos.config.main_box_classes ? notif.classList.add(theshtify_infos.config.main_box_classes) : "";
|
|
499
|
+
notif.style.width = "90%";
|
|
500
|
+
notif.style.maxWidth = `${theshtify_infos.config.display.width}px`;
|
|
501
|
+
notif.style.position = "fixed";
|
|
502
|
+
notif.style.zIndex = 999, 999;
|
|
503
|
+
notif.style.opacity = 0;
|
|
504
|
+
notif.style.fontFamily = `${theshtify_infos.config.font.family}`;
|
|
505
|
+
notif.style.fontSize = `${theshtify_infos.config.font.size}px`;
|
|
506
|
+
notif.style.fontWeight = `${theshtify_infos.config.font.weight}`;
|
|
507
|
+
notif.style.borderRadius = `${theshtify_infos.config.display.radius}px`;
|
|
508
|
+
notif.style.backgroundColor = theshtify_infos.config.display.colors[theshtify_infos.type].bg;
|
|
509
|
+
notif.setAttribute(
|
|
510
|
+
"index",
|
|
511
|
+
document.querySelectorAll(".Thesharsol-notifyer").length
|
|
512
|
+
);
|
|
513
|
+
if (theshtify_infos.config.bordered) {
|
|
514
|
+
notif.style.border = `${theshtify_infos.config.borderWidth}px ${currentColor().border.type} ${currentColor().border.color}`;
|
|
515
|
+
}
|
|
516
|
+
return notif;
|
|
517
|
+
}
|
|
518
|
+
function body() {
|
|
519
|
+
let body2 = document.createElement("div");
|
|
520
|
+
let bodyContent = document.createElement("div");
|
|
521
|
+
body2.setAttribute("style", "width:100%");
|
|
522
|
+
bodyContent.style.color = theshtify_infos.config.display.colors[theshtify_infos.type].color;
|
|
523
|
+
bodyContent.style.paddingLeft = `${theshtify_infos.config.display.padding.left}px`;
|
|
524
|
+
bodyContent.style.paddingRight = `${theshtify_infos.config.display.padding.right}px`;
|
|
525
|
+
bodyContent.style.paddingTop = `${theshtify_infos.config.display.padding.top}px`;
|
|
526
|
+
bodyContent.style.paddingBottom = `${theshtify_infos.config.display.padding.bottom}px`;
|
|
527
|
+
const title = span(theshtify_infos.title, true);
|
|
528
|
+
title.style.marginBottom = `${theshtify_infos.message != "" ? 4 : 0}px`;
|
|
529
|
+
theshtify_infos.title ? bodyContent.append(title) : "";
|
|
530
|
+
theshtify_infos.message ? bodyContent.append(span(theshtify_infos.message)) : "";
|
|
531
|
+
body2.append(bodyContent);
|
|
532
|
+
return body2;
|
|
533
|
+
}
|
|
534
|
+
function span(text = "", bold = false) {
|
|
535
|
+
let span2 = document.createElement("span");
|
|
536
|
+
span2.setAttribute(
|
|
537
|
+
"style",
|
|
538
|
+
`display:block;font-weight:${bold ? "bold" : "light"};`
|
|
539
|
+
);
|
|
540
|
+
if (text && text != "") {
|
|
541
|
+
span2.textContent = text;
|
|
542
|
+
}
|
|
543
|
+
return span2;
|
|
544
|
+
}
|
|
545
|
+
function dismiss() {
|
|
546
|
+
let dismiss2 = document.createElement("div");
|
|
547
|
+
let dismissContent = document.createElement("button");
|
|
548
|
+
dismissContent.classList.add("close-icon");
|
|
549
|
+
dismissContent.fontSize = `22px`;
|
|
550
|
+
dismiss2.setAttribute(
|
|
551
|
+
"style",
|
|
552
|
+
`display:flex;padding:${theshtify_infos.config.display.padding.top}px ${theshtify_infos.config.display.padding.top}px 0px ${theshtify_infos.config.display.padding.top}px;`
|
|
553
|
+
);
|
|
554
|
+
dismissContent.setAttribute(
|
|
555
|
+
"style",
|
|
556
|
+
`font-weight:bold;margin-left:auto;background:transparent;border:0px;color:${currentColor().color}`
|
|
557
|
+
);
|
|
558
|
+
dismiss2.append(dismissContent);
|
|
559
|
+
dismissContent.addEventListener("click", () => {
|
|
560
|
+
let boxToRemove = dismissContent.parentNode.parentNode;
|
|
561
|
+
moveDisplayedNotifications(
|
|
562
|
+
boxToRemove,
|
|
563
|
+
"remove",
|
|
564
|
+
parseInt(boxToRemove.getAttribute("index"))
|
|
565
|
+
);
|
|
566
|
+
boxToRemove.remove();
|
|
567
|
+
});
|
|
568
|
+
return dismiss2;
|
|
569
|
+
}
|
|
570
|
+
function progress() {
|
|
571
|
+
let progress2 = document.createElement("div");
|
|
572
|
+
let progressContent = document.createElement("div");
|
|
573
|
+
progress2.style.width = "100%";
|
|
574
|
+
progress2.style.borderRadius = `${theshtify_infos.config.display.radius}px`;
|
|
575
|
+
progress2.style.overflow = "hidden";
|
|
576
|
+
progress2.classList.add("progress");
|
|
577
|
+
progressContent.setAttribute("style", "height:2px;width:0px");
|
|
578
|
+
progressContent.style.minHeight = `${theshtify_infos.config.progressHeight}px`;
|
|
579
|
+
progressContent.style.width = "0px";
|
|
580
|
+
progressContent.classList.add("content");
|
|
581
|
+
progressContent.style.background = `${currentColor().progress ? currentColor().progress.bg : "white"}`;
|
|
582
|
+
progress2.append(progressContent);
|
|
583
|
+
return progress2;
|
|
584
|
+
}
|
|
585
|
+
function animProgress(box) {
|
|
586
|
+
let progressBar = box.querySelector(".progress");
|
|
587
|
+
if (progressBar != void 0) {
|
|
588
|
+
let progressBoxContent = box.querySelector(".content");
|
|
589
|
+
let maxProgressContentWidth = progressBar.offsetWidth;
|
|
590
|
+
progressBoxContent.style.width = "0px";
|
|
591
|
+
progressBoxContent.style.transitionDuration = `${theshtify_infos.config.duration}ms`;
|
|
592
|
+
requestAnimationFrame(() => {
|
|
593
|
+
progressBoxContent.style.width = `${maxProgressContentWidth}px`;
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function moveDisplayedNotifications(createdBox, moveType = "add", startIndex = 0) {
|
|
598
|
+
let notifBoxes = document.querySelectorAll(".Thesharsol-notifyer");
|
|
599
|
+
let offset = createdBox.offsetHeight + 20;
|
|
600
|
+
let boxesCumulatedHeihgt = offset;
|
|
601
|
+
switch (moveType) {
|
|
602
|
+
case "add":
|
|
603
|
+
for (let i = startIndex; i < notifBoxes.length; i++) {
|
|
604
|
+
boxesCumulatedHeihgt = changeBoxPosition(
|
|
605
|
+
notifBoxes,
|
|
606
|
+
i,
|
|
607
|
+
moveType,
|
|
608
|
+
boxesCumulatedHeihgt,
|
|
609
|
+
createdBox,
|
|
610
|
+
offset
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
break;
|
|
614
|
+
case "remove":
|
|
615
|
+
console.log("remove");
|
|
616
|
+
let si = Array.prototype.indexOf.call(notifBoxes, createdBox);
|
|
617
|
+
for (let i = si; i >= 0; i--) {
|
|
618
|
+
boxesCumulatedHeihgt = changeBoxPosition(
|
|
619
|
+
notifBoxes,
|
|
620
|
+
i,
|
|
621
|
+
moveType,
|
|
622
|
+
boxesCumulatedHeihgt,
|
|
623
|
+
createdBox,
|
|
624
|
+
offset
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
for (let j = si + 1; j < notifBoxes.length; j++) {
|
|
628
|
+
notifBoxes[j].setAttribute("index", j - 1);
|
|
629
|
+
console.log(si);
|
|
630
|
+
}
|
|
631
|
+
break;
|
|
632
|
+
default:
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
if (boxesCumulatedHeihgt > window.innerHeight * 50 / 100) {
|
|
636
|
+
notifBoxes[0].remove();
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
function changeBoxPosition(notifBoxes, i, moveType, boxesCumulatedHeihgt, createdBox, offset) {
|
|
640
|
+
let box = notifBoxes[i];
|
|
641
|
+
if (createdBox != box && box != void 0) {
|
|
642
|
+
if (theshtify_infos.config.y_pos == "bottom") {
|
|
643
|
+
box.style.top = moveType == "add" ? `${box.offsetTop - offset}px` : `${box.offsetTop + offset}px`;
|
|
644
|
+
}
|
|
645
|
+
if (theshtify_infos.config.y_pos == "top") {
|
|
646
|
+
box.style.top = moveType == "add" ? `${box.offsetTop + offset}px` : `${box.offsetTop - offset}px`;
|
|
647
|
+
}
|
|
648
|
+
boxesCumulatedHeihgt += box.offsetHeight;
|
|
649
|
+
}
|
|
650
|
+
return boxesCumulatedHeihgt;
|
|
651
|
+
}
|
|
652
|
+
function fadeShow(notif) {
|
|
653
|
+
requestAnimationFrame(() => {
|
|
654
|
+
notif.style.opacity = 0.9;
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
function fadeHide(notif) {
|
|
658
|
+
setTimeout(function() {
|
|
659
|
+
notif.classList.add("fade-out");
|
|
660
|
+
notif.addEventListener("transitionend", function handler() {
|
|
661
|
+
notif.removeEventListener("transitionend", handler);
|
|
662
|
+
notif.remove();
|
|
663
|
+
});
|
|
664
|
+
}, theshtify_infos.config.duration);
|
|
665
|
+
}
|
|
666
|
+
function addCallback(box = HTMLDivElement) {
|
|
667
|
+
box.addEventListener("click", () => {
|
|
668
|
+
theshtify_infos.callback();
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// lib/theshtifyCDN.js
|
|
673
|
+
window.theshtify = theshtify;
|
|
674
|
+
})();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(()=>{var r={title:"",message:"",type:"",lang:"en",config:{main_box_classes:"",x_pos:"right",y_pos:"top",font:{family:"arial",size:14,weight:""},min_duration:1e3,max_duration:5e3,duration:5e3,borderWidth:2,bordered:!1,progress:!1,progressHeight:2,closer:!1,trans:!1,display:{width:300,colors:{custom:{color:"white",bg:"#000",border:{type:"solid",color:"transparent"},progress:{bg:"#fff"}},success:{color:"white",bg:"rgba(1, 191, 102, 0.822)",border:{type:"solid",color:"transparent"},progress:{bg:"#fff"}},danger:{bg:"red",color:"white",border:{type:"solid",color:"transparent"},progress:{bg:"#fff"}},info:{bg:"rgba(7, 133, 250, 0.822)",color:"white",border:{type:"solid",color:"transparent"},progress:{bg:"#fff"}},warning:{bg:"#f89406",color:"black",border:{type:"solid",color:"transparent"},progress:{bg:"#fff"}}},padding:{left:10,right:10,top:10,bottom:10},margin:{left:20,right:20,top:20,bottom:20},radius:5}},callback:()=>{}},w=["success","info","danger","warning","custom"],g={x:["middle","left","right"],y:["middle","top","bottom"]},_={en:{errors:{type_error:"the {name} have to be {type} ",padding_error:"the padding must be a number or an object that include keys left, right, top, bottom with number values",type:"{name} is {type}",duration:"the {type} duration is {ms}MS ({sec}s)",position:"the {axis}_pos property have to be one the listed values {values}"},labels:{empty:"empty",undefined:"undefined",min:"min",max:"max"}}};function Z(e){let t=I(e);t!=!1&&(C(t),U(t),h(t),V(t),X(t),Y(t))}function x(e){let t=e.config??{};try{e.message&&A(e.message),e.title&&(r.title=e.title),t.main_box_classes&&t.main_box_classes!=""&&(r.config.main_box_classes=t.main_box_classes),t.duration&&N(t.duration),t.custom_colors&&v(t.custom_colors),e.type&&R(e.type),t.bordered&&q(t.bordered),t.bordered&&t.border_width&&T(t.border_width),t.radius&&O(t.radius),t.colors&&H(t.colors),t.x_align&&y("x",t.x_align),t.y_align&&y("y",t.y_align),t.font&&D(t.font),t.closer&&S(t.closer),t.progress&&z(t.progress),t.padding&&$(t.padding),e.callback&&k(e.callback),t.progress&&t.progress_height&&B(t.progress_height)}catch(i){return console.error(`theshtify error
|
|
2
|
+
${i}`),!1}return!0}function $(e){if(n(e,"number")){r.config.display.padding.left=e,r.config.display.padding.right=e,r.config.display.padding.top=e,r.config.display.padding.bottom=e;return}else if(n(e,"object")&&Object.keys(e).includes("left")&&n(e.left,"number")&&Object.keys(e).includes("right")&&n(e.right,"number")&&Object.keys(e).includes("top")&&n(e.top,"number")&&Object.keys(e).includes("bottom")&&n(e.bottom,"number")){r.config.display.padding=e;return}throw s(o().errors.padding_error)}function k(e){if(n(e,"function"))r.callback=e;else throw s(o().errors.type_error,{name:"callback",type:"function"})}function v(e){for(let t in e)Object.prototype.hasOwnProperty.call(e,t)&&E(t)&&(r.type=t,b(e[t]))}function C(e){document.querySelector("body").before(e);let t=F({width:e.offsetWidth,height:e.offsetHeight});e.style.left=`${t.x}px`,e.style.top=`${t.y}px`}function A(e=null){if(e!=null)switch(!0){case e=="":throw o().errors.type,{name:"message",type:o().labels.empty};case n(e,"undefined"):throw o().errors.type,{name:"message",type:o().labels.undefined};case!n(e,"string"):throw s(o().errors.type_error,{name:"message",type:"string"});default:r.message=e;break}else return e}function y(e,t){if(n(t,"string"))if(g[e].includes(t))r.config[`${e}_pos`]=t;else throw s(o().errors.position,{axis:e,values:g[e].join(",")});else throw s(o().errors.type_error,{name:"colors.color",type:"string"})}function H(e){if(n(e,"object"))r.type=="custom"&&b(e);else throw s(o().errors.type_error,{name:"colors",type:"object"})}function b(e){e.bg&&j(e.bg),e.color&&W(e.color),e.border.type&&P(e.border.type),e.border.color&&L(e.border.color),e.progress.bg&&M(e.progress.bg)}function E(e){return r.config.display.colors[e]??!1}function j(e){if(n(e,"string"))d().bg=e;else throw s(o().errors.type_error,{name:"colors.bg",type:"string"})}function W(e){if(n(e,"string"))d().color=e;else throw s(o().errors.type_error,{name:"colors.color",type:"string"})}function L(e){if(n(e,"string"))d().border.color=e;else throw s(o().errors.type_error,{name:"colors.border.color",type:"string"})}function P(e){if(n(e,"string"))d().border.type=e;else throw s(o().errors.type_error,{name:"colors.border.type",type:"string"})}function T(e){if(n(e,"number"))r.config.borderWidth=e;else throw s(o().errors.type_error,{name:"borderWidth",type:"number"})}function O(e){if(n(e,"number"))r.config.display.radius=e;else throw s(o().errors.type_error,{name:"radius",type:"number"})}function q(e=!1){if(n(e,"boolean"))r.config.bordered=e;else throw s(o().errors.type_error,{name:"bordered",type:"boolean"})}function z(e=!1){if(n(e,"boolean"))r.config.progress=e;else throw s(o().errors.type_error,{name:"progress",type:"boolean"})}function S(e=!1){if(n(e,"boolean"))r.config.closer=e;else throw s(o().errors.type_error,{name:"closer",type:"boolean"})}function B(e){if(n(e,"number"))r.config.progressHeight=e;else throw s(o().errors.type_error,{name:"progressHeight",type:"number"})}function M(e){if(n(e,"string"))d().progress.bg=e;else throw s(o().errors.type_error,{name:"progress.bg",type:"string"})}function N(e){if(n(e,"number")){if(e<=r.config.max_duration)r.config.duration=e;else throw s(o().errors.duration,{type:o().labels.max,ms:`${r.config.max_duration}`,sec:`${r.config.max_duration/1e3}`});if(e>=r.config.min_duration)r.config.duration=e;else throw s(o().errors.duration,{type:o().labels.min,ms:`${r.config.min_duration}`,sec:`${r.config.min_duration/1e3}`})}else throw s(o().errors.type_error,{name:"duration",type:"number"})}function R(e){if(e!=null)if(w.includes(e))r.type=e;else throw"the given type is not supported";else return e}function D(e){if(e){if(e.size)if(n(e.size,"number"))r.config.font.size=e.size;else throw s(o().errors.type_error,{name:"font.size",type:"number"});if(e.weight)if(n(e.weight,"number"))r.config.font.weight=e.weight;else throw s(o().errors.type_error,{name:"font.weight",type:"number"});if(e.family)if(n(e.family,"string"))r.config.font.family=e.family;else throw s(o().errors.type_error,{name:"font.family",type:"string"})}else return r.config.font}function o(){return _[r.lang]}function s(e="",t={}){let i=e;for(let l in t)Object.prototype.hasOwnProperty.call(t,l)&&(i=i.replace(`{${l}}`,t[l]));return i}function d(){return r.config.display.colors[r.type]}function F(e){let t={x:0,y:0};return r.config.x_pos=="left"&&(t.x=r.config.display.margin.left),r.config.x_pos=="right"&&(t.x=window.innerWidth-(e.width+r.config.display.margin.right)),r.config.x_pos=="middle"&&(t.x=(window.innerWidth-e.width)/2),r.config.y_pos=="top"&&(t.y=0+r.config.display.margin.top),r.config.y_pos=="bottom"&&(t.y=window.innerHeight-(e.height+r.config.display.margin.bottom)),r.config.y_pos=="middle"&&(t.y=(window.innerHeight-e.height)/2),t}function n(e,t){return typeof e===t}function I(e){if(x(e)){let t=G();return r.config.closer&&t.append(K()),t.append(J()),r.config.progress&&t.append(Q()),t}else return!1}function G(){var e=document.createElement("div");return e.setAttribute("class","Thesharsol-notifyer"),r.config.main_box_classes&&e.classList.add(r.config.main_box_classes),e.style.width="90%",e.style.maxWidth=`${r.config.display.width}px`,e.style.position="fixed",e.style.zIndex=999,e.style.opacity=0,e.style.fontFamily=`${r.config.font.family}`,e.style.fontSize=`${r.config.font.size}px`,e.style.fontWeight=`${r.config.font.weight}`,e.style.borderRadius=`${r.config.display.radius}px`,e.style.backgroundColor=r.config.display.colors[r.type].bg,e.setAttribute("index",document.querySelectorAll(".Thesharsol-notifyer").length),r.config.bordered&&(e.style.border=`${r.config.borderWidth}px ${d().border.type} ${d().border.color}`),e}function J(){let e=document.createElement("div"),t=document.createElement("div");e.setAttribute("style","width:100%"),t.style.color=r.config.display.colors[r.type].color,t.style.paddingLeft=`${r.config.display.padding.left}px`,t.style.paddingRight=`${r.config.display.padding.right}px`,t.style.paddingTop=`${r.config.display.padding.top}px`,t.style.paddingBottom=`${r.config.display.padding.bottom}px`;let i=u(r.title,!0);return i.style.marginBottom=`${r.message!=""?4:0}px`,r.title&&t.append(i),r.message&&t.append(u(r.message)),e.append(t),e}function u(e="",t=!1){let i=document.createElement("span");return i.setAttribute("style",`display:block;font-weight:${t?"bold":"light"};`),e&&e!=""&&(i.textContent=e),i}function K(){let e=document.createElement("div"),t=document.createElement("button");return t.classList.add("close-icon"),t.fontSize="22px",e.setAttribute("style",`display:flex;padding:${r.config.display.padding.top}px ${r.config.display.padding.top}px 0px ${r.config.display.padding.top}px;`),t.setAttribute("style",`font-weight:bold;margin-left:auto;background:transparent;border:0px;color:${d().color}`),e.append(t),t.addEventListener("click",()=>{let i=t.parentNode.parentNode;h(i,"remove",parseInt(i.getAttribute("index"))),i.remove()}),e}function Q(){let e=document.createElement("div"),t=document.createElement("div");return e.style.width="100%",e.style.borderRadius=`${r.config.display.radius}px`,e.style.overflow="hidden",e.classList.add("progress"),t.setAttribute("style","height:2px;width:0px"),t.style.minHeight=`${r.config.progressHeight}px`,t.style.width="0px",t.classList.add("content"),t.style.background=`${d().progress?d().progress.bg:"white"}`,e.append(t),e}function U(e){let t=e.querySelector(".progress");if(t!=null){let i=e.querySelector(".content"),l=t.offsetWidth;i.style.width="0px",i.style.transitionDuration=`${r.config.duration}ms`,requestAnimationFrame(()=>{i.style.width=`${l}px`})}}function h(e,t="add",i=0){let l=document.querySelectorAll(".Thesharsol-notifyer"),p=e.offsetHeight+20,f=p;switch(t){case"add":for(let c=i;c<l.length;c++)f=m(l,c,t,f,e,p);break;case"remove":console.log("remove");let a=Array.prototype.indexOf.call(l,e);for(let c=a;c>=0;c--)f=m(l,c,t,f,e,p);for(let c=a+1;c<l.length;c++)l[c].setAttribute("index",c-1),console.log(a);break;default:break}f>window.innerHeight*50/100&&l[0].remove()}function m(e,t,i,l,p,f){let a=e[t];return p!=a&&a!=null&&(r.config.y_pos=="bottom"&&(a.style.top=i=="add"?`${a.offsetTop-f}px`:`${a.offsetTop+f}px`),r.config.y_pos=="top"&&(a.style.top=i=="add"?`${a.offsetTop+f}px`:`${a.offsetTop-f}px`),l+=a.offsetHeight),l}function V(e){requestAnimationFrame(()=>{e.style.opacity=.9})}function X(e){setTimeout(function(){e.classList.add("fade-out"),e.addEventListener("transitionend",function t(){e.removeEventListener("transitionend",t),e.remove()})},r.config.duration)}function Y(e=HTMLDivElement){e.addEventListener("click",()=>{r.callback()})}})();
|