From: Agnibho Mondal Date: Tue, 28 Mar 2017 06:02:40 +0000 (+0530) Subject: Standardized routine.js X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=564d53f5a1d937165a45b1789664e5bb84a9227a;p=obscalc.git Standardized routine.js --- diff --git a/index.html b/index.html index 2f1f5cb..a5224bc 100755 --- a/index.html +++ b/index.html @@ -9,82 +9,86 @@ All rights reserved ********************************************************************** This file is part of ObsCalc. - + ObsCalc is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + ObsCalc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License - along with Obscalc. If not, see . + along with ObsCalc. If not, see . *********************************************************************** --> - - ObsCalc - - - - - + + ObsCalc + + + + + - - -
- - - + + +
+ + + diff --git a/src/Settings.vue b/src/Settings.vue index fe87f12..230f718 100644 --- a/src/Settings.vue +++ b/src/Settings.vue @@ -1,116 +1,116 @@ + *********************************************************************** + * Title: ObsCalc + * Description: An Obstetric Calculator + * Author: Agnibho Mondal + * Website: http://code.agnibho.com + ********************************************************************** + Copyright (c) 2016 Agnibho Mondal + All rights reserved + ********************************************************************** + This file is part of ObsCalc. + + ObsCalc is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ObsCalc is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Obscalc. If not, see . + *********************************************************************** +--> diff --git a/src/main.js b/src/main.js index b91310b..1635868 100644 --- a/src/main.js +++ b/src/main.js @@ -8,17 +8,17 @@ All rights reserved ********************************************************************** This file is part of ObsCalc. - + ObsCalc is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + ObsCalc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with Obscalc. If not, see . **********************************************************************/ @@ -45,27 +45,32 @@ import Settings from "./Settings.vue"; //Start app new Vue({ - el: "#app", - components: { - "by-date": ByDate, - "by-usg": ByUsg, - "settings-btn": Settings - }, - data: {settings: ""}, - mounted:function(){ - try{ - this.settings=JSON.parse(localStorage.getItem("settings")); - } - finally{ - if(this.settings==null){ - this.settings={dstyle:"cal"}; - } - else if(this.settings.dstyle!="cal" && this.settings.dstyle!="txt"){ - this.settings={dstyle:"cal"}; - } - } + el: "#app", + components: { + "by-date": ByDate, + "by-usg": ByUsg, + "settings-btn": Settings + }, + data: {settings: ""}, + mounted:function(){ + try{ + this.settings=JSON.parse(localStorage.getItem("obscalc_settings")); } + catch(e){ + } + finally{ + if(this.settings==null){ + this.settings={dstyle:"cal"}; + } + else if(this.settings.dstyle!="cal" && this.settings.dstyle!="txt"){ + this.settings={dstyle:"cal"}; + } + } + } }); //Routine jobs -import "./routine.js"; +import "./routine.js" + +//Source Map +//#sourceMappingURL=dist/bundle.js.map; diff --git a/src/routine.js b/src/routine.js index cb46151..dd075d8 100644 --- a/src/routine.js +++ b/src/routine.js @@ -1,128 +1,145 @@ /********************************************************************** - * Title: ObsCalc - * Description: An Obstetric Calculator + * Title: DietSurvey + * Description: Nutritional Assessment App * Author: Agnibho Mondal * Website: http://code.agnibho.com ********************************************************************** Copyright (c) 2016 Agnibho Mondal All rights reserved ********************************************************************** - This file is part of ObsCalc. - - ObsCalc is free software: you can redistribute it and/or modify + This file is part of DietSurvey. + + DietSurvey is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - - ObsCalc is distributed in the hope that it will be useful, + + DietSurvey is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License - along with Obscalc. If not, see . + along with DietSurvey. If not, see . **********************************************************************/ +$.ajaxSetup({cache:false}); + $(document).ready(function(){ - //Remove loader - $(".loader").remove(); - $(".container").fadeIn(); + //Remove loader + $(".loader").remove(); + $(".container").fadeIn(); - //Insert version code - $(".version").text(VERSION); + //Insert version code + $(".version").text(VERSION); + try{ + $(".data-ver").text(JSON.parse(localStorage.getItem(STORAGE)).version); + } catch(e){} - //Update copyright - $(".copyright").each(function(){ - if(new Date().getFullYear()>$(this).data("start")){ - $(this).text($(this).data("start")+"-"+new Date().getFullYear()); - } - else{ - $(this).text(new Date().getFullYear()); - } - }); + //Update copyright + $(".copyright").each(function(){ + if(new Date().getFullYear()>$(this).data("start")){ + $(this).text($(this).data("start")+"-"+new Date().getFullYear()); + } + else{ + $(this).text(new Date().getFullYear()); + } + }); - //Emit input on form reset - $("input[type='reset']").on("click", function(e){ - this.form.reset(); - $(this.form).find("input, select, textarea").each(function(){ - this.dispatchEvent(new Event("input")); - }); + //Emit input on form reset + $("input[type='reset']").on("click", function(e){ + this.form.reset(); + $(this.form).find("input, select, textarea").each(function(){ + this.dispatchEvent(new Event("input")); }); + }); - //Use custom datepicker if Firefox - if(navigator.userAgent.indexOf("Firefox")!=-1){ - $(".datepicker").datepicker({ - format:"yyyy-mm-dd", - autoclose:true - }).on("changeDate", function(){ - this.dispatchEvent(new Event("input")); - }); + //Change focus after number input + $(".jump-focus").on("input", function(){ + if($(this).val().length == $(this).prop("maxlength")){ + var all=$("input").toArray(); + var i=all.indexOf(this)+1; + $(all[i]).focus().select(); } - - //Change focus after number input - $(".jump-focus").on("input", function(){ - if($(this).val().length == $(this).prop("maxlength")){ - var all=$("input").toArray(); - var i=all.indexOf(this)+1; - $(all[i]).focus().select(); - } - }); + }); - //Defocus after input finished - $(".stop-focus").on("input", function(){ - if($(this).val().length == $(this).prop("maxlength")){ - $(this).blur(); - var target=$($(this).data("ref")); - console.log($(target).offset()); - $("html, body").animate({ - scrollTop: $(target).offset().top - }, 1000); - } - }); + //Defocus after input finished + $(".stop-focus").on("input", function(){ + if($(this).val().length == $(this).prop("maxlength")){ + $(this).blur(); + var target=$($(this).data("ref")); + console.log($(target).offset()); + $("html, body").animate({ + scrollTop: $(target).offset().top + }, 1000); + } + }); - //Notifications - $(window).resize(function(){ - $("#notify").width($(".container").width()-20); - }); - $(window).scroll(function(){ - $("#notify").width($(".container").width()-20); - }); - $.get("https://code.agnibho.com/obscalc/info.json", function(data){ - var vCurr=VERSION.split(".").map(Number); - var vLtst=data.latest.split(".").map(Number); - function isBiggerThan(v1, v2){ - while(v1.lengthv2[i]){ - return true; - } - } - return false; - } - if(isBiggerThan(data.latest, VERSION)){ - $("#notify").slideDown(); - $("#notify").width($(".container").width()-20); - $("#notify-text").text("A new version of ObsCalc 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("Download"); - } - else{ - $("#notify-link").attr("href", data.url); - $("#notify-link").text("Load"); - } - } - else{ - $("#notify-link").attr("href", data.url); - $("#notify-link").text("Load"); - } - } + //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 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.lengthv2[i]){ + return true; + } + } + return false; + } + //Compare versions + if(NOTIFY && isBiggerThan(data.latest, VERSION)){ + $("#notify").slideDown(); + $("#notify").width($(".container").width()-20); + $("#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("Download"); + } + else{ + $("#notify-link").attr("href", data.url); + $("#notify-link").text("Load"); + } + } + else{ + $("#notify-link").attr("href", data.url); + $("#notify-link").text("Load"); + } + } + //Update app data + try{ + if(data.data.latest>JSON.parse(localStorage.getItem(STORAGE)).version){ + $.get(data.data.src, function(d){ + localStorage.setItem(STORAGE, JSON.stringify(d)); + }); + } + } + catch(e){} + }); });