Skip to content

Commit

Permalink
Fix js bugs in the story functions from removing the jQuery (lobsters…
Browse files Browse the repository at this point in the history
  • Loading branch information
ymeynot45 authored Jul 27, 2022
1 parent 73aa8cc commit e7384bf
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions app/assets/javascripts/application.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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'}),
Expand Down Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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'));
}
});
Expand Down

0 comments on commit e7384bf

Please sign in to comment.