-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrid.js
101 lines (79 loc) · 2.85 KB
/
grid.js
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
"use strict";
// Define constants
var touchInteractionEnabled = false;
var isPortrait = window.matchMedia('(orientation: portrait)').matches;
// Define getter and setters for saving and retrieving local storage variables or default variables
if (inEditMode && isPortrait) {
// Override zoom when editing grid in portrait mode
// we may need it later
}
if (!inEditMode) {
// we may need it later
}
// Hook onto event that triggers on value change
function subscribeGridItem(definition) {
var formatter = definition.formatter;
var type = definition.type;
definition.unsubscribe();
definition.subscribe(function(value) {
if ($.isNumeric(value)) {
updateGridItem(definition, formatter(value));
} else {
updatePoiItem(definition, formatter(value.numberOfPois), value.lastPoi);
COBI.app.textToSpeech.write({content : "Grab a 🍺 in " + value.lastPoi, language : "en-US"});
presentSnackbar(value.lastPoi);
//var toast = value.lastPoi;
//M.toast({html: toast, displayLength: 5000, classes: "rounded"});
}
});
}
function updatePoiItem( definition, value, poiname) {
$('#' + definition.id + ' .value').html(`${value}`);
//$('#' + definition.id + ' .unit').html(`${poiname}`);
definition.value = value;
// update_crystal(group, definitions);
}
function linkDefinition( definition) {
$('#' + definition.id + " .label").html(definition.name);
$('#' + definition.id + " .unit").html(definition.unit);
$('#' + definition.id + " .value").html(definition.defaultValue);
subscribeGridItem(definition);
}
function hookDefinitions() {
linkDefinition(definitions[0]);
linkDefinition(definitions[4]);
linkDefinition(definitions[8]);
linkDefinition(definitions[6]);
linkDefinition(definitions[1]);
linkDefinition(definitions[2]);
linkDefinition(definitions[3]);
var container = $('#tamagochi')
}
// Update dom element with values for item
function updateGridItem(definition, value) {
$('#' + definition.id + ' .value').html(`${value}`);
// update_crystal(group, definitions);
definition.value = value;
}
function presentSnackbar(poi) {
var x = document.getElementById("snackbar");
x.innerHTML = "Grab a 🍺 in " + poi;
x.className = "show";
setTimeout(function(){ x.className = x.className.replace("show", ""); }, 4000);
}
$(window).on('load', function(e) {
var first_fix = false;
hookDefinitions();
COBI.mobile.location.subscribe(function(value, timestamp) {
if (!first_fix) {
biergarten.init(value.coordinate.latitude, value.coordinate.longitude, 10000);
first_fix = true;
}
biergarten.add_position(value.coordinate.latitude, value.coordinate.longitude)
});
crystal_init(definitions);
crystal_animate();
window.setInterval(function() {
update_crystal(group, definitions);
}, 1000);
});