';
container.innerHTML = null;
loadGIFs.innerHTML = null;
}
})
.catch(err => alert(err));
};
}
// Insert GIF markdown into comment box function
function insertGIF(url,form) {
var gif = "";
var commentBox = document.getElementById(form);
var old = commentBox.value;
commentBox.value = old + gif;
}
// When GIF keyboard is hidden, hide all GIFs
$('#gifModal').on('hidden.bs.modal', function (e) {
document.getElementById('gifSearch').value = null;
// load more gifs div
var loadGIFs = document.getElementById('gifs-load-more');
// no GIFs div
var noGIFs = document.getElementById('no-gifs-found');
// container div
var container = document.getElementById('GIFs');
// UI buttons
var backBtn = document.getElementById('gifs-back-btn');
var cancelBtn = document.getElementById('gifs-cancel-btn');
// Remove inner HTML from container var
container.innerHTML = '
Agree
Laugh
Confused
Sad
Happy
Awesome
Yes
No
Love
Please
Scared
Angry
Awkward
Cringe
OMG
Why
Gross
Meh
'
// Hide UI buttons
backBtn.innerHTML = null;
cancelBtn.innerHTML = null;
// Remove inner HTML from no gifs div
noGIFs.innerHTML = null;
// Hide no more gifs div
loadGIFs.innerHTML = null;
});
// comment collapse
// Toggle comment collapse
function collapse_comment(comment_id) {
var comment = "comment-" + comment_id;
document.getElementById(comment).classList.toggle("collapsed");
};
//Commenting form
// Expand comment box on focus, hide otherwise
$('.comment-box').focus(function (event) {
event.preventDefault();
$(this).parent().parent().addClass("collapsed");
});
// Comment edit form
toggleEdit=function(id){
comment=document.getElementById("comment-text-"+id);
form=document.getElementById("comment-edit-"+id);
box=document.getElementById('edit-box-comment-'+id);
actions = document.getElementById('comment-' + id +'-actions');
comment.classList.toggle("d-none");
form.classList.toggle("d-none");
actions.classList.toggle("d-none");
autoExpand(box);
};
// Post edit form
togglePostEdit=function(id){
body=document.getElementById("post-body");
title=document.getElementById("post-title");
form=document.getElementById("edit-post-body-"+id);
box=document.getElementById("post-edit-box-"+id);
box2=document.getElementById("post-edit-box2-"+id);
body.classList.toggle("d-none");
title.classList.toggle("d-none");
form.classList.toggle("d-none");
autoExpand(box);
autoExpand(box2);
};
//comment modding
function removeComment(post_id) {
url="/api/ban_comment/"+post_id
callback=function(){
document.getElementById("comment-"+post_id+"-only").classList.add("banned");
button=document.getElementById("moderate-"+post_id);
button.onclick=function(){approveComment(post_id)};
button.innerHTML='Approve'
}
post(url, callback, "Comment has been removed.")
};
function approveComment(post_id) {
url="/api/unban_comment/"+post_id
callback=function(){
document.getElementById("comment-"+post_id+"-only").classList.remove("banned");
button=document.getElementById("moderate-"+post_id);
button.onclick=function(){removeComment(post_id)};
button.innerHTML='Remove'
}
post(url, callback, "Comment has been approved.")
}
admin_comment=function(cid){
var xhr = new XMLHttpRequest();
xhr.open("post", "/api/distinguish_comment/"+cid);
var form = new FormData();
form.append('formkey', formkey());
xhr.withCredentials=true;
xhr.onload=function(){
if (xhr.status==200) {
comment=document.getElementById('comment-'+cid+'-only');
comment.innerHTML=JSON.parse(xhr.response)["html"];
}
else {
var commentError = document.getElementById("comment-error-text");
$('#toast-comment-success').toast('dispose');
$('#toast-comment-error').toast('dispose');
$('#toast-comment-error').toast('show');
commentError.textContent = JSON.parse(xhr.response)["error"];
}
}
xhr.send(form)
}
//Autoexpand textedit comments
function autoExpand (field) {
//get current scroll position
xpos=window.scrollX;
ypos=window.scrollY;
// Reset field height
field.style.height = 'inherit';
// Get the computed styles for the element
var computed = window.getComputedStyle(field);
// Calculate the height
var height = parseInt(computed.getPropertyValue('border-top-width'), 10)
+ parseInt(computed.getPropertyValue('padding-top'), 10)
+ field.scrollHeight
+ parseInt(computed.getPropertyValue('padding-bottom'), 10)
+ parseInt(computed.getPropertyValue('border-bottom-width'), 10)
+ 32;
field.style.height = height + 'px';
//keep window position from changing
window.scrollTo(xpos,ypos);
};
document.addEventListener('input', function (event) {
if (event.target.tagName.toLowerCase() !== 'textarea') return;
autoExpand(event.target);
}, false);
// Delete Post
function delete_postModal(id) {
// Passed data for modal
document.getElementById("deletePostButton-mobile").addEventListener("click", delete_post);
document.getElementById("deletePostButton").addEventListener("click", delete_post);
function delete_post(){
this.innerHTML='Deleting post';
this.disabled = true;
post('/delete_post/' + id,
callback = function() {
location.reload();
}
)
}
};
// Delete Comment
function delete_commentModal(id) {
// Passed data for modal
document.getElementById("deleteCommentButton").onclick = function() {
this.innerHTML='Deleting comment';
this.disabled = true;
post('/delete/comment/' + id,
callback = function() {
location.reload();
}
)
}
};
//Email verification text
function emailVerifyText() {
document.getElementById("email-verify-text").innerHTML = "Verification email sent! Please check your inbox.";
}
//flagging
// Flag Comment
report_commentModal = function(id, author) {
document.getElementById("comment-author").textContent = author;
//offtopic.disabled=true;
document.getElementById("reportCommentButton").onclick = function() {
this.innerHTML='Reporting comment';
this.disabled = true;
post('/api/flag/comment/' + id,
callback = function() {
document.getElementById("reportCommentFormBefore").classList.add('d-none');
document.getElementById("reportCommentFormAfter").classList.remove('d-none');
}
)
}
};
$('#reportCommentModal').on('hidden.bs.modal', function () {
var button = document.getElementById("reportCommentButton");
var beforeModal = document.getElementById("reportCommentFormBefore");
var afterModal = document.getElementById("reportCommentFormAfter");
button.innerHTML='Report comment';
button.disabled= false;
afterModal.classList.add('d-none');
if ( beforeModal.classList.contains('d-none') ) {
beforeModal.classList.remove('d-none');
}
});
// Flag Submission
report_postModal = function(id, author, board) {
document.getElementById("post-author").textContent = author;
selectbox=document.getElementById('report-type-dropdown');
selectbox.value='reason_not_selected';
submitbutton=document.getElementById("reportPostButton");
submitbutton.disabled=true;
submitbutton.onclick = function() {
this.innerHTML='Reporting post';
this.disabled = true;
var xhr = new XMLHttpRequest();
xhr.open("POST", '/api/flag/post/'+id, true);
var form = new FormData()
form.append("formkey", formkey());
dropdown=document.getElementById("report-type-dropdown");
form.append("report_type", dropdown.options[dropdown.selectedIndex].value);
xhr.withCredentials=true;
xhr.onload=function() {
document.getElementById("reportPostFormBefore").classList.add('d-none');
document.getElementById("reportPostFormAfter").classList.remove('d-none');
};
xhr.onerror=function(){alert(errortext)};
xhr.send(form);
}
};
$('#reportPostModal').on('hidden.bs.modal', function () {
var button = document.getElementById("reportPostButton");
var beforeModal = document.getElementById("reportPostFormBefore");
var afterModal = document.getElementById("reportPostFormAfter");
button.innerHTML='Report post';
button.disabled= false;
afterModal.classList.add('d-none');
if ( beforeModal.classList.contains('d-none') ) {
beforeModal.classList.remove('d-none');
}
});
//enlarge thumbs
// Enlarge submissionlisting thumbnail
enlarge_thumb = function(post_id) {
document.getElementById(post_id).classList.toggle("enlarged");
};
//iOS webapp stuff
(function(document,navigator,standalone) {
// prevents links from apps from oppening in mobile safari
// this javascript must be the first script in your
if ((standalone in navigator) && navigator[standalone]) {
var curnode, location=document.location, stop=/^(a|html)$/i;
document.addEventListener('click', function(e) {
curnode=e.target;
while (!(stop).test(curnode.nodeName)) {
curnode=curnode.parentNode;
}
// Condidions to do this only on links to your own app
// if you want all links, use if('href' in curnode) instead.
if('href' in curnode && ( curnode.href.indexOf('http') || ~curnode.href.indexOf(location.host) ) ) {
e.preventDefault();
location.href = curnode.href;
}
},false);
}
})(document,window.navigator,'standalone');
//POST
function post(url, callback, errortext) {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
var form = new FormData()
form.append("formkey", formkey());
xhr.withCredentials=true;
xhr.onerror=function() { alert(errortext); };
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) {
callback();
} else {
xhr.onerror();
}
};
xhr.send(form);
};
function post_toast(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
var form = new FormData()
form.append("formkey", formkey());
xhr.withCredentials=true;
xhr.onload = function() {
if (xhr.status==204) {}
else if (xhr.status >= 200 && xhr.status < 300) {
$('#toast-post-success').toast('dispose');
$('#toast-post-success').toast('show');
document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"];
callback(xhr)
return true
} else if (xhr.status >= 300 && xhr.status < 400) {
window.location.href = JSON.parse(xhr.response)["redirect"]
} else {
data=JSON.parse(xhr.response);
$('#toast-post-error').toast('dispose');
$('#toast-post-error').toast('show');
document.getElementById('toast-post-error-text').innerText = data["error"];
return false
}
};
xhr.send(form);
}
//Signup js
// Display username and password requirements on input
$('#password-register').on('input', function () {
var charCount = document.getElementById("password-register").value;
var id = document.getElementById("passwordHelpRegister");
var successID = document.getElementById("passwordHelpSuccess");
if (charCount.length >= 8) {
id.classList.add("d-none");
successID.classList.remove("d-none");
}
else {
id.classList.remove("d-none");
successID.classList.add("d-none");
};
});
// Search Icon
// Change navbar search icon when form is in focus, active states
$(".form-control").focus(function () {
$(this).prev('.input-group-append').removeClass().addClass('input-group-append-focus');
$(this).next('.input-group-append').removeClass().addClass('input-group-append-focus');
});
$(".form-control").focusout(function () {
$(this).prev('.input-group-append-focus').removeClass().addClass('input-group-append');
$(this).next('.input-group-append-focus').removeClass().addClass('input-group-append');
});
//spinner effect
$(document).ready(function() {
$('#login').submit(function() {
// disable button
$("#login_button").prop("disabled", true);
// add spinner to button
$("#login_button").html('Signing in');
});
});
$(document).ready(function() {
$('#signup').submit(function() {
// disable button
$("#register_button").prop("disabled", true);
// add spinner to button
$("#register_button").html('Registering');
});
});
// Mobile bottom navigation bar
window.onload = function () {
var prevScrollpos = window.pageYOffset;
window.onscroll = function () {
var currentScrollPos = window.pageYOffset;
var topBar = document.getElementById("fixed-bar-mobile");
var bottomBar = document.getElementById("mobile-bottom-navigation-bar");
var dropdown = document.getElementById("mobileSortDropdown");
var navbar = document.getElementById("navbar");
if (bottomBar != null) {
if (prevScrollpos > currentScrollPos && (window.innerHeight + currentScrollPos) < (document.body.offsetHeight - 65)) {
bottomBar.style.bottom = "0px";
}
else if (currentScrollPos <= 125 && (window.innerHeight + currentScrollPos) < (document.body.offsetHeight - 65)) {
bottomBar.style.bottom = "0px";
}
else if (prevScrollpos > currentScrollPos && (window.innerHeight + currentScrollPos) >= (document.body.offsetHeight - 65)) {
bottomBar.style.bottom = "-50px";
}
else {
bottomBar.style.bottom = "-50px";
}
}
// Execute if bottomBar exists
if (topBar != null && dropdown != null) {
if (prevScrollpos > currentScrollPos) {
topBar.style.top = "48px";
navbar.classList.remove("shadow");
}
else if (currentScrollPos <= 125) {
topBar.style.top = "48px";
navbar.classList.remove("shadow");
}
else {
topBar.style.top = "-48px";
dropdown.classList.remove('show');
navbar.classList.add("shadow");
}
}
prevScrollpos = currentScrollPos;
}
}
// Tooltips
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
$('.mention-user').click(function (event) {
if (event.which != 1) {
return
}
event.preventDefault();
window.location.href='/@' + $(this).data('original-name');
});