From: Agnibho Mondal Date: Tue, 28 Mar 2017 05:56:20 +0000 (+0530) Subject: Standardized routine.js X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=19df5f71cd52d7b9a8efe5fbcfe24f65f62caddd;p=dietsurvey.git Standardized routine.js --- diff --git a/index.html b/index.html index 3098cea..6b934d9 100755 --- a/index.html +++ b/index.html @@ -32,7 +32,11 @@ diff --git a/src/main.js b/src/main.js index b18a14c..6e0dad7 100644 --- a/src/main.js +++ b/src/main.js @@ -53,19 +53,19 @@ new Vue({ 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)); } } } diff --git a/src/routine.js b/src/routine.js index 4cc58f6..dd075d8 100644 --- a/src/routine.js +++ b/src/routine.js @@ -23,6 +23,8 @@ along with DietSurvey. If not, see . **********************************************************************/ +$.ajaxSetup({cache:false}); + $(document).ready(function(){ //Remove loader @@ -31,6 +33,9 @@ $(document).ready(function(){ //Insert version code $(".version").text(VERSION); + try{ + $(".data-ver").text(JSON.parse(localStorage.getItem(STORAGE)).version); + } catch(e){} //Update copyright $(".copyright").each(function(){ @@ -71,6 +76,16 @@ $(document).ready(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); @@ -78,9 +93,11 @@ $(document).ready(function(){ $(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.lengthJSON.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)); }); } }