I am working on a new version of the same project. Posted Here
An html page that will read and display places and routes from a kml file using Google Maps API. The earlier version used Leaflet's API. The Leaflet version had over a dozen files: html, js and css. It was always an effort to find the code that supported a feature. Perhaps there is an IDE that supports that. I use a fancy editor but its not really integrated.
So for my new version I was thinking of another approach: Putting all the code for the feature in one js file.
Similar to this: <See DebugControl.js below> which contains js code to build html and set style plus having any needed functions.
I'm looking for comments or recommendations for an approach to allow me to add features to the project without having so many different files or having a lot of none related code in the same file.
function addText(text, nl) {
// if(++debugCnt > MaxDebugOutput) return; // no more output now
var dboDiv = document.getElementById('debugOutput');
dboDiv.appendChild(document.createTextNode(text));
for(i=0;i < nl;i++)
dboDiv.appendChild(document.createElement('BR')); // to new line
}
/* Add new div to body to hold debug output */
const logDiv = document.createElement('div');
logDiv.id="debugOutput";
// Style it
logDiv.style.position = 'absolute'; // or 'fixed' if you want it to stay on screen
logDiv.style.top = '40px'; // below filename
logDiv.style.left = '20px';
logDiv.style.width = '400px';
logDiv.style.maxHeight = '90vh'; // max height = 90% of viewport height
logDiv.style.backgroundColor = 'pink';
logDiv.style.border = '1px solid #ccc';
logDiv.style.padding = '10px';
logDiv.style.overflowY = 'auto'; // vertical scroll when content exceeds max-height
logDiv.style.zIndex = '1000';
// add to body
document.body.appendChild(logDiv);
//----------------------------------------------------
// Add a new div to contextMenu div - handle toggle of showing log
const parentDiv = document.getElementById('contextMenu');
const newDiv = document.createElement('div');
newDiv.id = "cm-showLog";
newDiv.textContent = "Hide log";
parentDiv.appendChild(newDiv);
const showBtn = document.getElementById("cm-showLog");
var showingLog = true;
showBtn.addEventListener("click", () => {
if(showingLog) {
showBtn.textContent = "Show log";
logDiv.style.display = "none";
}else {
showBtn.textContent = "Hide log";
logDiv.style.display = "block";
}
showingLog = !showingLog; // toggle
});
/* Trap console.log to our function */
console.log = function(msg) {
addText(msg, 1);
}