This repository has been archived by the owner on Jan 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
executable file
·249 lines (206 loc) · 9.93 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<!doctype html>
<html>
<head>
<!-- this is the proper meta tag to use common special characters, etc. -->
<meta charset="UTF-8" />
<!-- this is necessary for responsive @media queries to work properly -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The Title to your website. Shows in the browser tab or window, as well as in search engine results. Not actually on the page anywhere -->
<title>Hack the Behance API</title>
<link href="https://opensource.keycdn.com/fontawesome/4.7.0/font-awesome.min.css" type="text/css" rel="stylesheet" />
<link href="basics.css" type="text/css" rel="stylesheet" />
</head>
<body>
<header>
<h1>Hack the Behance API</h1>
Your sitename, logo, links, etc. can go here. You'll probably want to replace what's in the headline tag with your name or something.
</header>
<main>
<h1>Work.</h1>
<div id="behance-magix">
<!-- insert some HTML via magic JS -->
<!-- this initially seeds the main div and shows something here even if JS doesn't load -->
<p>This will be erased when javascript draws our new content. But, you can also put other things here incase the behance API is down or for some other reason the javascript doesn't run/load, or if you burned through your 100 calls/hr. So maybe a placeholder image of a few of your projects, maybe a little explainer text, or something similar?</p>
<!-- ================================================== -->
<!-- ================================================== -->
<!-- this is the template for each project Thumbnail/Title combo -->
<!-- this will be replaced w/ all our items! -->
<!-- one project Card per project/entry on behance -->
<!-- ================================================== -->
<!-- ================================================== -->
<script id="project-cards" type="text/template">
{{#projects}}
<div class="project" id="b{{id}}">
<a href="#{{id}}" data-project-id="{{id}}">
<div class="image-wrapper">
<img src="{{covers.404}}" alt="{{name}}" />
</div>
<div class="info">
<h2 class="name">{{name}}</h2>
</div>
</a>
</div>
{{/projects}}
</script>
</div>
</main>
<footer>
<p>© copyright <span class="year dynamic">2017</span> YOUR NAME, or other footer-y stuff, etc.</p>
</footer>
<div id="dynamic-pages">
<!-- individual pages will appear to "print" here -->
</div>
<div id="anOrder" class="hidden">
<script id="order" type="text/template">
{{#projects}}
<div data-project-id="{{id}}">
{{id}}
</div>
{{/projects}}
</script>
</div>
<!-- All your javascript (other than typekit related stuff) -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- ================================================== -->
<!-- ================================================== -->
<!-- ================================================== -->
<!-- ================================================== -->
<!-- this is jquery, needed for a bunch of stuff -->
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<!-- this is mustache, required for the templating to happen -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.3.0/mustache.min.js"></script>
<!-- link to jquery cycle -->
<script src="http://malsup.github.io/min/jquery.cycle2.min.js"></script>
<!-- this makes the year in your footer always the current year -->
<script>
// dynamically update the year in the footer (not the best idea, but this works!...)
var d = new Date();
var year = d.getFullYear();
console.log('It is ' + year + '.');
$('footer .year.dynamic').html(year);
</script>
<script>
// your behance user machine name. Take it from your profile url
// www.behance.net/userName
var userName = 'kristianbjornard'
// this is your behance APIkey — figure out how to set this up at » URL TO COME
var apiKey = '5T8WWYiQqGy7sJV1sEQIdO2k8CDNDQS7'
// this url will provide a feed of content for the site based on your userName and apiKey.
var url = 'https://api.behance.net/v2/users/' + userName + '/projects/?api_key=' + apiKey +'&per_page=25&callback=?';
/* some issue where no more than 25 can be returned at a time, there are ways to ask for more? https://help.behance.net/hc/communities/public/questions/202357274-Number-of-Behance-API-request-results-limited-to-25- */
// log url in console to make sure that things are working so far.
// you can view this log output in console in developer tools in your browser.
console.log('connected to ' + url + '.');
// this is where the actual magic happens.
// $.getJSON is a jquery command that asks for JSON from a url and then lets you run functions on it.
$.getJSON(url, function(data) {
//mustache for project list/grid
var template = $('#project-cards').html();
var info = Mustache.to_html(template, data);
$('#behance-magix').html(info);
var template2 = $('#order').html();
var info2 = Mustache.to_html(template2, data);
$('#anOrder').html(info2);
$('.project a').click(function() {
$(this).parent().addClass("active");
// each project has a unique ID, we need it to build our project JSON url
var projectID = $(this).attr('data-project-id');
var nextProjectID = $(this).parent().attr('data-project-id');
var prevProjectID = $(this).attr('data-project-id');
// this then constructs the url for an individual project
var projectUrl = 'https://api.behance.net/v2/projects/' + projectID + '/?api_key=' + apiKey +'&callback=?';
// then we log the result to the console so we can double check that this is working correctly
console.log('trying to show ' + projectUrl + '.');
// okay, now since we're showing the project as a popup on top
// we need to stop the body from scrolling and only allow our popup to scroll
$('body').addClass('stop-scrolling');
console.log('body should stop scrolling and only overlay should scroll');
// we then run another getJSON request with the newly made individual project url
// this will allow us to on the fly generate some “pages” for our projects.
// more mustache templating will then happen
$.getJSON(projectUrl, function(data) {
//mustache for individual project “page”
var template = $('#project-page').html();
var info = Mustache.to_html(template, data);
$('#dynamic-pages').html(info);
$('.media_collection .slideshow').cycle({
fx: "scrollHorz",
slides: ".slide",
pager: ".cycle-pager"
});
$('.project-page button.close').click(function() {
$(this).parent().hide();
$('body').removeClass('stop-scrolling');
console.log('overlay should go away and body should go back to scrolling');
});
});
});
});
</script>
<!-- this is the template for our individual projects -->
<!-- ================================================== -->
<!-- ================================================== -->
<!-- ================================================== -->
<!-- ================================================== -->
<!-- this will print in the above "dynamic-pages" area -->
<script id="project-page" type="text/template">
<div class="project-page" id="project-{{project.id}}">
<div class="controls">
<button id="next"><i class="fa fa-hand-o-left fa-2x"></i></button>
<button id="prev"><i class="fa fa-hand-o-right fa-2x"></i></button>
</div>
<div class="container">
<h1>{{project.name}}</h1>
<p>{{project.description}}</p>
<ul class="modules-list list-reset">
{{#project.modules}}
<li class="module {{type}}">
{{#sizes}}<img src="
{{#sizes.max_1200}}{{sizes.max_1200}}{{/sizes.max_1200}}
{{^sizes.max_1200}}{{sizes.original}}{{/sizes.max_1200}}
" />
{{/sizes}}
{{#text_plain}}<p>{{text_plain}}</p>{{/text_plain}}
{{#original_embed}}<p>{{{original_embed}}}</p>{{/original_embed}}
<div class="slideshow">
{{#components}}
<div class="slide">
{{#sizes}}<img src="
{{#sizes.max_1200}}{{sizes.max_1200}}{{/sizes.max_1200}}
{{^sizes.max_1200}}{{sizes.original}}{{/sizes.max_1200}}
" />
{{/sizes}}
</div>
{{/components}}
</div>
<div class="cycle-pager"></div>
</li>
{{/project.modules}}
</ul>
<p>
<small>
<a href="{{project.url}}" target="_blank">See the original {{project.name}} post on Behance.net</a>
</small>
</p>
</div>
<button class="close"><i class="fa fa-times fa-2x"></i></button>
</div>
</script>
<style>
.slideshow, .slideshow * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
.slideshow { width: 100%; min-width: 200px; margin: auto; padding: 0; }
/* images */
.slideshow img {
width: 100%;
position: static;
display: block;
}
/* divs */
.slideshow div {
position: absolute; top: 0; left: 0;
width: 100%; padding: 0;
display:block;
}
</style>
</body>
</html>