зеркало из https://github.com/golang/pkgsite.git
42 строки
1.6 KiB
JavaScript
42 строки
1.6 KiB
JavaScript
'use strict';
|
||
/*!
|
||
* @license
|
||
* Copyright 2020 The Go Authors. All rights reserved.
|
||
* Use of this source code is governed by a BSD-style
|
||
* license that can be found in the LICENSE file.
|
||
*/
|
||
const fetchButton = document.querySelector('.js-fetchButton');
|
||
if (fetchButton) {
|
||
fetchButton.addEventListener('click', e => {
|
||
e.preventDefault();
|
||
fetchPath();
|
||
});
|
||
}
|
||
async function fetchPath() {
|
||
var _a;
|
||
const fetchMessageEl = document.querySelector('.js-fetchMessage');
|
||
const fetchMessageSecondary = document.querySelector('.js-fetchMessageSecondary');
|
||
const fetchButton = document.querySelector('.js-fetchButton');
|
||
const fetchLoading = document.querySelector('.js-fetchLoading');
|
||
if (!(fetchMessageEl && fetchMessageSecondary && fetchButton && fetchLoading)) {
|
||
return;
|
||
}
|
||
fetchMessageEl.textContent = `Fetching ${fetchMessageEl.dataset.path}`;
|
||
fetchMessageSecondary.textContent =
|
||
'Feel free to navigate away and check back later, we’ll keep working on it!';
|
||
fetchButton.style.display = 'none';
|
||
fetchLoading.style.display = 'block';
|
||
const response = await fetch(`/fetch${window.location.pathname}`, { method: 'POST' });
|
||
if (response.ok) {
|
||
window.location.reload();
|
||
return;
|
||
}
|
||
const responseText = await response.text();
|
||
fetchLoading.style.display = 'none';
|
||
fetchMessageSecondary.textContent = '';
|
||
const responseTextParsedDOM = new DOMParser().parseFromString(responseText, 'text/html');
|
||
fetchMessageEl.innerHTML =
|
||
(_a = responseTextParsedDOM.documentElement.textContent) !== null && _a !== void 0 ? _a : '';
|
||
}
|
||
//# sourceMappingURL=fetch.js.map
|