-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathunsplash.html
325 lines (304 loc) · 14.7 KB
/
unsplash.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--
# Flickr image slide show #
## Supported URI Query Parameters ##
Supports the following URI Query Parameters:
* TAGS : (required) the tags to use to search for images (separated by
commas ("%2C" when URI encoded)
* Default : "wild"
* INTERVAL : (optional) the slide interval in seconds
* Default : 3
* NUM_ITEMS : (optional) the number of images to include with the
slide show
* Default : 10
* TITLE : (optional) the title to use for the slide show
* LANG : (optional) the language to use for slide show text (like the
"Images from Flickr" and "by {ownername}" texts)
* "en" - English (Default)
* "nb" - Norwegian Bokmål
* "nn" - Norwegian Nynorsk
* API_KEY : (optional) a Flickr API Key. Specify this if more fine-
grained filtering is required (like only "Commercial use allowed")
* Uses the "flickr.photos.search" API instead of the Feed Service
Examples:
flickr.html?TAGS=national%2Cday%2Cnorway&INTERVAL=10&MAX_ITEMS=10
* Slide show with 10 items with the tags national, day, norway
(Norway National Day) shown with an 10 seconds interval
flickr.html?TAGS=easter%2Choliday%2Ccelebration&MAX_ITEMS=20
* Slide show with 20 items with the tags easter, holiday,
celebration (Easter Holiday Celebration) shown with the default
3 seconds interval
-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="coin-slider/coin-slider.js"></script>
<script type="text/javascript" src="../shared/lib/moment-with-locales.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="../shared/lib/jquery.transit.min.js" charset="UTF-8"></script>
<link rel="stylesheet" href="coin-slider/coin-slider-styles.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" type="text/css" href="../gcalflow/styles/loader.css" />
<title>Coin Slider: jQuery Image Slider Plugin with Unique Effects</title>
</head>
<body class="unsplash" data-lang="en">
<div id="loader-wrapper">
<div id="loader"></div>
<div class="loader-section section-left"></div>
<div class="loader-section section-right"></div>
</div>
<div id="header"></div>
<div id="games"></div>
<script>
jQuery.fn.animate = jQuery.fn.transit;
/**
* <http://stackoverflow.com/a/5158301>
*/
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
/**
* Get the current screen orientation
*
* @returns {string} a Flickr-compatible orientation string
*/
function getOrientation() {
var h = window.innerHeight,
w = window.innerWidth;
if (h < w) {
return "landscape";
}
if (h > w) {
return "portrait";
}
return "square";
}
// The base URL of the Flickr API Services
var baseUrl = "https://api.unsplash.com/",
baseHeight = 270, // The base slide show height
baseWidth = 480, // The base slide show width
sliderHeight = baseHeight + 0, // The slide show height
sliderWidth = baseWidth + 0, // The slide show width
orientation = getOrientation(), // The current screen orientation
imageOrientation = [orientation], // The preferred image orientations
initCoinSlider = null;
if (orientation == "square") {
// If orientation is "square" include both "landscape" and
// "portrait" with image orientations
imageOrientation.push("landscape", "portrait");
// Also set the slider width to the same as base height
sliderWidth = baseHeight + 0;
} else if (orientation == "portrait") {
// If orientation is "portrait", calcluate the correct slider width
// and slider height based on the window aspect ratio (window width
// divided by window height)
sliderWidth = baseHeight * (window.innerWidth / window.innerHeight);
sliderHeight = baseWidth * (window.innerWidth / window.innerHeight);
} else {
// Otherwise, we assume the orientation is "landscape" and set the
// slider width and height to their base width and height
sliderWidth = baseWidth;
sliderHeight = baseHeight;
}
/**
* Create a Coin Slider Item
* @param {URI} src - the image URI source
* @param {string} title - the title of the image
* @param {string|Date} datetaken - the date when the image was taken
* @param {string} ownername - the name of the owner of the image
*/
var createItem = function (src, title, datetaken, ownername) {
// Create a MomentJS Calendar string from "datetaken"
var sDate = moment(datetaken).calendar();
// Create a heading consisting of the "title" and the date string
var heading = "<b>" + title + "</b> <span>(" + sDate + ")</span>";
// Create a description of the "ownername"
var desc = "<span class=\"ownername\"><span>" + ownername + "<span></span>"; //"by " +ownername;
var $elem = $("<a/>"); // The item element to use
// Append a IMG element to the item element with its "src" attribute
// set to the image URI source
$("<img/>").attr({ src: src }).appendTo($elem);
// Append the heading and the description to the item element
// separated by a BR (hard break) element
$elem.append("<span>" + heading + "<br /> " + desc + "</span>");
// And at last append the item element to the slide show element
$elem.appendTo("#games");
};
/**
* Called when the window is resized
*/
var onResizeWindow = function () {
var h = window.innerHeight,
w = window.innerWidth;
function getMozTransform(scale) {
var translateX = "translateX(-50%)",
scale = "scale(" + scale + ")";
return {
"-moz-transform": translateX + " " + scale
};
}
//if (h < w) {
// Set the zoom level of the slide show element from the window/base
// height ratio
$("#games").css("zoom", h / baseHeight)
.css(getMozTransform(h / baseHeight));
//} else {
//$("#games").css("zoom", w / baseWidth);
//}
};
var createPlaceholderImages = function (num, lang) {
var placeholders = {
"en": "no-images-en.jpg",
"nb": "no-images-nb.jpg",
"nn": "no-images-nb.jpg"
}
var placeholder = placeholders[lang] || placeholders["en"];
console.log(placeholder);
$("body").css("background-image", 'url("' + placeholder + '")');
$("body").css("background-size", "100%");
//$("body").css("height", window.innerHeight + "px");
//$("body").css("width", window.innerWidth + "px");
//for (var i = 0; i < num; i++) {
// createItem(placeholder, "", new Date(), "-no-name-");
//}
};
// Add "on resize" event listener to the window
$(window).on("resize", onResizeWindow);
var TAGS = getParameterByName("TAGS") || "wild";
var COLLECTION_ID = getParameterByName("COLLECTION_ID") || "488182";
var NUM_ITEMS = getParameterByName("NUM_ITEMS") || 10;
var INTERVAL = getParameterByName("INTERVAL") || 3;
var API_KEY = getParameterByName("API_KEY");
var TITLE = getParameterByName("TITLE");
var LANG = getParameterByName("LANG") || "en";
var THEME_COLOR = getParameterByName("THEME_COLOR") || "";
moment.locale(LANG); // Use the current LANG as the moment locale
if (THEME_COLOR) {
switch (THEME_COLOR) {
case "green":
case "red":
case "dark":
case "variant-b":
case "variant-c":
$("body").addClass("theme-" + THEME_COLOR);
break;
}
}
// Use the current LANG as the preferred language of the commonly
// used texts
$("body").attr("data-lang", LANG);
/**
* Inits the Coin Slider slide show with the preferred options.
* Also triggers the resize event of the window
*/
initCoinSlider = function () {
$(window).trigger("resize");
//$("#games").css("zoom", document.documentElement.clientHeight / 270);
$('#games').coinslider({
hoverPause: false,
navigation: false,
opacity: 1.0, // opacity of title and navigation
delay: +INTERVAL * 1000,
sDelay: 50, // delay beetwen squares in ms
//delay: 3000 * 1000,
width: sliderWidth, //baseWidth, // width of slider panel
height: sliderHeight, //baseHeight, // height of slider panel
//spw: 7, // squares per width
//sph: 5, // squares per height
//width: document.documentElement.clientWidth,
//height: document.documentElement.clientHeight
});
}
/**
* Calls the Flicker API Service and creates a Coin Slider silde show
* from the data from Flickr.
*
* @param {string} API_KEY (optional) - The Flickr API Key to use with
* the Flickr API Service. If specified the "flickr.photos.search"
* API will be used instead of the Feed Service.
* Also only photos marked as "Commercial use allowed" will be
* included with the results.
*/
var createGallery = function(API_KEY) {
if (!!API_KEY) {
$.getJSON(baseUrl + "collections/" + COLLECTION_ID + "/photos", {
client_id: API_KEY,
per_page: NUM_ITEMS,
}, function (data) {
$("#header").text(TITLE || "");
if (data && data.length > 0) {
// If the API returned any photos, then loop through
// each one of them and add them to slide show gallery
$.each(data, function (i, item) {
console.log(item)
// Create a title from the "title" or fall back to
// the "id" wrapped inside "-" ("-{id}-")
var title = item.description || ("-" + item.id + "-");
var user = item.user.name + " (" + item.user.username + ")";
// Create and add the item to the slide show gallery
createItem(item.urls.regular, title, item.updated_at, user);
if (i == NUM_ITEMS || i + 1 == data.length) {
$("body").addClass("loaded");
// If the current index is the same as NUM_ITEMS
// _or_ we are at the last item, then initialize
// the slide show gallery and break out of the
// loop
initCoinSlider(); // Initialize slide show
return false; // Break out of the loop
}
});
} else {
$("#games").addClass("no-images");
$("body").addClass("loaded");
//createPlaceholderImages(NUM_ITEMS, LANG);
//setTimeout(createGallery, 30000);
//initCoinSlider();
}
}).fail(function() {
$("#games").addClass("no-images");
$("body").addClass("loaded");
});
} else {
$.getJSON(baseUrl + "feeds/photos_public.gne?jsoncallback=?", {
tags: TAGS || "wild",
tagmode: "all",
format: "json"
}, function (data) {
$("#header").text(TITLE || data.title);
if (data.items.length > 0) {
// If the API returned any photos, then loop through
// each one of them and add them to slide show gallery
$.each(data.items, function (i, item) {
console.log(item)
// Replace "_m." with "_b." to display large photos
var src = item.media.m.replace("_m.", "_b.");
// Create and add the item to the slide show gallery
createItem(src, item.title, item.date_taken, item.author);
if (i == NUM_ITEMS || i + 1 == data.items.length) {
$("body").addClass("loaded");
// If the current index is the same as NUM_ITEMS
// _or_ we are at the last item, then initialize
// the slide show gallery and break out of the
// loop
initCoinSlider(); // Initialize slide show
return false; // Break out of the loop
}
});
} else {
$("#games").addClass("no-images");
$("body").addClass("loaded");
//createPlaceholderImages(NUM_ITEMS, LANG);
//setTimeout(createGallery, 30000);
//initCoinSlider();
}
}).fail(function () {
$("#games").addClass("no-images");
$("body").addClass("loaded");
});
}
}
createGallery(API_KEY);
//$('#games').coinslider();
</script>
</body>
</html>