Skip to content

Commit

Permalink
Update previewStory() to remove jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
ymeynot45 committed Jun 28, 2022
1 parent a842d92 commit b9e6814
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions app/assets/javascripts/application.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ var _Lobsters = Class.extend({
}
},

previewStory: function(form) {
$("#inside").load("/stories/preview", $(form).serializeArray(),
function() {
Lobsters.runSelect2();
});
},

runSelect2: function() {
$("#story_tags_a").select2({
formatSelection: function(what) {
Expand Down Expand Up @@ -416,8 +409,18 @@ class _LobstersFunction {
});
}

previewStory(form) { //requires [runSelect2]

previewStory(formElement) {
const formData = new FormData(formElement);
const previewElement = document.getElementById('inside');
fetch('/stories/preview', {
method: 'post',
body: formData
}).then (response => {
response.text().then(text => {
previewElement.innerHTML = text;
});
});
Lobsters.runSelect2();
}

runSelect2() { //requires [] (will actully replace select2)
Expand Down Expand Up @@ -583,7 +586,7 @@ onPageLoad(() => {
});

on('click', 'button.story-preview', (event) => {
Lobsters.previewStory(parentSelector(event.target, 'form'));
Lobster.previewStory(parentSelector(event.target, 'form'));
});

// Comment Related Functions
Expand Down

0 comments on commit b9e6814

Please sign in to comment.