move version checking code into its own folder and file

This commit is contained in:
Jon Heller 2015-10-19 01:22:00 -04:00
parent e35c9e9fc5
commit 07ec697e2c
3 changed files with 33 additions and 15 deletions

View File

@ -27,6 +27,7 @@
<script src="js/moment-with-locales.min.js"></script>
<script src="js/config.js"></script>
<script src="js/rrule.js"></script>
<script src="js/version/version.js" type="text/javascript"></script>
<script src="js/compliments/compliments.js" type="text/javascript"></script>
<script src="js/weather/weather.js" type="text/javascript"></script>
<script src="js/time/time.js" type="text/javascript"></script>

View File

@ -45,21 +45,7 @@ jQuery(document).ready(function($) {
// }
// });
(function checkVersion()
{
$.getJSON('githash.php', {}, function(json, textStatus) {
if (json) {
if (json.gitHash != gitHash) {
window.location.reload();
window.location.href=window.location.href;
}
}
});
setTimeout(function() {
checkVersion();
}, 3000);
})();
version.init();
time.init();

31
js/version/version.js Normal file
View File

@ -0,0 +1,31 @@
var version = {
updateInterval: 3000,
intervalId: null
}
version.checkVersion = function () {
$.ajax({
type: 'GET',
url: 'githash.php',
success: function (data) {
// The githash variable is located in index.php
if (data && data.gitHash !== gitHash) {
window.location.reload();
window.location.href = window.location.href;
}
},
error: function () {
}
});
}
version.init = function () {
this.intervalId = setInterval(function () {
this.checkVersion();
}.bind(this), this.updateInterval);
}