mercredi 25 mars 2015

How to have enqueued JS listen for content change without page reload?


I've successfully registered and enqueued a js



function OnLoad() {
/* Do some removing and integration with the site on the output of an early stage plugin */
}
if (window.addEventListener) {
window.addEventListener('load', OnLoad, false);
} else if (window.attachEvent) {
window.attachEvent('onload', OnLoad);
}


into the footer like so:



function enqueue_ticket_link() {
wp_register_script( 'ticket_link', get_template_directory_uri() . '-child/library/js/ticket_link.js', array('jquery') );
wp_enqueue_script( 'ticket_link' );
}
add_action( 'get_footer', 'enqueue_ticket_link' );


It does exactly what I want it to do whenever the page is loaded / refreshed.


The plugin all in one calendar by timely I'm modifying the output of using js changes it's content (ie when I click on next month) without reloading the page like so:



<a class="ai1ec-next-page ai1ec-load-view ai1ec-btn ai1ec-btn-sm
ai1ec-btn-default " data-type="json" href="http://ift.tt/1Hy93Mw">
<i class="ai1ec-fa ai1ec-fa-chevron-right"></i>
</a>


Thus my script isn't rerun.


I would like to rerun the script whenever the plugin output is changed on the site, ie whenever a json-type link is clicked? I'm not sure I understand what exactly I'm talking about. I couldn't find an appropriate action hook to achieve this from inside the functions.php so I think I'm looking for another EventListener or something like that to add at the end of my js?


I'll be happy to receive any advice also on what I already have, it's snippet c&p result.


Many thanks!





Aucun commentaire:

Enregistrer un commentaire