-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
448 lines (346 loc) · 14.2 KB
/
app.js
File metadata and controls
448 lines (346 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
"use strict";
// Class definition
var KTApp = function () {
var initPageLoader = function () {
// CSS3 Transitions only after page load(.page-loading class added to body tag and remove with JS on page load)
KTUtil.removeClass(document.body, 'page-loading');
}
var initBootstrapTooltip = function (el, options) {
var delay = {};
// Handle delay options
if (el.hasAttribute('data-bs-delay-hide')) {
delay['hide'] = el.getAttribute('data-bs-delay-hide');
}
if (el.hasAttribute('data-bs-delay-show')) {
delay['show'] = el.getAttribute('data-bs-delay-show');
}
if (delay) {
options['delay'] = delay;
}
// Check dismiss options
if (el.hasAttribute('data-bs-dismiss') && el.getAttribute('data-bs-dismiss') == 'click') {
options['dismiss'] = 'click';
}
// Initialize popover
var tp = new bootstrap.Tooltip(el, options);
// Handle dismiss
if (options['dismiss'] && options['dismiss'] === 'click') {
// Hide popover on element click
el.addEventListener("click", function (e) {
tp.hide();
});
}
return tp;
}
var initBootstrapTooltips = function (el, options) {
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
initBootstrapTooltip(tooltipTriggerEl, {});
});
}
var initBootstrapPopover = function (el, options) {
var delay = {};
// Handle delay options
if (el.hasAttribute('data-bs-delay-hide')) {
delay['hide'] = el.getAttribute('data-bs-delay-hide');
}
if (el.hasAttribute('data-bs-delay-show')) {
delay['show'] = el.getAttribute('data-bs-delay-show');
}
if (delay) {
options['delay'] = delay;
}
// Handle dismiss option
if (el.getAttribute('data-bs-dismiss') == 'true') {
options['dismiss'] = true;
}
if (options['dismiss'] === true) {
options['template'] = '<div class="popover" role="tooltip"><div class="popover-arrow"></div><span class="popover-dismiss btn btn-icon"><i class="bi bi-x fs-2"></i></span><h3 class="popover-header"></h3><div class="popover-body"></div></div>'
}
// Initialize popover
var popover = new bootstrap.Popover(el, options);
// Handle dismiss click
if (options['dismiss'] === true) {
var dismissHandler = function (e) {
popover.hide();
}
el.addEventListener('shown.bs.popover', function () {
var dismissEl = document.getElementById(el.getAttribute('aria-describedby'));
dismissEl.addEventListener('click', dismissHandler);
});
el.addEventListener('hide.bs.popover', function () {
var dismissEl = document.getElementById(el.getAttribute('aria-describedby'));
dismissEl.removeEventListener('click', dismissHandler);
});
}
return popover;
}
var initBootstrapPopovers = function () {
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
initBootstrapPopover(popoverTriggerEl, {});
});
}
var initBootstrapScrollSpy = function () {
var elements = [].slice.call(document.querySelectorAll('[data-bs-spy="scroll"]'));
elements.map(function (element) {
var sel = element.getAttribute('data-bs-target');
var scrollContent = document.querySelector(element.getAttribute('data-bs-target'));
var scrollSpy = bootstrap.ScrollSpy.getInstance(scrollContent);
if (scrollSpy) {
scrollSpy.refresh();
}
});
}
var initBootstrapToast = function () {
var toastElList = [].slice.call(document.querySelectorAll('.toast'));
var toastList = toastElList.map(function (toastEl) {
return new bootstrap.Toast(toastEl, {})
});
}
var initButtons = function () {
var buttonsGroup = [].slice.call(document.querySelectorAll('[data-kt-buttons="true"]'));
buttonsGroup.map(function (group) {
var selector = group.hasAttribute('data-kt-buttons-target') ? group.getAttribute('data-kt-buttons-target') : '.btn';
// Toggle Handler
KTUtil.on(group, selector, 'click', function (e) {
var buttons = [].slice.call(group.querySelectorAll(selector + '.active'));
buttons.map(function (button) {
button.classList.remove('active');
});
this.classList.add('active');
});
});
}
var initCheck = function () {
// Toggle Handler
KTUtil.on(document.body, '[data-kt-check="true"]', 'change', function (e) {
var check = this;
var targets = document.querySelectorAll(check.getAttribute('data-kt-check-target'));
KTUtil.each(targets, function (target) {
if (target.type == 'checkbox') {
target.checked = check.checked;
} else {
target.classList.toggle('active');
}
});
});
}
var initSelect2 = function () {
// Check if jQuery included
if (typeof jQuery == 'undefined') {
return;
}
var elements = [].slice.call(document.querySelectorAll('[data-control="select2"], [data-kt-select2="true"]'));
elements.map(function (element) {
var options = {
dir: document.body.getAttribute('direction')
};
if (element.getAttribute('data-hide-search') == 'true') {
options.minimumResultsForSearch = Infinity;
}
$(element).select2(options);
});
}
var initAutosize = function () {
var inputs = [].slice.call(document.querySelectorAll('[data-kt-autosize="true"]'));
inputs.map(function (input) {
autosize(input);
});
}
var initCountUp = function () {
var elements = [].slice.call(document.querySelectorAll('[data-kt-countup="true"]:not(.counted)'));
elements.map(function (element) {
if (KTUtil.isInViewport(element) && KTUtil.visible(element)) {
var options = {};
var value = element.getAttribute('data-kt-countup-value');
value = parseFloat(value.replace(/,/g, ""));
if (element.hasAttribute('data-kt-countup-start-val')) {
options.startVal = parseFloat(element.getAttribute('data-kt-countup-start-val'));
}
if (element.hasAttribute('data-kt-countup-duration')) {
options.duration = parseInt(element.getAttribute('data-kt-countup-duration'));
}
if (element.hasAttribute('data-kt-countup-decimal-places')) {
options.decimalPlaces = parseInt(element.getAttribute('data-kt-countup-decimal-places'));
}
if (element.hasAttribute('data-kt-countup-prefix')) {
options.prefix = element.getAttribute('data-kt-countup-prefix');
}
if (element.hasAttribute('data-kt-countup-suffix')) {
options.suffix = element.getAttribute('data-kt-countup-suffix');
}
var count = new countUp.CountUp(element, value, options);
count.start();
element.classList.add('counted');
}
});
}
var initCountUpTabs = function () {
// Initial call
initCountUp();
// Window scroll event handler
window.addEventListener('scroll', initCountUp);
// Tabs shown event handler
var tabs = [].slice.call(document.querySelectorAll('[data-kt-countup-tabs="true"][data-bs-toggle="tab"]'));
tabs.map(function (tab) {
tab.addEventListener('shown.bs.tab', initCountUp);
});
}
var initTinySliders = function () {
// Init Slider
var initSlider = function (el) {
if (!el) {
return;
}
const tnsOptions = {};
// Convert string boolean
const checkBool = function (val) {
if (val === 'true') {
return true;
}
if (val === 'false') {
return false;
}
return val;
};
// get extra options via data attributes
el.getAttributeNames().forEach(function (attrName) {
// more options; https://github.com/ganlanyuan/tiny-slider#options
if ((/^data-tns-.*/g).test(attrName)) {
let optionName = attrName.replace('data-tns-', '').toLowerCase().replace(/(?:[\s-])\w/g, function (match) {
return match.replace('-', '').toUpperCase();
});
if (attrName === 'data-tns-responsive') {
// fix string with a valid json
const jsonStr = el.getAttribute(attrName).replace(/(\w+:)|(\w+ :)/g, function (matched) {
return '"' + matched.substring(0, matched.length - 1) + '":';
});
try {
// convert json string to object
tnsOptions[optionName] = JSON.parse(jsonStr);
}
catch (e) {
}
}
else {
tnsOptions[optionName] = checkBool(el.getAttribute(attrName));
}
}
});
const opt = Object.assign({}, {
container: el,
slideBy: 'page',
autoplay: true,
autoplayButtonOutput: false,
}, tnsOptions);
if (el.closest('.tns')) {
KTUtil.addClass(el.closest('.tns'), 'tns-initiazlied');
}
return tns(opt);
}
// Sliders
const elements = Array.prototype.slice.call(document.querySelectorAll('[data-tns="true"]'), 0);
if (!elements && elements.length === 0) {
return;
}
elements.forEach(function (el) {
initSlider(el);
});
}
var initSmoothScroll = function () {
if (SmoothScroll) {
new SmoothScroll('a[data-kt-scroll-toggle][href*="#"]', {
speed: 900,
offset: function (anchor, toggle) {
// Integer or Function returning an integer. How far to offset the scrolling anchor location in pixels
// This example is a function, but you could do something as simple as `offset: 25`
// An example returning different values based on whether the clicked link was in the header nav or not
if (anchor.hasAttribute('data-kt-scroll-offset')) {
var val = KTUtil.getResponsiveValue(anchor.getAttribute('data-kt-scroll-offset'));
return val;
} else {
return 0;
}
}
});
}
}
return {
init: function () {
this.initPageLoader();
this.initBootstrapTooltips();
this.initBootstrapPopovers();
this.initBootstrapScrollSpy();
this.initButtons();
this.initCheck();
this.initSelect2();
this.initCountUp();
this.initCountUpTabs();
this.initAutosize();
this.initTinySliders();
this.initSmoothScroll();
this.initBootstrapToast();
},
initPageLoader: function () {
initPageLoader();
},
initBootstrapTooltip: function (el, options) {
return initBootstrapTooltip(el, options);
},
initBootstrapTooltips: function () {
initBootstrapTooltips();
},
initBootstrapPopovers: function () {
initBootstrapPopovers();
},
initBootstrapPopover: function (el, options) {
return initBootstrapPopover(el, options);
},
initBootstrapScrollSpy: function () {
initBootstrapScrollSpy();
},
initBootstrapToast: function () {
initBootstrapToast();
},
initButtons: function () {
initButtons();
},
initCheck: function () {
initCheck();
},
initSelect2: function () {
initSelect2();
},
initCountUp: function () {
initCountUp();
},
initCountUpTabs: function () {
initCountUpTabs();
},
initAutosize: function () {
initAutosize();
},
initTinySliders: function () {
initTinySliders();
},
initSmoothScroll: function () {
initSmoothScroll();
},
isDarkMode: function () {
return document.body.classList.contains('dark-mode');
}
};
}();
// On document ready
KTUtil.onDOMContentLoaded(function () {
KTApp.init();
});
// On window load
window.addEventListener("load", function () {
KTApp.initPageLoader();
});
// Webpack support
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = KTApp;
}