From 07ec697e2c93f14c3b404298c8ab8192f5def59d Mon Sep 17 00:00:00 2001 From: Jon Heller Date: Mon, 19 Oct 2015 01:22:00 -0400 Subject: [PATCH] move version checking code into its own folder and file --- index.php | 1 + js/main.js | 16 +--------------- js/version/version.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 js/version/version.js diff --git a/index.php b/index.php index ade2ebed..a02f8b03 100644 --- a/index.php +++ b/index.php @@ -27,6 +27,7 @@ + diff --git a/js/main.js b/js/main.js index df645416..0070fd67 100755 --- a/js/main.js +++ b/js/main.js @@ -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(); diff --git a/js/version/version.js b/js/version/version.js new file mode 100644 index 00000000..5931a179 --- /dev/null +++ b/js/version/version.js @@ -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); + +} \ No newline at end of file