-
Notifications
You must be signed in to change notification settings - Fork 1
/
utility.js
65 lines (56 loc) · 1.89 KB
/
utility.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
var util = {};
(function () {
"use strict";
util.httpReq = function (method, url, callback, data) {
var req = new XMLHttpRequest();
req.addEventListener("readystatechange", function () {
if (req.readyState === 4) {
callback(req.status, req.responseText);
}
});
req.open(method, url);
req.send(data);
};
util.round = function (number, decimals) {
var mul = Math.pow(10, decimals);
return Math.round(number * mul) / mul;
};
util.format = function (number, unit, decimals) {
if (typeof decimals === "number") {
number = util.round(number, decimals);
}
return number + " " + unit;
};
util.formatWOSpace = function (number, unit, decimals) {
if (typeof decimals === "number") {
number = util.round(number, decimals);
}
return number + unit;
};
var weatherIconMap = { // Map DarkSky icon names to our icon files
"clear-day": "sun",
"clear-night": "moon-stars",
"rain": "cloud-rain",
"snow": "cloud-snow",
"sleet": "cloud-sleet",
"wind": "wind",
"fog": "fog",
"cloudy": "clouds",
"partly-cloudy-day": "cloud-sun",
"partly-cloudy-night": "cloud-moon"
};
util.getWeatherIcon = function (iconNameFromDarkSky) {
if (weatherIconMap[iconNameFromDarkSky]) {
return weatherIconMap[iconNameFromDarkSky];
}
return "question-circle";
};
util.isKindle = function () { /* I don't think there is a reliable way to do this */
return navigator.vendor === "Apple Inc." &&
navigator.platform === "Linux armv7l" &&
navigator.mimeTypes.length === 0 &&
navigator.plugins.length === 0 &&
screen.height === 600 &&
screen.width === 800;
};
}());