-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
153 lines (136 loc) · 4.69 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/src/jquery.csv.min.js"></script>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
/>
<style>
div{
text-align: center;
}
</style>
</head>
<body>
<div id="montreal" class="montreal">
<nav class="navbar navbar-light" style="background-color: #ed1b2f;">
<!-- Navbar content -->
<a class="navbar-brand" href="#"><h2>Explore Montreal Murals</h2></a>
</nav>
<h2 style="text-align:center">Explore Montreal Murals</h2>
<p>
<span>Score: {{score}}</span>
</p>
<button @click="changeImage" type="button" class="btn btn-primary">NextImage</button>
<button v-show="displayArtist[0]!=='...'" @click="played(0)" type="button" class="btn btn-danger">{{displayArtist[0]}}</button>
<button v-show="displayArtist[0]!=='...'" @click="played(1)" type="button" class="btn btn-danger">{{displayArtist[1]}}</button>
<button v-show="displayArtist[0]!=='...'" @click="played(2)" type="button" class="btn btn-danger">{{displayArtist[2]}}</button>
<div v-if="isLoading" class="loading"></div>
<div><img v-show="isLoaded" :src="image" @load="loaded"/></div>
<br>
</div>
<script>
var app = new Vue({
el: "#montreal",
data:{
msg: 'Hi all',
code: "",
accessToken: "",
error: false,
times: [],
inputReqID: "",
errorMessage: "",
link: "",
image:"",
isLoaded: false,
isLoading: false,
data:[],
score:0,
artists:[],
displayArtist:[],
correctArtist:-1 // index of correct artist in displayArtist array
},
created: function(){
var vm=this;
this.displayArtist = ["...","...","..."]
this.isLoaded = false;
this.isLoading = true;
$.get( "https://data.montreal.ca/dataset/53d2e586-6e7f-4eae-89a1-2cfa7fc29fa0/resource/f02401c2-8336-4086-9955-4c5592ace72e/download/murales.csv", function( CSVdata) {
vm.isLoaded = false;
vm.isLoading = true;
data = $.csv.toObjects(CSVdata);
var mural_index = Math.floor(Math.random()*234);
vm.image=data[mural_index]["image"];
console.log(data[mural_index]["image"]);
// load every unique artist to array for later access
var tmp = new Set();
for(let i = 0; i<data.length;i++){
tmp.add(data[i]["artiste"]);
}
artists = Array.from(tmp);
vm.updateButtons(mural_index);
});
},
mounted: function() {
console.log(this.code);
},
methods:{
loaded(){
this.isLoaded = true;
this.isLoading = false;
},
changeImage(){
this.isLoaded = false;
this.isLoading = true;
var mural_index = Math.floor(Math.random()*234);
this.image=data[mural_index]["image"];
console.log(data[mural_index]["image"]);
this.updateButtons(mural_index);
},
played(choice){
if(correct==choice){
alert("Great jobs! That's the correct answer. ")
this.score+=1;
}
else{
alert("Wrong Answer! The correct answer is "+this.displayArtist[correct]);
}
this.changeImage();
},
updateButtons(mural_index){
this.displayArtist[0]=data[mural_index]["artiste"];
var tmpIndex = Math.floor(Math.random()*artists.length);
while(artists[tmpIndex]==this.displayArtist[0]){
tmpIndex = Math.floor(Math.random()*artists.length);
}
this.displayArtist[1] = artists[tmpIndex];
while(artists[tmpIndex]==this.displayArtist[0] || artists[tmpIndex]==this.displayArtist[1]){
tmpIndex = Math.floor(Math.random()*artists.length);
}
this.displayArtist[2] = artists[tmpIndex];
this.displayArtist = this.displayArtist.sort(() => 0.5 - Math.random()); // shuffle array
console.log(this.displayArtist);
for(let i = 0; i < this.displayArtist.length;i++){
if(this.displayArtist[i]==data[mural_index]["artiste"]){
correct=i;
}
}
}
}
})
</script>
<style>
.loading {
background: transparent url('https://miro.medium.com/max/882/1*9EBHIOzhE1XfMYoKz1JcsQ.gif') center no-repeat;
height: 400px;
width: 400px;
margin:0 auto;
}
</style>
</body>
</html>