Skip to content

Commit

Permalink
Try It Out: Cache last auth value
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Nov 8, 2021
1 parent 20f4594 commit 3f98009
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions resources/js/tryitout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
window.abortControllers = {};

function cacheAuthValue() {
// Whenever the auth header is set for one endpoint, cache it for the others
window.lastAuthValue = '';
document.querySelectorAll(`label[id^=auth-] > input`)
.forEach(el => {
el.addEventListener('change', (event) => {
window.lastAuthValue = event.target.value;
document.querySelectorAll(`label[id^=auth-] > input`)
.forEach(otherInput => {
if (otherInput === el) return;
// Don't block the main thread
setTimeout(() => {
otherInput.value = window.lastAuthValue;
}, 0);
});
});
});
}

window.addEventListener('DOMContentLoaded', cacheAuthValue);

function getCookie(name) {
if (!document.cookie) {
return null;
Expand Down

0 comments on commit 3f98009

Please sign in to comment.