theshtify 1.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/LICENSE +21 -0
- package/css/notif.css +41 -0
- package/lib/notif.js +311 -0
- package/lib/test.js +11 -0
- package/lib/theshtifyCDN.js +151 -0
- package/package.json +27 -0
- package/readme.md +61 -0
- package/test.html +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 thesharsol
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/css/notif.css
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
.notif {
|
|
2
|
+
width: 30%;
|
|
3
|
+
position: absolute;
|
|
4
|
+
padding: 10px 20px;
|
|
5
|
+
background-color: white;
|
|
6
|
+
font-family: "nunito";
|
|
7
|
+
border-radius: 5px;
|
|
8
|
+
box-shadow: 0px 0px 10px silver;
|
|
9
|
+
opacity: 0;
|
|
10
|
+
color: white;
|
|
11
|
+
z-index: 2000;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.notif.warning {
|
|
15
|
+
background-color: #f89406;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.notif.danger {
|
|
19
|
+
background-color: red;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.notif.info {
|
|
23
|
+
background-color: rgba(7, 133, 250, 0.822);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.notif.success {
|
|
27
|
+
background-color: rgba(1, 191, 102, 0.822);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.close-icon:after {
|
|
31
|
+
display: inline-block;
|
|
32
|
+
content: "\00d7";
|
|
33
|
+
/* This will render the 'X' */
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.Thesharsol-notifyer {
|
|
38
|
+
overflow: hidden;
|
|
39
|
+
padding: 2px;
|
|
40
|
+
transition: top linear 0.2s;
|
|
41
|
+
}
|
package/lib/notif.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
|
|
2
|
+
class Notif {
|
|
3
|
+
#config = {
|
|
4
|
+
x_pos: 'right',
|
|
5
|
+
y_pos: 'top',
|
|
6
|
+
font:{
|
|
7
|
+
family:'arial',
|
|
8
|
+
size:14,
|
|
9
|
+
weight:''
|
|
10
|
+
},
|
|
11
|
+
duration: 5000,
|
|
12
|
+
borderWidth: 2,
|
|
13
|
+
bordered: false,
|
|
14
|
+
progress: false,
|
|
15
|
+
closer: false,
|
|
16
|
+
trans: false,
|
|
17
|
+
display: {
|
|
18
|
+
width: 300,
|
|
19
|
+
colors: {
|
|
20
|
+
custom: {
|
|
21
|
+
color: 'white',
|
|
22
|
+
bg: '#000',
|
|
23
|
+
border: {
|
|
24
|
+
type:'solid',
|
|
25
|
+
color: 'transparent',
|
|
26
|
+
},
|
|
27
|
+
progress: {
|
|
28
|
+
bg: '#fff'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
success: {
|
|
32
|
+
color: 'white',
|
|
33
|
+
bg: 'rgba(1, 191, 102, 0.822)',
|
|
34
|
+
border: {
|
|
35
|
+
type:'solid',
|
|
36
|
+
color: 'transparent',
|
|
37
|
+
},
|
|
38
|
+
progress: {
|
|
39
|
+
bg: '#fff'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
danger: {
|
|
43
|
+
bg: 'red',
|
|
44
|
+
color: 'white',
|
|
45
|
+
border: {
|
|
46
|
+
type:'solid',
|
|
47
|
+
color: 'transparent',
|
|
48
|
+
},
|
|
49
|
+
progress: {
|
|
50
|
+
bg: '#fff'
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
info: {
|
|
54
|
+
bg: 'rgba(7, 133, 250, 0.822)',
|
|
55
|
+
color: 'white',
|
|
56
|
+
border: {
|
|
57
|
+
type:'solid',
|
|
58
|
+
color: 'transparent',
|
|
59
|
+
},
|
|
60
|
+
progress: {
|
|
61
|
+
bg: '#fff'
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
warning: {
|
|
65
|
+
bg: '#f89406',
|
|
66
|
+
color: 'black',
|
|
67
|
+
border: {
|
|
68
|
+
type:'solid',
|
|
69
|
+
color: 'transparent',
|
|
70
|
+
},
|
|
71
|
+
progress: {
|
|
72
|
+
bg: '#fff'
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
padding: {
|
|
77
|
+
left: 10,
|
|
78
|
+
right: 10,
|
|
79
|
+
top: 10,
|
|
80
|
+
bottom: 10
|
|
81
|
+
},
|
|
82
|
+
margin: {
|
|
83
|
+
left: 20,
|
|
84
|
+
right: 20,
|
|
85
|
+
top: 20,
|
|
86
|
+
bottom: 20
|
|
87
|
+
},
|
|
88
|
+
radius: 10,
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
#type;
|
|
92
|
+
#message;
|
|
93
|
+
constructor(config) {
|
|
94
|
+
this.config = config;
|
|
95
|
+
this.type = "danger";
|
|
96
|
+
this.message = "notification";
|
|
97
|
+
}
|
|
98
|
+
get config() {
|
|
99
|
+
return this.#config;
|
|
100
|
+
}
|
|
101
|
+
set config(config) {
|
|
102
|
+
for (const key in config) {
|
|
103
|
+
if (Object.hasOwnProperty.call(this.#config, key)) {
|
|
104
|
+
this.#config[key] == config[key];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
configure(config) {
|
|
109
|
+
config.message ? this.message = config.message : '';
|
|
110
|
+
config.type ? this.type = config.type : '';
|
|
111
|
+
(config.colors != undefined && config.type == 'custom') ? this.config.display.colors.custom = config.colors : '';
|
|
112
|
+
config.duration ? this.config.duration = config.duration : '';
|
|
113
|
+
config.x_align ? this.config.x_pos = config.x_align : '';
|
|
114
|
+
config.y_align ? this.config.y_pos = config.y_align : '';
|
|
115
|
+
config.bordered ? this.config.bordered = config.bordered : '';
|
|
116
|
+
config.closer ? this.config.closer = config.closer : '';
|
|
117
|
+
config.progress ? this.config.progress = config.progress : '';
|
|
118
|
+
(config.bordered && config.colors != undefined && config.type == 'custom' && config.colors.border != undefined) ? this.config.display.colors.custom.border = config.colors.border : '';
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
get message() {
|
|
122
|
+
return this.#message;
|
|
123
|
+
}
|
|
124
|
+
set message(message) {
|
|
125
|
+
this.#message = message;
|
|
126
|
+
}
|
|
127
|
+
get type() {
|
|
128
|
+
return this.#type;
|
|
129
|
+
}
|
|
130
|
+
set type(type) {
|
|
131
|
+
this.#type = type;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
getPosition(boxSize) {
|
|
135
|
+
let retPos = {
|
|
136
|
+
x: 0,
|
|
137
|
+
y: 0
|
|
138
|
+
}
|
|
139
|
+
this.config.x_pos == 'left' ? retPos.x = this.config.display.margin.left : 0;
|
|
140
|
+
this.config.x_pos == 'right' ? retPos.x = window.innerWidth - (boxSize.width + this.config.display.margin.right) : 0;
|
|
141
|
+
this.config.x_pos == 'middle' ? retPos.x = (window.innerWidth - boxSize.width) / 2 : 0;
|
|
142
|
+
this.config.y_pos == 'top' ? retPos.y = 0 + this.config.display.margin.top : 0;
|
|
143
|
+
this.config.y_pos == 'bottom' ? retPos.y = window.innerHeight - (boxSize.height + this.config.display.margin.bottom) : 0;
|
|
144
|
+
this.config.y_pos == 'middle' ? retPos.y = (window.innerHeight - boxSize.height) / 2 : 0;
|
|
145
|
+
return retPos;
|
|
146
|
+
}
|
|
147
|
+
moveDisplayedNotifications(createdBox) {
|
|
148
|
+
let notifBoxes = document.querySelectorAll('.Thesharsol-notifyer');
|
|
149
|
+
let offset = createdBox.offsetHeight + 20;
|
|
150
|
+
//
|
|
151
|
+
let boxesCumulatedHeihgt = offset;
|
|
152
|
+
notifBoxes.forEach(box => {
|
|
153
|
+
|
|
154
|
+
if (createdBox != box) {
|
|
155
|
+
|
|
156
|
+
if (this.config.y_pos == 'bottom') {
|
|
157
|
+
box.style.top = `${box.offsetTop - offset}px`;
|
|
158
|
+
}
|
|
159
|
+
if (this.config.y_pos == 'top') {
|
|
160
|
+
box.style.top = `${box.offsetTop + offset}px`;
|
|
161
|
+
}
|
|
162
|
+
boxesCumulatedHeihgt += box.offsetHeight;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
console.log(boxesCumulatedHeihgt + '-----' + ((window.innerHeight * 70) / 100))
|
|
166
|
+
if (boxesCumulatedHeihgt > ((window.innerHeight * 50) / 100)) {
|
|
167
|
+
console.log(boxesCumulatedHeihgt)
|
|
168
|
+
notifBoxes[0].remove();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
get currentColor() {
|
|
172
|
+
return this.config.display.colors[this.#type];
|
|
173
|
+
}
|
|
174
|
+
notify(infos) {
|
|
175
|
+
let notif = this.buildBox(infos);
|
|
176
|
+
document.querySelector("body").before(notif);
|
|
177
|
+
|
|
178
|
+
let pos = this.getPosition({ width: notif.offsetWidth, height: notif.offsetHeight });
|
|
179
|
+
notif.style.left = `${pos.x}px`;
|
|
180
|
+
notif.style.top = `${pos.y}px`;
|
|
181
|
+
this.animProgress(notif);
|
|
182
|
+
this.moveDisplayedNotifications(notif)
|
|
183
|
+
|
|
184
|
+
var op = 0;
|
|
185
|
+
var it = setInterval(function () {
|
|
186
|
+
op = op + 0.01;
|
|
187
|
+
notif.style.opacity = op;
|
|
188
|
+
// console.log(notif)
|
|
189
|
+
if (op > 0.9) {
|
|
190
|
+
clearInterval(it);
|
|
191
|
+
}
|
|
192
|
+
}, 1);
|
|
193
|
+
|
|
194
|
+
setTimeout(function () {
|
|
195
|
+
var op = 1;
|
|
196
|
+
var it = setInterval(function () {
|
|
197
|
+
op = op - 0.01;
|
|
198
|
+
notif.style.opacity = op;
|
|
199
|
+
// console.log(notif)
|
|
200
|
+
if (op < 0.01) {
|
|
201
|
+
notif.remove();
|
|
202
|
+
clearInterval(it);
|
|
203
|
+
}
|
|
204
|
+
}, 1);
|
|
205
|
+
}, this.config.duration);
|
|
206
|
+
}
|
|
207
|
+
buildBox(infos) {
|
|
208
|
+
this.configure(infos);
|
|
209
|
+
let box = this.mainContainer();
|
|
210
|
+
this.config.closer ? box.append(this.dismiss()) : '';
|
|
211
|
+
box.append(this.body());
|
|
212
|
+
this.config.progress ? box.append(this.progress()) : '';
|
|
213
|
+
|
|
214
|
+
return box;
|
|
215
|
+
}
|
|
216
|
+
container() {
|
|
217
|
+
let box = document.createElement('div');
|
|
218
|
+
let content = document.createElement('div');
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
box.append(content);
|
|
223
|
+
return box;
|
|
224
|
+
}
|
|
225
|
+
mainContainer() {
|
|
226
|
+
var notif = document.createElement("div");
|
|
227
|
+
|
|
228
|
+
notif.setAttribute("class", "Thesharsol-notifyer");
|
|
229
|
+
notif.style.width = `${this.config.display.width}px`;
|
|
230
|
+
notif.style.position = 'absolute';
|
|
231
|
+
notif.style.opacity = 0;
|
|
232
|
+
|
|
233
|
+
notif.style.fontFamily = `${this.config.font.family}`;
|
|
234
|
+
notif.style.fontSize = `${this.config.font.size}px`;
|
|
235
|
+
notif.style.fontWeight= `${this.config.font.weight}`;
|
|
236
|
+
|
|
237
|
+
notif.style.borderRadius = `${this.config.display.radius}px`;
|
|
238
|
+
notif.style.backgroundColor = this.config.display.colors[this.#type].bg;
|
|
239
|
+
|
|
240
|
+
if (this.config.bordered) {
|
|
241
|
+
notif.style.border = `${this.config.borderWidth}px ${this.currentColor.border.type} ${this.currentColor.border.color}`
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return notif;
|
|
245
|
+
}
|
|
246
|
+
body() {
|
|
247
|
+
let body = document.createElement('div');
|
|
248
|
+
let bodyContent = document.createElement('div');
|
|
249
|
+
body.setAttribute('style', 'width:100%')
|
|
250
|
+
// bodyContent.setAttribute('style','width:100%')
|
|
251
|
+
|
|
252
|
+
bodyContent.style.color = this.config.display.colors[this.#type].color;
|
|
253
|
+
bodyContent.style.paddingLeft = `${this.config.display.padding.left}px`;
|
|
254
|
+
bodyContent.style.paddingRight = `${this.config.display.padding.right}px`;
|
|
255
|
+
bodyContent.style.paddingTop = `${this.config.display.padding.top}px`;
|
|
256
|
+
bodyContent.style.paddingBottom = `${this.config.display.padding.bottom}px`;
|
|
257
|
+
bodyContent.innerText = this.message;
|
|
258
|
+
body.append(bodyContent);
|
|
259
|
+
return body;
|
|
260
|
+
}
|
|
261
|
+
dismiss() {
|
|
262
|
+
let dismiss = document.createElement('div');
|
|
263
|
+
let dismissContent = document.createElement('div');
|
|
264
|
+
// style
|
|
265
|
+
dismissContent.classList.add('close-icon');
|
|
266
|
+
dismissContent.fontSize = `22px`
|
|
267
|
+
dismiss.setAttribute('style', `display:flex;padding:${this.config.display.padding.top}px ${this.config.display.padding.top}px 0px ${this.config.display.padding.top}px;`);
|
|
268
|
+
dismissContent.setAttribute('style', 'font-weight:bold;margin-left:auto');
|
|
269
|
+
|
|
270
|
+
dismiss.append(dismissContent);
|
|
271
|
+
return dismiss;
|
|
272
|
+
}
|
|
273
|
+
progress() {
|
|
274
|
+
let progress = document.createElement('div');
|
|
275
|
+
let progressContent = document.createElement('div');
|
|
276
|
+
progress.style.width = '100%';
|
|
277
|
+
progress.style.borderRadius = `${this.config.display.radius}px`;
|
|
278
|
+
progress.style.overflow = 'hidden'
|
|
279
|
+
progress.classList.add('progress');
|
|
280
|
+
progressContent.setAttribute('style', 'height:2px;width:0px');
|
|
281
|
+
|
|
282
|
+
progressContent.style.minHeight = '10px';
|
|
283
|
+
progressContent.style.width = '0px';
|
|
284
|
+
progressContent.classList.add('content');
|
|
285
|
+
progressContent.style.background = `${this.currentColor.progress ? this.currentColor.progress.bg : 'white'}`;
|
|
286
|
+
progress.append(progressContent);
|
|
287
|
+
return progress;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
animProgress(box) {
|
|
291
|
+
let progressBar = box.querySelector('.progress');
|
|
292
|
+
let progressBoxContent = box.querySelector('.content');
|
|
293
|
+
|
|
294
|
+
//
|
|
295
|
+
let maxProgressContentWidth = progressBar.offsetWidth;
|
|
296
|
+
let increment = maxProgressContentWidth / (this.config.duration / 30);
|
|
297
|
+
let width = 0;
|
|
298
|
+
let incInt = setInterval(() => {
|
|
299
|
+
width += increment;
|
|
300
|
+
progressBoxContent.style.width = `${width}px`;
|
|
301
|
+
|
|
302
|
+
console.log(width);
|
|
303
|
+
if (maxProgressContentWidth <= width) {
|
|
304
|
+
clearInterval(incInt);
|
|
305
|
+
}
|
|
306
|
+
}, 30);
|
|
307
|
+
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// alert()
|
|
311
|
+
export let Notifier = new Notif();
|
package/lib/test.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"function" != typeof
|
|
2
|
+
Object.create && (
|
|
3
|
+
Object.create = function (t) {
|
|
4
|
+
function o() {
|
|
5
|
+
|
|
6
|
+
} return o.prototype = t, new o
|
|
7
|
+
}),
|
|
8
|
+
function (t, o, i, s) {
|
|
9
|
+
"use strict";
|
|
10
|
+
var n = { _positionClasses: ["bottom-left", "bottom-right", "top-right", "top-left", "bottom-center", "top-center", "mid-center"], _defaultIcons: ["success", "error", "info", "warning"], init: function (o, i) { this.prepareOptions(o, t.toast.options), this.process() }, prepareOptions: function (o, i) { var s = {}; "string" == typeof o || o instanceof Array ? s.text = o : s = o, this.options = t.extend({}, i, s) }, process: function () { this.setup(), this.addToDom(), this.position(), this.bindToast(), this.animate() }, setup: function () { var o = ""; if (this._toastEl = this._toastEl || t("<div></div>", { "class": "jq-toast-single" }), o += '<span class="jq-toast-loader"></span>', this.options.allowToastClose && (o += '<span class="close-jq-toast-single">×</span>'), this.options.text instanceof Array) { this.options.heading && (o += '<h2 class="jq-toast-heading">' + this.options.heading + "</h2>"), o += '<ul class="jq-toast-ul">'; for (var i = 0; i < this.options.text.length; i++)o += '<li class="jq-toast-li" id="jq-toast-item-' + i + '">' + this.options.text[i] + "</li>"; o += "</ul>" } else this.options.heading && (o += '<h2 class="jq-toast-heading">' + this.options.heading + "</h2>"), o += this.options.text; this._toastEl.html(o), this.options.bgColor !== !1 && this._toastEl.css("background-color", this.options.bgColor), this.options.textColor !== !1 && this._toastEl.css("color", this.options.textColor), this.options.textAlign && this._toastEl.css("text-align", this.options.textAlign), this.options.icon !== !1 && (this._toastEl.addClass("jq-has-icon"), -1 !== t.inArray(this.options.icon, this._defaultIcons) && this._toastEl.addClass("jq-icon-" + this.options.icon)), this.options["class"] !== !1 && this._toastEl.addClass(this.options["class"]) }, position: function () { "string" == typeof this.options.position && -1 !== t.inArray(this.options.position, this._positionClasses) ? "bottom-center" === this.options.position ? this._container.css({ left: t(o).outerWidth() / 2 - this._container.outerWidth() / 2, bottom: 20 }) : "top-center" === this.options.position ? this._container.css({ left: t(o).outerWidth() / 2 - this._container.outerWidth() / 2, top: 20 }) : "mid-center" === this.options.position ? this._container.css({ left: t(o).outerWidth() / 2 - this._container.outerWidth() / 2, top: t(o).outerHeight() / 2 - this._container.outerHeight() / 2 }) : this._container.addClass(this.options.position) : "object" == typeof this.options.position ? this._container.css({ top: this.options.position.top ? this.options.position.top : "auto", bottom: this.options.position.bottom ? this.options.position.bottom : "auto", left: this.options.position.left ? this.options.position.left : "auto", right: this.options.position.right ? this.options.position.right : "auto" }) : this._container.addClass("bottom-left") }, bindToast: function () { var t = this; this._toastEl.on("afterShown", function () { t.processLoader() }), this._toastEl.find(".close-jq-toast-single").on("click", function (o) { o.preventDefault(), "fade" === t.options.showHideTransition ? (t._toastEl.trigger("beforeHide"), t._toastEl.fadeOut(function () { t._toastEl.trigger("afterHidden") })) : "slide" === t.options.showHideTransition ? (t._toastEl.trigger("beforeHide"), t._toastEl.slideUp(function () { t._toastEl.trigger("afterHidden") })) : (t._toastEl.trigger("beforeHide"), t._toastEl.hide(function () { t._toastEl.trigger("afterHidden") })) }), "function" == typeof this.options.beforeShow && this._toastEl.on("beforeShow", function () { t.options.beforeShow() }), "function" == typeof this.options.afterShown && this._toastEl.on("afterShown", function () { t.options.afterShown() }), "function" == typeof this.options.beforeHide && this._toastEl.on("beforeHide", function () { t.options.beforeHide() }), "function" == typeof this.options.afterHidden && this._toastEl.on("afterHidden", function () { t.options.afterHidden() }) }, addToDom: function () { var o = t(".jq-toast-wrap"); if (0 === o.length ? (o = t("<div></div>", { "class": "jq-toast-wrap" }), t("body").append(o)) : (!this.options.stack || isNaN(parseInt(this.options.stack, 10))) && o.empty(), o.find(".jq-toast-single:hidden").remove(), o.append(this._toastEl), this.options.stack && !isNaN(parseInt(this.options.stack), 10)) { var i = o.find(".jq-toast-single").length, s = i - this.options.stack; s > 0 && t(".jq-toast-wrap").find(".jq-toast-single").slice(0, s).remove() } this._container = o }, canAutoHide: function () { return this.options.hideAfter !== !1 && !isNaN(parseInt(this.options.hideAfter, 10)) }, processLoader: function () { if (!this.canAutoHide() || this.options.loader === !1) return !1; var t = this._toastEl.find(".jq-toast-loader"), o = (this.options.hideAfter - 400) / 1e3 + "s", i = this.options.loaderBg, s = t.attr("style") || ""; s = s.substring(0, s.indexOf("-webkit-transition")), s += "-webkit-transition: width " + o + " ease-in; -o-transition: width " + o + " ease-in; transition: width " + o + " ease-in; background-color: " + i + ";", t.attr("style", s).addClass("jq-toast-loaded") }, animate: function () { var t = this; if (this._toastEl.hide(), this._toastEl.trigger("beforeShow"), "fade" === this.options.showHideTransition.toLowerCase() ? this._toastEl.fadeIn(function () { t._toastEl.trigger("afterShown") }) : "slide" === this.options.showHideTransition.toLowerCase() ? this._toastEl.slideDown(function () { t._toastEl.trigger("afterShown") }) : this._toastEl.show(function () { t._toastEl.trigger("afterShown") }), this.canAutoHide()) { var t = this; o.setTimeout(function () { "fade" === t.options.showHideTransition.toLowerCase() ? (t._toastEl.trigger("beforeHide"), t._toastEl.fadeOut(function () { t._toastEl.trigger("afterHidden") })) : "slide" === t.options.showHideTransition.toLowerCase() ? (t._toastEl.trigger("beforeHide"), t._toastEl.slideUp(function () { t._toastEl.trigger("afterHidden") })) : (t._toastEl.trigger("beforeHide"), t._toastEl.hide(function () { t._toastEl.trigger("afterHidden") })) }, this.options.hideAfter) } }, reset: function (o) { "all" === o ? t(".jq-toast-wrap").remove() : this._toastEl.remove() }, update: function (t) { this.prepareOptions(t, this.options), this.setup(), this.bindToast() } }; t.toast = function (t) { var o = Object.create(n); return o.init(t, this), { reset: function (t) { o.reset(t) }, update: function (t) { o.update(t) } } }, t.toast.options = { text: "", heading: "", showHideTransition: "fade", allowToastClose: !0, hideAfter: 3e3, loader: !0, loaderBg: "#9EC600", stack: 5, position: "bottom-left", bgColor: !1, textColor: !1, textAlign: "left", icon: !1, beforeShow: function () { }, afterShown: function () { }, beforeHide: function () { }, afterHidden: function () { } }
|
|
11
|
+
}(jQuery, window, document);
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
let theshtify_basic_infos = {
|
|
2
|
+
type: '',
|
|
3
|
+
message: '',
|
|
4
|
+
config: {
|
|
5
|
+
x_pos: 'right',
|
|
6
|
+
y_pos: 'top',
|
|
7
|
+
duration: 5000,
|
|
8
|
+
bordered: false,
|
|
9
|
+
display: {
|
|
10
|
+
width: 300,
|
|
11
|
+
colors: {
|
|
12
|
+
custom: {
|
|
13
|
+
color: 'white',
|
|
14
|
+
bg: '#000'
|
|
15
|
+
},
|
|
16
|
+
success: {
|
|
17
|
+
color: 'white',
|
|
18
|
+
bg: 'rgba(1, 191, 102, 0.822)'
|
|
19
|
+
},
|
|
20
|
+
danger: {
|
|
21
|
+
bg: 'red',
|
|
22
|
+
color: 'white'
|
|
23
|
+
},
|
|
24
|
+
info: {
|
|
25
|
+
bg: 'rgba(7, 133, 250, 0.822)',
|
|
26
|
+
color: 'white'
|
|
27
|
+
},
|
|
28
|
+
warning: {
|
|
29
|
+
bg: '#f89406',
|
|
30
|
+
color: 'black'
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
padding: {
|
|
34
|
+
left: 10,
|
|
35
|
+
right: 10,
|
|
36
|
+
top: 10,
|
|
37
|
+
bottom: 10
|
|
38
|
+
},
|
|
39
|
+
margin: {
|
|
40
|
+
left: 20,
|
|
41
|
+
right: 20,
|
|
42
|
+
top: 20,
|
|
43
|
+
bottom: 20
|
|
44
|
+
},
|
|
45
|
+
radius: 10
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function theshtify(infos = theshtify_basic_params) {
|
|
51
|
+
var notif = document.createElement("div");
|
|
52
|
+
configure(infos);
|
|
53
|
+
notif.setAttribute("class", "Thesharsol-notifyer");
|
|
54
|
+
notif.innerHTML = infos.message;
|
|
55
|
+
notif.style.width = `${theshtify_basic_infos.config.display.width}px`;
|
|
56
|
+
notif.style.position = 'absolute';
|
|
57
|
+
notif.style.opacity = 0;
|
|
58
|
+
notif.style.backgroundColor = theshtify_basic_infos.config.display.colors[theshtify_basic_infos.type].bg;
|
|
59
|
+
notif.style.color = theshtify_basic_infos.config.display.colors[theshtify_basic_infos.type].color;
|
|
60
|
+
notif.style.paddingLeft = `${theshtify_basic_infos.config.display.padding.left}px`;
|
|
61
|
+
notif.style.paddingRight = `${theshtify_basic_infos.config.display.padding.right}px`;
|
|
62
|
+
notif.style.paddingTop = `${theshtify_basic_infos.config.display.padding.top}px`;
|
|
63
|
+
notif.style.paddingBottom = `${theshtify_basic_infos.config.display.padding.bottom}px`;
|
|
64
|
+
// console.log((window.innerWidth * 35) / 100)
|
|
65
|
+
notif.style.borderRadius = `${theshtify_basic_infos.config.display.radius}px`;
|
|
66
|
+
document.querySelector("body").before(notif);
|
|
67
|
+
|
|
68
|
+
// console.log({ width: notif.offsetWidth, height: notif.offsetHeight });
|
|
69
|
+
let pos = getPosition({ width: notif.offsetWidth, height: notif.offsetHeight });
|
|
70
|
+
// let event = new CustomEvent('Thesharsol-notify', { detail: { height: notif.offsetHeight } })
|
|
71
|
+
notif.style.left = `${pos.x}px`;
|
|
72
|
+
notif.style.top = `${pos.y}px`;
|
|
73
|
+
moveDisplayedNotifications(notif)
|
|
74
|
+
// alert(notif.offsetTop)
|
|
75
|
+
// console.log(pos)
|
|
76
|
+
|
|
77
|
+
// notif.style.left = window.innerWidth - (window.innerWidth * 35) / 100 + "px";
|
|
78
|
+
// notif.style.top = window.innerHeight - (notif.offsetHeight + 30) + "px";
|
|
79
|
+
var op = 0;
|
|
80
|
+
var it = setInterval(function () {
|
|
81
|
+
op = op + 0.01;
|
|
82
|
+
notif.style.opacity = op;
|
|
83
|
+
// console.log(notif)
|
|
84
|
+
if (op > 0.9) {
|
|
85
|
+
clearInterval(it);
|
|
86
|
+
}
|
|
87
|
+
}, 1);
|
|
88
|
+
|
|
89
|
+
setTimeout(function () {
|
|
90
|
+
var op = 1;
|
|
91
|
+
var it = setInterval(function () {
|
|
92
|
+
op = op - 0.01;
|
|
93
|
+
notif.style.opacity = op;
|
|
94
|
+
// console.log(notif)
|
|
95
|
+
if (op < 0.01) {
|
|
96
|
+
notif.remove();
|
|
97
|
+
clearInterval(it);
|
|
98
|
+
}
|
|
99
|
+
}, 5);
|
|
100
|
+
}, theshtify_basic_infos.config.duration);
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
function configure(config) {
|
|
104
|
+
config.message ? theshtify_basic_infos.message = config.message : '';
|
|
105
|
+
config.type ? theshtify_basic_infos.type = config.type : '';
|
|
106
|
+
(config.colors != undefined && config.type == 'custom') ? theshtify_basic_infos.config.display.colors.custom = config.colors : '';
|
|
107
|
+
config.duration ? theshtify_basic_infos.config.duration = config.duration : '';
|
|
108
|
+
config.x_align ? theshtify_basic_infos.config.x_pos = config.x_align : '';
|
|
109
|
+
config.y_align ? theshtify_basic_infos.config.y_pos = config.y_align : '';
|
|
110
|
+
config.bordered ? theshtify_basic_infos.config.bordered = config.bordered : '';
|
|
111
|
+
}
|
|
112
|
+
function getPosition(boxSize) {
|
|
113
|
+
let retPos = {
|
|
114
|
+
x: 0,
|
|
115
|
+
y: 0
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
theshtify_basic_infos.config.x_pos == 'left' ? retPos.x = theshtify_basic_infos.config.display.margin.left : 0;
|
|
119
|
+
theshtify_basic_infos.config.x_pos == 'right' ? retPos.x = window.innerWidth - (boxSize.width + theshtify_basic_infos.config.display.margin.right) : 0;
|
|
120
|
+
theshtify_basic_infos.config.x_pos == 'middle' ? retPos.x = (window.innerWidth - boxSize.width) / 2 : 0;
|
|
121
|
+
theshtify_basic_infos.config.y_pos == 'top' ? retPos.y = 0 + theshtify_basic_infos.config.display.margin.top : 0;
|
|
122
|
+
theshtify_basic_infos.config.y_pos == 'bottom' ? retPos.y = window.innerHeight - (boxSize.height + theshtify_basic_infos.config.display.margin.bottom) : 0;
|
|
123
|
+
theshtify_basic_infos.config.y_pos == 'middle' ? retPos.y = (window.innerHeight - boxSize.height) / 2 : 0;
|
|
124
|
+
|
|
125
|
+
return retPos;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function moveDisplayedNotifications(createdBox) {
|
|
129
|
+
let notifBoxes = document.querySelectorAll('.Thesharsol-notifyer');
|
|
130
|
+
let offset = createdBox.offsetHeight + 20;
|
|
131
|
+
//
|
|
132
|
+
let boxesCumulatedHeihgt = offset;
|
|
133
|
+
notifBoxes.forEach(box => {
|
|
134
|
+
|
|
135
|
+
if (createdBox != box) {
|
|
136
|
+
|
|
137
|
+
if (theshtify_basic_infos.config.y_pos == 'bottom') {
|
|
138
|
+
box.style.top = `${box.offsetTop - offset}px`;
|
|
139
|
+
}
|
|
140
|
+
if (theshtify_basic_infos.config.y_pos == 'top') {
|
|
141
|
+
box.style.top = `${box.offsetTop + offset}px`;
|
|
142
|
+
}
|
|
143
|
+
boxesCumulatedHeihgt += box.offsetHeight;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
console.log(boxesCumulatedHeihgt + '-----' + ((window.innerHeight * 70) / 100))
|
|
147
|
+
if (boxesCumulatedHeihgt > ((window.innerHeight * 50) / 100)) {
|
|
148
|
+
console.log(boxesCumulatedHeihgt)
|
|
149
|
+
notifBoxes[0].remove();
|
|
150
|
+
}
|
|
151
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "theshtify",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Thesharsol notifyer is a lightweight, vanilla JS toast notification library.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"directories": {
|
|
7
|
+
"lib": "lib"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/thesharsol/theshtify.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"notification",
|
|
18
|
+
"toast",
|
|
19
|
+
"notif"
|
|
20
|
+
],
|
|
21
|
+
"author": "BEBE EPEE Ivan Sampi",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/thesharsol/theshtify/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/thesharsol/theshtify#readme"
|
|
27
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
<!-- [](https://www.npmjs.com/package/vaui-notif) -->
|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
Thesharsol notifyer is a lightweight, vanilla JS toast notification library.
|
|
7
|
+
|
|
8
|
+
## Demo
|
|
9
|
+
|
|
10
|
+
[Click here](https://apvarun.github.io/toastify-js/)
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
* Multiple stacked notifications
|
|
15
|
+
* Customizable
|
|
16
|
+
* No blocking of execution thread
|
|
17
|
+
|
|
18
|
+
### Customization options
|
|
19
|
+
|
|
20
|
+
* Notification Text
|
|
21
|
+
* Duration
|
|
22
|
+
* Background color
|
|
23
|
+
* Close icon display
|
|
24
|
+
* Display position
|
|
25
|
+
* Offset position
|
|
26
|
+
* font
|
|
27
|
+
* progress
|
|
28
|
+
* border radius
|
|
29
|
+
* borders
|
|
30
|
+
### example
|
|
31
|
+
```js
|
|
32
|
+
Notif.Notifier.notify(
|
|
33
|
+
{
|
|
34
|
+
message: 'text',
|
|
35
|
+
x_align:'middle',
|
|
36
|
+
y_align:'top',
|
|
37
|
+
type:'custom',
|
|
38
|
+
// duration:300
|
|
39
|
+
colors:{
|
|
40
|
+
bg:'yellow',
|
|
41
|
+
color:'black',
|
|
42
|
+
border:2
|
|
43
|
+
},
|
|
44
|
+
radius:5,
|
|
45
|
+
bordered:false,
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
{
|
|
55
|
+
"firstName": "John",
|
|
56
|
+
"lastName": "Smith",
|
|
57
|
+
"age": 25
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Here's a sentence with a footnote. [^1]
|
package/test.html
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<link rel="stylesheet" href="./css/notif.css" />
|
|
8
|
+
<title>Document</title>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<button id="notif_button" onclick="notify()">Start a notification</button>
|
|
13
|
+
</body>
|
|
14
|
+
<script>
|
|
15
|
+
async function notify() {
|
|
16
|
+
let Notif = await import('./lib/notif.js');
|
|
17
|
+
|
|
18
|
+
Notif.Notifier.notify(
|
|
19
|
+
{
|
|
20
|
+
message: 'welcome i am the first test notification',
|
|
21
|
+
x_align: 'middle',
|
|
22
|
+
y_align: 'top',
|
|
23
|
+
type: 'success',
|
|
24
|
+
font:{
|
|
25
|
+
|
|
26
|
+
},
|
|
27
|
+
// duration:300,
|
|
28
|
+
colors: {
|
|
29
|
+
bg: '#efefef',
|
|
30
|
+
color: 'black',
|
|
31
|
+
border: {
|
|
32
|
+
type: 'solid',
|
|
33
|
+
color: 'gray'
|
|
34
|
+
},
|
|
35
|
+
progress:{
|
|
36
|
+
bg:'gray'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
radius:2,
|
|
40
|
+
bordered: true,
|
|
41
|
+
closer: true,
|
|
42
|
+
progress: true
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
<!-- <script src="./lib/theshtifyCDN.js"></script> -->
|
|
49
|
+
<!-- <script>
|
|
50
|
+
function notify(){
|
|
51
|
+
theshtify({
|
|
52
|
+
message: 'text',
|
|
53
|
+
x_align:'middle',
|
|
54
|
+
y_align:'top',
|
|
55
|
+
type:'custom',
|
|
56
|
+
// duration:300,
|
|
57
|
+
colors:{
|
|
58
|
+
bg:'#efefef',
|
|
59
|
+
color:'black',
|
|
60
|
+
border:2
|
|
61
|
+
},
|
|
62
|
+
bordered:false,
|
|
63
|
+
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
</script> -->
|
|
67
|
+
|
|
68
|
+
</html>
|