quick-post-controls.js: format

This commit is contained in:
Zankaria 2024-08-24 00:52:29 +02:00
parent 990484fac5
commit 3453ff5aed

View file

@ -14,13 +14,12 @@
*/ */
$(document).ready(function() { $(document).ready(function() {
var open_form = function() { let open_form = function() {
var thread = $(this).parent().parent().hasClass('op'); let thread = $(this).parent().parent().hasClass('op');
var id = $(this).attr('name').match(/^delete_(\d+)$/)[1]; let id = $(this).attr('name').match(/^delete_(\d+)$/)[1];
var submitButton;
if (this.checked) { if (this.checked) {
var post_form = $('<form class="post-actions" method="post" style="margin:10px 0 0 0">' + let post_form = $('<form class="post-actions" method="post" style="margin:10px 0 0 0">' +
'<div style="text-align:right">' + '<div style="text-align:right">' +
(!thread ? '<hr>' : '') + (!thread ? '<hr>' : '') +
@ -39,26 +38,26 @@ $(document).ready(function(){
' <input type="submit" name="report" value="' + _('Report') + '">' + ' <input type="submit" name="report" value="' + _('Report') + '">' +
'</div>' + '</div>' +
'</form>'); '</form>');
let board = $(this).parent().parent().parent().attr("data-board");
if ($('form[name="post"]:first').length) { if ($('form[name="post"]:first').length) {
var board=$(this).parent().parent().parent().attr("data-board");
post_form post_form
.attr('action', $('form[name="post"]:first').attr('action')) .attr('action', $('form[name="post"]:first').attr('action'))
.append('<input type="hidden" value="' + board + '" name="board" />'); .append('<input type="hidden" value="' + board + '" name="board" />');
} else { } else {
var board=$(this).parent().parent().parent().attr("data-board"); if (!board) {//better not to show a form if it isn't going to work
if(board){ return;
}
post_form.attr('action', '/post.php'); //doesn't respect $config["root"] but... post_form.attr('action', '/post.php'); //doesn't respect $config["root"] but...
post_form.append('<input type="hidden" value="' + board + '" name="board" />'); post_form.append('<input type="hidden" value="' + board + '" name="board" />');
}else{
return;//better not to show a form if it isn't going to work
}
} }
post_form.find('input:not([type="checkbox"]):not([type="submit"]):not([type="hidden"])').keypress(function(e) { post_form.find('input:not([type="checkbox"]):not([type="submit"]):not([type="hidden"])').keypress(function(e) {
if (e.which == 13) { if (e.which == 13) {
e.preventDefault(); e.preventDefault();
if($(this).attr('name') == 'password') { if ($(this).attr('name') === 'password') {
post_form.find('input[name=delete]').click(); post_form.find('input[name=delete]').click();
} else if($(this).attr('name') == 'reason') { } else if ($(this).attr('name') === 'reason') {
post_form.find('input[name=report]').click(); post_form.find('input[name=report]').click();
} }
@ -74,22 +73,23 @@ $(document).ready(function(){
post_form.prependTo($(this).parent().parent().find('div.body')); post_form.prependTo($(this).parent().parent().find('div.body'));
} else { } else {
post_form.appendTo($(this).parent().parent()); post_form.appendTo($(this).parent().parent());
//post_form.insertBefore($(this));
} }
$(window).trigger('quick-post-controls', post_form); $(window).trigger('quick-post-controls', post_form);
} else { } else {
var elm = $(this).parent().parent().find('form'); let elm = $(this).parent().parent().find('form');
if(elm.attr('class') == 'post-actions') if (elm.attr('class') == 'post-actions') {
elm.remove(); elm.remove();
} }
}
}; };
var init_qpc = function() { let init_qpc = function() {
$(this).change(open_form); $(this).change(open_form);
if(this.checked) if (this.checked) {
$(this).trigger('change'); $(this).trigger('change');
}
}; };
$('div.post input[type=checkbox].delete').each(init_qpc); $('div.post input[type=checkbox].delete').each(init_qpc);
@ -98,4 +98,3 @@ $(document).ready(function(){
$(post).find('input[type=checkbox].delete').each(init_qpc); $(post).find('input[type=checkbox].delete').each(init_qpc);
}); });
}); });