Skip to content

Commit

Permalink
Merge commit 'b9e68140' into jqueryless
Browse files Browse the repository at this point in the history
Adding work done while waitting for the last pull request to be accepted
  • Loading branch information
ymeynot45 committed Jun 30, 2022
2 parents 48b23c1 + b9e6814 commit 32a38cf
Showing 1 changed file with 25 additions and 34 deletions.
59 changes: 25 additions & 34 deletions app/assets/javascripts/application.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@ var _Lobsters = Class.extend({
commentFlagReasons: { <%= Vote::COMMENT_REASONS.map{|k,v|
"#{k.inspect}: #{v.inspect}" }.join(", ") %> },

upvoteStory: function(voterEl) {
Lobster.vote("story", voterEl, 1);
},
flagStory: function(voterEl) {
Lobsters._showFlagWhyAt("story", voterEl, function(k) {
Lobster.vote("story", voterEl, -1, k); });
},

upvoteComment: function(voterEl) {
Lobster.vote("comment", voterEl, 1);
},
flagComment: function(voterEl) {
Lobsters._showFlagWhyAt("comment", voterEl, function(k) {
Lobster.vote("comment", voterEl, -1, k); });
},
_showFlagWhyAt: function(thingType, voterEl, onChooseWhy) {
if (!Lobsters.curUser)
return Lobster.bounceToLogin();
Expand Down Expand Up @@ -96,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 @@ -373,12 +351,14 @@ class _LobstersFunction {

}

flagComment(voterEl) { //requires [_showFlagWhyAt]

flagComment(voterEl) {
Lobsters._showFlagWhyAt("comment", voterEl, function(k) {
Lobster.vote("comment", voterEl, -1, k); });
}

flagStory(voterEl) { //requires [_showFlagWhyAt]

flagStory(voterEl) {
Lobsters._showFlagWhyAt("story", voterEl, function(k) {
Lobster.vote("story", voterEl, -1, k); });
}

hideStory(hiderEl) {
Expand Down Expand Up @@ -430,8 +410,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 @@ -462,10 +452,11 @@ class _LobstersFunction {
}

upvoteComment(voterEl) {

Lobster.vote("comment", voterEl, 1);
}

upvoteStory(voterEl) {
Lobster.vote("story", voterEl, 1);
}

vote(thingType, voterEl, point, reason) {
Expand Down Expand Up @@ -578,12 +569,12 @@ onPageLoad(() => {

on('click', 'li.story a.upvoter', (event) => {
event.preventDefault();
Lobsters.upvoteStory(event.target);
Lobster.upvoteStory(event.target);
});

on('click', 'li.story a.flagger', (event) => {
event.preventDefault();
Lobsters.flagStory(event.target);
Lobster.flagStory(event.target);
});

on('click', 'li.story a.hider', (event) => {
Expand All @@ -597,19 +588,19 @@ onPageLoad(() => {
});

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

// Comment Related Functions

on('click', '.comment a.flagger', (event) => {
event.preventDefault();
Lobsters.flagComment(event.target);
Lobster.flagComment(event.target);
});

on("click", '.comment a.upvoter', (event) => {
event.preventDefault();
Lobsters.upvoteComment(event.target);
Lobster.upvoteComment(event.target);
});

on('click', 'button.comment-preview', (event) => {
Expand Down

0 comments on commit 32a38cf

Please sign in to comment.