Completed
Branch test (745d7d)
by Jonathan
08:28
created

kintRich.toggle   C

Complexity

Conditions 7
Paths 13

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 13
nop 2
dl 0
loc 26
rs 6.7272
c 0
b 0
f 0
1
if (typeof window.kintRich === 'undefined') {
2
    window.kintRich = (function() {
3
        'use strict';
4
5
        var kintRich = {
6
            selectText: function(element) {
7
                var selection = window.getSelection();
8
                var range = document.createRange();
9
10
                range.selectNodeContents(element.lastChild);
11
                range.setStart(element.firstChild, 0);
12
                selection.removeAllRanges();
13
                selection.addRange(range);
14
            },
15
16
            each: function(selector, callback) {
17
                Array.prototype.slice
18
                    .call(document.querySelectorAll(selector), 0)
19
                    .forEach(callback);
20
            },
21
22
            hasClass: function(target, className) {
23
                if (!target.classList) {
24
                    return false;
25
                }
26
27
                if (typeof className === 'undefined') {
28
                    className = 'kint-show';
29
                }
30
                return target.classList.contains(className);
31
            },
32
33
            addClass: function(target, className) {
34
                if (typeof className === 'undefined') {
35
                    className = 'kint-show';
36
                }
37
                target.classList.add(className);
38
            },
39
40
            removeClass: function(target, className) {
41
                if (typeof className === 'undefined') {
42
                    className = 'kint-show';
43
                }
44
                target.classList.remove(className);
45
                return target;
46
            },
47
48
            toggle: function(element, hide) {
49
                var parent = kintRich.getChildren(element);
50
51
                if (!parent) {
52
                    return;
53
                }
54
55
                if (typeof hide === 'undefined') {
56
                    hide = kintRich.hasClass(element);
57
                }
58
59
                if (hide) {
60
                    kintRich.removeClass(element);
61
                } else {
62
                    kintRich.addClass(element);
63
                }
64
65
                if (parent.childNodes.length === 1) {
66
                    parent = parent.childNodes[0].childNodes[0]; // reuse variable cause I can
67
68
                    // parent is checked in case of empty <pre> when array("\n") is dumped
69
                    if (parent && kintRich.hasClass(parent, 'kint-parent')) {
70
                        kintRich.toggle(parent, hide);
71
                    }
72
                }
73
            },
74
75
            toggleChildren: function(element, hide) {
76
                var parent = kintRich.getChildren(element);
77
78
                if (!parent) {
79
                    return;
80
                }
81
82
                var nodes = parent.getElementsByClassName('kint-parent');
83
                var i = nodes.length;
84
85
                if (typeof hide === 'undefined') {
86
                    hide = !kintRich.hasClass(element);
87
                }
88
89
                while (i--) {
90
                    kintRich.toggle(nodes[i], hide);
91
                }
92
            },
93
94
            toggleAll: function(caret) {
95
                var elements = document.getElementsByClassName('kint-parent');
96
                var i = elements.length;
97
                var visible = !kintRich.hasClass(caret.parentNode);
98
99
                while (i--) {
100
                    kintRich.toggle(elements[i], visible);
101
                }
102
            },
103
104
            switchTab: function(target) {
105
                var lis;
106
                var el = target.previousSibling;
107
                var index = 0;
108
109
                target.parentNode.getElementsByClassName('kint-active-tab')[0].className = '';
110
                target.className = 'kint-active-tab';
111
112
                // take the index of clicked title tab and make the same n-th content tab visible
113
114
                while (el) {
115
                    if (el.nodeType === 1) {
116
                        index++;
117
                    }
118
119
                    el = el.previousSibling;
120
                }
121
122
                lis = target.parentNode.nextSibling.childNodes;
123
124
                for (var i = 0; i < lis.length; i++) {
125
                    if (i === index) {
126
                        lis[i].style.display = 'block';
127
128
                        if (lis[i].childNodes.length === 1) {
129
                            el = lis[i].childNodes[0].childNodes[0];
130
131
                            if (el && kintRich.hasClass(el, 'kint-parent')) {
132
                                kintRich.toggle(el, false);
133
                            }
134
                        }
135
                    } else {
136
                        lis[i].style.display = 'none';
137
                    }
138
                }
139
            },
140
141
            // Shitty people using shitty regex fuck up the JS when they see <head> or <meta charset>
142
            // so we have to write this obfuscation to make sure it works after minification
143
            mktag: function(contents) {
144
                return '<' + contents + '>';
145
            },
146
147
            openInNewWindow: function(kintContainer) {
148
                var newWindow = window.open();
149
150
                if (newWindow) {
151
                    newWindow.document.open();
152
                    newWindow.document.write(
153
                        kintRich.mktag('html') +
154
                            kintRich.mktag('head') +
155
                            kintRich.mktag('title') +
156
                            'Kint (' +
157
                            new Date().toISOString() +
158
                            ')' +
159
                            kintRich.mktag('/title') +
160
                            kintRich.mktag('meta charset="utf-8"') +
161
                            document.getElementsByClassName('kint-script')[0].outerHTML +
162
                            document.getElementsByClassName('kint-style')[0].outerHTML +
163
                            kintRich.mktag('/head') +
164
                            kintRich.mktag('body') +
165
                            '<input style="width: 100%" placeholder="Take some notes!">' +
166
                            '<div class="kint-rich">' +
167
                            kintContainer.parentNode.outerHTML +
168
                            '</div>' +
169
                            kintRich.mktag('/body')
170
                    );
171
                    newWindow.document.close();
172
                }
173
            },
174
175
            sortTable: function(table, column) {
176
                var tbody = table.tBodies[0];
177
178
                [].slice
179
                    .call(table.tBodies[0].rows)
180
                    .sort(function(a, b) {
181
                        a = a.cells[column].textContent.trim().toLocaleLowerCase();
182
                        b = b.cells[column].textContent.trim().toLocaleLowerCase();
183
184
                        // In lieu of natsort we just sort all numbers before strings
185
                        if (!isNaN(a) && !isNaN(b)) {
186
                            a = parseFloat(a);
187
                            b = parseFloat(b);
188
                        } else if (isNaN(a) && !isNaN(b)) {
189
                            return 1;
190
                        } else if (isNaN(b) && !isNaN(a)) {
191
                            return -1;
192
                        }
193
194
                        if (a < b) {
195
                            return -1;
196
                        }
197
                        if (a > b) {
198
                            return 1;
199
                        }
200
201
                        return 0;
202
                    })
203
                    .forEach(function(el) {
204
                        tbody.appendChild(el);
205
                    });
206
            },
207
208
            showAccessPath: function(target) {
209
                var nodes = target.childNodes;
210
211
                for (var i = 0; i < nodes.length; i++) {
212
                    if (kintRich.hasClass(nodes[i], 'access-path')) {
213
                        if (kintRich.hasClass(nodes[i], 'kint-show')) {
214
                            kintRich.removeClass(nodes[i]);
215
                        } else {
216
                            kintRich.addClass(nodes[i]);
217
                            kintRich.selectText(nodes[i]);
218
                        }
219
                        return;
220
                    }
221
                }
222
            },
223
224
            getParentByClass: function(el, className) {
225
                if (typeof className === 'undefined') {
226
                    className = 'kint-rich';
227
                }
228
229
                for (;;) {
230
                    el = el.parentNode;
231
                    if (!el || kintRich.hasClass(el, className)) {
232
                        break;
233
                    }
234
                }
235
236
                return el;
237
            },
238
239
            getParentHeader: function(el, allowChildren) {
240
                var nodeName = el.nodeName.toLowerCase();
241
242
                while (nodeName !== 'dd' && nodeName !== 'dt' && kintRich.getParentByClass(el)) {
243
                    el = el.parentNode;
244
                    nodeName = el.nodeName.toLowerCase();
245
                }
246
247
                if (!kintRich.getParentByClass(el)) {
248
                    return null;
249
                }
250
251
                if (nodeName === 'dd' && allowChildren) {
252
                    el = el.previousElementSibling;
253
                }
254
255
                if (
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if el && el.nodeName.toLowe...lass(el, "kint-parent") is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
256
                    el &&
257
                    el.nodeName.toLowerCase() === 'dt' &&
258
                    kintRich.hasClass(el, 'kint-parent')
259
                ) {
260
                    return el;
261
                }
262
            },
263
264
            getChildren: function(element) {
265
                do {
266
                    element = element.nextElementSibling;
267
                } while (element && element.nodeName.toLowerCase() !== 'dd');
268
                return element;
269
            },
270
271
            keyboardNav: {
272
                targets: [], // all visible toggle carets
273
                target: 0, // currently selected caret
274
                active: false,
275
276
                fetchTargets: function() {
277
                    kintRich.keyboardNav.targets = [];
278
                    kintRich.each('.kint-rich nav, .kint-tabs>li:not(.kint-active-tab)', function(
279
                        el
280
                    ) {
281
                        if (el.offsetWidth !== 0 || el.offsetHeight !== 0) {
282
                            kintRich.keyboardNav.targets.push(el);
283
                        }
284
                    });
285
                },
286
287
                sync: function(noscroll) {
288
                    var prevElement = document.querySelector('.kint-focused');
289
                    if (prevElement) {
290
                        kintRich.removeClass(prevElement, 'kint-focused');
291
                    }
292
293
                    if (kintRich.keyboardNav.active) {
294
                        var el = kintRich.keyboardNav.targets[kintRich.keyboardNav.target];
295
                        kintRich.addClass(el, 'kint-focused');
296
297
                        if (!noscroll) {
298
                            kintRich.keyboardNav.scroll(el);
299
                        }
300
                    }
301
                },
302
303
                scroll: function(el) {
304
                    var offsetTop = function(el) {
305
                        return el.offsetTop + (el.offsetParent ? offsetTop(el.offsetParent) : 0);
306
                    };
307
308
                    var top = offsetTop(el);
309
310
                    if (kintRich.folder) {
311
                        var container = kintRich.folder.querySelector('dd.kint-folder');
312
                        container.scrollTo(0, top - container.clientHeight / 2);
313
                    } else {
314
                        window.scrollTo(0, top - window.innerHeight / 2);
315
                    }
316
                },
317
318
                moveCursor: function(diff) {
319
                    kintRich.keyboardNav.target += diff;
320
321
                    while (kintRich.keyboardNav.target < 0) {
322
                        kintRich.keyboardNav.target += kintRich.keyboardNav.targets.length;
323
                    }
324
                    while (kintRich.keyboardNav.target >= kintRich.keyboardNav.targets.length) {
325
                        kintRich.keyboardNav.target -= kintRich.keyboardNav.targets.length;
326
                    }
327
328
                    kintRich.keyboardNav.sync();
329
                },
330
331
                setCursor: function(elem) {
332
                    kintRich.keyboardNav.fetchTargets();
333
334
                    for (var i = 0; i < kintRich.keyboardNav.targets.length; i++) {
335
                        if (elem === kintRich.keyboardNav.targets[i]) {
336
                            kintRich.keyboardNav.target = i;
337
                            return true;
338
                        }
339
                    }
340
341
                    return false;
342
                },
343
            },
344
345
            mouseNav: {
346
                lastClickTarget: null,
347
                lastClickTimer: null,
348
                lastClickCount: 0,
349
350
                renewLastClick: function() {
351
                    window.clearTimeout(kintRich.mouseNav.lastClickTimer);
352
                    kintRich.mouseNav.lastClickTimer = window.setTimeout(function() {
353
                        kintRich.mouseNav.lastClickTarget = null;
354
                        kintRich.mouseNav.lastClickTimer = null;
355
                        kintRich.mouseNav.lastClickCount = 0;
356
                    }, 250);
357
                },
358
            },
359
360
            folder: null,
361
        };
362
363
        window.addEventListener(
364
            'click',
365
            function(e) {
366
                var target = e.target;
367
                var nodeName = target.nodeName.toLowerCase();
368
369
                if (
370
                    kintRich.mouseNav.lastClickTarget &&
371
                    kintRich.mouseNav.lastClickTimer &&
372
                    kintRich.mouseNav.lastClickCount
373
                ) {
374
                    target = kintRich.mouseNav.lastClickTarget;
375
376
                    if (kintRich.mouseNav.lastClickCount === 1) {
377
                        kintRich.toggleChildren(target.parentNode);
378
                        kintRich.keyboardNav.setCursor(target);
379
                        kintRich.keyboardNav.sync(true);
380
                        kintRich.mouseNav.lastClickCount++;
381
382
                        kintRich.mouseNav.renewLastClick();
383
                    } else {
384
                        kintRich.toggleAll(target);
385
                        kintRich.keyboardNav.setCursor(target);
386
                        kintRich.keyboardNav.sync(true);
387
                        kintRich.keyboardNav.scroll(target);
388
389
                        window.clearTimeout(kintRich.mouseNav.lastClickTimer);
390
                        kintRich.mouseNav.lastClickTarget = null;
391
                        kintRich.mouseNav.lastClickTarget = null;
392
                        kintRich.mouseNav.lastClickCount = 0;
393
                    }
394
395
                    return false;
396
                }
397
398
                if (!kintRich.getParentByClass(target)) {
399
                    return;
400
                }
401
402
                // auto-select name of variable
403
                if (nodeName === 'dfn') {
404
                    kintRich.selectText(target);
405
                } else if (nodeName === 'th') {
406
                    if (!e.ctrlKey) {
407
                        kintRich.sortTable(
408
                            target.parentNode.parentNode.parentNode,
409
                            target.cellIndex
410
                        );
411
                    }
412
                    return false;
413
                }
414
415
                // Ensure the header at least is selected
416
                target = kintRich.getParentHeader(target);
417
                if (target) {
418
                    kintRich.keyboardNav.setCursor(target.querySelector('nav'));
419
                    kintRich.keyboardNav.sync(true);
420
                }
421
422
                target = e.target;
423
424
                if (nodeName === 'li' && target.parentNode.className === 'kint-tabs') {
425
                    // switch tabs
426
                    if (target.className !== 'kint-active-tab') {
427
                        kintRich.switchTab(target);
428
                    }
429
                    target = kintRich.getParentHeader(target, true);
430
                    if (target) {
431
                        kintRich.keyboardNav.setCursor(target.querySelector('nav'));
432
                        kintRich.keyboardNav.sync(true);
433
                    }
434
                    return false;
435
                } else if (nodeName === 'nav') {
436
                    // handle clicks on the navigation caret
437
                    if (target.parentNode.nodeName.toLowerCase() === 'footer') {
438
                        kintRich.keyboardNav.setCursor(target);
439
                        kintRich.keyboardNav.sync(true);
440
                        target = target.parentNode;
441
                        if (kintRich.hasClass(target)) {
442
                            kintRich.removeClass(target);
443
                        } else {
444
                            kintRich.addClass(target);
445
                        }
446
                    } else {
447
                        // ensure double/triple click has different behaviour, see below
448
                        kintRich.toggle(target.parentNode);
449
                        kintRich.keyboardNav.fetchTargets();
450
                        kintRich.mouseNav.lastClickCount = 1;
451
                        kintRich.mouseNav.lastClickTarget = target;
452
                        kintRich.mouseNav.renewLastClick();
453
                    }
454
455
                    return false;
456
                } else if (kintRich.hasClass(target, 'kint-ide-link')) {
457
                    // add ajax call to contact editor but prevent link default action
458
                    var ajax = new XMLHttpRequest();
0 ignored issues
show
Bug introduced by
The variable XMLHttpRequest seems to be never declared. If this is a global, consider adding a /** global: XMLHttpRequest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
459
                    ajax.open('GET', target.href);
460
                    ajax.send(null);
461
                    return false;
462
                } else if (kintRich.hasClass(target, 'kint-popup-trigger')) {
463
                    var kintContainer = target.parentNode;
464
                    if (kintContainer.nodeName.toLowerCase() === 'footer') {
465
                        kintContainer = kintContainer.previousSibling;
466
                    } else {
467
                        while (kintContainer && !kintRich.hasClass(kintContainer, 'kint-parent')) {
468
                            kintContainer = kintContainer.parentNode;
469
                        }
470
                    }
471
472
                    kintRich.openInNewWindow(kintContainer);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
473
                } else if (kintRich.hasClass(target, 'kint-access-path-trigger')) {
474
                    kintRich.showAccessPath(target.parentNode);
475
                    return false;
476
                } else if (nodeName === 'pre' && e.detail === 3) {
477
                    // triple click pre to select it all
478
                    kintRich.selectText(target);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
479
                } else if (kintRich.getParentByClass(target, 'kint-source') && e.detail === 3) {
480
                    kintRich.selectText(kintRich.getParentByClass(target, 'kint-source'));
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
481
                } else if (kintRich.hasClass(target, 'access-path')) {
482
                    kintRich.selectText(target);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
483
                } else if (nodeName !== 'a') {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if nodeName !== "a" is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
484
                    target = kintRich.getParentHeader(target);
485
                    if (target) {
486
                        kintRich.toggle(target);
487
                        kintRich.keyboardNav.fetchTargets();
488
                    }
489
                    return false;
490
                }
491
            },
492
            false
493
        );
494
495
        // keyboard navigation
496
        window.onkeydown = function(e) {
497
            // direct assignment is used to have priority over ex FAYT
498
            // do nothing if alt/ctrl key is pressed or if we're actually typing somewhere
499
            if (e.target !== document.body || e.altKey || e.ctrlKey) {
500
                return;
501
            }
502
503
            if (e.keyCode === 68) {
504
                // 'd' : toggles navigation on/off
505
                if (kintRich.keyboardNav.active) {
506
                    kintRich.keyboardNav.active = false;
507
                } else {
508
                    kintRich.keyboardNav.active = true;
509
                    kintRich.keyboardNav.fetchTargets();
510
511
                    if (kintRich.keyboardNav.targets.length === 0) {
512
                        kintRich.keyboardNav.active = false;
513
                        return true;
514
                    }
515
                }
516
517
                kintRich.keyboardNav.sync();
518
                return false;
519
            } else if (!kintRich.keyboardNav.active) {
520
                return true;
521
            } else if (e.keyCode === 9) {
522
                // TAB : moves up/down depending on shift key
523
                kintRich.keyboardNav.moveCursor(e.shiftKey ? -1 : 1);
524
                return false;
525
            } else if (e.keyCode === 38 || e.keyCode === 75) {
526
                // ARROW UP : moves up
527
                kintRich.keyboardNav.moveCursor(-1);
528
                return false;
529
            } else if (e.keyCode === 40 || e.keyCode === 74) {
530
                // ARROW DOWN : down
531
                kintRich.keyboardNav.moveCursor(1);
532
                return false;
533
            }
534
535
            var kintNode = kintRich.keyboardNav.targets[kintRich.keyboardNav.target];
536
            if (kintNode.nodeName.toLowerCase() === 'li') {
537
                // we're on a trace tab
538
                if (e.keyCode === 32 || e.keyCode === 13) {
539
                    // SPACE/ENTER
540
                    kintRich.switchTab(kintNode);
541
                    kintRich.keyboardNav.fetchTargets();
542
                    kintRich.keyboardNav.sync();
543
                    return false;
544
                } else if (e.keyCode === 39 || e.keyCode === 76) {
545
                    // arrows
546
                    kintRich.keyboardNav.moveCursor(1);
547
                    return false;
548
                } else if (e.keyCode === 37 || e.keyCode === 72) {
549
                    kintRich.keyboardNav.moveCursor(-1);
550
                    return false;
551
                }
552
            }
553
554
            // simple dump
555
            kintNode = kintNode.parentNode;
556
557
            if (e.keyCode === 65) {
558
                // 'a' : toggles access path on/off
559
                kintRich.showAccessPath(kintNode);
560
                return false;
561
            } else if (
562
                kintNode.nodeName.toLowerCase() === 'footer' &&
563
                kintRich.hasClass(kintNode.parentNode, 'kint-rich')
564
            ) {
565
                // Minitrace needs special class handling
566
                if (e.keyCode === 32 || e.keyCode === 13) {
567
                    if (kintRich.hasClass(kintNode)) {
568
                        kintRich.removeClass(kintNode);
569
                    } else {
570
                        kintRich.addClass(kintNode);
571
                    }
572
                } else if (e.keyCode === 37 || e.keyCode === 72) {
573
                    kintRich.removeClass(kintNode);
574
                } else if (e.keyCode === 39 || e.keyCode === 76) {
575
                    kintRich.addClass(kintNode);
576
                } else {
577
                    return true;
578
                }
579
580
                return false;
581
            } else if (e.keyCode === 32 || e.keyCode === 13) {
582
                // SPACE/ENTER : toggles
583
                kintRich.toggle(kintNode);
584
                kintRich.keyboardNav.fetchTargets();
585
                return false;
586
            } else if (
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if e.keyCode === 39 || e.ke... 37 || e.keyCode === 72 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
587
                e.keyCode === 39 ||
588
                e.keyCode === 76 ||
589
                e.keyCode === 37 ||
590
                e.keyCode === 72
591
            ) {
592
                // ARROW LEFT/RIGHT : respectively hides/shows and traverses
593
                var hide = e.keyCode === 37 || e.keyCode === 72;
594
595
                if (kintRich.hasClass(kintNode)) {
596
                    // expand/collapse all children if immediate ones are showing
597
                    kintRich.toggleChildren(kintNode, hide);
598
                    kintRich.toggle(kintNode, hide);
599
                } else {
600
                    // traverse to parent and THEN hide
601
                    if (hide) {
602
                        var parent = kintRich.getParentHeader(kintNode.parentNode.parentNode, true);
603
604
                        if (parent) {
605
                            kintNode = parent;
606
                            kintRich.keyboardNav.setCursor(kintNode.querySelector('nav'));
607
                            kintRich.keyboardNav.sync();
608
                        }
609
                    }
610
611
                    kintRich.toggle(kintNode, hide);
612
                }
613
614
                kintRich.keyboardNav.fetchTargets();
615
                return false;
616
            }
617
        };
618
619
        window.addEventListener('load', function() {
620
            kintRich.folder = document.querySelector('.kint-rich.kint-folder');
621
622
            if (!kintRich.folder) {
623
                return;
624
            }
625
626
            // Remove duplicate folders from DOM
627
            var folders = document.querySelectorAll('.kint-rich.kint-folder');
628
            [].forEach.call(folders, function(elem) {
629
                if (elem === kintRich.folder) {
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
630
                } else {
631
                    elem.parentNode.removeChild(elem);
632
                }
633
            });
634
635
            var container = kintRich.folder.querySelector('dd');
636
637
            // Add kint dumps to folder
638
            var kints = document.querySelectorAll('.kint-rich');
639
            [].forEach.call(kints, function(elem) {
640
                if (elem === kintRich.folder) {
641
                    return;
642
                }
643
644
                elem.parentNode.removeChild(elem);
645
                container.append(elem);
646
            });
647
648
            document.body.append(kintRich.folder);
649
        });
650
651
        return kintRich;
652
    })();
653
}
654