-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
126 lines (103 loc) · 3.83 KB
/
index.html
File metadata and controls
126 lines (103 loc) · 3.83 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Preparación VISU</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous">
<style>
html, body {
height: 100%;
}
[v-cloak] {
display: none !important;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
<script src="https://unpkg.com/vue@3.2.21"></script>
</head>
<body class="d-flex flex-column flex-grow-1 bg-dark text-light">
<nav class="navbar navbar-dark bg-success">
<div class="container-fluid">
<span class="navbar-brand mb-0 h1">Preparación VISU</span>
</div>
</nav>
<noscript>
<p class="alert alert-error">Esta página necesita JavaScript para funcionar.</p>
</noscript>
<div class="d-flex flex-grow-1" v-cloak id="app">
<div v-if="obj"
class="d-flex flex-column justify-content-end flex-grow-1"
style="background-position: center;background-repeat: no-repeat;background-size: contain;"
v-bind:style="{ backgroundImage: 'url(media/' + obj.image + ')' }">
<div class="d-flex justify-content-between p-3" style="background-color: rgba(0, 0, 0, .8);">
<h4 style="text-shadow: 0 0 10px #000;">
<i>{{ obj.name }}</i> ({{ obj.family }}) <span v-if="obj.discoverer"> - {{ obj.discoverer }}</span>
</h4>
<button class="btn btn-light" v-on:click="advance()">Siguiente</button>
</div>
</div>
<div v-if="!obj" class="container my-3 text-center">
<button class="btn btn-light" v-on:click="advance()">¡Comenzar!</button>
</div>
</div>
<script>
// The following code was written by P. Sempere on 3 Nov 2021
// between 19:48 and 21:05 to help their partner with their examns
fetch('data.json')
.then(response => response.json())
.then(data => {
let indexes = new Array();
let iterator = indexes.values();
// To be random we generate an array of random indexes and
// iterate over it, when we've finished the iteration, we simply
// generate another one
function generateIndexes() {
// Generate a new array so we start fresh
indexes = new Array(data.length);
// The following loop does NOT iterate over the first position
// so we must ensure that it always gets a value
indexes[0] = 0;
// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
for (let i = indexes.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
const temp = indexes[i] || i;
indexes[i] = indexes[j] || j;
indexes[j] = temp;
}
iterator = indexes.values();
}
// First generation
generateIndexes();
const App = {
data() {
return {
obj: null,
}
},
methods: {
advance() {
let next = iterator.next();
if (next.done) {
generateIndexes();
// We assume that we have at least one item in data
next = iterator.next();
}
this.obj = data[next.value];
}
}
};
Vue.createApp(App).mount('#app');
})
.catch(err => {
console.error(err);
window.alert('¡No se pudieron cargar los datos!');
})
</script>
</body>
</html>