| 1 |
(function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
function toast(message) { |
| 5 |
var el = document.getElementById('rl6-toast'); |
| 6 |
if (!el) { |
| 7 |
return; |
| 8 |
} |
| 9 |
|
| 10 |
el.textContent = message; |
| 11 |
el.classList.add('is-visible'); |
| 12 |
|
| 13 |
window.clearTimeout(toast.timer); |
| 14 |
toast.timer = window.setTimeout(function () { |
| 15 |
el.classList.remove('is-visible'); |
| 16 |
}, 4200); |
| 17 |
} |
| 18 |
|
| 19 |
function closeModal() { |
| 20 |
var modal = document.getElementById('rl6-modal'); |
| 21 |
var body = document.getElementById('rl6-modal-body'); |
| 22 |
|
| 23 |
if (modal) { |
| 24 |
modal.classList.remove('is-open'); |
| 25 |
modal.setAttribute('aria-hidden', 'true'); |
| 26 |
} |
| 27 |
|
| 28 |
if (body) { |
| 29 |
body.innerHTML = ''; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
function openVideo(videoId) { |
| 34 |
var modal = document.getElementById('rl6-modal'); |
| 35 |
var body = document.getElementById('rl6-modal-body'); |
| 36 |
|
| 37 |
if (!modal || !body || !videoId) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
var iframe = document.createElement('iframe'); |
| 42 |
iframe.src = 'https://www.youtube.com/embed/' + encodeURIComponent(videoId) + '?rel=0'; |
| 43 |
iframe.title = 'RabbitLoader help video'; |
| 44 |
iframe.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share'; |
| 45 |
iframe.allowFullscreen = true; |
| 46 |
iframe.className = 'rl6-video-frame'; |
| 47 |
|
| 48 |
body.appendChild(iframe); |
| 49 |
modal.classList.add('is-open'); |
| 50 |
modal.setAttribute('aria-hidden', 'false'); |
| 51 |
} |
| 52 |
|
| 53 |
document.addEventListener('DOMContentLoaded', function () { |
| 54 |
var disconnect = document.getElementById('rl5-disconnect-button'); |
| 55 |
|
| 56 |
if (disconnect) { |
| 57 |
disconnect.addEventListener('click', async function (event) { |
| 58 |
event.preventDefault(); |
| 59 |
|
| 60 |
if (!window.confirm('Disconnect this WordPress site from RabbitLoader?')) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
disconnect.disabled = true; |
| 65 |
var original = disconnect.textContent; |
| 66 |
disconnect.textContent = 'Disconnecting…'; |
| 67 |
|
| 68 |
try { |
| 69 |
var cfg = window.RL5AdminConfig || window.RL5Config || {}; |
| 70 |
var params = new URLSearchParams({ |
| 71 |
action: 'rabbitloader_disconnect', |
| 72 |
rl_nonce: cfg.nonce || '' |
| 73 |
}); |
| 74 |
|
| 75 |
var response = await fetch(cfg.ajaxUrl, { |
| 76 |
method: 'POST', |
| 77 |
credentials: 'same-origin', |
| 78 |
headers: { |
| 79 |
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' |
| 80 |
}, |
| 81 |
body: params.toString() |
| 82 |
}); |
| 83 |
|
| 84 |
var body = await response.json(); |
| 85 |
|
| 86 |
if (!response.ok || !body || body.result !== true) { |
| 87 |
throw new Error(body && body.message ? body.message : 'Disconnect failed.'); |
| 88 |
} |
| 89 |
|
| 90 |
window.location.assign(body.redirect_url || cfg.dashboardUrl || window.location.href); |
| 91 |
} catch (error) { |
| 92 |
disconnect.disabled = false; |
| 93 |
disconnect.textContent = original; |
| 94 |
window.alert(error && error.message ? error.message : 'Disconnect failed.'); |
| 95 |
} |
| 96 |
}); |
| 97 |
} |
| 98 |
|
| 99 |
var refresh = document.getElementById('rl5-refresh-dashboard'); |
| 100 |
if (refresh) { |
| 101 |
refresh.addEventListener('click', function (event) { |
| 102 |
event.preventDefault(); |
| 103 |
window.location.reload(); |
| 104 |
}); |
| 105 |
} |
| 106 |
|
| 107 |
var purge = document.getElementById('rl5-purge-all'); |
| 108 |
if (purge) { |
| 109 |
purge.addEventListener('click', async function (event) { |
| 110 |
event.preventDefault(); |
| 111 |
|
| 112 |
if (!window.confirm('Purge all pages? This clears the optimized cache for every page on this site and rebuilds them. It may briefly increase load on your server.')) { |
| 113 |
return; |
| 114 |
} |
| 115 |
|
| 116 |
var status = document.getElementById('rl5-purge-status'); |
| 117 |
purge.disabled = true; |
| 118 |
var original = purge.textContent; |
| 119 |
purge.textContent = 'Purging…'; |
| 120 |
if (status) { status.textContent = ''; } |
| 121 |
|
| 122 |
try { |
| 123 |
var cfg = window.RL5AdminConfig || window.RL5Config || {}; |
| 124 |
var params = new URLSearchParams({ |
| 125 |
action: 'rabbitloader_purge', |
| 126 |
rl_nonce: cfg.nonce || '' |
| 127 |
}); |
| 128 |
|
| 129 |
var response = await fetch(cfg.ajaxUrl, { |
| 130 |
method: 'POST', |
| 131 |
credentials: 'same-origin', |
| 132 |
headers: { |
| 133 |
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' |
| 134 |
}, |
| 135 |
body: params.toString() |
| 136 |
}); |
| 137 |
|
| 138 |
var body = await response.json(); |
| 139 |
|
| 140 |
if (!response.ok || !body || body.result !== true) { |
| 141 |
throw new Error(body && body.message ? body.message : 'Purge failed.'); |
| 142 |
} |
| 143 |
|
| 144 |
if (status) { status.textContent = body.message || 'Purge started.'; } |
| 145 |
toast(body.message || 'Purge started.'); |
| 146 |
} catch (error) { |
| 147 |
if (status) { status.textContent = ''; } |
| 148 |
window.alert(error && error.message ? error.message : 'Purge failed.'); |
| 149 |
} finally { |
| 150 |
purge.disabled = false; |
| 151 |
purge.textContent = original; |
| 152 |
} |
| 153 |
}); |
| 154 |
} |
| 155 |
|
| 156 |
document.querySelectorAll('.rl6-ui-preview').forEach(function (button) { |
| 157 |
button.addEventListener('click', function () { |
| 158 |
toast(button.getAttribute('data-message') || 'This control will be wired after the UI is approved.'); |
| 159 |
}); |
| 160 |
}); |
| 161 |
|
| 162 |
document.querySelectorAll('.rl6-profile-card').forEach(function (card) { |
| 163 |
card.addEventListener('click', function () { |
| 164 |
document.querySelectorAll('.rl6-profile-card').forEach(function (item) { |
| 165 |
item.classList.remove('is-selected'); |
| 166 |
}); |
| 167 |
card.classList.add('is-selected'); |
| 168 |
toast((card.getAttribute('data-rl6-profile') || 'Profile') + ' selected for UI preview only. No live setting was changed.'); |
| 169 |
}); |
| 170 |
}); |
| 171 |
|
| 172 |
document.querySelectorAll('.rl6-video-card').forEach(function (card) { |
| 173 |
card.addEventListener('click', function () { |
| 174 |
openVideo(card.getAttribute('data-video-id') || ''); |
| 175 |
}); |
| 176 |
}); |
| 177 |
|
| 178 |
document.querySelectorAll('[data-rl6-close-modal]').forEach(function (button) { |
| 179 |
button.addEventListener('click', closeModal); |
| 180 |
}); |
| 181 |
|
| 182 |
document.addEventListener('keydown', function (event) { |
| 183 |
if (event.key === 'Escape') { |
| 184 |
closeModal(); |
| 185 |
} |
| 186 |
}); |
| 187 |
|
| 188 |
var copy = document.getElementById('rl6-copy-diagnostics'); |
| 189 |
if (copy) { |
| 190 |
copy.addEventListener('click', async function () { |
| 191 |
var value = copy.getAttribute('data-diagnostics') || ''; |
| 192 |
|
| 193 |
try { |
| 194 |
var parsed = JSON.parse(value); |
| 195 |
var text = Object.keys(parsed).map(function (key) { |
| 196 |
return key + ': ' + parsed[key]; |
| 197 |
}).join('\n'); |
| 198 |
|
| 199 |
await navigator.clipboard.writeText(text); |
| 200 |
toast('Diagnostics copied.'); |
| 201 |
} catch (error) { |
| 202 |
toast('Could not copy diagnostics.'); |
| 203 |
} |
| 204 |
}); |
| 205 |
} |
| 206 |
}); |
| 207 |
})(); |
| 208 |
|