fluoride: Fix syntax and formatting

This commit is contained in:
r 2020-06-21 17:18:12 +00:00
parent 1936044137
commit 69f2c3d226
1 changed files with 33 additions and 33 deletions

View File

@ -8,7 +8,7 @@ var reverseActions = {
}; };
function getCSRFToken() { function getCSRFToken() {
var tag = document.querySelector("meta[name='csrf_token']") var tag = document.querySelector("meta[name='csrf_token']");
if (tag) if (tag)
return tag.getAttribute("content"); return tag.getAttribute("content");
return ""; return "";
@ -34,7 +34,7 @@ function http(method, url, body, type, success, error) {
} }
function updateActionForm(id, f, action) { function updateActionForm(id, f, action) {
f.querySelector('[type="submit"]').value = action; f.querySelector("[type='submit']").value = action;
f.action = "/" + action + "/" + id; f.action = "/" + action + "/" + id;
f.dataset.action = action; f.dataset.action = action;
} }
@ -44,20 +44,23 @@ function handleLikeForm(id, f) {
event.preventDefault(); event.preventDefault();
var action = f.dataset.action; var action = f.dataset.action;
var forms = document.querySelectorAll(".status-"+id+" .status-like"); var forms = document.
querySelectorAll(".status-"+id+" .status-like");
for (var i = 0; i < forms.length; i++) { for (var i = 0; i < forms.length; i++) {
updateActionForm(id, forms[i], reverseActions[action]); updateActionForm(id, forms[i], reverseActions[action]);
} }
var body = "csrf_token=" + encodeURIComponent(getCSRFToken()); var body = "csrf_token=" + encodeURIComponent(getCSRFToken());
var contentType = "application/x-www-form-urlencoded"; var contentType = "application/x-www-form-urlencoded";
http("POST", "/fluoride/" + action + "/" + id, body, contentType, function(res, type) { http("POST", "/fluoride/" + action + "/" + id,
body, contentType, function(res, type) {
var data = JSON.parse(res); var data = JSON.parse(res);
var count = data.data; var count = data.data;
if (count === 0) { if (count === 0)
count = ""; count = "";
} var counts = document.
var counts = document.querySelectorAll(".status-"+id+" .status-like-count"); querySelectorAll(".status-"+id+" .status-like-count");
for (var i = 0; i < counts.length; i++) { for (var i = 0; i < counts.length; i++) {
if (count > 0) { if (count > 0) {
counts[i].innerHTML = "(" + count + ")"; counts[i].innerHTML = "(" + count + ")";
@ -78,20 +81,23 @@ function handleRetweetForm(id, f) {
event.preventDefault(); event.preventDefault();
var action = f.dataset.action; var action = f.dataset.action;
var forms = document.querySelectorAll(".status-"+id+" .status-retweet"); var forms = document.
querySelectorAll(".status-"+id+" .status-retweet");
for (var i = 0; i < forms.length; i++) { for (var i = 0; i < forms.length; i++) {
updateActionForm(id, forms[i], reverseActions[action]); updateActionForm(id, forms[i], reverseActions[action]);
} }
var body = "csrf_token=" + encodeURIComponent(getCSRFToken()); var body = "csrf_token=" + encodeURIComponent(getCSRFToken());
var contentType = "application/x-www-form-urlencoded"; var contentType = "application/x-www-form-urlencoded";
http("POST", "/fluoride/" + action + "/" + id, body, contentType, function(res, type) { http("POST", "/fluoride/" + action + "/" + id,
body, contentType, function(res, type) {
var data = JSON.parse(res); var data = JSON.parse(res);
var count = data.data; var count = data.data;
if (count === 0) { if (count === 0)
count = ""; count = "";
} var counts = document.
var counts = document.querySelectorAll(".status-"+id+" .status-retweet-count"); querySelectorAll(".status-"+id+" .status-retweet-count");
for (var i = 0; i < counts.length; i++) { for (var i = 0; i < counts.length; i++) {
if (count > 0) { if (count > 0) {
counts[i].innerHTML = "(" + count + ")"; counts[i].innerHTML = "(" + count + ")";
@ -109,26 +115,22 @@ function handleRetweetForm(id, f) {
function isInView(el) { function isInView(el) {
var ract = el.getBoundingClientRect(); var ract = el.getBoundingClientRect();
if (ract.top > 0 && ract.bottom < window.innerHeight) { if (ract.top > 0 && ract.bottom < window.innerHeight)
return true; return true;
}
return false; return false;
} }
function handleReplyToLink(div) { function handleReplyToLink(div) {
if (!div) { if (!div)
return; return;
} var id = div.firstElementChild.getAttribute("href");
var id = div.firstElementChild.getAttribute('href'); if (!id || id[0] != "#")
if (!id || id[0] != '#') {
return; return;
}
div.firstElementChild.onmouseenter = function(event) { div.firstElementChild.onmouseenter = function(event) {
var id = event.target.getAttribute('href'); var id = event.target.getAttribute("href");
var status = document.querySelector(id); var status = document.querySelector(id);
if (!status) { if (!status)
return; return;
}
if (isInView(status)) { if (isInView(status)) {
status.classList.add("highlight"); status.classList.add("highlight");
} else { } else {
@ -137,7 +139,7 @@ function handleReplyToLink(div) {
var ract = event.target.getBoundingClientRect(); var ract = event.target.getBoundingClientRect();
if (ract.top > window.innerHeight / 2) { if (ract.top > window.innerHeight / 2) {
copy.style.bottom = (window.innerHeight - copy.style.bottom = (window.innerHeight -
window.scrollY - ract.top) + 'px'; window.scrollY - ract.top) + "px";
} }
event.target.parentElement.appendChild(copy); event.target.parentElement.appendChild(copy);
} }
@ -147,7 +149,7 @@ function handleReplyToLink(div) {
if (popup) { if (popup) {
event.target.parentElement.removeChild(popup); event.target.parentElement.removeChild(popup);
} else { } else {
var id = event.target.getAttribute('href'); var id = event.target.getAttribute("href");
document.querySelector(id) document.querySelector(id)
.classList.remove("highlight"); .classList.remove("highlight");
} }
@ -156,11 +158,10 @@ function handleReplyToLink(div) {
function handleReplyLink(div) { function handleReplyLink(div) {
div.firstElementChild.onmouseenter = function(event) { div.firstElementChild.onmouseenter = function(event) {
var id = event.target.getAttribute('href'); var id = event.target.getAttribute("href");
var status = document.querySelector(id); var status = document.querySelector(id);
if (!status) { if (!status)
return; return;
}
if (isInView(status)) { if (isInView(status)) {
status.classList.add("highlight"); status.classList.add("highlight");
} else { } else {
@ -169,7 +170,7 @@ function handleReplyLink(div) {
var ract = event.target.getBoundingClientRect(); var ract = event.target.getBoundingClientRect();
if (ract.left > window.innerWidth / 2) { if (ract.left > window.innerWidth / 2) {
copy.style.right = (window.innerWidth - copy.style.right = (window.innerWidth -
ract.right - 12) + 'px';; ract.right - 12) + "px";
} }
event.target.parentElement.appendChild(copy); event.target.parentElement.appendChild(copy);
} }
@ -179,9 +180,8 @@ function handleReplyLink(div) {
if (popup) { if (popup) {
event.target.parentElement.removeChild(popup); event.target.parentElement.removeChild(popup);
} else { } else {
var id = event.target.getAttribute('href'); var id = event.target.getAttribute("href");
document.querySelector(id) document.querySelector(id).classList.remove("highlight");
.classList.remove("highlight");
} }
} }
} }
@ -195,7 +195,7 @@ function handleStatusLink(a) {
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
var statuses = document.querySelectorAll(".status-container"); var statuses = document.querySelectorAll(".status-container");
for (var i = 0; i < statuses.length; i++) { for (var i = 0; i < statuses.length; i++) {
var s = statuses[i] var s = statuses[i];
var id = s.dataset.id; var id = s.dataset.id;
var likeForm = s.querySelector(".status-like"); var likeForm = s.querySelector(".status-like");