Only send new Ticks on AJAX update
THis reduces the overhead of re-sending huge amounts of HTML code to the frontend without any new data to display.
This commit is contained in:
parent
5158b8fdb7
commit
de347e1f81
@ -180,7 +180,8 @@ class WPLiveticker2 {
|
|||||||
if ( 1 === self::$_options['enable_ajax'] ) {
|
if ( 1 === self::$_options['enable_ajax'] ) {
|
||||||
$output .= ' wplt2-ticker-ajax" '
|
$output .= ' wplt2-ticker-ajax" '
|
||||||
. 'data-wplt2-ticker="' . $atts['ticker'] . '" '
|
. 'data-wplt2-ticker="' . $atts['ticker'] . '" '
|
||||||
. 'data-wplt2-limit="' . $atts['limit'];
|
. 'data-wplt2-limit="' . $atts['limit'] . '" '
|
||||||
|
. 'data-wplt2-last="' . time();
|
||||||
}
|
}
|
||||||
$output .= '">';
|
$output .= '">';
|
||||||
|
|
||||||
@ -281,6 +282,9 @@ class WPLiveticker2 {
|
|||||||
'terms' => $slug,
|
'terms' => $slug,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
'date_query' => array(
|
||||||
|
'after' => date( 'c', $last_poll ),
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = new WP_Query( $query_args );
|
$query = new WP_Query( $query_args );
|
||||||
|
@ -42,9 +42,14 @@ WPLT2.update = function () {
|
|||||||
jQuery.each(update, function (i, u) {
|
jQuery.each(update, function (i, u) {
|
||||||
jQuery.each(WPLT2.ticker, function (j, t) {
|
jQuery.each(WPLT2.ticker, function (j, t) {
|
||||||
if (t.s === u.s) {
|
if (t.s === u.s) {
|
||||||
// Set HTML content.
|
// Prepend HTML of new ticks.
|
||||||
jQuery(t.e).html(u.h);
|
jQuery(t.e).prepend(u.h);
|
||||||
// Set last poll timestamp.
|
// Remove tail, if limit is set.
|
||||||
|
const l = jQuery(t.e).data('wplt2Limit');
|
||||||
|
if (l > 0) {
|
||||||
|
jQuery(t.e).find('li').slice(l).remove();
|
||||||
|
}
|
||||||
|
// Update last poll timestamp.
|
||||||
jQuery(t.e).data('wplt2Last', u.t);
|
jQuery(t.e).data('wplt2Last', u.t);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user