-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjavascript-test.html
More file actions
161 lines (136 loc) · 5.32 KB
/
Copy pathjavascript-test.html
File metadata and controls
161 lines (136 loc) · 5.32 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
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
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./assets/css/reset.css">
<link rel="stylesheet" href="./assets/css/style.css">
<title>JS test page</title>
</head>
<body>
<style>
* {
box-sizing: border-box;
}
#test-div {
display: grid;
grid-template-columns: 1fr 2fr 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
grid-gap: 20px 20px;
}
.painting-card {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
}
.painting {
width: 200px;
}
.colors {
display: flex;
justify-content: space-between;
}
.block {
width: 60px;
height: 20px;
margin: 5px;
position: relative;
background-color: black;
}
</style>
<div id="test-div"></div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script>
let paintings = [
{
paintingName: "The Harvesters",
objectID: 435809,
palette: ["rgb(214, 152, 70)", "rgb(37, 31, 17)", "rgb(114, 62, 17)"]
// palette: { primaryColor: "", secondaryColor: "", tertiaryColor: "" }
//rainyPalette: {}, nightPalette: {} etc
},
{
paintingName: "Madonna and Child",
objectID: 459136,
palette: ["rgb(11, 6, 9)", "rgb(216, 152, 69)", "rgb(163, 5, 4)"]
},
{
paintingName: "The Dance Class",
objectID: 438817,
palette: ["rgb(85, 94, 56)", "rgb(88, 58, 26)", "rgb(150, 140, 113)"]
},
{
paintingName: "Whalers",
objectID: 437854,
palette: ["rgb(219, 201, 169)", "rgb(193, 180, 147)", "rgb(39, 28, 15)"]
},
{
paintingName: "View of Toledo",
objectID: 436575,
palette: ["rgb(35, 81, 89)", "rgb(71, 68, 49)", "rgb(90, 103, 62)"]
},
{
paintingName: "Young Woman with a Water Pitcher",
objectID: 437881,
palette: ["rgb(17, 40, 64)", "rgb(141, 133, 112)", "rgb(38, 20, 23)"]
},
{
paintingName: "Boating",
objectID: 436947,
palette: ["rgb(101, 134, 166)", "rgb(89, 57, 36)", "rgb(216, 212, 209)"]
},
{
paintingName: "La Berceuse",
objectID: 437984,
palette: ["rgb(29, 89, 68)", "rgb(142, 16, 16)", "rgb(191, 130, 24)"]
},
]
let paintingNumber = 0;
//Met API ajax call
for (let i = 0, numberPaintings = paintings.length; i < numberPaintings; i++) {
paintingNumber = i;
let thisPainting = paintings[paintingNumber];
let metQueryURL = "https://collectionapi.metmuseum.org/public/collection/v1/objects/" + thisPainting.objectID;
$.ajax({
url: metQueryURL,
method: "GET"
}).then(function (response) {
console.log(response);
// if (!isPublicDomain) {
// console.log("Can't use this one!");
// }
let paintingTitle = response.title;
let artist = response.artistDisplayName;
let artistBio = response.artistDisplayBio;
let artistNationality = response.artistNationality;
let medium = response.medium;
//might have to remove all non-number characters from response depending on how this is used
let year = response.objectDate;
let paintingURL = response.primaryImageSmall;
console.log(paintingTitle);
console.log(artist);
console.log(artistBio);
console.log(artistNationality);
console.log(medium);
console.log(year);
console.log(paintingURL);
let newPainting = $("<div>", { class: "painting-card", id: "painting-" + paintingNumber });
let infoSection = $("<section>", { class: "info" });
let paintingImage = $("<img>", { class: "painting", src: paintingURL, alt: "painting" });
infoSection.append(paintingImage);
newPainting.append(infoSection);
let colorSection = $("<section>", { class: "colors" });
for (let j = 0; j < 3; j++) {
let newColor = $("<figure>", { class: "color-" + j + " block", style: "background: " + thisPainting.palette[j] + ";" });
colorSection.append(newColor);
}
newPainting.append(colorSection);
$("#test-div").append(newPainting);
})
}
</script>
</body>
</html>