<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
+var NAME="DietSurvey";
var VERSION="3.0.0";
+var STORAGE="dietsurvey_data";
+var INFO_URL="https://code.agnibho.com/dietsurvey/info.json";
+var NOTIFY=true;
</script>
<style>
.loader {
animation: spin 2s linear infinite;
}
- @keyframes spin {
- 0% { transform: rotate(0deg); }
- 100% { transform: rotate(360deg); }
- }
+ @keyframes spin {
+ 0% { transform: rotate(0deg); }
+ 100% { transform: rotate(360deg); }
+ }
</style>
</head>
data: {dataObj: {family: [], food: []}, dataRef: false},
created:function(){
try{
- var loc=JSON.parse(localStorage.getItem("dietsurvey_data"));
+ var loc=JSON.parse(localStorage.getItem(STORAGE));
if(loc.version>data.version){
this.dataRef=loc;
}
else{
this.dataRef=data;
- localStorage.setItem("dietsurvey_data", JSON.stringify(data));
+ localStorage.setItem(STORAGE, JSON.stringify(data));
}
}
catch(e){
if(!this.dataRef){
this.dataRef=data;
- localStorage.setItem("dietsurvey_data", JSON.stringify(data));
+ localStorage.setItem(STORAGE, JSON.stringify(data));
}
}
}
along with DietSurvey. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************/
+$.ajaxSetup({cache:false});
+
$(document).ready(function(){
//Remove loader
//Insert version code
$(".version").text(VERSION);
+ try{
+ $(".data-ver").text(JSON.parse(localStorage.getItem(STORAGE)).version);
+ } catch(e){}
//Update copyright
$(".copyright").each(function(){
}
});
+ //Use custom datepicker if Firefox
+ if($(".datepicker").length && navigator.userAgent.indexOf("Firefox")!=-1){
+ $(".datepicker").datepicker({
+ format:"yyyy-mm-dd",
+ autoclose:true
+ }).on("changeDate", function(){
+ this.dispatchEvent(new Event("input"));
+ });
+ }
+
//Notifications
$(window).resize(function(){
$("#notify").width($(".container").width()-20);
$(window).scroll(function(){
$("#notify").width($(".container").width()-20);
});
- $.get("https://code.agnibho.com/dietsurvey/info.json", function(data){
+ //Get data from server
+ $.get(INFO_URL, function(data){
var vCurr=VERSION.split(".").map(Number);
var vLtst=data.latest.split(".").map(Number);
+ //Define version comparator
function isBiggerThan(v1, v2){
while(v1.length<v2.length){
v1.push(0);
}
return false;
}
- if(isBiggerThan(data.latest, VERSION)){
+ //Compare versions
+ if(NOTIFY && isBiggerThan(data.latest, VERSION)){
$("#notify").slideDown();
$("#notify").width($(".container").width()-20);
- $("#notify-text").text("A new version of DietSurvey is available.");
+ $("#notify-text").text("A new version of "+NAME+" is available.");
if(document.URL.indexOf("http://")==-1 && document.URL.indexOf("https://")==-1){
if(/(android)/i.test(navigator.userAgent)){
$("#notify-link").attr("href", data.apk);
$("#notify-link").text("Load");
}
}
+ //Update app data
try{
- if(data.data.latest>JSON.parse(localStorage.getItem("dietsurvey_data")).version){
+ if(data.data.latest>JSON.parse(localStorage.getItem(STORAGE)).version){
$.get(data.data.src, function(d){
- localStorage.setItem("dietsurvey_data", JSON.stringify(d));
+ localStorage.setItem(STORAGE, JSON.stringify(d));
});
}
}