bobjoll 0.0.4

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.
Files changed (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -0
  3. package/package.json +25 -0
  4. package/scss/layout/_footer.scss +10 -0
  5. package/scss/layout/_header.scss +10 -0
  6. package/scss/modules/_fonts.scss +26 -0
  7. package/scss/modules/_reset.scss +219 -0
  8. package/scss/modules/bourbon/addons/_clearfix.scss +25 -0
  9. package/scss/modules/bourbon/addons/_ellipsis.scss +30 -0
  10. package/scss/modules/bourbon/addons/_position.scss +48 -0
  11. package/scss/modules/bourbon/addons/_prefixer.scss +66 -0
  12. package/scss/modules/bourbon/addons/_size.scss +51 -0
  13. package/scss/modules/bourbon/addons/_timing-functions.scss +34 -0
  14. package/scss/modules/bourbon/addons/_triangle.scss +63 -0
  15. package/scss/modules/bourbon/css3/_calc.scss +4 -0
  16. package/scss/modules/bourbon/css3/_flex-box.scss +287 -0
  17. package/scss/modules/bourbon/css3/_keyframes.scss +36 -0
  18. package/scss/modules/bourbon/css3/_linear-gradient.scss +38 -0
  19. package/scss/modules/bourbon/css3/_placeholder.scss +8 -0
  20. package/scss/modules/bourbon/css3/_selection.scss +42 -0
  21. package/scss/modules/bourbon/css3/_transition.scss +71 -0
  22. package/scss/modules/mixins/_component.scss +9 -0
  23. package/scss/modules/mixins/_grid.scss +75 -0
  24. package/scss/modules/mixins/_helpers.scss +224 -0
  25. package/scss/modules/variables/_colors.scss +447 -0
  26. package/scss/modules/variables/_general.scss +235 -0
  27. package/scss/partials/_accordion-v1-0.scss +165 -0
  28. package/scss/partials/_autocomplete-v1-0.scss +55 -0
  29. package/scss/partials/_general-v1-0.scss +51 -0
  30. package/scss/partials/_grid-v1-0.scss +109 -0
  31. package/scss/partials/_helper-v1-0.scss +299 -0
  32. package/scss/partials/_icon-v2-0.scss +323 -0
  33. package/scss/partials/_list-v1-0.scss +100 -0
  34. package/scss/partials/_modal-v1-0.scss +159 -0
  35. package/scss/partials/_notification-v1-1.scss +297 -0
  36. package/scss/partials/_progress-bar-v1.0.scss +25 -0
  37. package/scss/partials/_range-v1.0.scss +75 -0
  38. package/scss/partials/_tooltipFixed-v1.0.scss +128 -0
  39. package/scss/partials/_typography-v1-0.scss +201 -0
  40. package/scss/partials/animations/_fade.scss +23 -0
  41. package/scss/partials/animations/_rotate.scss +11 -0
  42. package/scss/partials/animations/_scale.scss +23 -0
  43. package/scss/partials/animations/_slide.scss +31 -0
  44. package/scss/partials/button-v4-0/_component.scss +304 -0
  45. package/scss/partials/form/_checkbox-and-radio-v1-0.scss +187 -0
  46. package/scss/partials/form/_dropdowns-v1-0.scss +323 -0
  47. package/scss/partials/form/_general-v1-0.scss +166 -0
  48. package/scss/partials/form/_group-v1-0.scss +157 -0
  49. package/scss/partials/form/_password-v1-0.scss +28 -0
  50. package/scss/partials/form/_switch-v1-0.scss +128 -0
  51. package/scss/partials/form/_upload-v1-0.scss +91 -0
  52. package/ts/library/common.ts +30 -0
  53. package/ts/library/cookie.ts +47 -0
  54. package/ts/library/delegate.ts +122 -0
  55. package/ts/library/dom.ts +124 -0
  56. package/ts/library/event.ts +138 -0
  57. package/ts/library/extend.js +32 -0
  58. package/ts/library/gr/dom.q.ts +12 -0
  59. package/ts/library/gr/social/dependency/twitter_pu.js +66 -0
  60. package/ts/library/gr/social/facebook.ts +154 -0
  61. package/ts/library/gr/social/google.ts +127 -0
  62. package/ts/library/gr/social/index.ts +35 -0
  63. package/ts/library/gr/social/twitter.ts +65 -0
  64. package/ts/library/helpers.ts +9 -0
  65. package/ts/library/number-abbreviate.js +57 -0
  66. package/ts/library/settings.ts +7 -0
  67. package/ts/library/storage.ts +131 -0
  68. package/ts/library/svg4everybody.legacy.js +122 -0
  69. package/ts/partials/accordion-v1.0.ts +104 -0
  70. package/ts/partials/accordionTabs-v1.0.ts +27 -0
  71. package/ts/partials/alert-v1.0.ts +51 -0
  72. package/ts/partials/copy-v1.0.ts +17 -0
  73. package/ts/partials/countdown-v1.0.ts +119 -0
  74. package/ts/partials/dropdown-v1.0.ts +247 -0
  75. package/ts/partials/hbs-v1.0.ts +9 -0
  76. package/ts/partials/modal-v1.0.ts +213 -0
  77. package/ts/partials/notifications-v1.1.ts +376 -0
  78. package/ts/partials/notify-v1.0.ts +746 -0
  79. package/ts/partials/password-v1.0.ts +19 -0
  80. package/ts/partials/popover-v1.0.ts +125 -0
  81. package/ts/partials/progress-bar-v1.0.ts +29 -0
  82. package/ts/partials/scroll-v1.0.ts +169 -0
  83. package/ts/partials/scrollable-v1.0.ts +90 -0
  84. package/ts/partials/tabs-v1.0.ts +79 -0
  85. package/ts/partials/tags-v1.0.ts +21 -0
  86. package/ts/partials/trigger-v2.0.ts +155 -0
  87. package/ts/partials/upload-v1.0.ts +17 -0
  88. package/ts/views/hbs/alert-v1.0/element.html.hbs +35 -0
  89. package/ts/views/hbs/countdown-v1.0/countdown-inner.hbs +39 -0
  90. package/ts/views/hbs/countdown-v1.0/countdown.hbs +4 -0
  91. package/ts/views/hbs/dropdown-v1.0/element.html.hbs +70 -0
  92. package/ts/views/hbs/helpers.js +58 -0
  93. package/ts/views/hbs/modal-v1.0/element.html.hbs +17 -0
  94. package/ts/views/hbs/notification-v1.1/element-disable.html.hbs +26 -0
  95. package/ts/views/hbs/notification-v1.1/element.html.hbs +43 -0
  96. package/ts/views/hbs/notification-v1.1/wrapper.html.hbs +4 -0
@@ -0,0 +1,376 @@
1
+ import { Cookie } from 'bobjoll/ts/library/cookie';
2
+ import { Settings } from 'Settings';
3
+ import View from 'BobjollView';
4
+
5
+ const EXT = View.ext;
6
+ const STORAGE_VISIBILITY_NS = 'notification-visibility';
7
+ const STORAGE_COUNT_NS = 'notification-count';
8
+ const extend = require('bobjoll/ts/library/extend');
9
+
10
+ export default class Notifications {
11
+ public settings: DefaultSettings;
12
+ private wrapper: HTMLElement | null = null;
13
+ public active: any;
14
+
15
+ constructor(settings?: Settings) {
16
+ const defaultSettings: DefaultSettings = {
17
+ fixed: false,
18
+ recurrent: false,
19
+ timeout: 5000,
20
+ template: require(`BobjollTemplate/notification-v1.1/element.${EXT}`),
21
+ position: 'bottom-left',
22
+ cookieExpiry: new Date(new Date().getTime() + (365 * 24 * 60 * 60 * 1000)),
23
+ }
24
+
25
+ this.setup();
26
+ this.active = {};
27
+ this.settings = extend(defaultSettings, settings);
28
+ }
29
+
30
+ private setup() {
31
+ let template = require(`BobjollTemplate/notification-v1.1/wrapper.${EXT}`);
32
+ let wrapper = document.getElementById('notifications');
33
+
34
+ if (!wrapper) {
35
+ document.body.insertAdjacentHTML('beforeend', View.render(template));
36
+ wrapper = document.getElementById('notifications');
37
+ }
38
+
39
+ if (wrapper) {
40
+ this.wrapper = wrapper;
41
+ }
42
+ }
43
+
44
+ private anchor(position: Position) {
45
+ let name = `notifications__${position}`;
46
+ let anchor = document.querySelector(`.${name}`);
47
+
48
+ if (!anchor) {
49
+ anchor = document.createElement('div');
50
+ anchor.className = name;
51
+
52
+ if (this.wrapper) {
53
+ this.wrapper.insertAdjacentElement('afterbegin', anchor);
54
+ }
55
+ }
56
+
57
+ return anchor;
58
+ }
59
+
60
+ public insert(settings: InsertSettings) {
61
+ let options = extend(this.settings, settings);
62
+ let anchor: Element = this.anchor(options.position);
63
+ let position: any = options.position.match(/top/) ? 'beforeend' : 'afterbegin';
64
+ let target = options.target ? ('string' === typeof options.target ? document.querySelector(options.target) : options.target) : null;
65
+ let notification = document.getElementById(options.id);
66
+ let staticNotification = 'static' === options.position;
67
+
68
+ if (!notification || !options.id) {
69
+ if (!options.id && options.recurrent) {
70
+ options.recurrent = false;
71
+
72
+ console.warn('You have to define a fixed ID for this notification in order for recurrent to work properly.');
73
+ }
74
+
75
+ if (options.recurrent && (Cookie.getItem(`${STORAGE_VISIBILITY_NS}--${options.id}`) === 'false')) {
76
+ return;
77
+ }
78
+
79
+ options.id = options.id || `notifications_${new Date().getTime()}`;
80
+
81
+ if (target) {
82
+ anchor = staticNotification ? target : document.body;
83
+ position = staticNotification ? 'afterend' : 'beforeend';
84
+ }
85
+
86
+ if (staticNotification) {
87
+ options.class += ' notification--static';
88
+ }
89
+
90
+ if (options.insert) {
91
+ anchor = options.insert.element;
92
+ position = options.insert.position;
93
+ }
94
+
95
+ anchor.insertAdjacentHTML(position, View.render(options.template, options));
96
+
97
+ notification = document.getElementById(options.id);
98
+
99
+ if (notification && options.recurrentMax) {
100
+ notification.dataset.recurrentMax = options.recurrentMax;
101
+ }
102
+
103
+ if (notification && options.recurrentPrint && options.recurrentMax) {
104
+ notification.dataset.recurrentPrint = 'true';
105
+
106
+ let count: number = parseFloat(Cookie.getItem(`${STORAGE_COUNT_NS}--${options.id}_count`) || '0');
107
+
108
+ count++;
109
+
110
+ Cookie.setItem(`${STORAGE_COUNT_NS}--${options.id}_count`, count.toString(), {
111
+ path: '/',
112
+ domain: document.domain,
113
+ expires: options.cookieExpiry || this.settings.cookieExpiry
114
+ });
115
+
116
+ if (count && count >= parseFloat(options.recurrentMax)) {
117
+ Cookie.removeItem(`${STORAGE_COUNT_NS}--${options.id}_count`);
118
+ Cookie.setItem(`${STORAGE_VISIBILITY_NS}--${options.id}`, 'false', {
119
+ path: '/',
120
+ domain: document.domain,
121
+ expires: options.cookieExpiry || this.settings.cookieExpiry
122
+ });
123
+ }
124
+ }
125
+
126
+ if (notification && options.cookieExpiry) {
127
+ notification.dataset.cookieExpiry = options.cookieExpiry.getTime();
128
+ }
129
+
130
+ if (target) {
131
+ if (notification && 'static' !== options.position) {
132
+ const notificationBounding = notification.getBoundingClientRect();
133
+ const notificationTriangle = (<HTMLElement>notification.querySelector('.notification__triangle'));
134
+ const targetBounding = target.getBoundingClientRect();
135
+ const scrollPosition = this.getScrollPosition();
136
+
137
+ notification.classList.add('notification--absolute');
138
+
139
+ if (options.position.match(/top/)) {
140
+ notification.style.bottom = `${(window.innerHeight - targetBounding.bottom - scrollPosition) + targetBounding.height + parseFloat(Settings['small-spacing'])}px`;
141
+
142
+ if (notificationTriangle) {
143
+ notificationTriangle.style.top = '100%';
144
+ notificationTriangle.style.left = '50%';
145
+ notificationTriangle.style.transform = 'translateX(-50%)';
146
+ }
147
+ }
148
+
149
+ if (options.position.match(/bottom/)) {
150
+ notification.style.top = `${targetBounding.top + targetBounding.height + scrollPosition + parseFloat(Settings['small-spacing'])}px`;
151
+
152
+ if (notificationTriangle) {
153
+ notificationTriangle.style.bottom = '100%';
154
+ notificationTriangle.style.left = '50%';
155
+ notificationTriangle.style.transform = 'translateX(-50%) rotate(180deg)';
156
+ }
157
+ }
158
+
159
+ if (options.position.match(/left/)) {
160
+ notification.style.left = `${targetBounding.left}px`;
161
+
162
+ if (notificationTriangle) {
163
+ notificationTriangle.style.left = `${Settings['base-spacing']}`;
164
+ notificationTriangle.style.right = "";
165
+ }
166
+ }
167
+
168
+ if (options.position.match(/right/)) {
169
+ notification.style.right = `${window.innerWidth - targetBounding.right}px`;
170
+
171
+ if (notificationTriangle) {
172
+ notificationTriangle.style.left = "";
173
+ notificationTriangle.style.right = `${Settings['base-spacing']}`;
174
+ }
175
+ }
176
+
177
+ if (options.position.match(/-center/)) {
178
+ notification.style.left = `${targetBounding.left - (Math.abs(targetBounding.width - notificationBounding.width) / 2)}px`;
179
+ }
180
+ }
181
+ }
182
+
183
+ this.show(options.id);
184
+
185
+ if (options.events && options.events.onload) {
186
+ options.events.onload();
187
+ }
188
+
189
+ if (!options.fixed) {
190
+ this.active[options.id] = {};
191
+ this.active[options.id].timeout = setTimeout(() => this.hide(options.id), options.timeout);
192
+ } else {
193
+ const notification = document.getElementById(options.id);
194
+
195
+ if (notification) {
196
+ const buttonLink = notification.querySelector('a.link-action');
197
+ const close = notification.querySelector('.notification__close');
198
+
199
+ if (buttonLink && options.events && options.events.click) {
200
+ buttonLink.addEventListener('click', () => {
201
+ options.events.click();
202
+ });
203
+ }
204
+
205
+ if (close) {
206
+ close.addEventListener('click', () => {
207
+ if (options.events && options.events.close) {
208
+ options.events.close();
209
+ }
210
+ this.hide(options.id);
211
+ });
212
+ }
213
+ }
214
+ }
215
+ }
216
+
217
+ return options.id;
218
+ }
219
+
220
+ public hide(id: string, hideRecurrent?: boolean) {
221
+ const notification = document.getElementById(id);
222
+
223
+ if (notification) {
224
+ const recurrent = notification.dataset.recurrent;
225
+
226
+ notification.classList.add('animation--fade-out');
227
+
228
+ if (recurrent) {
229
+ const userDisable = (<HTMLInputElement>notification.querySelector('.notification__disable input'));
230
+ const recurrentMax = notification.dataset.recurrentMax;
231
+ const recurrentPrint = notification.dataset.recurrenPrint;
232
+ const cookieExpiry = notification.dataset.cookieExpiry;
233
+ const cookieExpiryDate = new Date(parseFloat(cookieExpiry || '0'));
234
+
235
+ if (userDisable && userDisable.checked || hideRecurrent) {
236
+ Cookie.setItem(`${STORAGE_VISIBILITY_NS}--${id}`, 'false', {
237
+ path: '/',
238
+ domain: document.domain,
239
+ expires: cookieExpiry ? cookieExpiryDate : this.settings.cookieExpiry
240
+ });
241
+ } else if (recurrentMax) {
242
+ let count: number = parseFloat(Cookie.getItem(`${STORAGE_COUNT_NS}--${id}_count`) || '0');
243
+
244
+ if (!recurrentPrint && 'undefined' !== typeof count) {
245
+ count++;
246
+ }
247
+
248
+ Cookie.setItem(`${STORAGE_COUNT_NS}--${id}_count`, count.toString(), {
249
+ path: '/',
250
+ domain: document.domain,
251
+ expires: cookieExpiry ? cookieExpiryDate : this.settings.cookieExpiry
252
+ });
253
+
254
+ if (count && count >= parseFloat(recurrentMax)) {
255
+ Cookie.removeItem(`${STORAGE_COUNT_NS}--${id}_count`);
256
+ Cookie.setItem(`${STORAGE_VISIBILITY_NS}--${id}`, 'false', {
257
+ path: '/',
258
+ domain: document.domain,
259
+ expires: cookieExpiry ? cookieExpiryDate : this.settings.cookieExpiry
260
+ });
261
+ }
262
+ }
263
+ }
264
+
265
+ if (this.active[id]) {
266
+ clearTimeout(this.active[id].timeout);
267
+ delete this.active[id];
268
+ }
269
+
270
+ setTimeout(() => {
271
+ if (notification.parentNode) {
272
+ notification.parentNode.removeChild(notification);
273
+ }
274
+ }, parseFloat(Settings['base-duration']));
275
+ }
276
+ }
277
+
278
+ public show(id: string) {
279
+ const notification = document.getElementById(id);
280
+
281
+ if (notification) {
282
+ notification.classList.add('notification--show');
283
+ }
284
+ }
285
+
286
+ public getSettings(id: string) {
287
+ const cookieItemCount = Cookie.getItem(`${STORAGE_COUNT_NS}--${id}_count`);
288
+ const cookieItemVisibility = Cookie.getItem(`${STORAGE_VISIBILITY_NS}--${id}`);
289
+ const itemCount = cookieItemCount ? parseFloat(cookieItemCount) : undefined;
290
+ const itemVisibility = cookieItemVisibility ? true : false;
291
+
292
+ let item: {
293
+ count?: number;
294
+ visibility?: boolean;
295
+ } = {};
296
+
297
+ if ('undefined' !== typeof itemCount) {
298
+ item.count = itemCount;
299
+ }
300
+
301
+ if ('undefined' !== typeof itemVisibility) {
302
+ item.visibility = itemVisibility;
303
+ }
304
+
305
+ return item;
306
+ }
307
+
308
+ getScrollPosition(): number {
309
+ // return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
310
+ return window.pageYOffset || document.body.scrollTop;
311
+ }
312
+ }
313
+
314
+
315
+ export interface Position {
316
+ 'static': string;
317
+ 'bottom-center': HTMLElement;
318
+ 'bottom-left': HTMLElement;
319
+ 'bottom-right': HTMLElement;
320
+ 'center': HTMLElement;
321
+ 'top-center': HTMLElement;
322
+ 'top-left': HTMLElement;
323
+ 'top-right': HTMLElement;
324
+ };
325
+
326
+ export interface DefaultSettings {
327
+ fixed: boolean;
328
+ recurrent: boolean;
329
+ timeout: number;
330
+ template: Function;
331
+ position: keyof Position;
332
+ cookieExpiry: Date;
333
+ }
334
+
335
+ export interface Settings {
336
+ fixed?: boolean;
337
+ recurrent?: boolean;
338
+ recurrentMax?: number;
339
+ recurrentPrint?: boolean;
340
+ timeout?: number;
341
+ template?: Function;
342
+ position?: keyof Position;
343
+ cookieExpiry?: Date;
344
+ }
345
+
346
+ export interface Link {
347
+ arrow?: boolean;
348
+ clickAndClose?: boolean;
349
+ customClass?: string;
350
+ extraAttr?: string;
351
+ target: string;
352
+ text: string;
353
+ url: string;
354
+ }
355
+
356
+ export interface InsertSettings extends Settings {
357
+ id?: string;
358
+ class?: string;
359
+ html?: string;
360
+ target?: string | Element;
361
+ insert?: {
362
+ element: Element;
363
+ position: 'beforeend' | 'beforebegin' | 'afterend' | 'afterbegin';
364
+ };
365
+ position?: keyof Position;
366
+ cookieExpiry?: Date;
367
+ type?: string;
368
+ title?: string;
369
+ content?: string;
370
+ link?: Link;
371
+ events?: {
372
+ onload?: Function;
373
+ click?: Function;
374
+ close?: Function;
375
+ };
376
+ }