theshtify 1.0.0 → 1.0.2

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/index.html ADDED
@@ -0,0 +1,54 @@
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/theshtify.css" />
8
+ <title>theshtify</title>
9
+ </head>
10
+
11
+ <body>
12
+ <button id="notif_button" onclick="notify()">theshtify</button>
13
+ </body>
14
+ <script src="./lib/theshtifyCDN.js"></script>
15
+ <script>
16
+
17
+ function notify() {
18
+ let config = {
19
+ x_align: 'right',
20
+ y_align: 'top',
21
+ duration: 5000,
22
+ font: {
23
+ size: 15,
24
+ weight: 900,
25
+ family: 'arlon'
26
+ },
27
+ custom_colors: {
28
+ success: {
29
+ bg: '#0C7059',
30
+ color: '#E0BC29',
31
+ border: {
32
+ type: '#solid',
33
+ color: '#E0BC29'
34
+ },
35
+ progress: {
36
+ bg: '#E0BC29'
37
+ }
38
+ },
39
+ /** you can also add other types configs */
40
+ },
41
+ radius: 20,
42
+ bordered: true,
43
+ border_width: 1,
44
+ closer: true,
45
+ progress: true,
46
+ progress_height: 2
47
+
48
+ }
49
+ theshtify({ message: 'welcome to theshtify', type: 'success', config: config });
50
+ }
51
+ </script>
52
+
53
+
54
+ </html>
@@ -0,0 +1,32 @@
1
+ let config = {
2
+ x_align: 'right',
3
+ y_align: 'top',
4
+ duration: 5000,
5
+ font: {
6
+ size: 15,
7
+ weight: 900,
8
+ family: 'arlon'
9
+ },
10
+ custom_colors: {
11
+ success: {
12
+ bg: '#0C7059',
13
+ color: '#E0BC29',
14
+ border: {
15
+ type: '#085241',
16
+ color: 'gray'
17
+ },
18
+ progress: {
19
+ bg: '#E0BC29'
20
+ }
21
+ },
22
+ /** you can also add other types configs */
23
+ },
24
+ radius: 20,
25
+ bordered: true,
26
+ border_width: 1,
27
+ closer: true,
28
+ progress: true,
29
+ progress_height: 2
30
+
31
+ }
32
+ theshtify({ message: 'welcome to theshtify', type: 'success', config: config });
package/lib/notif.js CHANGED
@@ -3,15 +3,17 @@ class Notif {
3
3
  #config = {
4
4
  x_pos: 'right',
5
5
  y_pos: 'top',
6
- font:{
7
- family:'arial',
8
- size:14,
9
- weight:''
6
+ font: {
7
+ family: 'arial',
8
+ size: 14,
9
+ weight: ''
10
10
  },
11
+ max_duration: 5000,
11
12
  duration: 5000,
12
13
  borderWidth: 2,
13
14
  bordered: false,
14
15
  progress: false,
16
+ progressHeight: 2,
15
17
  closer: false,
16
18
  trans: false,
17
19
  display: {
@@ -21,7 +23,7 @@ class Notif {
21
23
  color: 'white',
22
24
  bg: '#000',
23
25
  border: {
24
- type:'solid',
26
+ type: 'solid',
25
27
  color: 'transparent',
26
28
  },
27
29
  progress: {
@@ -32,7 +34,7 @@ class Notif {
32
34
  color: 'white',
33
35
  bg: 'rgba(1, 191, 102, 0.822)',
34
36
  border: {
35
- type:'solid',
37
+ type: 'solid',
36
38
  color: 'transparent',
37
39
  },
38
40
  progress: {
@@ -43,7 +45,7 @@ class Notif {
43
45
  bg: 'red',
44
46
  color: 'white',
45
47
  border: {
46
- type:'solid',
48
+ type: 'solid',
47
49
  color: 'transparent',
48
50
  },
49
51
  progress: {
@@ -54,7 +56,7 @@ class Notif {
54
56
  bg: 'rgba(7, 133, 250, 0.822)',
55
57
  color: 'white',
56
58
  border: {
57
- type:'solid',
59
+ type: 'solid',
58
60
  color: 'transparent',
59
61
  },
60
62
  progress: {
@@ -65,7 +67,7 @@ class Notif {
65
67
  bg: '#f89406',
66
68
  color: 'black',
67
69
  border: {
68
- type:'solid',
70
+ type: 'solid',
69
71
  color: 'transparent',
70
72
  },
71
73
  progress: {
@@ -85,7 +87,7 @@ class Notif {
85
87
  top: 20,
86
88
  bottom: 20
87
89
  },
88
- radius: 10,
90
+ radius: 5,
89
91
  }
90
92
  };
91
93
  #type;
@@ -105,11 +107,19 @@ class Notif {
105
107
  }
106
108
  }
107
109
  }
110
+ set duration(duration) {
111
+ let c_duration = parseInt(duration);
112
+ if (c_duration != NaN) {
113
+ c_duration <= this.config.max_duration ?
114
+ this.config.duration = c_duration :
115
+ console.error('the max duration has to be 5the duration of the notification provided is longer than the maximum posting duration and has therefore been set at the maximum value.');
116
+ }
117
+ }
108
118
  configure(config) {
109
119
  config.message ? this.message = config.message : '';
110
120
  config.type ? this.type = config.type : '';
111
121
  (config.colors != undefined && config.type == 'custom') ? this.config.display.colors.custom = config.colors : '';
112
- config.duration ? this.config.duration = config.duration : '';
122
+ config.duration ? this.duration = config.duration : '';
113
123
  config.x_align ? this.config.x_pos = config.x_align : '';
114
124
  config.y_align ? this.config.y_pos = config.y_align : '';
115
125
  config.bordered ? this.config.bordered = config.bordered : '';
@@ -144,30 +154,53 @@ class Notif {
144
154
  this.config.y_pos == 'middle' ? retPos.y = (window.innerHeight - boxSize.height) / 2 : 0;
145
155
  return retPos;
146
156
  }
147
- moveDisplayedNotifications(createdBox) {
157
+ moveDisplayedNotifications(createdBox, moveType = "add", startIndex = 0) {
148
158
  let notifBoxes = document.querySelectorAll('.Thesharsol-notifyer');
149
159
  let offset = createdBox.offsetHeight + 20;
150
160
  //
151
161
  let boxesCumulatedHeihgt = offset;
152
- notifBoxes.forEach(box => {
153
-
154
- if (createdBox != box) {
155
162
 
156
- if (this.config.y_pos == 'bottom') {
157
- box.style.top = `${box.offsetTop - offset}px`;
163
+ switch (moveType) {
164
+ case "add":
165
+ for (let i = startIndex; i < notifBoxes.length; i++) {
166
+ boxesCumulatedHeihgt = this.changeBoxPosition(notifBoxes, i, moveType, boxesCumulatedHeihgt, createdBox, offset);
158
167
  }
159
- if (this.config.y_pos == 'top') {
160
- box.style.top = `${box.offsetTop + offset}px`;
168
+ break;
169
+ case "remove":
170
+ console.log('remove')
171
+ let si = Array.prototype.indexOf.call(notifBoxes, createdBox);
172
+ for (let i = si; i >= 0; i--) {
173
+ boxesCumulatedHeihgt = this.changeBoxPosition(notifBoxes, i, moveType, boxesCumulatedHeihgt, createdBox, offset);
161
174
  }
162
- boxesCumulatedHeihgt += box.offsetHeight;
163
- }
164
- });
165
- console.log(boxesCumulatedHeihgt + '-----' + ((window.innerHeight * 70) / 100))
175
+ for (let j = (si + 1); j < notifBoxes.length; j++) {
176
+ notifBoxes[j].setAttribute('index', j - 1);
177
+ console.log((si))
178
+ }
179
+ break;
180
+ default:
181
+ break;
182
+ }
183
+
184
+
166
185
  if (boxesCumulatedHeihgt > ((window.innerHeight * 50) / 100)) {
167
- console.log(boxesCumulatedHeihgt)
168
186
  notifBoxes[0].remove();
169
187
  }
170
188
  }
189
+ changeBoxPosition(notifBoxes, i, moveType, boxesCumulatedHeihgt, createdBox, offset) {
190
+ let box = notifBoxes[i];
191
+
192
+ if (createdBox != box && box != undefined) {
193
+
194
+ if (this.config.y_pos == 'bottom') {
195
+ box.style.top = moveType == "add" ? `${box.offsetTop - offset}px` : `${box.offsetTop + offset}px`;
196
+ }
197
+ if (this.config.y_pos == 'top') {
198
+ box.style.top = moveType == "add" ? `${box.offsetTop + offset}px` : `${box.offsetTop - offset}px`;
199
+ }
200
+ boxesCumulatedHeihgt += box.offsetHeight;
201
+ }
202
+ return boxesCumulatedHeihgt;
203
+ }
171
204
  get currentColor() {
172
205
  return this.config.display.colors[this.#type];
173
206
  }
@@ -217,8 +250,6 @@ class Notif {
217
250
  let box = document.createElement('div');
218
251
  let content = document.createElement('div');
219
252
 
220
-
221
-
222
253
  box.append(content);
223
254
  return box;
224
255
  }
@@ -232,11 +263,11 @@ class Notif {
232
263
 
233
264
  notif.style.fontFamily = `${this.config.font.family}`;
234
265
  notif.style.fontSize = `${this.config.font.size}px`;
235
- notif.style.fontWeight= `${this.config.font.weight}`;
266
+ notif.style.fontWeight = `${this.config.font.weight}`;
236
267
 
237
268
  notif.style.borderRadius = `${this.config.display.radius}px`;
238
269
  notif.style.backgroundColor = this.config.display.colors[this.#type].bg;
239
-
270
+ notif.setAttribute('index', document.querySelectorAll('.Thesharsol-notifyer').length)
240
271
  if (this.config.bordered) {
241
272
  notif.style.border = `${this.config.borderWidth}px ${this.currentColor.border.type} ${this.currentColor.border.color}`
242
273
  }
@@ -260,14 +291,20 @@ class Notif {
260
291
  }
261
292
  dismiss() {
262
293
  let dismiss = document.createElement('div');
263
- let dismissContent = document.createElement('div');
294
+ let dismissContent = document.createElement('button');
264
295
  // style
265
296
  dismissContent.classList.add('close-icon');
266
297
  dismissContent.fontSize = `22px`
267
298
  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');
299
+ dismissContent.setAttribute('style', 'font-weight:bold;margin-left:auto;background:transparent;border:0px');
269
300
 
270
301
  dismiss.append(dismissContent);
302
+
303
+ dismissContent.addEventListener('click', () => {
304
+ let boxToRemove = dismissContent.parentNode.parentNode;
305
+ this.moveDisplayedNotifications(boxToRemove, "remove", parseInt(boxToRemove.getAttribute("index")));
306
+ boxToRemove.remove()
307
+ })
271
308
  return dismiss;
272
309
  }
273
310
  progress() {
@@ -279,7 +316,7 @@ class Notif {
279
316
  progress.classList.add('progress');
280
317
  progressContent.setAttribute('style', 'height:2px;width:0px');
281
318
 
282
- progressContent.style.minHeight = '10px';
319
+ progressContent.style.minHeight = `${this.config.progressHeight}px`;
283
320
  progressContent.style.width = '0px';
284
321
  progressContent.classList.add('content');
285
322
  progressContent.style.background = `${this.currentColor.progress ? this.currentColor.progress.bg : 'white'}`;
@@ -299,7 +336,6 @@ class Notif {
299
336
  width += increment;
300
337
  progressBoxContent.style.width = `${width}px`;
301
338
 
302
- console.log(width);
303
339
  if (maxProgressContentWidth <= width) {
304
340
  clearInterval(incInt);
305
341
  }
@@ -308,4 +344,4 @@ class Notif {
308
344
  }
309
345
  }
310
346
  // alert()
311
- export let Notifier = new Notif();
347
+ export let theshtify = new Notif();