-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
117 lines (87 loc) · 3.02 KB
/
main.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
(function($) {
'use strict';
var geo = null;
window.geocode = function(latitude, longitude) {
let ifr = document.getElementById('geocode');
if (geo == null) {
geo = ifr.contentWindow;
}
const promise = new Promise(function(resolve, reject) {
window.addEventListener('message', __onMessage);
if (!ifr.status) {
ifr._ifrloaded = function() {
geo = ifr.contentWindow;
__call();
};
} else {
__call();
}
function __call() {
geo.postMessage({latitude:latitude, longitude:longitude}, '*');
}
function __onMessage(event) {
let data = event.data;
if (typeof data === 'string') {
data = JSON.parse( data );
}
window.removeEventListener('message', __onMessage);
if (data.status !== 'OK') {
reject( data );
} else {
resolve( data );
}
}
});
return promise;
}
/** @brief When our location has been successfully established.
* @param position Our location.
*/
function geoSuccess(position) {
var clock = $('#canvas').data('contextualClock');
clock.setCoords(position.coords.latitude,
position.coords.longitude);
$('#status').addClass('success')
.html( clock.geoStr() );
// http://maps.googleapis.com/maps/api/geocode/json?latlng=39.40,-76.94&sensor=true
}
/** @brief When our location has been successfully established.
* @param position Our location.
*/
function geoError(msg) {
$('#status').addClass('error')
.html( ($.type(msg) === 'string' ? msg : 'failed') );
}
function _ready() {
geo = document.getElementById('geocode').contentWindow;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
} else {
geoError('not supported');
}
//$('#canvas').contextualClock({interval:10, test:true});
$('#canvas').contextualClock({interval:500});
//$('#canvas').contextualClock({interval:2});
}
$(document).ready(function() {
let ifr = document.getElementById('geocode');
if (!ifr.status) {
ifr.onload = function() {
if (ifr._ifrloaded) { ifr._ifrloaded(); }
};
}
_ready();
/*
let iframe = document.getElementById('geocode');
iframe.onload = function() { return _ready(); };
// */
/*
$('<iframe/>', {
id: 'geocode',
src: 'geocode.html',
style: 'display:none',
load: _ready
}).appendTo('body');
// */
});
}(jQuery));