Fix js bugs in the story functions from removing the jQuery (#1116)

This commit is contained in:
William Karsten 2022-07-27 17:21:55 -05:00 committed by GitHub
parent 73aa8cc01f
commit e7384bf7e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 9 deletions

View File

@ -217,13 +217,14 @@ class _LobstersFunction {
const title_field = document.getElementById('story_title');
const formData = new FormData();
const old_text = button.textContent;
button.setAttribute("disabled", true);
button.textContent = "Fetching...";
formData.append('fetch_url', targetUrl);
if (targetUrl == "")
return;
button.setAttribute("disabled", true);
button.textContent = "Fetching...";
formData.append('fetch_url', targetUrl);
fetchWithCSRF('/stories/fetch_url_attributes', {
method: 'post',
headers: new Headers({'X-Requested-With': 'XMLHttpRequest'}),
@ -295,12 +296,12 @@ class _LobstersFunction {
previewStory(formElement) {
const formData = new FormData(formElement);
const previewElement = document.getElementById('inside');
fetch('/stories/preview', {
fetchWithCSRF('/stories/preview', {
method: 'post',
body: formData
}).then (response => {
response.text().then(text => {
replace(previewElement, text);
previewElement.innerHTML = text;
Lobsters.runSelect2();
});
});
@ -514,7 +515,7 @@ onPageLoad(() => {
Lobster.checkStoryTitle()
if (document.getElementById('story_url') && !document.getElementById('story_preview').firstElementChild) {
if (document.getElementById('story_url') && document.getElementById('story_preview') && !document.getElementById('story_preview').firstElementChild) {
document.getElementById('story_url').focus()
}
@ -576,9 +577,9 @@ onPageLoad(() => {
}
// check for dupe if there's a URL, but not when editing existing
if (document.getElementById('story_url') &&
document.querySelector('input[name="_method"]') &&
(document.querySelector('input[name="_method"]').getAttribute('value') !== 'put')) {
if (document.getElementById('story_url').getAttribute('value') !== "" &&
(!document.querySelector('input[name="_method"]') ||
document.querySelector('input[name="_method"]').getAttribute('value') === 'put')) {
Lobster.checkStoryDuplicate(parentSelector(document.getElementById('story_url'), 'form'));
}
});