/* javascript for html, CSS and JS template
   Copyright by Anthony Vogelaar, Perth UK
   rev 0.10  2025-02-27  Initial release */

// ====================== Global variables and events ======================

const header    = document.getElementById("header")
const ev_source = new EventSource("/events")

document.getElementById("btn1").addEventListener("click", onBtnClick)
document.getElementById("btn2").addEventListener("click", onBtnClick)
document.getElementById("btn3").addEventListener("click", onBtnClick)
document.getElementById("btn4").addEventListener("click", onBtnClick)

// =============================== domain =================================

function onLoad(ev) {
   console.log('running ....')
}


function onBtnClick(ev) {
   let id = this.id
   header.innerText = id
}


ev_source.onmessage = (event) => {
   header.innerText = event.data
}

// ============================== start ===================================

window.addEventListener("load", onLoad)

// ============================== end =====================================
