Hi, i wrote my own code to reply without refresh the page, this code works in all version, one code for all forums.
Before, you need "allow external forms" in security tab, on your administration panel.
if your language isn't english you need change this line:
|
- Demo:
10.11.2016 09:00:18 the code has been updated. New system notification.
- Old version:
- Code:
console.log('//-Written by Chalo ------ Open Source 2014-2016 -----//');
console.log('//--------- http://www.opensourcephpbb3.com ----------//');
console.log('//------------------- Version: 1.2 -------------------//');
var ajax_reply = {
lang: {
success_reply: 'Your message has been entered successfully', // <--- change this text exactly like is display in your language board
flood: 'Flood control is active on this forum, please wait 10 second(s) before replying or posting',
error_reply: 'Try again',
words_reply: 'You need 5 letters at least',
button_send_reply: 'Send data...',
notice_original: 'No predefined text',
wait_notice: 'Please be patient, sending data to the server',
color_a: 'linear-gradient(to bottom, #febbbb 0%,#fe9090 45%,#ff5c5c 100%)',
color_b: 'linear-gradient(to bottom, #ffaf4b 0%,#ff920a 100%)',
color_c: 'linear-gradient(to bottom, #87e0fd 0%,#53cbf1 40%,#05abe0 100%)',
color_d: 'linear-gradient(to bottom, #ff3019 0%,#cf0404 100%)',
color_e: 'linear-gradient(to bottom, #d2ff52 0%,#91e842 100%)'
},
length_reply: 5, //min letters in the textarea before reply
init: function () {
ajax_reply.isTheme = /\/t\d+/g.test(window.location.pathname);
ajax_reply.phpbb2 = document.getElementsByClassName('bodylinewidth').length;
ajax_reply.phpbb3 = document.getElementById('phpbb');
ajax_reply.invision = document.getElementById('ipbwrapper');
ajax_reply.punbb = document.getElementById('pun-intro');
ajax_reply.form_reply = ajax_reply.isTheme && document.forms.post;
ajax_reply.button_reply = ajax_reply.isTheme && document.forms.post.post;
ajax_reply.button_value_reply = ajax_reply.isTheme && document.forms.post.post.value;
ajax_reply.textarea = ajax_reply.isTheme && document.forms.post.message;
ajax_reply.action_reply = ajax_reply.isTheme && document.forms.post.action;
ajax_reply.send_post();
},
notice_div: function (c, f) {
var a, b, d, e, g;
g = document.getElementsByClassName('notice_reply');
b = document.getElementsByClassName('sceditor-group')[0];
d = b.parentNode;
a = !g.length ? document.createElement('DIV') : g[0];
e = 'height:20px;line-height: 1.5;border-radius: 3px; text-shadow: 0 1px rgba(255, 255, 255, 0.46)';
!g.length && (a.classList.add('notice_reply'), a.setAttribute('style', e), d.insertBefore(a, b));
a.style.display = 'block';
a.innerHTML = 'undefined' == typeof c ? ajax_reply.lang.notice_original : c;
a.style.background = 'undefined' == typeof f ? ajax_reply.lang.color_a : f;
setTimeout(function () {
a.style.display == 'block' && (a.style.display = 'none')
}, 5000)
},
send_post: function () {
var c, h, a, l, o, d, b;
h = ajax_reply.action_reply;
ajax_reply.form_reply && (ajax_reply.button_reply.onclick = function () {
l = $(ajax_reply.textarea).sceditor('instance');
l.updateOriginal();
if (l.val().length > ajax_reply.length_reply) {
ajax_reply.button_reply.value = ajax_reply.lang.button_send_reply;
$.post(h, $(ajax_reply.form_reply).serialize() + '&post=1&prevent_post=1', function (e) {
a = e.indexOf(ajax_reply.lang.success_reply);
b = e.indexOf(ajax_reply.lang.flood);
c = $('a[href*="viewtopic"]', e).length && $('a[href*="viewtopic"]', e)[0].href;
d = c && c.match(/(\w+)$/g)[0];
o = d && (d - 1);
b > 0 ? (ajax_reply.notice_div(ajax_reply.lang.flood, ajax_reply.lang.color_b), ajax_reply.button_reply.value = ajax_reply.button_value_reply) : e.indexOf('A new') > 0 ? $.post(document.location.pathname, $('[name="post"]', e).serialize(), function (c) {
a < 0 ? ajax_reply.notice_div(ajax_reply.lang.error_reply) : (ajax_reply.new_post(c, d, l, o), ajax_reply.button_reply.value = ajax_reply.button_value_reply)
}) : a < 0 ? ajax_reply.notice_div(ajax_reply.lang.error_reply) : (ajax_reply.new_post(c, d, l, o), ajax_reply.button_reply.value = ajax_reply.button_value_reply, ajax_reply.notice_div(ajax_reply.lang.wait_notice, ajax_reply.lang.color_c))
})
} else {
ajax_reply.notice_div(ajax_reply.lang.words_reply, ajax_reply.lang.color_d);
}
return false
})
},
new_post: function (c, a, l, o) {
var d, f, g, h, b, m, n, s;
$.get(c, function (e) {
b = $('.post--' + a, e)[0];
d = b.innerHTML;
f = b.className;
g = 'p' + a;
n = ajax_reply.phpbb2 ? 'tr' : 'div';
h = '<' + n + ' id="' + g + '" class="' + f + ' new_ajax_post" style="display:none">' + d + '</' + n + '>';
m = document.getElementsByClassName('post--' + o);
m.length ? (m[0].insertAdjacentHTML('afterend', h), $('.new_ajax_post').fadeIn(1e3)) : ajax_reply.post_pag(h);
}).success(function () {
l.val('');
ajax_reply.notice_div(ajax_reply.lang.success_reply, ajax_reply.lang.color_e)
})
},
post_pag: function (h) {
var e = ajax_reply.punbb ? document.getElementsByClassName('topic')[0] : ajax_reply.phpbb2 ? document.getElementsByClassName('catBottom')[0].parentNode.previousElementSibling : ajax_reply.phpbb3 ? document.getElementsByName('bottomtitle')[0].previousElementSibling : ajax_reply.invision && document.getElementsByClassName('topic-footer')[0].previousElementSibling;
ajax_reply.punbb ? e.insertAdjacentHTML('beforeend', h) : e.insertAdjacentHTML('afterend', h);
$('.new_ajax_post').fadeIn(1e3);
}
};
$(function () {
(document.getElementById('logout') && $.sceditor) && ajax_reply.init()
});
UPDATE 09:32:53 06.01.2018 = for all version
- Code:
//----- Written by Chalo ------ Open Source 2014-2018 -----//
//----------http://www.opensourcephpbb3.com --------------//
//------------------- Version: 2.02 ----------------------//
var os = {
lang: {
success_reply: 'Your message has been entered successfully',
flood: 'Flood control is active on this forum, please wait 10 second(s) before replying or posting',
error_reply: 'Try again',
words_reply: 'You need 5 letters at least',
button_send_reply: 'Send data...',
notice_original: 'No predefined text',
placeholder: 'Write something...',
wait_notice: 'Please be patient, sending data to the server',
color_a: 'linear-gradient(to bottom, #febbbb 0%,#fe9090 45%,#ff5c5c 100%)',
color_b: 'linear-gradient(to bottom, #ffaf4b 0%,#ff920a 100%)',
color_c: 'linear-gradient(to bottom, #87e0fd 0%,#53cbf1 40%,#05abe0 100%)',
color_d: 'linear-gradient(to bottom, #ff3019 0%,#cf0404 100%)',
color_e: 'linear-gradient(to bottom, #d2ff52 0%,#91e842 100%)'
},
control: {
// change this text exactly like is display in your language board;
success_reply: 'Your message has been entered successfully',
flood: 'Flood control is active on this forum, please wait 10 second(s) before replying or posting',
},
length_reply: 5,
init: function () {
os.isTheme = /\/t\d+/g.test(window.location.pathname);
os.phpbb2 = document.getElementsByClassName('bodylinewidth').length;
os.modernbb = document.getElementsByClassName('modernbb').length,
os.form_reply = os.isTheme && document.forms.post;
os.button_reply = os.isTheme && document.forms.post.post;
os.button_value_reply = os.isTheme && document.forms.post.post.value;
os.textarea = os.isTheme && document.forms.post.message;
os.action_reply = os.isTheme && document.forms.post.action;
os.intance = os.isTheme && $(os.textarea).sceditor('instance');
os.isTheme && (os.form_reply.getElementsByTagName('textarea')[1].placeholder = os.lang.placeholder);
os.isTheme && os.send_post()
},
notice_div: function (e, t) {
var o, n, s, l, i;
i = document.getElementsByClassName('notice_reply');
n = document.getElementsByClassName('sceditor-group')[0];
s = n.parentNode, o = i.length ? i[0] : document.createElement('DIV');
l = 'height:20px;line-height: 1.5;border-radius: 3px; text-shadow: 0 1px rgba(255, 255, 255, 0.46)';
!i.length && (o.classList.add('notice_reply'), o.style.cssText = l, s.insertBefore(o, n));
o.style.display = 'block';
o.innerHTML = 'undefined' == typeof e ? os.lang.notice_original : e;
o.style.background = 'undefined' == typeof t ? os.lang.color_a : t;
setTimeout(function () {
'block' == o.style.display && (o.style.display = 'none')
}, 1000)
},
vT: function (h) {
var i, g = h.getElementsByTagName('a');
for (i in g) {
/\/viewtopic/g.test(g[i].href) && (os.view_url = g[i].href)
}
},
sZ: function (b) {
var a, i, j, l, s = [];
if ('object' == typeof b && 'FORM' == b.nodeName) {
l = b.elements.length;
for (i = 0; l > i; i++)
if (a = b.elements[i], a.name && !a.disabled && 'file' != a.type && 'reset' != a.type && 'submit' != a.type && 'button' != a.type)
if ('select-multiple' == a.type)
for (j = b.elements[i].options.length - 1; j >= 0; j--) a.options[j].selected && (s[s.length] = encodeURIComponent(a.name) + '=' + encodeURIComponent(a.options[j].value));
else('checkbox' != a.type && 'radio' != a.type || a.checked) && (s[s.length] = encodeURIComponent(a.name) + '=' + encodeURIComponent(a.value))
}
return s.join('&').replace(/%20/g, '+');
},
sC: function (o, e, t, s) {
e = e || 500, s = s || window;
var a = o.clientHeight < 150 ? o.clientHeight * 2 : o.clientHeight < 300 ? o.clientHeight : o.clientHeight > 400 && '',
n = s.scrollTop - a || window.pageYOffset - a;
if ('number' == typeof o) var r = parseInt(o);
else var r = os.gT(o, n);
var l = Date.now(),
i = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || function (o) {
window.setTimeout(o, 15)
},
a = function () {
var c = Date.now() - l;
s !== window ? s.scrollTop = os.pS(n, r, c, e) : window.scroll(0, os.pS(n, r, c, e)), c > e ? 'function' == typeof t && t(o) : i(a)
};
a()
},
eC: function (t) {
return t < .5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
},
pS: function (o, e, s, r) {
return o + (e - o) * os.eC(s / r)
},
gT: function (o, e) {
return 'HTML' === o.nodeName ? -e : o.getBoundingClientRect().top + e
},
XML: function (a, b, f) {
var c;
c = window.XMLHttpRequest ? new XMLHttpRequest : window.ActiveXObject && (new ActiveXObject('Microsoft.XMLHTTP'));
'undefined' != typeof a ? c.open('POST', b) : c.open('GET', b, true);
c.responseType = 'document';
c.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
c.send('undefined' != typeof a ? a : '');
c.onreadystatechange = function () {
this.readyState == 4 && this.status == 200 && (f(this));
};
},
last: function (a) {
return a[a.length - 1]
},
cover: function (c) {
var a = document.getElementsByClassName('sceditor-resize-cover')[0];
a.style.display = c != false ? 'block' : 'none';
a.innerHTML = c != false ? c : '';
if (c != false) {
a.style.color = '#fff';
a.style.fontSize = '20px';
a.style.lineHeight = '12';
a.style.textAlign = 'center'
}
},
send_post: function () {
var e, t, o, n, s, l, i;
n = os.intance;
os.form_reply && (os.button_reply.onclick = function () {
n.updateOriginal();
if (n.val().length > os.length_reply) {
os.cover('Cargando...');
os.button_reply.value = os.lang.button_send_reply;
os.XML(os.sZ(os.form_reply) + '¬ify=on&&post=1&prevent_post=1', os.action_reply, function (x) {
t = x.responseXML;
os.vT(t);
o = t.body.innerHTML.indexOf(os.control.success_reply);
i = t.body.innerHTML.indexOf(os.control.flood);
e = os.view_url;
l = e && e.match(/(\w+)$/g)[0];
s = l && l - 1;
if (i > 0) {
os.notice_div(os.lang.flood, os.lang.color_b);
os.button_reply.value = os.button_value_reply;
} else if (0 > o) {
os.notice_div(os.lang.error_reply)
} else {
os.new_post(e, l, n, s);
os.button_reply.value = os.button_value_reply;
os.notice_div(os.lang.wait_notice, os.lang.color_c)
}
})
} else {
os.notice_div(os.lang.words_reply, os.lang.color_d)
}
return false
})
},
new_post: function (e, t, o, n) {
var s, l, i, a, r, p, w, c;
os.XML('', e, function (x) {
e = x.responseXML;
r = e.getElementsByClassName('post--' + t)[0];
s = r.innerHTML;
l = r.className;
w = os.phpbb2 ? r.nextElementSibling.outerHTML : '';
i = 'p' + t;
c = os.phpbb2 ? 'tr' : 'div';
a = '<' + c + ' id="' + i + '" class="' + l + ' new_ajax_post">' + s + '</' + c + '>' + (os.phpbb2 ? w : '');
p = !os.phpbb2 ? os.last(document.getElementsByClassName('post')) : document.getElementsByClassName('catBottom')[0].parentNode.previousElementSibling;
os.cover(false);
p.insertAdjacentHTML('afterend', a);
o.val('');
os.notice_div(os.lang.success_reply, os.lang.color_e);
os.sC(document.getElementById(i), 500)
})
}
};
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('logout') && $.sceditor && os.init()
}, false);
Last edited by Ch@lo Valdez on June 1st 2018, 4:34 pm; edited 11 times in total