Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable quick reply on index #804

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions inc/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
'hash',
'board',
'thread',
'active-page',
'mod',
'name',
'email',
Expand Down
28 changes: 17 additions & 11 deletions js/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,26 @@ $(window).ready(function() {
$.ajax({
url: document.location,
success: function(data) {
$(data).find('div.post.reply').each(function() {
var id = $(this).attr('id');
if($('#' + id).length == 0) {
$(this).insertAfter($('div.post:last').next()).after('<br class="clear">');
$(document).trigger('new_post', this);
// watch.js & auto-reload.js retrigger
setTimeout(function() { $(window).trigger("scroll"); }, 100);
}
$(data).find('div.thread').each(function(){
var tr_id = $(this).attr('id');
$(this).find('div.post.reply').each(function() {
var id = $(this).attr('id');
if($('#' + id).length == 0) {
$(this).insertAfter($('#' + tr_id + ' div.post:last').next());
$(document).trigger('new_post', this);
// watch.js & auto-reload.js retrigger
setTimeout(function() { $(window).trigger("scroll"); }, 100);
}
});
});

highlightReply(post_response.id);
window.location.hash = post_response.id;
$(window).scrollTop($('div.post#reply_' + post_response.id).offset().top);

if ($(window).scrollTop($('div.post#reply_' + post_response.id))){
$(window).scrollTop($('div.post#reply_' + post_response.id).offset().top);
} else {
window.scrollTo(0,document.body.offsetHeight);
}
$(form).find('input[type="submit"]').val(submit_txt);
$(form).find('input[type="submit"]').removeAttr('disabled');
$(form).find('input[name="subject"],input[name="file_url"],\
Expand Down Expand Up @@ -137,4 +143,4 @@ $(window).ready(function() {
$('form#quick-reply').off('submit');
setup_form($('form#quick-reply'));
});
});
});
28 changes: 24 additions & 4 deletions js/quick-reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,17 @@
</style>').appendTo($('head'));
};

var show_quick_reply = function(){
if($('div.banner').length == 0)
return;
var show_quick_reply = function(target_id){

let in_index = false;

if($('div.banner').length == 0) {
var thread_sel = $(`#reply_${target_id}, #op_${target_id}`).closest("[id*=thread_");
var thread_id = thread_sel.attr("id").replace("thread_", "");
var board = thread_sel.attr("data-board");
in_index = true;
}

if($('#quick-reply').length != 0)
return;

Expand Down Expand Up @@ -295,6 +303,18 @@

$postForm.appendTo($('body')).hide();
$origPostForm = $('form[name="post"]:first');

if (in_index) {
$(`<input type='hidden' name='thread' value='${thread_id}'></input>`).appendTo($("#quick-reply"));
$("#quick-reply .handle").append(document.createTextNode(`(${thread_id})`));
$("#quick-reply input[type='submit']").attr("value", button_reply);
$(`<input type='hidden' name='board' value='${board}'></input>`).appendTo($("#quick-reply"));

// support if captcha is only enabled for threads
if (post_captcha === 'false') {
$("#quick-reply .captcha").remove();
}
}

// Synchronise body text with original post form
$origPostForm.find('textarea[name="body"]').on('change input propertychange', function() {
Expand Down Expand Up @@ -387,7 +407,7 @@
$(window).on('cite', function(e, id, with_link) {
if ($(this).width() <= 400)
return;
show_quick_reply();
show_quick_reply(id);
if (with_link) {
$(document).ready(function() {
if ($('#' + id).length) {
Expand Down
10 changes: 9 additions & 1 deletion post.php
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,15 @@ function delete_cyclical_posts(string $boardUri, int $threadId, int $cycleLimit)
}

if (!$post['mod']) {
$post['antispam_hash'] = checkSpam(array($board['uri'], isset($post['thread']) ? $post['thread'] : ($config['try_smarter'] && isset($_POST['page']) ? 0 - (int)$_POST['page'] : null)));

if (isset($_POST['active-page']) && $_POST['active-page'] === 'index') {
$page = isset($_POST['page']) ? (int)$_POST['page'] : 0;
$extra_salt = $config['try_smarter'] ? -$page : 0;
} else {
$extra_salt = $post['thread'];
}

$post['antispam_hash'] = checkSpam(array($board['uri'], $extra_salt));
if ($post['antispam_hash'] === true)
error($config['error']['spam']);
}
Expand Down
2 changes: 2 additions & 0 deletions templates/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ function ready() {

var post_date = "{{ config.post_date }}";
var max_images = {{ config.max_images }};
var button_reply = "{{ config.button_reply }}";
var post_captcha = "{{ config.captcha.native.new_thread_capt ? 'false' : 'true' }}"

onReady(init);

Expand Down
7 changes: 6 additions & 1 deletion templates/post_form.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<form name="post" onsubmit="return doPost(this);" enctype="multipart/form-data" action="{{ config.post_url }}" method="post">
{{ antibot.html() }}
{% if id %}<input type="hidden" name="thread" value="{{ id }}">{% endif %}
{% if id %}
<input type="hidden" name="thread" value="{{ id }}">
<input type="hidden" name="active-page" value="thread">
{% else %}
<input type="hidden" name="active-page" value="index">
{% endif %}
{{ antibot.html() }}
<input type="hidden" name="board" value="{{ board.uri }}">
{{ antibot.html() }}
Expand Down
2 changes: 1 addition & 1 deletion templates/post_reply.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% apply spaceless %}
{% include 'post/poster_id.html' %}&nbsp;
<a class="post_no" id="post_no_{{ post.id }}" onclick="highlightReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('', '50') }}{% else %}{{ post.link }}{% endif %}">No.</a>
<a class="post_no" onclick="citeReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('q', '50') }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a>
<a class="post_no" onclick="return citeReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('q', '50') }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a>
</p>
{% endapply %}
{% include 'post/fileinfo.html' %}
Expand Down
2 changes: 1 addition & 1 deletion templates/post_thread.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% apply spaceless %}
{% include 'post/poster_id.html' %}&nbsp;
<a class="post_no" id="post_no_{{ post.id }}" onclick="highlightReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('', '50') }}{% else %}{{ post.link }}{% endif %}">No.</a>
<a class="post_no" onclick="citeReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('q', '50') }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a>
<a class="post_no" onclick="return citeReply({{ post.id }})" href="{% if isnoko50 %}{{ post.link('q', '50') }}{% else %}{{ post.link('q') }}{% endif %}">{{ post.id }}</a>
{% if post.sticky %}
{% if config.font_awesome %}
<i class="fa fa-thumb-tack" title="Sticky"></i>
Expand Down