This repository was archived by the owner on Jan 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdemoid.html
More file actions
85 lines (75 loc) · 3.26 KB
/
demoid.html
File metadata and controls
85 lines (75 loc) · 3.26 KB
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
84
85
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Un audio por ID</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<style type="text/css">
#datos{
margin-top:40px;
}
.tarjeta{
max-width: 430px;
}
</style>
</head>
<body>
<div class="container" id="datos">
<img id="cargando" src="https://ebarnette15.files.wordpress.com/2013/03/loading-3.gif%3Fw%3D150%26h%3D120">
</div>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script type="text/javascript">
function sacarVariablesUrl() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
};
function iniciar () {
id = sacarVariablesUrl()["id"] || "3311086";
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
datos = JSON.parse(xmlHttp.responseText);
console.log(datos)
dato = datos.page.items[0];
var datosListos = '<div class="panel panel-info tarjeta">';
datosListos += '<div class="panel-heading" id="titulo"><strong>'+dato.title+'</strong></div>';
datosListos += '<div class="panel-body"><a target="_blank" href="http://www.rtve.es/drmn/embed/audio/'+id+'"><img src="'+dato.imageSEO+'" alt="'+dato.alt+'"></a>';
if (dato.programInfo && dato.programInfo.title != null) {
datosListos += '<h4>En '+dato.programInfo.title+'</h4>';
};
datosListos += '<p>'+dato.description+'</p>';
if (dato.programInfo && dato.programInfo.ageRange != null) {
datosListos += '<p><span class="pull-left"><em>'+dato.programInfo.ageRange+'</em></span>';
};
datosListos += '<span class="glyphicon glyphicon-eye-open pull-right">'+dato.numVisits+'</span></p></div>';
datosListos += '<div class="text-center panel-footer">';
datosListos += '<a target="_blank" href="'+dato.htmlUrl+'">Ver más</a></div>';
datosListos += '</div>';
document.getElementById("cargando").style.display = "none";
document.getElementById("datos").innerHTML = datosListos;
} else if (xmlHttp.readyState === 4 && xmlHttp.status === 400) {
datos = JSON.parse(xmlHttp.responseText);
console.error("ERROR! 400 - Solicitud incorrecta!");
document.getElementById("cargando").style.display = "none";
document.getElementById("datos").innerHTML += "<h3>ERROR! 400 - Solicitud incorrecta!</h3>";
} else if (xmlHttp.readyState === 4 && xmlHttp.status === 404) {
datos = JSON.parse(xmlHttp.responseText);
console.error("ERROR! 404 - No encontrado!");
document.getElementById("cargando").style.display = "none";
document.getElementById("datos").innerHTML += "<h3>ERROR! 404 - No encontrado!</h3>";
}
};
xmlHttp.open("GET", "http://api.rtve.es/api/audios/"+id+".json", true);
xmlHttp.send();
};
iniciar();
</script>
</body>
</html>