-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
83 lines (75 loc) · 2.78 KB
/
index.html
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
<!DOCTYPE html>
<html lang="es">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8" />
<title>Conversor CelFar</title>
<script type="text/javascript" src="js/jquery-1.7.min.js"></script>
<script type="text/javascript" src="js/bugomatic.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
new BugOMatic('js').start();
});
var VAL_DECIMALS = 0;
var VAL_LENGTH = 1;
var VAL_ZERO = 2;
var validators = [
{"valid" : function(input) {return input.length != 0 && !isNaN(input);}, "error": "El valor ingresado no es un número (recuerde que los decimales deben expresarse con '.' y no con ',')"},
{"valid" : function(input) {return input.replace(/[^\d]/g,'').length < 7; }, "error": "El valor ingresado es muy largo"},
{"valid" : function(input) {return parseInt(input) >= -273;}, "error": "El valor ingresado está debajo del <a href='http://es.wikipedia.org/wiki/Cero_absoluto'>0 absoluto</a>"},
];
function celcius_to_fahrenheit(celcius) {
return ((parseFloat(celcius)*9.0)/5.0) + 32;
}
function fahrenheit_to_celcius(fahrenheit) {
return (parseFloat(fahrenheit) - 32)*5.0/9.0;
}
var converters = {"celcius" : celcius_to_fahrenheit, "fahrenheit" : fahrenheit_to_celcius };
function validate(validators, value) {
var valid = true;
$(validators).each(function() {
if (!this.valid(value)) {
$("#output").append(this.error + "</br>");
return valid = false;
}
});
return valid;
}
function convert() {
$("#output").empty();
input = $("#input")[0];
var converter = converters[$("#input_type")[0].value];
var valid = validate(validators, input.value);
if (valid) {
$("#output").append(converter(input.value));
}
}
function reset_output() {
$("#output").empty().append("Pendiente de cálculo...");
}
$(document).ready(function() {
reset_output();
$("#input").keyup(function(event){
if (event.keyCode != 13) {
reset_output();
}
});
$("#converterform").submit(function() {
convert();
return false;
});
});
</script>
<h1>CelFar</h1>
<p id="description">Conversor de temperaturas entre grados <a href="http://es.wikipedia.org/wiki/Grado_Celsius">Celcius</a> y <a href="http://es.wikipedia.org/wiki/Grado_Fahrenheit">Fahrenheit</a></p>
<div id="converter">
<form id="converterform" action="">
<input id="input" class="input" type="text" />
<input type="submit" class="button" value="convertir!"/>
<span id="output" class="output"></span>
<input id="input_type" type="hidden" value="celcius"/>
</form>
</div>
</body>
</html>