Template Events & Listeners updated for ajax - how?

For support and discussion related to templates, themes, and imagesets in phpBB 3.2.
Post Reply
User avatar
axe70
Registered User
Posts: 752
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio
Contact:

Template Events & Listeners updated for ajax - how?

Post by axe70 »

Hello all, the problem in short is this:

Code: Select all

{PRIVATE_MESSAGE_COUNT}
i grab and try to pass the above to an ajax script, using something like this into overall_header.html

Code: Select all

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
$(document).on("click", "a", function() {...
the code follow sending out to an ajax script the {PRIVATE_MESSAGE_COUNT} value.
The problem is that in case of a new PM view event, the PM count passed is the previous and not the updated, so i guess someone can help me to understand how to resolve this problem?

How i can grab the updated PM count value?

I've also reproduce the thing on external page, that use sql to get this data, but as this would be more easy and compact code, i really guess there is a solution for the above.
Thank you!
Do not take me too serious
Anyway i do not like Discourse
User avatar
axe70
Registered User
Posts: 752
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio
Contact:

Re: Template Events & Listeners updated for ajax - how?

Post by axe70 »

in this hard night i've just return over, thinking that maybe this could be resolved (without going to see all the code about, that will require me maybe hours, if no hint in the while come out!) with something like this?
note: i have try on fly this, including jquery lib right above as it seem to be not available on phpBB header (after will be translated so in pure js maybe to avoid the jquery inclusion)

Code: Select all

jQuery(document).ready(function() {
    var x = $('.badge').html();
    alert(x);
});
it return the correct value, but i still guess for a more advanced hint if possible! 8-)
Do not take me too serious
Anyway i do not like Discourse
User avatar
Hanakin
Front-End Dev Team Lead
Front-End Dev Team Lead
Posts: 1065
Joined: Wed Dec 30, 2009 8:14 am
Name: Michael Miday
Contact:

Re: Template Events & Listeners updated for ajax - how?

Post by Hanakin »

jquery is included in the footer. It is not included in the header for good reason its a best practice to include none render based JS it in the footer.
User avatar
axe70
Registered User
Posts: 752
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio
Contact:

Re: Template Events & Listeners updated for ajax - how?

Post by axe70 »

yes thank you! The above as explained is just an example ...
Do not take me too serious
Anyway i do not like Discourse
User avatar
axe70
Registered User
Posts: 752
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio
Contact:

Re: Template Events & Listeners updated for ajax - how?

Post by axe70 »

so, of course i have return over just now again. The most easy solution, maybe can be this code applied on overall_footer.html:

Code: Select all

window.onload = function() {
var pmn = $('.badge').html();
parent.send_toMyParent(pmn);
}
OR

Code: Select all

window.onload = function() {
var pmn = "{PRIVATE_MESSAGE_COUNT}";
parent.send_toMyParent(pmn);
}
this is it.

the parent page, execute so

Code: Select all

send_toMyParent(pmn)
js function when value of pm count is updated with correct value in phpBB, that has been updated before to be sent. It can be controlled to be executed only when needed also, sending together the value of the page of phpBB you are on or checking for it (better) directly into phpBB footer with simply js like this (yes can be rewrite to be also more compact):

Code: Select all

window.onload = function() {
var href = window.location.href;
var ckr = href.indexOf('i=pm&mode=view') > -1;
if(ckr == true){	
var pmn = $('.badge').html();
parent.send_toMyParent(pmn);
}
}
My poor English should require to explain better the logic behind, hours of effort, so accept the above just as hint.
Do not take me too serious
Anyway i do not like Discourse
Post Reply

Return to “[3.2.x] Styles Support & Discussion”