-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
83 lines (70 loc) · 3.37 KB
/
scripts.js
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
let baseURL = 'https://cors-anywhere.herokuapp.com/https://puppr-676a9.uk.r.appspot.com/';
let baseShelterURL = 'https://torontohumanesociety.com/adopt-a-pet/dogs/';
let matchBtn = document.querySelector("#match");
let rejectBtn = document.querySelector("#reject");
let shelter_array = ["images/doggo.jpg"];
let link_array = ["https://torontohumanesociety.com/adopt-a-pet/dogs/41015170"]; //I'm adding a repeated link for the first fake dog
let dogname_array = ["Molly"];
let dogage_array = ["2"];
let dogdesc_array = ["Molly is the most energetic dog you will ever meet! She is constantly wagging her tail, and running to say hi to people. She absolutely loves park days, and will happily be sprinting back and forth across the field until is completely out of energy, then she will continue running. Molly is one to adore countrysides, with the nice long walks as the sunsets, and playing catch in the grass. She is always curious, and you will always see her saying (or attempting to say) hi to the nearly wildlife. Her favourite toy is the outdoors; rain or shine, winter or summer, as soon as you open that door, she will be outside in a heartbeat."];
let dogsex_array = ["female"];
let dogprimbreed_array = ["Shepherd"];
let dogsecbreed_array = ["Mix"];
const fetchData = (location) => {
axios.get(baseURL + location.toLowerCase())
.then(response => {
for (var key in response.data) {
shelter_array.push(response.data[key]['Photo']);
link_array.push(baseShelterURL + response.data[key]['ID']);
dogname_array.push(response.data[key]['Name']);
dogage_array.push((parseInt(response.data[key]['Age']) / 14).toFixed(0));
dogdesc_array.push(response.data[key]["description"].split("<br/><br/>", 2));
dogsex_array.push(response.data[key]['Sex']);
dogprimbreed_array.push(response.data[key]['PrimaryBreed']);
dogsecbreed_array.push(response.data[key]['SecondaryBreed']);
}
console.log(shelter_array);
console.log(link_array);
});
}
function page_load() {
fetchData('Toronto');
}
let shelter_num = 0;
var slide_i = 1;
show_slide(slide_i);
var i;
function add_slide(n) {
show_slide(slide_i += n);
shelter_num += 1;
if (shelter_num > shelter_array.length) {
shelter_num = shelter_array.length;
}
}
function show_slide(n) {
var pic = document.getElementById("dog-pic");
var name = document.getElementById("dogname");
var age = document.getElementById("dogage");
var sex = document.getElementById("dogsex");
var breed = document.getElementById("dogbreed");
var desc = document.getElementById("dogdesc");
pic.src = shelter_array[n - 1];
name.innerHTML = "Name: " + dogname_array[n - 1];
age.innerHTML = "Age: " + dogage_array[n - 1];
sex.innerHTML = "Sex: " + dogsex_array[n - 1];
breed.innerHTML = "Breed: " + dogprimbreed_array[n - 1] + ", " + dogsecbreed_array[n - 1];
desc.innerHTML = dogdesc_array[n - 1];
}
let selected_dogs = [];
let selected_links = [];
let num = 1;
function add_to_profile() {
selected_dogs.push(shelter_array[shelter_num]);
selected_links.push(link_array[shelter_num]);
add_slide(1);
document.getElementById("dog" + num).src = selected_dogs[num - 1];
num += 1;
}
function open_link(n) {
window.open(selected_links[n - 1]);
}