Skip to content

Instantly share code, notes, and snippets.

@urosevic
Created May 12, 2019 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urosevic/ae1afc8533ead1e5d8bebbbdb69578b6 to your computer and use it in GitHub Desktop.
Save urosevic/ae1afc8533ead1e5d8bebbbdb69578b6 to your computer and use it in GitHub Desktop.
Stock Ticker: Do not call quote update from front-end
var stockticker_loaded = false;
var stocktickers_load = function() {
var stocktickers = jQuery('.stock-ticker-wrapper');
if ( 'undefined' !== typeof stocktickers ) {
jQuery.each(stocktickers, function(i,v){
var obj = jQuery(this);
jQuery.ajax({
type: 'post',
dataType: 'json',
url: stockTickerJs.ajax_url,
data: {
'action': 'stockticker_load',
'symbols': jQuery(this).data('stockticker_symbols'),
'show': jQuery(this).data('stockticker_show'),
'number_format': jQuery(this).data('stockticker_number_format'),
'decimals': jQuery(this).data('stockticker_decimals'),
'static': jQuery(this).data('stockticker_static'),
'class': jQuery(this).data('stockticker_class'),
'speed': jQuery(this).data('stockticker_speed'),
'empty': jQuery(this).data('stockticker_empty'),
'duplicate': jQuery(this).data('stockticker_duplicate')
},
success: function(response) {
if ( response.status == 'success' ) {
stockticker_loaded = true;
obj.html(response.message);
if ( ! obj.data('stockticker_static') ) {
jQuery(obj).find('.stock_ticker').stockTicker({ startEmpty:jQuery(obj).data('stockticker_empty'), duplicate:jQuery(obj).data('stockticker_duplicate'), speed:jQuery(obj).data('stockticker_speed') });
}
}
}
});
});
}
};
jQuery(document).ready(function() {
stocktickers_load();
var stockTickerReload = setInterval(function() {
if ( stockticker_loaded ) {
clearInterval(stockTickerReload);
} else {
stocktickers_load();
}
}, 5000);
// Short-circuit selective refresh events if not in customizer preview or pre-4.5.
if ( 'undefined' === typeof wp || ! wp.customize || ! wp.customize.selectiveRefresh ) {
return;
}
// Re-load Stock Ticker widgets when a partial is rendered.
wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function( placement ) {
if ( placement.container ) {
stocktickers_load();
}
} );
});
var stockticker_loaded=!1,stocktickers_load=function(){var t=jQuery(".stock-ticker-wrapper");void 0!==t&&jQuery.each(t,function(t,e){var c=jQuery(this);jQuery.ajax({type:"post",dataType:"json",url:stockTickerJs.ajax_url,data:{action:"stockticker_load",symbols:jQuery(this).data("stockticker_symbols"),show:jQuery(this).data("stockticker_show"),number_format:jQuery(this).data("stockticker_number_format"),decimals:jQuery(this).data("stockticker_decimals"),static:jQuery(this).data("stockticker_static"),class:jQuery(this).data("stockticker_class"),speed:jQuery(this).data("stockticker_speed"),empty:jQuery(this).data("stockticker_empty"),duplicate:jQuery(this).data("stockticker_duplicate")},success:function(t){"success"==t.status&&(stockticker_loaded=!0,c.html(t.message),c.data("stockticker_static")||jQuery(c).find(".stock_ticker").stockTicker({startEmpty:jQuery(c).data("stockticker_empty"),duplicate:jQuery(c).data("stockticker_duplicate"),speed:jQuery(c).data("stockticker_speed")}))}})})};jQuery(document).ready(function(){stocktickers_load();var t=setInterval(function(){stockticker_loaded?clearInterval(t):stocktickers_load()},5e3);"undefined"!=typeof wp&&wp.customize&&wp.customize.selectiveRefresh&&wp.customize.selectiveRefresh.bind("partial-content-rendered",function(t){t.container&&stocktickers_load()})});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment