|
| 1 | +/* |
| 2 | + * Bootstrap for standalone Debug Toolbar pages (?debugbar_time=...). |
| 3 | + */ |
| 4 | + |
| 5 | +if (! document.getElementById('debugbar_loader')) { |
| 6 | + if (typeof loadDoc !== 'function') { |
| 7 | + window.loadDoc = function (time) { |
| 8 | + if (isNaN(time)) { |
| 9 | + return; |
| 10 | + } |
| 11 | + |
| 12 | + window.location.href = ciSiteURL + '?debugbar_time=' + time; |
| 13 | + }; |
| 14 | + } |
| 15 | + |
| 16 | + (function () { |
| 17 | + function ensureToolbarContainer(icon, toolbar) { |
| 18 | + let toolbarContainer = document.getElementById('toolbarContainer'); |
| 19 | + |
| 20 | + if (toolbarContainer) { |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + toolbarContainer = document.createElement('div'); |
| 25 | + toolbarContainer.setAttribute('id', 'toolbarContainer'); |
| 26 | + |
| 27 | + if (icon) { |
| 28 | + toolbarContainer.appendChild(icon); |
| 29 | + } |
| 30 | + |
| 31 | + if (toolbar) { |
| 32 | + toolbarContainer.appendChild(toolbar); |
| 33 | + } |
| 34 | + |
| 35 | + document.body.appendChild(toolbarContainer); |
| 36 | + } |
| 37 | + |
| 38 | + function initStandaloneToolbar() { |
| 39 | + if (typeof ciDebugBar !== 'object') { |
| 40 | + return; |
| 41 | + } |
| 42 | + |
| 43 | + const icon = document.getElementById('debug-icon'); |
| 44 | + const toolbar = document.getElementById('debug-bar'); |
| 45 | + |
| 46 | + if (! toolbar || ! icon) { |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + const currentTime = new URLSearchParams(window.location.search).get('debugbar_time'); |
| 51 | + |
| 52 | + if (currentTime && ! isNaN(currentTime)) { |
| 53 | + if (! localStorage.getItem('debugbar-time')) { |
| 54 | + localStorage.setItem('debugbar-time', currentTime); |
| 55 | + } |
| 56 | + localStorage.setItem('debugbar-time-new', currentTime); |
| 57 | + } |
| 58 | + |
| 59 | + ensureToolbarContainer(icon, toolbar); |
| 60 | + ciDebugBar.init(); |
| 61 | + } |
| 62 | + |
| 63 | + if (document.readyState === 'loading') { |
| 64 | + document.addEventListener('DOMContentLoaded', initStandaloneToolbar, false); |
| 65 | + } else { |
| 66 | + initStandaloneToolbar(); |
| 67 | + } |
| 68 | + })(); |
| 69 | +} |
0 commit comments