-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
81 lines (69 loc) · 2.66 KB
/
script.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
;
(function(angular) {
'use strict';
function isNumeric(num) {
return !isNaN(num);
}
// http://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number
function decimalPlaces(num) {
var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
if (!match) {
return 0;
}
return Math.max(
0,
// Number of digits right of decimal point.
(match[1] ? match[1].length : 0)
// Adjust for scientific notation.
- (match[2] ? +match[2] : 0));
}
function toFloat(num, decPlaces) {
return num.toFixed(decPlaces);
}
function convertNumbers(input, factor) {
var lines_in = input.split("\n");
var lines_out = [];
for (var i = 0; i < lines_in.length; i++) {
var words_in = lines_in[i].split(" ");
var words_out = [];
for (var j = 0; j < words_in.length; j++) {
var word = words_in[j];
if (words_in[j] != "") {
if (isNumeric(words_in[j])) {
var num_dec = decimalPlaces(words_in[j])
word = toFloat(words_in[j] * factor, num_dec);
}
}
words_out.push(word);
}
lines_out.push(words_out.join(" "));
}
return lines_out.join("\n");
}
angular.module('myapp', [])
.filter('convert', function() {
return function(input, factor) {
input = input || '';
return convertNumbers(input, factor);
};
})
.controller('mycontroller', ['$scope', '$http', function($scope, $http) {
$scope.angstrom = '';
$scope.bohr = '';
$scope.factor = 0.52917721067;
$scope.getGitInfo = function() {
$scope.loaded = false;
$http.get("https://api.github.com/repos/bast/angstrom-bohr/git/refs/heads/gh-pages")
.success(function(data) {
$scope.last_sha = data.object.sha;
$scope.last_sha_short = data.object.sha.substring(0, 8);
$http.get("https://api.github.com/repos/bast/angstrom-bohr/commits/" + $scope.last_sha)
.success(function(data) {
$scope.last_version_date = data.commit.author.date;
$scope.loaded = true;
})
})
}
$scope.getGitInfo();
}]);
})(window.angular);