Improved DOM handling of auto-refresher

Table and usage list are now identified by unique IDs, making
future modifications safer.
This commit is contained in:
Mike 2014-01-16 15:20:49 -06:00
parent 61c4d6875e
commit a90ded6a00
2 changed files with 11 additions and 11 deletions

View File

@ -32,7 +32,7 @@ var firstLoop = true;
// Modify the document body // Modify the document body
var domUl = document.getElementsByTagName("ul"); var domUl = document.getElementById("noJsUsage");
var domBody = document.getElementsByTagName("body"); var domBody = document.getElementsByTagName("body");
var wrapperDiv = document.createElement("div"); var wrapperDiv = document.createElement("div");
@ -41,8 +41,8 @@ wrapperDiv.innerHTML = "The parameters used by the masterserver API will display
"<label for=\"refreshTimeId\">Refresh time (in seconds):</label> <input id=\"refreshTimeId\" type=\"number\" width=\"3\" min=\"10\" max=\"999\" /> <label for=\"refreshTimeId\">(minimum 10)</label>"; "<label for=\"refreshTimeId\">Refresh time (in seconds):</label> <input id=\"refreshTimeId\" type=\"number\" width=\"3\" min=\"10\" max=\"999\" /> <label for=\"refreshTimeId\">(minimum 10)</label>";
wrapperDiv.style.paddingLeft = "30px"; wrapperDiv.style.paddingLeft = "30px";
domBody[0].insertBefore(wrapperDiv, domUl[0]); domBody[0].insertBefore(wrapperDiv, domUl);
domUl[0].parentNode.removeChild(domUl[0]); domUl.parentNode.removeChild(domUl);
// Modifying string object to support startsWith(String) function // Modifying string object to support startsWith(String) function
@ -260,13 +260,13 @@ function timedRequest()
serverList = newServerList; serverList = newServerList;
// Write to actual table when done only, otherwise the browser trips as it tries to fix the partial table formatting // Write to actual table when done only, otherwise the browser trips as it tries to fix the partial table formatting
var tableDOM = document.getElementsByTagName("tbody"); var tableDOM = document.getElementById("gamesTable");
tableDOM[0].innerHTML = table; tableDOM.innerHTML = table;
//debugger; //debugger;
for(var gameIndex = 100; gameIndex < 200; ++gameIndex) { for(var gameIndex = 100; gameIndex < 200; ++gameIndex) {
setupGameStatsLink(gameIndex); setupGameStatsLink(gameIndex);
} }
// Catch empty case // Catch empty case
if(jsonText.length === 0) if(jsonText.length === 0)

View File

@ -62,7 +62,7 @@
echo ' </head>' . PHP_EOL; echo ' </head>' . PHP_EOL;
echo ' <body>' . PHP_EOL; echo ' <body>' . PHP_EOL;
echo ' <h1><a href="' . htmlspecialchars( PRODUCT_URL ) . '">' . htmlspecialchars( PRODUCT_NAME ) . '</a> gameservers</h1>' . PHP_EOL; echo ' <h1><a href="' . htmlspecialchars( PRODUCT_URL ) . '">' . htmlspecialchars( PRODUCT_NAME ) . '</a> gameservers</h1>' . PHP_EOL;
echo ' <table>' . PHP_EOL; echo ' <table id="gamesTable">' . PHP_EOL;
echo ' <tr>' . PHP_EOL; echo ' <tr>' . PHP_EOL;
echo ' <th title="glestVersion">Version</th>' . PHP_EOL; echo ' <th title="glestVersion">Version</th>' . PHP_EOL;
echo ' <th title="status">Status</th>' . PHP_EOL; echo ' <th title="status">Status</th>' . PHP_EOL;
@ -216,7 +216,7 @@
} }
echo ' <p>Usage:</p>' . PHP_EOL; echo ' <p>Usage:</p>' . PHP_EOL;
echo ' <ul>' . PHP_EOL; echo ' <ul id="noJsUsage">' . PHP_EOL;
echo ' <li>You can have this page auto <a href="?refresh=60" rel="nofollow">refresh every 60 seconds</a> by appending <code>?refresh=60</code> to the URL. Minimum refresh time is 10 seconds.</li>' . PHP_EOL; echo ' <li>You can have this page auto <a href="?refresh=60" rel="nofollow">refresh every 60 seconds</a> by appending <code>?refresh=60</code> to the URL. Minimum refresh time is 10 seconds.</li>' . PHP_EOL;
echo ' <li>The parameters used by the masterserver API will display when you move your mouse pointer over any of the table headings.</li>' . PHP_EOL; echo ' <li>The parameters used by the masterserver API will display when you move your mouse pointer over any of the table headings.</li>' . PHP_EOL;
echo ' </ul>' . PHP_EOL; echo ' </ul>' . PHP_EOL;