forked from Klerith/jquery-avanzado
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path034.html
68 lines (43 loc) · 1.44 KB
/
034.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Avanzado</title>
<!-- Estilo del Boostrap 4 -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/estilo.css">
</head>
<body>
<h1>Algún texto</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor.
</p>
<a class="fetchSize" href="001.html">Archivo 001.html</a>
<a class="fetchSize" href="034.html">Archivo 034.html</a>
<a class="fetchSize" href="assets/img/ball.png">Pelota</a>
<!-- Librería de jQuery -->
<script src="assets/libs/jquery-3.min.js" charset="utf-8"></script>
<script>
$('a.fetchSize').each( function(){
var link = this;
$.ajax({
type: 'HEAD',
url: link.href,
complete: function(xhr){
var size = xhr.getResponseHeader('Content-Length');
size = humanizar(size);
// append a los links
$(link).append('('+ size +')');
}
});
});
function humanizar( size ){
var unidades = ['bytes','KB','MB','GB','TB'];
var ord = Math.floor( Math.log(size) / Math.log(1024) );
ord = Math.min( Math.max(0,ord), unidades.length -1 );
var s = Math.round( (size/Math.pow(1024,ord)) * 100 ) / 100;
return s + ' ' + unidades[ord]
}
</script>
</body>
</html>