Fix for ajax posting not showing you your new post
- TODO: there are console.logs that still need to be removed - Posting was loading the new page twice - once in ajax.js and once in auto-reload.js. auto-reload will handle this behaviour, the other is commented out - The new post does not immediately show up when immediately ajax requesting the page after posting completes. Adding an epoch query parameter did not change this. Instead of figuring out why it was easier to add a 500ms delay before requesting the page, now it seems to work well.
This commit is contained in:
parent
11ee04f973
commit
efb74f0eb6
|
@ -79,6 +79,8 @@ $(window).ready(function() {
|
||||||
|| (!settings.get('always_noko_replies', true) && !post_response.noko)) {
|
|| (!settings.get('always_noko_replies', true) && !post_response.noko)) {
|
||||||
document.location = post_response.redirect;
|
document.location = post_response.redirect;
|
||||||
} else {
|
} else {
|
||||||
|
console.log("do nothing for now, this behaviour will be handled by auto-reload.js");
|
||||||
|
/*
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: document.location,
|
url: document.location,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
@ -105,9 +107,14 @@ $(window).ready(function() {
|
||||||
contentType: false,
|
contentType: false,
|
||||||
processData: false
|
processData: false
|
||||||
}, 'html');
|
}, 'html');
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
$(form).find('input[type="submit"]').val(_('Posted...'));
|
$(form).find('input[type="submit"]').val(_('Posted...'));
|
||||||
$(document).trigger("ajax_after_post", post_response);
|
$(document).trigger("ajax_after_post", post_response);
|
||||||
|
$(form).find('input[type="submit"]').val(submit_txt);
|
||||||
|
$(form).find('input[type="submit"]').removeAttr('disabled');
|
||||||
|
$(form).find('input[name="subject"],input[name="file_url"],\
|
||||||
|
textarea[name="body"],input[type="file"]').val('').change();
|
||||||
} else {
|
} else {
|
||||||
alert(_('An unknown error occured when posting!'));
|
alert(_('An unknown error occured when posting!'));
|
||||||
$(form).find('input[type="submit"]').val(submit_txt);
|
$(form).find('input[type="submit"]').val(submit_txt);
|
||||||
|
|
|
@ -232,10 +232,18 @@ $(document).ready(function(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: document.location,
|
url: document.location,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
console.log("poll ajax succes");
|
||||||
|
console.log(data);
|
||||||
var loaded_posts = 0; // the number of new posts loaded in this update
|
var loaded_posts = 0; // the number of new posts loaded in this update
|
||||||
|
|
||||||
$(data).find('div.post.reply').each(function() {
|
$(data).find('div.post.reply').each(function() {
|
||||||
|
console.log("new data post reply:", this);
|
||||||
var id = $(this).attr('id');
|
var id = $(this).attr('id');
|
||||||
|
console.log("new data post reply id:", id);
|
||||||
|
|
||||||
|
// check that this post doesn't already exist
|
||||||
if($('#' + id).length == 0) {
|
if($('#' + id).length == 0) {
|
||||||
|
console.log("post with id ", id, "does not already exist on the page");
|
||||||
if (!new_posts) {
|
if (!new_posts) {
|
||||||
first_new_post = this;
|
first_new_post = this;
|
||||||
makeIcon('reply');
|
makeIcon('reply');
|
||||||
|
@ -245,17 +253,22 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($("div.post").length > 1){
|
if ($("div.post").length > 1){
|
||||||
|
console.log("adding post A");
|
||||||
$(this).parent().insertAfter($('div.post:not(.post-hover):last').parent().next()).after('<br class="clear">');
|
$(this).parent().insertAfter($('div.post:not(.post-hover):last').parent().next()).after('<br class="clear">');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
console.log("adding post B");
|
||||||
$(this).insertAfter($('div.post:not(.post-hover):last')).after('<br class="clear">');
|
$(this).insertAfter($('div.post:not(.post-hover):last')).after('<br class="clear">');
|
||||||
}
|
}
|
||||||
new_posts++;
|
new_posts++;
|
||||||
loaded_posts++;
|
loaded_posts++;
|
||||||
$(document).trigger('new_post', this);
|
$(document).trigger('new_post', this);
|
||||||
recheck_activated();
|
recheck_activated();
|
||||||
|
} else {
|
||||||
|
console.log("post with id ", id, "already exists on the page, not adding");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
time_loaded = Date.now(); // interop with watch.js
|
time_loaded = Date.now(); // interop with watch.js
|
||||||
|
|
||||||
|
|
||||||
|
@ -312,8 +325,13 @@ $(document).ready(function(){
|
||||||
};
|
};
|
||||||
|
|
||||||
$(post).on('submit', function(e){
|
$(post).on('submit', function(e){
|
||||||
poll(manualUpdate = true);
|
console.log("post on submit");
|
||||||
dothis(this);
|
setTimeout(
|
||||||
|
function() {
|
||||||
|
poll(manualUpdate = true)
|
||||||
|
},
|
||||||
|
500
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(window).scrollStopped(function() {
|
$(window).scrollStopped(function() {
|
||||||
|
|
Loading…
Reference in New Issue