-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
187 lines (173 loc) · 4.81 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>API Homework</title>
<script src="https://fb.me/react-0.13.3.js"></script>
<script src="https://fb.me/JSXTransformer-0.13.3.js"></script>
<script type="text/jsx;harmony=true">
const url = 'https://api.indiegogo.com/1/campaigns.json?api_token=e377270bf1e9121da34cb6dff0e8af52a03296766a8e955c19f62f593651b346'
function makeRequest (url, callback) {
var httpRequest;
if (window.XMLHttpRequest) {
httpRequest = new XMLHttpRequest();
}
httpRequest.onreadystatechange = responseHandler;
httpRequest.open('GET', url);
httpRequest.send();
function responseHandler () {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) {
callback(JSON.parse(httpRequest.responseText));
} else {
alert('There was a problem with the request.');
}
}
}
}
makeRequest(url, data => {
React.render(<App cards={data.response} />, document.body)
})
var Card = React.createClass({
getInitialState(){
return {
showDetails: false
}
},
toggleDetailsVisibility(){
this.setState({
showDetails: !this.state.showDetails
})
},
render(){
return (
<a key={this.props.data.id} href={this.props.data.web_url}>
{ this.state.showDetails ?
<div style={styles.card} onMouseEnter={this.toggleDetailsVisibility} onMouseLeave={this.toggleDetailsVisibility}>
<h2 style={styles.title}>{this.props.data.title}</h2>
<span style={styles.title}>{this.props.data.tagline}</span>
</div>
:
<div style={styles.card} onMouseEnter={this.toggleDetailsVisibility} onMouseLeave={this.toggleDetailsVisibility}>
<img style={styles.img} src={this.props.data.baseball_card_image_url} />
</div>
}
</a>
)
}
})
var App = React.createClass({
getInitialState(){
return {
filterText: ''
}
},
setFilterText(event){
this.setState({
filterText: event.target.value
})
},
filterCards(cards, filterText){
return filterText === '' ? cards : cards.filter(card => (card.title+card.tagline).toLowerCase().indexOf(filterText.toLowerCase())>-1)
},
renderFilter(){
return (
<h1 style={styles.h1}>{'Search Campaigns:'}
<input type='text' onChange={this.setFilterText} style={styles.filter} />
</h1>
)
},
hide(){
styles.title.display = 'none';
styles.tagline.display = 'none';
console.log(this)
},
show(){
styles.title.display = 'block';
styles.tagline.display = 'block';
console.log(this)
},
renderCards(){
return this.filterCards(this.props.cards, this.state.filterText).map(card => {
return (
<Card data={card} />
)
})
},
render(){
return (
<div style={styles.body}>
{this.renderFilter()}
<div style={styles.container}>
{this.renderCards()}
</div>
</div>
)
}
})
const styles = {
/* IndieGoGo Color Palette:
#ee0577 Pink
#f3f4f4 grey
#6A6A6A dark grey */
body: {
backgroundColor: 'white',
margin: 0,
padding: 0,
fontFamily: 'Helvetica, sans-serif'
},
container: {
maxWidth: '1100px',
marginLeft: 'auto',
marginRight: 'auto',
},
h1: {
fontSize: '71px',
letterSpacing: '1px',
backgroundColor: '#ee0577', /*IndieGoGo Pink*/
color: 'white',
boxShadow: '0 1px 4px #6A6A6A', /*dark grey*/
margin: 0,
marginLeft: '-115px',
padding: '10px',
textAlign: 'center'
},
filter: {
color: '#ee0577', /*IndieGoGo Pink*/
height: '70px',
fontSize: '50px',
maxWidth: '315px',
marginRight: '-31px',
verticalAlign: 'middle',
marginTop: '-5px',
marginLeft: '5px',
outline: 0
},
card: {
float: 'left',
boxShadow: '0 1px 4px #6A6A6A', /*dark grey*/
width: '320px',
height: '320px',
margin: '10px'
},
img: {
width: '320px',
height: '320px'
},
title: {
fontSize: '24px',
textAlign: 'center',
color: '#ee0577', /*IndieGoGo Pink*/
},
tagline: {
textAlign: 'left',
marginLeft: '10px',
marginRight: '10px',
color: '#6A6A6A' /*dark grey*/
}
}
</script>
</head>
<body>
</body>
</html>