-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
1246 lines (1047 loc) · 56.8 KB
/
index.html
File metadata and controls
1246 lines (1047 loc) · 56.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<!-- Page formatting information -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta name="Author" content="Chantal Kronenburg & Aaron Krupp, Caminos de Agua"/>
<!-- Include jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Include both libraries for plotting stamen basemaps -->
<!-- Include Leaflet libraries (through carto) including leaflet label plugin -->
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css"></link>
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script>
<script src="https://leaflet.github.io/Leaflet.label/leaflet.label.js"></script> <!-- files necessary for labels in leaflet -->
<!-- Include this next line if you want to use FREE Stamen basemap tiles -->
<!-- stamen tiles -> <script type="text/javascript" src="https://stamen-maps.a.ssl.fastly.net/js/tile.stamen.js"></script><!--Include Stamen JavaScript to get basemap tiles-->
<!-- stamenTiles --> <script type="text/javascript" src="stamen/stamen.js"></script>
<!-- this is a modfied version of the code hosted at https://stamen-maps.a.ssl.fastly.net/js/tile.stamen.js"> -->
<!-- Include stylesheets for calculator and map -->
<link rel="stylesheet" type="text/css" href="calc_styles.css"></link>
<link rel="stylesheet" type="text/css" href="rainmap_styles.css"></link>
<!-- Include data globals for calc and rainmap and scripts for rainmap -->
<script src="https://caminosdeagua.github.io/rainwater-calculator/data/rainstations.js" type="text/javascript"></script>
<script src="globals.js" type="text/javascript"></script>
<script src="rainmap_global.js" type="text/javascript" /></script>
<!-- ----------- MAKE LANGUAGE CHANGES HERE!!! ------------- -->
<!-- Include text-to-display file of the relevant language:
make sure to select "calc_English.js" or "calc_Spanish.js"
and the same for the rainmap files. -->
<script src="calc_English.js" type="text/javascript"></script>
<script src="rainmap_display_English.js" type="text/javascript"></script>
<!------------------------------------------------------------->
<script src="rainmap_scripts.js" type="text/javascript" /></script>
<script>
document.title = CALC_TITLE; // Adds title to calc from calc_Language.js
</script>
</head>
<body onload="init();">
<!-- This next div (id=mobile_browser_display) is what shows up when the user opens the URL on a mobile browser -->
<div id="mobile_browser_display" align="center" style="display: none;">
<div style="width: 100%; text-align: center;">
<a id="caminos_logo_mobile" href="https://www.caminosdeaguamexico.org">
<img class="caminos_logo_img" src="http://caminosdeagua.github.io/rainwater-calculator/img/caminos_logo_circle.png"></img>
</a>
</div>
<p id="mobile_browser_message"></p>
</div>
<!-- Everything else that follows is what displays on a desktop/laptop or tablet browser -->
<div id="everything" style="height: 100%; width: 100%">
<!-- Left hand side (inputs) for the calculator. The LHS is fullscreen for inputs,
and is the left side of the screen when the outputs are being displayed. -->
<div id="left_hand_side">
<div id="LHS_inputs">
<!-- the top text goes here -->
<a id="caminos_logo" href="https://www.caminosdeaguamexico.org" target="_blank">
<img class="caminos_logo_img" src="http://caminosdeagua.github.io/rainwater-calculator/img/caminos_logo_circle.png"></img>
</a>
<h1 class="headers" id="header"></h1>
<h3 class="headers" id="sub_header"></h3>
<!-- start the form!!! -->
<form id="calc_form" class="form">
<div style="text-align: center;"> <!-- this div is necessary to easily center the form box, see http://stackoverflow.com/questions/283961/centering-a-div-block-without-the-width for details -->
<div id="form_box">
<big><p class="headers" id="instructions" align="center"></p></big>
<!-- Select your municipality -->
<div style="display: inline-block; ">
<div id="form_box_left" class="inside_form_box">
<div id="WaterMapDiv" style="padding-top: 10px;">
<label id="muni0" class="map_related_text"></label><br>
<div id="WaterMap"></div>
</div>
<!-- If the user is entering their own data -->
<div id="MonthlyUseDiv">
<p id="monthly_rain_lbl"></p>
<div class="rain_column" id="rain_column_1">
<div class="rain_entry_wrapper"><label for="jan_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="jan_rain" name="rain" value="none" min="0" step="any" /></div>
<div class="rain_entry_wrapper"><label for="feb_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="feb_rain" name="rain" value="none" min="0" step="any" /></div>
<div class="rain_entry_wrapper"><label for="mar_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="mar_rain" name="rain" value="none" min="0" step="any" /></div>
<div class="rain_entry_wrapper"><label for="apr_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="apr_rain" name="rain" value="none" min="0" step="any" /></div>
</div>
<div class="rain_column" id="rain_column_2">
<div class="rain_entry_wrapper"><label for="may_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="may_rain" name="rain" value="none" min="0" step="any" /></div>
<div class="rain_entry_wrapper"><label for="jun_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="jun_rain" name="rain" value="none" min="0" step="any" /></div>
<div class="rain_entry_wrapper"><label for="jul_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="jul_rain" name="rain" value="none" min="0" step="any" /></div>
<div class="rain_entry_wrapper"><label for="aug_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="aug_rain" name="rain" value="none" min="0" step="any" /></div>
</div>
<div class="rain_column" id="rain_column_3">
<div class="rain_entry_wrapper"><label for="sep_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="sep_rain" name="rain" value="none" min="0" step="any" /></div>
<div class="rain_entry_wrapper"><label for="oct_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="oct_rain" name="rain" value="none" min="0" step="any" /></div>
<div class="rain_entry_wrapper"><label for="nov_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="nov_rain" name="rain" value="none" min="0" step="any" /></div>
<div class="rain_entry_wrapper"><label for="dec_rain" name="rain_lbl"></label><input class="rain_lbl" type="number" id ="dec_rain" name="rain" value="none" min="0" step="any" /></div>
</div>
</div>
<br style="font-size: 2px;">
<div id="monthly_use_cluster">
<input type="checkbox" id="useMonthly"></input>
<div id="useMonthly_lbl" style="display: inline-block;">
</div>
</div>
</div>
<div id = "full_box_right" class="inside_form_box" align="center">
<div id="form_box_right" align="left">
<!-- How many people in your household? -->
<div>
<label for="ppl" id="ppl0"></label>
<input type="number" class="number_input" id="ppl" value="1" min="1" max="9999" step="1"/>
</div>
<!-- Length of your roof -->
<div>
<label for="length" id = "length0"></label>
<input type="number" class="number_input" id="length" value="1" min="1" max="99" step="any"/>
</div>
<!-- Width of your roof -->
<div>
<label for="width" id = "width0"></label>
<input type="number" class="number_input" id="width" value="1" min="1" max="99" step="any"/>
</div>
<br>
<!-- Type of roof -->
<div>
<label id="roof0"></label><br>
<div class="tooltip_roof" onmouseover="highlight(this)" onmouseleave="unHighlight(this)">
<input type="radio" id="cement_roof" name="roof_type" value="0" checked>.</input>
<div name="roof_imgs" class="tooltip_img"></div>
</div>
<div class="tooltip_roof" onmouseover="highlight(this)" onmouseleave="unHighlight(this)">
<input type="radio" id="sheet_roof" name="roof_type" value="1" >.</input>
<div name="roof_imgs" class="tooltip_img"></div>
</div>
<div class="tooltip_roof" onmouseover="highlight(this)" onmouseleave="unHighlight(this)">
<input type="radio" id="spanish_roof" name="roof_type" value="2" >.</input>
<div name="roof_imgs" class="tooltip_img"></div>
</div>
<div class="tooltip_roof" onmouseover="highlight(this)" onmouseleave="unHighlight(this)" style="margin-bottom: 20px;">
<input type="radio" id="other_roof" name="roof_type" value="3" >.</input>
<div name="roof_imgs" class="tooltip_img"></div>
</div>
</div>
</div>
<!--When you press this button, it stops letting you edit the form
and displays the inputs back to the user -->
<div class="button" >
<button type="button" onclick="incrementHash();" id="calc_button"></button>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<!-- This id=LHS_display shows up after the user presses "calculate"-->
<div id="LHS_display">
<h1 id="header_display"></h1>
<h3 id="sub_header_display"></h3>
<p id="instructions_display"></p>
<div class="to_indent">
<p name="display_text">.</p>
<p name="display_text">.</p>
<p name="display_text">.</p>
<p name="display_text">.</p>
<br><br>
<div class="button" align="center">
<button onclick="incrementHash();" id="back2inputs_button" ></button>
</div>
</div>
<p id="ps_note"></p>
</div>
</div>
<!-- The right hand side displays the calculated resullts in simple or complex form -->
<div id="right_hand_side" align="center">
<div class="footer" align="right"></div>
<div id="min_header" class="results_headers"></div>
<div class="outer_row" id="top_box">
<div class="tooltip" id="left" name="min_water" onmouseover="addTooltipText(this)">
<span class="tooltiptext"></span>
<div class="text_in_center">
<label name="min_water_lbl" class="output_text"></label><br>
<label name="min_water_numb" class="return_num"></label><br>
<label name="min_water_lbl" class="output_text"></label>
</div>
</div>
<div class="tooltip" id="center" name="min_roof" onmouseover="addTooltipText(this)">
<span class="tooltiptext"></span>
<div class="text_in_center">
<label name="min_roof_lbl" class="output_text"></label><br>
<label name="min_roof_numb" class="return_num" ></label><br>
<label name="min_roof_lbl" class="output_text"></label>
</div>
</div>
<div class="tooltip" id="right" name="min_tank" onmouseover="addTooltipText(this)">
<span class="tooltiptext"></span>
<div class="text_in_center">
<label name="min_tank_lbl" class="output_text"></label><br>
<label name="min_tank_numb" class="return_num"></label><br>
<label name="min_tank_lbl" class="output_text"></label>
</div>
</div>
</div>
<div id="real_header" class="results_headers"></div>
<div class="outer_row" id="bottom_box">
<div class="tooltip" id="left" name="real_water" onmouseover="addTooltipText(this)">
<span class="tooltiptext"></span>
<div class="text_in_center">
<label name="real_water_lbl" class="output_text"></label><br>
<label name="real_water_numb" class="return_num"></label><br>
<label name="real_water_lbl" class="output_text"></label>
</div>
</div>
<div class="tooltip" id="center" name="real_roof" onmouseover="addTooltipText(this)">
<span class="tooltiptext"></span>
<div class="text_in_center">
<label name="real_roof_lbl" class="output_text"></label><br>
<label name="real_roof_numb" class="return_num"></label><br>
<label name="real_roof_lbl" class="output_text"></label>
</div>
</div>
<div class="tooltip" id="right" name="real_tank" onmouseover="addTooltipText(this)">
<span class="tooltiptext"></span>
<div class="text_in_center">
<label name="real_tank_lbl" class="output_text"></label><br>
<label name="real_tank_numb" class="return_num"></label><br>
<label name="real_tank_lbl" class="output_text"></label>
</div>
</div>
</div>
<a id="caminos_logo2" href="https://www.caminosdeaguamexico.org" target="_blank">
<img class="caminos_logo_img" src="http://caminosdeagua.github.io/rainwater-calculator/img/caminos_logo_circle.png"></img>
</a>
</div>
</div>
<script>
////////////////////////////////////////////////////////////////////
//// function init() ////
//// ////
//// Loads the text in the correct language, and sets up ////
//// some basic form parameters. Initializes the form, ////
//// stores the starting values in a global, and hides all ////
//// error messages and extra text that needs to be hidden. ////
////////////////////////////////////////////////////////////////////
function init() {
if(detectMobile()) { // check if the browser is a mobile browser
applyMobileDisplay()
} else {
location.hash = 0; // hashes (#) are used as a hack to allow the user to navigate
// back/forward in their web browser, since this web-app's
// functionality doesn't involve server calls and is entirely
// javascript- and browser-based.
// See the functions incrementHash() and onhashchange() for details.
initForm();
initEmbeddedMap();
hideComplexOutput();
setTimeout(function() { // a 1 second timeout allows the geojson rain data to load
loadStartingValues();
displayStuff = inputs2outputs(allData);
displayOutputs(displayStuff);
addLanguageText();
}, 1000)
startInterrupt();
}
};
////////////////////////////////////////////////////////////////////
//// function detectMobile() ////
//// ////
//// Checks to see if the user is on a mobile browser. ////
//// Args: none. ////
//// Returns: true if mobile, false otherwise ////
////////////////////////////////////////////////////////////////////
function detectMobile() { // Thanks to Michael Zaporozhets for this function: http://stackoverflow.com/questions/11381673/detecting-a-mobile-browser
var check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
return check;
};
////////////////////////////////////////////////////////////////////
//// function applyMobileDisplay() ////
//// ////
//// Applies the mobile display, removes desktop display. ////
////////////////////////////////////////////////////////////////////
function applyMobileDisplay() {
document.getElementById("mobile_browser_message").innerHTML = MOBILE_BROWSER_MESSAGE;
document.getElementById("everything").style.display = "none";
document.getElementById("mobile_browser_display").style.display = "block";
}
////////////////////////////////////////////////////////////////////
//// function addLanguageText() ////
//// ////
//// Loads the text in the correct display language. ////
////////////////////////////////////////////////////////////////////
function addLanguageText(){
document.getElementById("header").innerHTML = HEADER; // Puts the correct language text on the page
document.getElementById("sub_header").innerHTML = SUB_HEADER; // for all elements
document.getElementById("instructions").innerHTML = INSTRUCTIONS;
document.getElementById("useMonthly_lbl").innerHTML = CHECKBOX_LBL;
document.getElementById("muni0").innerHTML = MUNI0_LBL;
document.getElementById("ppl0").innerHTML = PPL0_LBL;
document.getElementById("length0").innerHTML = LENGTH0_LBL;
document.getElementById("width0").innerHTML = WIDTH0_LBL;
document.getElementById("roof0").innerHTML = ROOF0_LBL;
document.getElementById("cement_roof").nextSibling.data = CEMENT_ROOF_LBL;
document.getElementById("sheet_roof").nextSibling.data = SHEET_ROOF_LBL;
document.getElementById("spanish_roof").nextSibling.data = SPANISH_ROOF_LBL;
document.getElementById("other_roof").nextSibling.data = OTHER_ROOF_LBL;
document.getElementById("calc_button").innerHTML = CALC_BUTTON_LBL;
document.getElementById("back2inputs_button").innerHTML = BACK2INPUTS_BUTTON_LBL;
document.getElementById("header_display").innerHTML = HEADER;
document.getElementById("sub_header_display").innerHTML = LHS_DISPLAY_TITLE;
document.getElementById("instructions_display").innerHTML = LHS_INSTRUCTIONS;
document.getElementById("monthly_rain_lbl").innerHTML = MONTHLY_RAIN_LBL;
document.getElementById("ps_note").innerHTML = PS_NOTE;
var els = document.getElementsByClassName("footer")
for (var i=0; i<els.length; i++) {
els[i].innerHTML = FOOTER_TXT;
};
// label the monthly rain boxes //
els = document.getElementsByName("rain_lbl")
for(var i=0; i<els.length; i++) {
els[i].innerHTML = MONTHS[i]+":";
}
// grab the helper images //
els = document.getElementsByName("roof_imgs");
for(var i=0; i<els.length; i++) {
els[i].innerHTML = "<a href="+ROOF_URLS[i]+"target='_blank'><img src="+ROOF_URLS[i]+" style='height: 126px; width: 126px; margin: 2px; border: 0px; border-radius: 15px;'></img></a>";
}
updateOutputText();
}
////////////////////////////////////////////////////////////////////
//// function initForm() ////
//// ////
//// Initializes the form to not auto-validate so we can ////
//// display our own error messages. ////
////////////////////////////////////////////////////////////////////
function initForm() {
form = document.getElementById("calc_form"); // Sets the global form so everyone can access it;
form.noValidate = true; // Turns off auto-validate so we can self-validate
form.onchange = validateForm;
form.onsubmit = validateForm;
form.onkeyup = validateForm;
}
////////////////////////////////////////////////////////////////////
//// function loadStartingValues() ////
//// ////
//// Loads the starting values into a global array. ////
////////////////////////////////////////////////////////////////////
function loadStartingValues() {
document.getElementById("useMonthly").checked = false; // make sure checkbox defaults to map-view
allData = { // initializes the structure of the global, allData
place: mun,
municipality_name: MUN_STARTING_VALUE,
station_name: STATION_STARTING_VALUE,
ppl: Number(document.getElementById("ppl").value), // and feeds in initial conditions.
length: Number(document.getElementById("length").value),
width: Number(document.getElementById("width").value),
roof_type: 0,
useMonthly: Boolean(document.getElementById("useMonthly").checked)
};
els = document.getElementsByName("roof_type");
for (var i=0; i<els.length; i++) {
if(els[i].checked) {allData.roof_type = els[i].value}
}
}
////////////////////////////////////////////////////////////////////
//// function hideComplexOutput() ////
//// ////
//// Hides the LHS_display. ////
////////////////////////////////////////////////////////////////////
function hideComplexOutput() {
document.getElementById("LHS_display").style.opacity = 0;
document.getElementById("LHS_display").hidden = true;
}
////////////////////////////////////////////////////////////////////
//// function updateLHS(el) ////
//// ////
//// Updateds the LHS depending on whether the use_Monthly ////
//// checkbox is checked. It takes in an HTML element and ////
//// adjusts the display on the LHS accordingly. ////
////////////////////////////////////////////////////////////////////
function updateLHS(el) {
if (el.id == "useMonthly") { // if checkbox is the changed element
if (el.checked) { // if using monthly data
fadeOut(WaterMapDiv, true)
fadeIn(MonthlyUseDiv)
} else { // if using data from the map
fadeOut(MonthlyUseDiv, true)
fadeIn(WaterMapDiv)
document.getElementById("calc_button").disabled = false;
};
}
if (document.getElementById("useMonthly").checked) {
if (anyRain()) {
document.getElementById("calc_button").disabled = false;
} else {
document.getElementById("calc_button").disabled = true;
}
}
}
////////////////////////////////////////////////////////////////////
//// function anyRain() ////
//// ////
//// returns true if there's any rain, otherwise returns ////
//// false. ////
////////////////////////////////////////////////////////////////////
function anyRain() { //
var els = document.getElementsByName("rain");
var totalRain = 0;
for (var i=0; i<MONTHS.length; i++) {
totalRain += Number(els[i].value);
}
var people = Number(document.getElementById("ppl").value);
var sensitivity = totalRain/people;
if (sensitivity > EPSILON) {return true}
else {return false}
}
////////////////////////////////////////////////////////////////////
//// function updateOutputText() ////
//// ////
//// Updates the text that's displayed on the LHS display ////
//// screen after the user submits the form. ////
////////////////////////////////////////////////////////////////////
function updateOutputText() {
var indent = "\xa0\xa0\xa0";
// print monthly rainfall if entered manually.
if (allData.useMonthly) {
DISPLAY_TXT[0] = MONTHLY_USE_TXT+"<br>"
for (var i=0; i<MONTHS.length; i++) {
DISPLAY_TXT[0] += indent+FULL_MONTHS_DISPLAY[i]+": <b>"+allData[RAINS[i]]+"</b>"+UNITS+"<br>";
}
} else { // otherwise display person's location
DISPLAY_TXT[0] = MUN_TXT[0]+allData.municipality_name+MUN_TXT[1]; // Display municipality message
}
// print # of people in household
if (allData.ppl > 1) { // Parse person (1) or people (>1)
DISPLAY_TXT[1] = PPL_TXT[0]+allData.ppl+PPL_TXT[2];
} else {
DISPLAY_TXT[1] = PPL_TXT[0]+allData.ppl+PPL_TXT[1];
}
// print roof dimensions
if (allData.length == 1 && allData.width == 1) {
DISPLAY_TXT[2] = LEN_WID_TXT[0]+allData.length+SINGULAR_DIMENSION+LEN_WID_TXT[1]+allData.width+SINGULAR_DIMENSION+LEN_WID_TXT[2];
} else if (allData.length == 1) {
DISPLAY_TXT[2] = LEN_WID_TXT[0]+allData.length+SINGULAR_DIMENSION+LEN_WID_TXT[1]+allData.width+PLURAL_DIMENSION+LEN_WID_TXT[2];
} else if (allData.width == 1) {
DISPLAY_TXT[2] = LEN_WID_TXT[0]+allData.length+PLURAL_DIMENSION+LEN_WID_TXT[1]+allData.width+SINGULAR_DIMENSION+LEN_WID_TXT[2];
} else {
DISPLAY_TXT[2] = LEN_WID_TXT[0]+allData.length+PLURAL_DIMENSION+LEN_WID_TXT[1]+allData.width+PLURAL_DIMENSION+LEN_WID_TXT[2];
}
// print roof type
DISPLAY_TXT[3] = ROOF_TYPE_TXT[0]+ROOF_TYPES_LOWER[allData.roof_type]+ROOF_TYPE_TXT[1];
var els = document.getElementsByClassName("water_use"); // Display all other water uses.
var els = document.getElementsByName("display_text"); // Actually update all the <p> elements
for (var i=0; i<els.length; i++) {
els[i].innerHTML = DISPLAY_TXT[i];
};
}
////////////////////////////////////////////////////////////////////
//// function keydown(event) [Prevent form submit on enter] ////
//// ////
//// checks to see if the key that was pressed was ////
//// key #13 (enter/return). If so, it prevents the default ////
//// behavior of submitting the form. That way, we never ////
//// send the data anywhere, just calculate some stuff with ////
//// it here. ////
////////////////////////////////////////////////////////////////////
$(document).ready(function() {
$(window).keydown(function(event){
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});
});
////////////////////////////////////////////////////////////////////
//// function keypress(event) [check validity of keystroke] ////
//// ////
//// checks to see if the key that was pressed was ////
//// a valid key. If not, doesn't allow keypress. ////
////////////////////////////////////////////////////////////////////
$('input').bind('keypress', function (event) {
if (event.target.type == "number") { // If it's being entered in a numeric field
//console.log(event)
//console.log("key pressed is: "+event.originalEvent.charCode)
if (!event.originalEvent.charCode) {
return true;
} else if (!numAcceptableKeys.includes(event.originalEvent.charCode)) { // If the key isn't a number or a movement key
event.preventDefault(); // prevent behavior
return false;
} else {
return true;
};
} else { // If the field isn't a number, allow all behavior.
return true;
};
});
////////////////////////////////////////////////////////////////////
//// fucntion validateForm(event) ////
//// ////
//// Takes an element, el. If the value of el is forbidden ////
//// or outside of the relevant ranges, replaces it with the ////
//// closest reasonable alternative. ////
//// This is called every time the form is changed (user ////
//// leaves the relevant element by pressing tab or clicking ////
//// outside). At the end, this function calls updateLHS(el) ////
//// to update the left hand side to account for personal ////
//// monthly rainwater data entry. ////
////////////////////////////////////////////////////////////////////
function validateForm(event) {
event = (event ? event : window.event);
var el = (event.target ? event.target : event.srcElement);
var value = Number(el.value);
if (event.type != 'keyup') {
if (el.id == "ppl") {
if (value < el.min) {
el.value = el.min;
} else if (value > el.max) {
el.value = el.max;
} else if (value % 1 != 0 & el.id == "ppl") {
el.value = parseInt(value, 10);
};
} else if (el.id == "length" | el.id == "width") {
if (value < el.min) {
el.value = el.min;
} else if (value > el.max) {
el.value = el.max;
};
};
}
updateLHS(el)
}
////////////////////////////////////////////////////////////////////
//// functions fadeIn(el), fadeOut(el) ////
//// ////
//// Fades in or out the passed element by adjusting the ////
//// the div element's opacity in steps. Many thanks to: ////////////////////
//// http://www.chrisbuttery.com/articles/fade-in-fade-out-with-javascript/ ////
//// for this simple and lovely bit of js. Cheers! ////
//// If the div is visible, fadeIn does nothing. If it's not, fade out ////
//// does nothing. ////
////////////////////////////////////////////////////////////////////////////////////
function fadeOut(el, hide){
(function fade() {
if ((el.style.opacity -= .09) < 0) {
el.style.opacity = 0;
} else {
requestAnimationFrame(fade);
}
})();
if (hide) {
el.style.display = "none";
};
el.hidden = true;
}
function fadeIn(el){
el.style.opacity = 0;
el.hidden = false;
el.style.display = "inline-block";
(function fade() {
var val = parseFloat(el.style.opacity);
if (!((val += .075) > 1)) {
el.style.opacity = val;
requestAnimationFrame(fade);
}
})();
}
////////////////////////////////////////////////////////////////////
//// --- BUG FIX FOR QUICK BACK/FORWARD CLICK --- ////
//// function startInterrupt() / checkAndPatchLayout() ////
//// ////
//// This interrupt checks to make sure the correct display ////
//// is being shown. For even hashes (#0, #2, #4, etc.) the ////
//// input panel should be full-window. For odd hashes, the ////
//// LHS display and RHS results should share the window. ////
//// startInterrupt() initializes the interrupt which calls ////
//// checkAndPatchLayout(). ////
//// checkAndPatchLayout() adjusts the display LHS/RHS widths////
//// based on the hash's parity. ////
////////////////////////////////////////////////////////////////////
function startInterrupt() {
var myInterval = setInterval( "checkAndPatchLayout()", INTERRUPT_INTERVAL); // interrupts to make sure the panels are being displayed correctly
}
function checkAndPatchLayout() { // this corrects for people rapidly clicking the browser's "back" or "forward" buttons.
var hash = Number(location.hash.substring(1));
if (hash%2 == 0) { // if the hash is even, display the input pane
document.getElementById("left_hand_side").style.width = INPUT_WIDTH_BEFORE;
document.getElementById("right_hand_side").style.width = OUTPUT_WIDTH_BEFORE;
document.getElementById("caminos_logo2").style.display = "none";
} else { // if the hash is odd, display the output/display panes
document.getElementById("left_hand_side").style.width = INPUT_WIDTH_AFTER;
document.getElementById("right_hand_side").style.width = String(window.innerWidth - INPUT_WIDTH_AFTER_RAW - 1)+"px";
document.getElementById("caminos_logo2").style.display = "block";
}
}
////////////////////////////////////////////////////////////////////
//// function displayOutputs ////
//// ////
//// Takes the calculated outputs and displays them on the ////
//// right hand side panel. ////
////////////////////////////////////////////////////////////////////
function displayOutputs(o) {
// Display RHS headers
document.getElementById("min_header").innerHTML = MIN_HEADER;
document.getElementById("real_header").innerHTML = REAL_HEADER;
// Display all text
var elRealRoof = document.getElementsByName("real_roof")[0]
var elRealTank = document.getElementsByName("real_tank")[0]
var elRealTankLbls=document.getElementsByName("real_roof_lbl");
var elMinRoof = document.getElementsByName("min_roof")[0]
var elMinWater = document.getElementsByName("min_water")[0]
var elMinTank = document.getElementsByName("min_tank")[0]
var elMinRoofLbls = document.getElementsByName("min_roof_lbl");
var elMinWaterLbls = document.getElementsByName("min_water_lbl");
var elMinTankLbls = document.getElementsByName("min_tank_lbl");
// if the user's roof IS large enough
if (o.minRoofArea <= o.actualRoofArea) {
elMinRoof.style.backgroundColor = GREEN;
elMinWater.style.backgroundColor = GREEN;
elMinTank.style.backgroundColor = GREEN;
elMinRoofLbls[0].innerHTML = MIN_ROOF_LBL_GREEN[0];
elMinRoofLbls[1].innerHTML = MIN_ROOF_LBL_GREEN[1];
document.getElementsByName("real_tank_numb")[0].innerHTML = numberWithCommas(Math.round(o.actualTankVolume));
} else { // if the user's roof is TOO SMALL
elMinRoof.style.backgroundColor = RED;
elMinWater.style.backgroundColor = RED;
elMinTank.style.backgroundColor = RED;
elMinRoofLbls[0].innerHTML = MIN_ROOF_LBL_RED[0];
elMinRoofLbls[1].innerHTML = MIN_ROOF_LBL_RED[1];
document.getElementsByName("real_tank_numb")[0].innerHTML = numberWithCommas(Math.round(Math.max.apply(null, [o.actualTankVolume, o.maxMonthlyCollection])));
}
// Display all the numbers, rounded to 0 or 2 decimal places, depending
document.getElementsByName("min_roof_numb")[0].innerHTML = numberWithCommas(Math.round(o.minRoofArea));
document.getElementsByName("min_tank_numb")[0].innerHTML = numberWithCommas(Math.round(o.minTankVolume));
document.getElementsByName("real_roof_numb")[0].innerHTML = numberWithCommas(Math.round10(o.actualRoofArea, -2));
document.getElementsByName("min_water_numb")[0].innerHTML = numberWithCommas(Math.round(o.minWater));
document.getElementsByName("real_water_numb")[0].innerHTML = numberWithCommas(Math.round(o.actualWater));
// Fill in more language text
var els=document.getElementsByName("real_tank_lbl");
for (var i=0; i<els.length; i++) {
els[i].innerHTML = REAL_TANK_LBL[i];
}
var els=document.getElementsByName("min_tank_lbl");
for (var i=0; i<els.length; i++) {
els[i].innerHTML = MIN_TANK_LBL[i];
}
var els=document.getElementsByName("real_roof_lbl");
for (var i=0; i<els.length; i++) {
els[i].innerHTML = REAL_ROOF_LBL[i];
}
var els=document.getElementsByName("min_water_lbl");
els[0].innerHTML = MIN_WATER_LBL[0];
els[1].innerHTML = MIN_WATER_LBL[1]+"<b><big>"+numberWithCommas(Math.round(o.essentialDailyUse)) +"</big></b>"+MIN_WATER_LBL[2];
var els=document.getElementsByName("real_water_lbl");
for (var i=0; i<els.length; i++) {
els[i].innerHTML = REAL_WATER_LBL[i];
}
}
////////////////////////////////////////////////////////////////////
//// function incrementHash ////
//// ////
//// Grabs the current hash from the URL and stores it in ////
//// the global "hash". Then increments the URL's hash by 1. ////
////////////////////////////////////////////////////////////////////
function incrementHash() {
hash = Number(location.hash.substring(1));
location.hash = hash+1;
}
////////////////////////////////////////////////////////////////////
//// function onhashchange ////
//// ////
//// When the hash changes, if the parity is the same, do ////
//// nothing. Otherwise, toggle to the other state. After ////
//// toggling, adjust the global "hash" to the current value ////
////////////////////////////////////////////////////////////////////
window.onhashchange = function() {
var hashNumb = Number(location.hash.substring(1));
if (hashNumb%2 != hash%2) { // if we're going to a new page, do some stuff...
if (hashNumb%2 == 1) { // if the new hash is odd, display the output panel
left2right();
} else { // if the hash is even, display the input panel
right2left();
}
hash = Number(location.hash.substring(1)); // update so that current previous hash = current hash
}
}
////////////////////////////////////////////////////////////////////
//// functions left2right / right2left / replace(e0, e1) ////
//// ////
//// The functions execute the preliminary steps in switching////
//// from the input (left) panel to the display/results ////
//// (right) panel: ////
//// left2right --- do all calculations! swap out the LHS ////
//// content, then shift the panel widths. ////
//// right2left --- same as above but without the calcs. ////
//// replace(e0, e1) --- fades out e0 and fades in e1. e0 is ////
//// hidden in the process.
////////////////////////////////////////////////////////////////////
function left2right() {
calculateStuff();
replace('LHS_inputs','LHS_display');
widthShift();
}
function right2left() {
replace('LHS_display','LHS_inputs');
widthShift();
}
function replace(e2hide, e2show) {
fadeOut(document.getElementById(e2hide), true);
fadeIn(document.getElementById(e2show));
}
////////////////////////////////////////////////////////////////////
//// function widthShift ////
//// ////
//// Toggles between the input and results panels. ////
//// Slides all scrollbars to the top after each toggle. ////
////////////////////////////////////////////////////////////////////
function widthShift() {
var lhs = document.getElementById("left_hand_side").offsetWidth;
var rhs = document.getElementById("right_hand_side").offsetWidth;
if (lhs > rhs) {
document.getElementById("left_hand_side").style.width = INPUT_WIDTH_AFTER;
document.getElementById("right_hand_side").style.width = String(window.innerWidth - INPUT_WIDTH_AFTER_RAW - 1)+"px";
document.getElementById("caminos_logo2").style.display = "block";
$("#right_hand_side").scrollTop(0);
$("#LHS_display").scrollTop(0);
} else {
document.getElementById("left_hand_side").style.width = INPUT_WIDTH_BEFORE;
document.getElementById("right_hand_side").style.width = OUTPUT_WIDTH_BEFORE;
document.getElementById("caminos_logo2").style.display = "none";
$("#right_hand_side").scrollTop(0);
$("#LHS_inputs").scrollTop(0);
};
}
////////////////////////////////////////////////////////////////////
//// function inputs2outputs ////
//// ////
//// Takes the user's entered inputs and converts them into ////
//// outputs. This is the function that contains all of the ////
//// citeable-materials, it is the backbone of the actual ////
//// calculation process. ////
//// ////
//// Arguments: ////
//// inputs --- a dictionary of all of the user inputs ////
//// ////
//// Returns: ////
//// outputs --- a dictionary of things to display to ////
//// user. Fields include: ////
//// essentialDailyUse [L/day] ////
//// totalOtherUse [L/day] ////
//// minTankSize [L] ////
//// montlyUse [L] (a 1x12 array with a ////
//// cell for each month's use) ////
//// monlyCollection [L] (1x12 array) ////
//// minWater [L] ////
//// actualWater [L] ////
//// ////
//// Algorithm: ////
//// CHANTAL WILL FILL OUT THIS SECTION OF THE COMMENTS ////
//// WITH HER USUAL FOCUS ON STYLE AND CLARITY =) ////
//// ////
//// Update/Revision History: ////
//// aaron krupp 2/Nov/2016 empty function written ////
//// comments header written ////
////////////////////////////////////////////////////////////////////
function inputs2outputs(inputs) {
var outputs = {essentialDailyUse: 0,
minTankVolume: 0,
minRoofArea: 0,
actualRoofArea: 0,
actualTankVolume: 0,
maxMonthCollection: 0
};
//////////////////////////////////////////////////////////////////
// This next sextion calculates the minimum adequate roof //
// and cistern sizes for the provided family size and area. //
//////////////////////////////////////////////////////////////////
var essential = ESSENTIAL_DAILY_USE * (inputs.ppl); // essential daily use / household
var rainfall;
if (inputs.useMonthly) { // grab monthly use rain
rainfall = [inputs.jan_rain, inputs.feb_rain, inputs.mar_rain, inputs.apr_rain, inputs.may_rain, inputs.jun_rain, inputs.jul_rain, inputs.aug_rain, inputs.sep_rain, inputs.oct_rain, inputs.nov_rain, inputs.dec_rain];
} else {
rainfall = getRainfall(inputs.place); // grabs rainfall from geojson data for the selected polygon.
}
// next lines are for displaying used rain data//
var totalRain = 0;
for (var i=0; i<12; i++){
console.log(FULL_MONTHS[i]+": "+rainfall[i]+" mm"); // use the english version of months so debugging can be consistently in English (in case we do lots of other languages)
totalRain += Number(rainfall[i]);
}
console.log("TOTAL RAINFALL: "+totalRain+" mm");
/////////////////////////////////////////////////
var testArea = 0; // start with area of 0 (it gets bumped up to 1 in the first loop itteration);
var testAreaAdequate = false; // default: user doesn't have adequate roof space.
if (rainfall[0] != -1 && totalRain != 0) { // as long as something's been entered for rainfall: i.e. if the rainfall data has loaded:
while (!testAreaAdequate) { // while there isn't enough roof area
testArea=testArea+1; // increment the area
var test;
if (inputs.useMonthly) {
test = getCisternSize(rainfall, testArea, EFFS[inputs.roof_type], essential ,-1 , inputs.useMonthly) // get the cistern size for entered monthly rainfall
} else {
test = getCisternSize(rainfall, testArea, EFFS[inputs.roof_type], essential , SMA_START_MONTH, inputs.useMonthly) // get cistern size for Independence watershed
}
testAreaAdequate = test.adequate; // and store whether this roof is adeqaute
}
} else { // If the rainfall data hasn't loaded yet
var test = {adequate: false, volume: 0}// fill with some made up data
testArea = 99999999999999; // This is just an outrageously large number
} // so that it will say "your roof isn't big enough!"
// if the user hasn't entered a roof size.
//////////////////////////////////////////////////////////////////
// This next sextion calculates the required minimum cistern //
// size if the user wanted to collect 100% of the water off //
// their provided roof size in the average year. //
//////////////////////////////////////////////////////////////////
var actualArea = inputs.length * inputs.width;
var actual;
if(inputs.useMonthly) {
actual = getCisternSize(rainfall, actualArea, EFFS[inputs.roof_type], essential, -1, inputs.useMonthly);
} else {
actual = getCisternSize(rainfall, actualArea, EFFS[inputs.roof_type], essential, SMA_START_MONTH, inputs.useMonthly);
}
var maxRain = Math.max.apply(null, rainfall);
var maxMonthlyCollection = maxRain*actualArea;
outputs.essentialDailyUse = essential; // Water consumption for cooking & drinking [L/day]
outputs.minTankVolume = test.volume; // once the roof size is adequate, this is the volume of the requisite cistern [L]
outputs.actualRoofArea = actualArea; // the user-provided roof area [m2]
outputs.minRoofArea = testArea; // and this holds the minimum acceptable roof size for supporting the given population [m2]
outputs.actualTankVolume = actual.volume; // cistern volume required to capture 100% of rainfall on user-provided roof area [L]
outputs.maxMonthlyCollection = maxMonthlyCollection // maximum volume collectible in a month
outputs.minWater = 365*essential; // Total water collected off the minimum roof area [L/year]
outputs.actualWater = actual.totalCollected;// Total water collected off the actual roof area [L/year]
return outputs
}
////////////////////////////////////////////////////////////////////
//// function getCisternSize ////
//// ////
//// Args: ////
//// rainfall 1x12 array with monthly rainfall [mm] ////