From 930378a5ef2e1eaf190da01033fabf40d4c17e8a Mon Sep 17 00:00:00 2001 From: Brandon Dusseau Date: Mon, 26 Jan 2015 15:21:48 -0500 Subject: [PATCH] 1.1.0 - Better error handling/proper doctype and encoding added --- changelog.txt | 8 ++++ functions.js | 109 ++++++++++++++++++++++++++++++++++++-------------- index.html | 7 +++- loader.gif | Bin 0 -> 2248 bytes style.css | 19 ++++++++- 5 files changed, 109 insertions(+), 34 deletions(-) create mode 100644 changelog.txt create mode 100644 loader.gif diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 0000000..49e58a5 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,8 @@ +1.1.0 - 26 January 2015 + * Added calendar caching; if calendar is loaded and connection is lost, + calendar will remain present until the page is reloaded. + * Removed bulky error message and added notification at bottom right. + * If connection is lost, the script attempts to reload the calendar at a + shorter interval. + * Added proper DOCTYPE and character encoding to HTML document + * AJAX request now uses callbacks to allow for more flexibility. diff --git a/functions.js b/functions.js index d9ee788..7f7b1e1 100644 --- a/functions.js +++ b/functions.js @@ -1,8 +1,50 @@ +// Provides callback for AJAX call +var updateView = function(result, response) { + // How often to update (in seconds) + var interval = 60; + var tempInterval = interval; + + // Set up references to loading indicator + var loadtext = document.getElementById("loadertext"); + var loadbox = document.getElementById("loader"); + + // If the AJAX call was successful + if (result == true) { + + // Read into a buffer and display, ignoring any passed in buffer + document.getElementById("content").innerHTML = response; + + // Hide the loading indicator and reset the update interval + loadtext.innerHTML = ""; + loader.style.display = "none"; + tempInterval = interval; + + // AJAX call failed + } else { + + // Display the passed in buffer if available, to avoid losing calendar + if (typeof(response) != "undefined") { + document.getElementById("content").innerHTML = response; + } + + // Add some text to the loading animation and display it. + loadtext.innerHTML = "Connection error. Retrying..."; + loader.style.display = "block"; + + // Loop more quickly to recover from error condition + tempInterval = 5; + } + + // Request on an interval + setTimeout(function() { ajaxcall(response) }, tempInterval * 1000); +} + // Requests calendar file -function ajaxcall() { +function ajaxcall(buf) { + // Generate cache breaker var decache = new Date().getTime(); - + // Make AJAX request var xmlhttp; if (window.XMLHttpRequest) { @@ -11,35 +53,40 @@ function ajaxcall() { else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } - - xmlhttp.onreadystatechange=function() { - // Display response on OK - if (xmlhttp.readyState==4 && xmlhttp.status==200) { - document.getElementById("content").innerHTML=xmlhttp.responseText; - } - - // Handle HTTP errors - else if (xmlhttp.readyState==4 && xmlhttp.status != 200) { - document.getElementById("content").innerHTML = - "
\n\t
Error
\n\t
\n" + - "\t\t
Failed to load data from server. Please check the network connection.
\n" + - "\t
\n
\n"; - } + + xmlhttp.onreadystatechange = function() { + var result = false; + var response = ""; + + // Display response on OK + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + result = true; + response = xmlhttp.responseText; + + // Send the result to the callback + updateView(result, response); + } + + // Handle HTTP errors + else if (xmlhttp.readyState==4 && xmlhttp.status != 200) { + result = false; + response = buf; + + // Send the result to the callback + updateView(result, response); + } } - + // Send request - xmlhttp.open("GET","schedule.php?d=" + decache,true); + xmlhttp.open("GET","schedule.php?d=" + decache, true); xmlhttp.send(); - - // Request every 60 seconds - setTimeout("ajaxcall();", 60000); } // Displays the current date and time function updateClock() { var d = new Date(); var curr_date = d.getDate(); - + // Select a suffix for the date var sup = ""; if (curr_date == 1 || curr_date == 21 || curr_date == 31) { @@ -51,28 +98,28 @@ function updateClock() { } else { sup = "th"; } - + // Set options for date display var date_options = { weekday: "long", month: "long", day: "numeric" }; - + // Set options for time display var time_options = { hour: "numeric", minute: "2-digit", second: "2-digit", hour12: true }; - + // Generate the date string and add it to the document var datestring = d.toLocaleDateString("en-US", date_options) + sup + "" + - d.toLocaleTimeString("en-US", time_options) + ""; + d.toLocaleTimeString("en-US", time_options) + ""; document.getElementById("clock").innerHTML=datestring; - + // Repeat every second - setTimeout("updateClock();", 1000); -} + setTimeout("updateClock();", 1000); + } -// Begins loops -function bootstrap() { + // Begins loops + function bootstrap() { ajaxcall(); updateClock(); } diff --git a/index.html b/index.html index 8cf1668..d0c1369 100644 --- a/index.html +++ b/index.html @@ -1,11 +1,16 @@ + Schedule - + + +
diff --git a/loader.gif b/loader.gif new file mode 100644 index 0000000000000000000000000000000000000000..55f6c643f7f3cbfd237763149fc3611c32bfff84 GIT binary patch literal 2248 zcmcJRYf#fy7Qn+p9_!B5Qi=r}BC)oOn!uu9K&*riFoFTK5S2#^5KMqPfIt!;A@77F zBtQrfLI?zt@Je72L_mbqs;E)1wu*y@ZQ0@!E3mL--QCuOc4nuu^Y_!v-VgW7y>rj+ zcg~!9ZyY8T5l%pW-UqFKHipCD=;`S}p-{20u_O|SPNx%zL^K-x%i@1efp0cr(Vv|_ zA(PM{@L(6G_4UA?{ZNHO0)v>nok?bpwi9v*tb7_F8&0O?&_IE&T|IxdzH86MNgF{y zuJ|nzn66R8!rhU_(VwWY$<3df5~CKb(D&T$_dgzOTm0AV=c6rKe$>xNCNho{CPa|q zqgF6~bLyH(VKj26BU3>Qy8;f}$@wq>mUe+Hf~}=1;>;bFxk3N<`x_o#;P)<2%>4f? zX7bgoFF*9YG1vNphh2O0vP1}nt$d$;q%m{H(6$YL?tjkw z#C<0RRQjpV{T&Z>S$RrvNri`tKor7tg#Z-kG-P(4CFDH))7fy^A1iEiB`=1_c zqfEVQge?z?>3e){*k+dt3PW5uppuFpa(G$gCb3jTU}qJyLV9>p254H26S8q`XK(tBUTLgWC#`Y)%>L<3b>&lolL`Ja$;CK z5>qH*NGj-5p?eXiIJ-KGuh4jC&n4>I^l;N*BgG;&%WB$Bb(Yfj#+JUcE~&C#TMr!@ z|1$*q`Slw&CxFTAz~oC&-m#Qvcdt9E9B`ogOx)aS?(o!0*+WkenyA)I!*r7GpNIR# zrsHzGd_K(`oa}kGjH~5P?4SE{cGym=T-xbASy^(Fb@EhMIhn_%OJMv^3Y=4sEoUAV zRaezkHYoElS^9JN%__0bMAZt~TG~3Qy42=AtF70fGnNX&YBPrV4WpsRXz0YP+Ys>G zd-o?F04wwYDtL(l@2~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