var stock_value = parseFloat(Math.round(stock_data.value * 100) / 100).toFixed(2);
var el = document.getElementById("t_" + stock_name);
var old_stock_value = el.innerHTML;
el.innerHTML = stock_value;
if (parseFloat(old_stock_value) <parseFloat(stock_value)){
el.style.backgroundColor = "lightgreen";
} else {
el.style.backgroundColor = "tomato";
}
window.setTimeout(function clearBackground() {
el.style.backgroundColor = "white";
}, 500);
}
function toggle_updates(){
if (source){
source.close();
source = null;
} else {
start_updates();
}
}
</script>
</head>
<body>
<h1>Server Sent Events DelphiMVCFramework Example</h1>
<divid="notSupported">
Your browser does not support Server Sent Events. Please use <ahref="https://www.mozilla.org/firefox/new/">Firefox</a> or <ahref="https://www.google.com/chrome/browser">Google Chrome</a>.
</div>
<pclass="hint">
This is a simple Server Sent Events (SSE) example using DelphiMVCFramework that updates stock prices when market moves. Data source is predefined array with titles. These is random delay between 500 msec and 1 sec between each event.