]>
Softwares of Agnibho - pdosage.git/blob - src/routine.js
1 /**********************************************************************
3 * Description: Nutritional Assessment App
4 * Author: Agnibho Mondal
5 * Website: http://code.agnibho.com
6 **********************************************************************
7 Copyright (c) 2016 Agnibho Mondal
9 **********************************************************************
10 This file is part of DietSurvey.
12 DietSurvey is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 DietSurvey is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with DietSurvey. If not, see <http://www.gnu.org/licenses/>.
24 **********************************************************************/
26 $.ajaxSetup({cache
:false});
28 $(document
).ready(function(){
31 $(".loader").remove();
32 $(".container").fadeIn();
35 $(".version").text(VERSION
);
37 $(".data-ver").text(JSON
.parse(localStorage
.getItem(STORAGE
)).version
);
41 $(".copyright").each(function(){
42 if(new Date().getFullYear()>$(this).data("start")){
43 $(this).text($(this).data("start")+"-"+new Date().getFullYear());
46 $(this).text(new Date().getFullYear());
50 //Emit input on form reset
51 $("input[type='reset']").on("click", function(e
){
53 $(this.form
).find("input, select, textarea").each(function(){
54 this.dispatchEvent(new Event("input"));
58 //Change focus after number input
59 $(".jump-focus").on("input", function(){
60 if($(this).val().length
== $(this).prop("maxlength")){
61 var all
=$("input").toArray();
62 var i
=all
.indexOf(this)+1;
63 $(all
[i
]).focus().select();
67 //Defocus after input finished
68 $(".stop-focus").on("input", function(){
69 if($(this).val().length
== $(this).prop("maxlength")){
71 var target
=$($(this).data("ref"));
72 console
.log($(target
).offset());
73 $("html, body").animate({
74 scrollTop
: $(target
).offset().top
79 //Use custom datepicker if Firefox
80 if($(".datepicker").length
&& navigator
.userAgent
.indexOf("Firefox")!=-1){
81 $(".datepicker").datepicker({
84 }).on("changeDate", function(){
85 this.dispatchEvent(new Event("input"));
90 $(window
).resize(function(){
91 $("#notify").width($(".container").width()-20);
93 $(window
).scroll(function(){
94 $("#notify").width($(".container").width()-20);
96 //Get data from server
97 $.get(INFO_URL
, function(data
){
98 var vCurr
=VERSION
.split(".").map(Number
);
99 var vLtst
=data
.latest
.split(".").map(Number
);
100 //Define version comparator
101 function isBiggerThan(v1
, v2
){
102 while(v1
.length
<v2
.length
){
105 while(v2
.length
<v1
.length
){
108 for(var i
=0; i
<v1
.length
; i
++){
116 if(NOTIFY
&& isBiggerThan(data
.latest
, VERSION
)){
117 $("#notify").slideDown();
118 $("#notify").width($(".container").width()-20);
119 $("#notify-text").text("A new version of "+NAME
+" is available.");
120 if(document
.URL
.indexOf("http://")==-1 && document
.URL
.indexOf("https://")==-1){
121 if(/(android)/i.test(navigator
.userAgent
)){
122 $("#notify-link").attr("href", data
.apk
);
123 $("#notify-link").text("Download");
126 $("#notify-link").attr("href", data
.url
);
127 $("#notify-link").text("Load");
131 $("#notify-link").attr("href", data
.url
);
132 $("#notify-link").text("Load");
137 if(data
.data
.latest
>JSON
.parse(localStorage
.getItem(STORAGE
)).version
){
138 $.get(data
.data
.src
, function(d
){
139 localStorage
.setItem(STORAGE
, JSON
.stringify(d
));