-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
55 lines (43 loc) · 1.43 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
var API_URL = 'https://api.forecast.io/forecast/245e43548516a03f6afd16e5bf31af69/';
navigator.geolocation.getCurrentPosition(function(location){
var lat = location.coords.latitude;
var long = location.coords.longitude;
getJSONP(API_URL + lat + ',' + long, 'addTempToSpan');
});
var docFragment = document.createDocumentFragment();
// generated by hmtl2dom
var h1 = document.createElement('H1');
docFragment.appendChild(h1);
var text = document.createTextNode("Current Temperature: ");
h1.appendChild(text);
var span = document.createElement('SPAN');
h1.appendChild(span);
var text_0 = document.createTextNode("70");
span.appendChild(text_0);
var text_1 = document.createTextNode("ºF");
h1.appendChild(text_1);
return docFragment;
function addTempToSpan(data) {
debugger;
var body = document.body;
var temperature = data.currently.temperature.toFixed(1);
body.innerHTML = '';
body.appendChild(createWeatherNode(temperature));
//var span = document.querySelector('span');
//span.innerHTML = data.currently.temperature.toFixed(1);
}
function getJSONP(url, cb) {
var script = document.createElement('script');
script.src = url + '?callback=' + cb;
document.body.appendChild(script);
}
/*function getJSON(url, cb) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function () {
if (this.status >= 200 && this.status < 400) {
cb(JSON.parse(this.response));
}
};
xhr.send();
}*/